Re: [PATCH v2 0/3] mm: thp: reduce unnecessary start_stop_khugepaged() calls

From: Breno Leitao

Date: Fri Mar 06 2026 - 05:31:23 EST


On Fri, Mar 06, 2026 at 02:14:31PM +0800, Baolin Wang wrote:
>
>
> On 3/5/26 10:04 PM, Breno Leitao wrote:
> > Writing to /sys/kernel/mm/transparent_hugepage/enabled causes
> > start_stop_khugepaged() called independent of any change.
> > start_stop_khugepaged() SPAMs the printk ring buffer overflow with the
> > exact same message, even when nothing changes.
> >
> > For instance, if you have a custom vm.min_free_kbytes, just touching
> > /sys/kernel/mm/transparent_hugepage/enabled causes a printk message.
> > Example:
> >
> > # sysctl -w vm.min_free_kbytes=112382
> > # for i in $(seq 100); do echo never > /sys/kernel/mm/transparent_hugepage/enabled ; done
> >
> > and you have 100 WARN messages like the following, which is pretty dull:
> >
> > khugepaged: min_free_kbytes is not updated to 112381 because user defined value 112382 is preferred
> >
> > A similar message shows up when setting thp to "always":
> >
> > # for i in $(seq 100); do
> > # echo 1024 > /proc/sys/vm/min_free_kbytes
> > # echo always > /sys/kernel/mm/transparent_hugepage/enabled
> > # done
> >
> > And then, we have 100 messages like:
> >
> > khugepaged: raising min_free_kbytes from 1024 to 67584 to help transparent hugepage allocations
> >
> > This is more common when you have a configuration management system that
> > writes the THP configuration without an extra read, assuming that
> > nothing will happen if there is no change in the configuration, but it
> > prints these annoying messages.
> >
> > For instance, at Meta's fleet, ~10K servers were producing 3.5M of
> > these messages per day.
> >
> > Fix this by making the sysfs _store helpers a no-op if there is no state
> > change.
> >
> > This version is heavily based on Lorezo's suggestion on V1.
>
> Thanks for doing this. And you should also consider the shmem parts:
> shmem_enabled_store() and thpsize_shmem_enabled_store(), both of which will
> also call start_stop_khugepaged().
>
> That means you can also generate lots of messages with the following script.
>
> # for i in $(seq 100); do
> # echo 1024 > /proc/sys/vm/min_free_kbytes
> # echo always > /sys/kernel/mm/transparent_hugepage/shmem_enabled
> # done

Thanks for the input, I will include it in the fixes also.


--breno