Re: [PATCH v7 2/4] mm: huge_memory: refactor anon_enabled_store() with set_anon_enabled_mode()
From: David Hildenbrand (Arm)
Date: Mon Mar 23 2026 - 05:11:21 EST
On 3/17/26 16:33, Breno Leitao wrote:
> Consolidate the repeated spin_lock/set_bit/clear_bit pattern in
> anon_enabled_store() into a new set_anon_enabled_mode() helper that
> loops over an orders[] array, setting the bit for the selected mode
> and clearing the others.
>
> Introduce enum anon_enabled_mode and anon_enabled_mode_strings[]
> for the per-order anon THP setting.
>
> Use sysfs_match_string() with the anon_enabled_mode_strings[] table
> to replace the if/else chain of sysfs_streq() calls.
>
> The helper uses __test_and_set_bit()/__test_and_clear_bit() to track
> whether the state actually changed, so start_stop_khugepaged() is only
> called when needed. When the mode is unchanged,
> set_recommended_min_free_kbytes() is called directly to preserve the
> watermark recalculation behavior of the original code.
>
> Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
> Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@xxxxxxxxxx>
> ---
Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
--
Cheers,
David