]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm/page_alloc: make percpu_pagelist_high_fraction reads lock-free
authorAboorva Devarajan <aboorvad@linux.ibm.com>
Mon, 1 Dec 2025 06:00:09 +0000 (11:30 +0530)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 15 Jan 2026 06:16:21 +0000 (22:16 -0800)
When page isolation loops indefinitely during memory offline, reading
/proc/sys/vm/percpu_pagelist_high_fraction blocks on pcp_batch_high_lock,
causing hung task warnings.

Make procfs reads lock-free since percpu_pagelist_high_fraction is a
simple integer with naturally atomic reads, writers still serialize via
the mutex.

This prevents hung task warnings when reading the procfs file during
long-running memory offline operations.

[akpm@linux-foundation.org: add comment, per Michal]
Link: https://lkml.kernel.org/r/aS_y9AuJQFydLEXo@tiehlicka
Link: https://lkml.kernel.org/r/20251201060009.1420792-1-aboorvad@linux.ibm.com
Signed-off-by: Aboorva Devarajan <aboorvad@linux.ibm.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Brendan Jackman <jackmanb@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Zi Yan <ziy@nvidia.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/page_alloc.c

index c380f063e8b7bd383186479fc8c2b7a51243278d..3dce96f3be494c0c5e0971a942334ac78f5037f9 100644 (file)
@@ -6667,11 +6667,19 @@ static int percpu_pagelist_high_fraction_sysctl_handler(const struct ctl_table *
        int old_percpu_pagelist_high_fraction;
        int ret;
 
+       /*
+        * Avoid using pcp_batch_high_lock for reads as the value is read
+        * atomically and a race with offlining is harmless.
+        */
+
+       if (!write)
+               return proc_dointvec_minmax(table, write, buffer, length, ppos);
+
        mutex_lock(&pcp_batch_high_lock);
        old_percpu_pagelist_high_fraction = percpu_pagelist_high_fraction;
 
        ret = proc_dointvec_minmax(table, write, buffer, length, ppos);
-       if (!write || ret < 0)
+       if (ret < 0)
                goto out;
 
        /* Sanity checking to avoid pcp imbalance */