Re: [PATCH] mm/khugepaged: cap min_free_kbytes recommendation at 1 GiB
From: Nimrod Oren
Date: Tue Aug 04 2026 - 03:40:40 EST
On 29/07/2026 3:17, Andrew Morton wrote:
> On Tue, 28 Jul 2026 23:20:14 +0300 Nimrod Oren <noren@xxxxxxxxxx> wrote:
>> Add an absolute 1 GiB cap to the recommendation, in addition to the
>> existing percentage cap. This bounds the automatic recommendation to a
>> sane value on systems with large pageblocks while preserving existing
>> behavior for typical systems with 2 MiB pageblocks.
>
> Another hard-coded number isn't pretty :(
The 1 GiB value follows the RFC discussion.
Would a dedicated constant (e.g. THP_MIN_FREE_MAX_PAGES) make it better?
Would using a new sysctl be preferable?
>> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
>> index 27e8f3077e80..d9caf10e05b5 100644
>> --- a/mm/khugepaged.c
>> +++ b/mm/khugepaged.c
>> @@ -23,6 +23,7 @@
>> #include <linux/ksm.h>
>> #include <linux/pgalloc.h>
>> #include <linux/backing-dev.h>
>> +#include <linux/sizes.h>
>
> Why this?
For SZ_1G. It's already included transitively, so I'll drop it in the
next revision.
>> #include <asm/tlb.h>
>> #include "internal.h"
>> @@ -3096,9 +3097,13 @@ void set_recommended_min_free_kbytes(void)
>> recommended_min += pageblock_nr_pages * nr_zones *
>> MIGRATE_PCPTYPES * MIGRATE_PCPTYPES;
>>
>> - /* don't ever allow to reserve more than 5% of the lowmem */
>> + /*
>> + * Don't ever allow to reserve more than 5% of lowmem or 1 GiB,
>> + * whichever is smaller.
>> + */
>> recommended_min = min(recommended_min,
>> (unsigned long) nr_free_buffer_pages() / 20);
>> + recommended_min = min(recommended_min, SZ_1G / PAGE_SIZE);
>> recommended_min <<= (PAGE_SHIFT-10);
>>
>> if (recommended_min > min_free_kbytes) {
>
> Is a min_free_kbytes documentation update needed?
> Documentation/admin-guide/sysctl/vm.rst.
I can document THP's automatic recommendation there in the next
revision, along with whichever capping mechanism we decide on.
Thanks for the review!