Re: [PATCH 1/2] mm: huge_memory: use sysfs_match_string() in defrag_store()

From: David Hildenbrand (Arm)

Date: Thu Apr 02 2026 - 04:26:04 EST


On 3/20/26 17: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>
> ---
> mm/huge_memory.c | 60 ++++++++++++++++++++++++++++++++------------------------
> 1 file changed, 34 insertions(+), 26 deletions(-)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 3fc02913b63e3..4843e2154038f 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -421,6 +421,29 @@ ssize_t single_hugepage_flag_store(struct kobject *kobj,
> return count;
> }
>
> +enum defrag_mode {
> + DEFRAG_ALWAYS = 0,
> + DEFRAG_DEFER = 1,
> + DEFRAG_DEFER_MADVISE = 2,
> + DEFRAG_MADVISE = 3,
> + DEFRAG_NEVER = 4,
> +};

These numbers should get assigned as default (C standard) I think, and
can be dropped.



Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

--
Cheers,

David