Re: [PATCH 1/2] mm: huge_memory: use sysfs_match_string() in defrag_store()
From: Lance Yang
Date: Fri Apr 03 2026 - 01:09:30 EST
On 2026/3/21 00:05, Breno Leitao wrote:
Replace the if/else chain of sysfs_streq() calls in defrag_store()
with sysfs_match_string() and a defrag_mode_strings[] table.
Introduce enum defrag_mode and defrag_flags[] array mapping each mode
to its corresponding transparent_hugepage_flag. The store function now
loops over defrag_flags[], setting the bit for the selected mode and
clearing the others. When mode is DEFRAG_NEVER (index 4), no index
in the 4-element defrag_flags[] matches, so all flags are cleared.
Note that the enum ordering (always, defer, defer+madvise, madvise,
never) differs from the original if/else chain order in defrag_store()
(always, defer+madvise, defer, madvise, never). This is intentional to
match the display order used by defrag_show().
This is a follow-up cleanup to commit 522dfb4ba71f ("mm: huge_memory:
refactor anon_enabled_store() with change_anon_orders()") which applied
the same sysfs_match_string() pattern to anon_enabled_store().
Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
---
Thanks.
Tested-by: Lance Yang <lance.yang@xxxxxxxxx>
With David's comments addressed, feel free to add:
Reviewed-by: Lance Yang <lance.yang@xxxxxxxxx>
Cheers,
Lance