Re: [PATCH 1/2] mm: huge_memory: use sysfs_match_string() in defrag_store()
From: Barry Song
Date: Fri Apr 03 2026 - 02:47:15 EST
On Sat, Mar 21, 2026 at 12:06 AM Breno Leitao <leitao@xxxxxxxxxx> 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>
> ---
LGTM,
Reviewed-by: Barry Song <baohua@xxxxxxxxxx>