Re: [PATCH v3] mm: remove min_free_kbytes adjustment for THP

From: Zi Yan

Date: Tue Sep 08 2026 - 08:24:59 EST


On Tue Sep 8, 2026 at 7:54 AM EDT, Vlastimil Babka (SUSE) wrote:
> On 9/1/26 21:01, Nimrod Oren wrote:
>> When THP is enabled, set_recommended_min_free_kbytes() may raise
>> min_free_kbytes using a heuristic that scales with pageblock_nr_pages.
>> Commit f000565adb77 ("thp: set recommended min free kbytes") added this
>> heuristic to help keep pageblocks free and reduce fragmentation for THP
>> allocations.
>>
>> The recommendation scales poorly with larger base page sizes. With the
>> default arm64 pageblock sizes, the contribution per eligible zone
>> before applying the existing cap of 5% of low memory is:
>>
>> 4 KiB pages: 2 MiB pageblock, 22 MiB per zone
>> 16 KiB pages: 32 MiB pageblock, 352 MiB per zone
>> 64 KiB pages: 512 MiB pageblock, 5.5 GiB per zone
>>
>> Even with that cap, min_free_kbytes can reach excessive levels.
>>
>> The automatic min_free_kbytes increase predates proactive compaction
>> and many subsequent changes to compaction. Given those changes,
>> increasing min_free_kbytes for THP by default is no longer clearly
>> justified.
>>
>> Remove set_recommended_min_free_kbytes() and all associated
>> recalculation paths. With this policy gone, min_free_kbytes is
>> controlled only by the page allocator's default calculation and the
>> vm.min_free_kbytes sysctl. Users who want additional headroom may set a
>> higher value via that sysctl.
>>
>> Link: https://lore.kernel.org/r/20260831075635.2244437-1-noren@xxxxxxxxxx/
>> Suggested-by: Michal Hocko <mhocko@xxxxxxxx>
>> Signed-off-by: Nimrod Oren <noren@xxxxxxxxxx>
>> ---
>> v3:
>> * Replace the 1 GiB cap with removal of the THP-driven min_free_kbytes
>> increase as suggested by Michal.
>> * Remove all associated recalculation paths.
>> * Make min_free_kbytes, user_min_free_kbytes,
>> calculate_min_free_kbytes(), and setup_per_zone_wmarks() static.
>> * Drop the now-unused declarations and khugepaged's page_alloc.h include.
>> * Drop the obsolete v2 documentation addition.
>>
>> v2:
>> * Use a named constant for the cap.
>> * Drop explicit linux/sizes.h include.
>> * Update min_free_kbytes documentation.
>> https://lore.kernel.org/r/20260831075635.2244437-1-noren@xxxxxxxxxx/
>>
>> v1:
>> * Cap the final recommendation at 1 GiB as suggested by Lorenzo.
>> https://lore.kernel.org/r/20260728202014.2517142-1-noren@xxxxxxxxxx/
>>
>> RFC v1:
>> https://lore.kernel.org/r/20260716173504.760369-1-noren@xxxxxxxxxx/
>> ---
>> include/linux/khugepaged.h | 5 ----
>> mm/huge_memory.c | 14 ---------
>> mm/internal.h | 8 -----
>> mm/khugepaged.c | 60 --------------------------------------
>> mm/page_alloc.c | 11 +++----
>> mm/page_alloc.h | 2 --
>> mm/shmem.c | 7 -----
>> 7 files changed, 4 insertions(+), 103 deletions(-)
>
> Given neither of the patchset versions achieved universal acceptance, could
> we try just disabling all the automatic (re)calculations of min_free_kbytes
> the first moment the sysctl gets adjusted from userspace?

Sounds good to me. Johannes, WDYT?

--
Best Regards,
Yan, Zi