[PATCH v4 0/2] mm/hugetlb: refactor sysfs/sysctl interfaces

Hui Zhu posted 2 patches 1 month, 2 weeks ago
There is a newer version of this series
MAINTAINERS           |   2 +
mm/Makefile           |   2 +-
mm/hugetlb.c          | 852 +-----------------------------------------
mm/hugetlb_internal.h | 114 ++++++
mm/hugetlb_sysctl.c   | 134 +++++++
mm/hugetlb_sysfs.c    | 630 +++++++++++++++++++++++++++++++
6 files changed, 890 insertions(+), 844 deletions(-)
create mode 100644 mm/hugetlb_internal.h
create mode 100644 mm/hugetlb_sysctl.c
create mode 100644 mm/hugetlb_sysfs.c
[PATCH v4 0/2] mm/hugetlb: refactor sysfs/sysctl interfaces
Posted by Hui Zhu 1 month, 2 weeks ago
From: Hui Zhu <zhuhui@kylinos.cn>

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:
v4:
According to the comments of David Hildenbrand, add copyright of
hugetlb.c to hugetlb_internal.h, hugetlb_sysctl.c and hugetlb_sysfs.c.
v3:
According to the comments of SeongJae Park, updated MAINTAINERS to
add new files.
Removed the wrong copyright in hugetlb_internal.h.
v2:
According to the comments of David Hildenbrand, removed the wrong
copyright in the file headers.

Hui Zhu (2):
  mm/hugetlb: extract sysfs into hugetlb_sysfs.c
  mm/hugetlb: extract sysctl into hugetlb_sysctl.c

 MAINTAINERS           |   2 +
 mm/Makefile           |   2 +-
 mm/hugetlb.c          | 852 +-----------------------------------------
 mm/hugetlb_internal.h | 114 ++++++
 mm/hugetlb_sysctl.c   | 134 +++++++
 mm/hugetlb_sysfs.c    | 630 +++++++++++++++++++++++++++++++
 6 files changed, 890 insertions(+), 844 deletions(-)
 create mode 100644 mm/hugetlb_internal.h
 create mode 100644 mm/hugetlb_sysctl.c
 create mode 100644 mm/hugetlb_sysfs.c

-- 
2.43.0
Re: [PATCH v4 0/2] mm/hugetlb: refactor sysfs/sysctl interfaces
Posted by Oscar Salvador 1 month, 1 week ago
On Wed, Nov 05, 2025 at 10:42:42AM +0800, Hui Zhu wrote:
> From: Hui Zhu <zhuhui@kylinos.cn>
> 
> 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:
> v4:
> According to the comments of David Hildenbrand, add copyright of
> hugetlb.c to hugetlb_internal.h, hugetlb_sysctl.c and hugetlb_sysfs.c.
> v3:
> According to the comments of SeongJae Park, updated MAINTAINERS to
> add new files.
> Removed the wrong copyright in hugetlb_internal.h.
> v2:
> According to the comments of David Hildenbrand, removed the wrong
> copyright in the file headers.
> 
> Hui Zhu (2):
>   mm/hugetlb: extract sysfs into hugetlb_sysfs.c
>   mm/hugetlb: extract sysctl into hugetlb_sysctl.c

I am replying here as a response to https://lore.kernel.org/linux-mm/58d3c50f-2b4a-4053-a846-613434d5bcd9@redhat.com/T/#mf694af3f5a6ca56b76adf66352cbb88d022fe36c

So, taking a look at patch#1 as an example,which moves sysfs stuff into hugetlb_sysfs.c.
I have the feeling we are moving too much stuff. It is true that drawing a line
is not easy, but e.g: you mention

The following components are moved to mm/hugetlb_sysfs.c:
- hugetlb page demote functions (demote_free_hugetlb_folios,
  demote_pool_huge_page)

I __think__ that moving demote_store() into hugetlb_sysfs.c is fine, but although
demote_pool_huge_page and demote_free_hugetlb_folios are only called from there,
they look more than a sysfs interface and more like hugetlb generic code.

Again, drawing a like might be difficult, but I think that e.g: we should only move
sysfs entry points functions into hugetlb_sysfs.c

Does that make sense?
 

-- 
Oscar Salvador
SUSE Labs
Re: [PATCH v4 0/2] mm/hugetlb: refactor sysfs/sysctl interfaces
Posted by David Hildenbrand 1 month, 1 week ago
On 05.11.25 15:16, Oscar Salvador wrote:
> On Wed, Nov 05, 2025 at 10:42:42AM +0800, Hui Zhu wrote:
>> From: Hui Zhu <zhuhui@kylinos.cn>
>>
>> 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:
>> v4:
>> According to the comments of David Hildenbrand, add copyright of
>> hugetlb.c to hugetlb_internal.h, hugetlb_sysctl.c and hugetlb_sysfs.c.
>> v3:
>> According to the comments of SeongJae Park, updated MAINTAINERS to
>> add new files.
>> Removed the wrong copyright in hugetlb_internal.h.
>> v2:
>> According to the comments of David Hildenbrand, removed the wrong
>> copyright in the file headers.
>>
>> Hui Zhu (2):
>>    mm/hugetlb: extract sysfs into hugetlb_sysfs.c
>>    mm/hugetlb: extract sysctl into hugetlb_sysctl.c
> 
> I am replying here as a response to https://lore.kernel.org/linux-mm/58d3c50f-2b4a-4053-a846-613434d5bcd9@redhat.com/T/#mf694af3f5a6ca56b76adf66352cbb88d022fe36c
> 
> So, taking a look at patch#1 as an example,which moves sysfs stuff into hugetlb_sysfs.c.
> I have the feeling we are moving too much stuff. It is true that drawing a line
> is not easy, but e.g: you mention
> 
> The following components are moved to mm/hugetlb_sysfs.c:
> - hugetlb page demote functions (demote_free_hugetlb_folios,
>    demote_pool_huge_page)
> 
> I __think__ that moving demote_store() into hugetlb_sysfs.c is fine, but although
> demote_pool_huge_page and demote_free_hugetlb_folios are only called from there,
> they look more than a sysfs interface and more like hugetlb generic code.
> 
> Again, drawing a like might be difficult, but I think that e.g: we should only move
> sysfs entry points functions into hugetlb_sysfs.c

That matches my comments from [1], right?


[1] 
https://lore.kernel.org/linux-mm/58d3c50f-2b4a-4053-a846-613434d5bcd9@redhat.com/T/#mda7f5c2ea07233857af094367b573475011bf0d4

-- 
Cheers

David