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

From: Lance Yang

Date: Thu May 21 2026 - 09:40:08 EST




On 2026/5/18 20:32, 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>
---

Thanks.

Tested-by: Lance Yang <lance.yang@xxxxxxxxx>