mm/hugetlb: refactor sysfs/sysctl interfaces
Subsystems (2)
v2 cover mm/hugetlb: refactor sysfs/sysctl interfaces
From: Hui Zhu <[email protected]>
The hugetlb.c file has grown significantly and become difficult to maintain. This patch series extracts the sysfs and sysctl interface code into separate dedicated files to improve code organization.
The refactoring includes:
- Patch 1: Extract sysfs interface into mm/hugetlb_sysfs.c
- Patch 2: Extract sysctl interface into mm/hugetlb_sysctl.c
No functional changes are introduced in this series. The code is moved as-is, with only minor formatting adjustments for code style consistency. This should make future maintenance and enhancements to the hugetlb subsystem easier.
Testing: The patch series has been compile-tested and maintains the same functionality as the original code.
Changelog:
v2:
According to the comments of David, remove the wrong copyright in the file headers.
Geliang Tang (1):
mm/hugetlb: extract sysfs into hugetlb_sysfs.c
Hui Zhu (1):
mm/hugetlb: extract sysctl into hugetlb_sysctl.c
mm/Makefile | 2 +- mm/hugetlb.c | 852 +----------------------------------------- mm/hugetlb_internal.h | 116 ++++++ mm/hugetlb_sysctl.c | 133 +++++++ mm/hugetlb_sysfs.c | 629 +++++++++++++++++++++++++++++++ 5 files changed, 888 insertions(+), 844 deletions(-) create mode 100644 mm/hugetlb_internal.h create mode 100644 mm/hugetlb_sysctl.c create mode 100644 mm/hugetlb_sysfs.c
Signature · 1 line
2.43.0
PATCH v2 1/2 mm/hugetlb: extract sysfs into hugetlb_sysfs.c
From: Geliang Tang <[email protected]>
Currently, hugetlb.c contains both core management logic and sysfs interface implementations, making it difficult to maintain. This patch extracts the sysfs-related code into a dedicated file to improve code organization.
The following components are moved to mm/hugetlb_sysfs.c:
- hugetlb page demote functions (demote_free_hugetlb_folios, demote_pool_huge_page)
- sysfs attribute definitions and handlers
- sysfs kobject management functions
- NUMA per-node hstate attribute registration
Several inline helper functions and macros are moved to mm/hugetlb_internal.h:
- hstate_is_gigantic_no_runtime()
- next_node_allowed()
- get_valid_node_allowed()
- hstate_next_node_to_alloc()
- hstate_next_node_to_free()
- for_each_node_mask_to_alloc/to_free macros
To support code sharing, these functions are changed from static to exported symbols:
- remove_hugetlb_folio()
- add_hugetlb_folio()
- init_new_hugetlb_folio()
- prep_and_add_allocated_folios()
- __nr_hugepages_store_common()
The Makefile is updated to compile hugetlb_sysfs.o when CONFIG_HUGETLBFS is enabled. This maintains all existing functionality while improving maintainability by separating concerns.
--- mm/Makefile | 2 +- mm/hugetlb.c | 720 +----------------------------------------- mm/hugetlb_internal.h | 110 +++++++ mm/hugetlb_sysfs.c | 629 ++++++++++++++++++++++++++++++++++++ 4 files changed, 749 insertions(+), 712 deletions(-) create mode 100644 mm/hugetlb_internal.h create mode 100644 mm/hugetlb_sysfs.c
mm/Makefile +1 -1
@@ -78,7 +78,7 @@ endif obj-$(CONFIG_SWAP) += page_io.o swap_state.o swapfile.o obj-$(CONFIG_ZSWAP) += zswap.o obj-$(CONFIG_HAS_DMA) += dmapool.o -obj-$(CONFIG_HUGETLBFS) += hugetlb.o +obj-$(CONFIG_HUGETLBFS) += hugetlb.o hugetlb_sysfs.o ifdef CONFIG_CMA obj-$(CONFIG_HUGETLBFS) += hugetlb_cma.o endif
mm/hugetlb.c +9 -711
785 lines not on this page · raw message
mm/hugetlb_internal.h new file +110 -0
110 lines not on this page · raw message
mm/hugetlb_sysfs.c new file +629 -0
629 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 2/2 mm/hugetlb: extract sysctl into hugetlb_sysctl.c
In reply to Hui ZhuFrom: Hui Zhu <[email protected]>
Following the extraction of sysfs code, this patch moves the sysctl interface implementation into a dedicated file to further improve code organization and maintainability of the hugetlb subsystem.
The following components are moved to mm/hugetlb_sysctl.c:
- proc_hugetlb_doulongvec_minmax()
- hugetlb_sysctl_handler_common()
- hugetlb_sysctl_handler()
- hugetlb_mempolicy_sysctl_handler() (CONFIG_NUMA)
- hugetlb_overcommit_handler()
- hugetlb_table[] sysctl table definition
- hugetlb_sysctl_init()
The hugetlb_internal.h header file is updated to declare the sysctl initialization function with proper #ifdef guards for configurations without CONFIG_SYSCTL support.
The Makefile is updated to compile hugetlb_sysctl.o when CONFIG_HUGETLBFS is enabled. This refactoring reduces the size of hugetlb.c and logically separates the sysctl interface from core hugetlb management code.
No functional changes are introduced; all code is moved as-is from hugetlb.c with consistent formatting.
--- mm/Makefile | 2 +- mm/hugetlb.c | 132 ----------------------------------------- mm/hugetlb_internal.h | 6 ++ mm/hugetlb_sysctl.c | 133 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+), 133 deletions(-) create mode 100644 mm/hugetlb_sysctl.c
mm/Makefile +1 -1
@@ -78,7 +78,7 @@ endif obj-$(CONFIG_SWAP) += page_io.o swap_state.o swapfile.o obj-$(CONFIG_ZSWAP) += zswap.o obj-$(CONFIG_HAS_DMA) += dmapool.o -obj-$(CONFIG_HUGETLBFS) += hugetlb.o hugetlb_sysfs.o +obj-$(CONFIG_HUGETLBFS) += hugetlb.o hugetlb_sysfs.o hugetlb_sysctl.o ifdef CONFIG_CMA obj-$(CONFIG_HUGETLBFS) += hugetlb_cma.o endif
mm/hugetlb.c +0 -132
150 lines not on this page · raw message
mm/hugetlb_internal.h +6 -0
@@ -107,4 +107,10 @@ extern ssize_t __nr_hugepages_store_common(bool obey_mempolicy,extern void hugetlb_sysfs_init (void )__init ; +#ifdef CONFIG_SYSCTL +extern void hugetlb_sysctl_init (void ); +#else +static inline void hugetlb_sysctl_init (void ) { } +#endif +#endif /* _LINUX_HUGETLB_INTERNAL_H */
mm/hugetlb_sysctl.c new file +133 -0
133 lines not on this page · raw message
Signature · 1 line
2.43.0