Re: [PATCH v3 1/2] mm: shmem: refactor thpsize_shmem_enabled_store() with sysfs_match_string()

From: Barry Song

Date: Fri May 22 2026 - 04:08:48 EST


On Mon, May 18, 2026 at 8:33 PM <ranxiaokai627@xxxxxxx> wrote:
>
> From: Ran Xiaokai <ran.xiaokai@xxxxxxxxxx>
>
> Inspired by commit 82d9ff648c6c ("mm: huge_memory: refactor
> anon_enabled_store() with set_anon_enabled_mode()"), refactor
> thpsize_shmem_enabled_store() using sysfs_match_string().
> This eliminates the duplicated spin_lock/unlock(), set/clear_bit(),
> calls across all branches, reducing code duplication.
>
> Behavioral change:
> Call start_stop_khugepaged() only when the mode actually changes.
> If unchanged, call set_recommended_min_free_kbytes() to preserve
> legacy watermark behavior. This avoids unnecessary khugepaged restarts.
>
> Tested with selftests ./run_kselftest.sh -t mm:ksft_thp.sh,
> all test cases passed.
>
> Signed-off-by: Ran Xiaokai <ran.xiaokai@xxxxxxxxxx>

Reviewed-by: Barry Song <baohua@xxxxxxxxxx>