Skip to contentSkip to conversation

mm/page_alloc: only update NUMA min ratios on sysctl write

PATCH Applied Jianlin Shi 2 participants 4 messages Jun 4 – Jul 28

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/page_alloc: only update NUMA min ratios on sysctl write

The sysctl handlers for min_unmapped_ratio and min_slab_ratio invoke setup_min_unmapped_ratio() and setup_min_slab_ratio() unconditionally after proc_dointvec_minmax(), even for read operations.

These setup functions first zero all per-NUMA node thresholds (min_unmapped_pages and min_slab_pages) before recalculating them. Reading /proc sysctl entries therefore temporarily resets node reclaim thresholds to zero, which may disturb the behavior of __node_reclaim() and node_reclaim() during the recomputation.

Fix this by only calling the setup functions when the sysctl is actually written (write == 1), matching the behavior of existing sysctl handlers like min_free_kbytes and watermark_scale_factor.

This only affects systems with CONFIG_NUMA.

---
 mm/page_alloc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mm/page_alloc.c +4 -2
index 2d4b6f1a5..0387d2afd 100644
@@ -6636,7 +6636,8 @@ static int sysctl_min_unmapped_ratio_sysctl_handler(const struct ctl_table *tabl
 	if (rc)
 		return rc;
 
-	setup_min_unmapped_ratio();
+	if (write)
+		setup_min_unmapped_ratio();
 
 	return 0;
 }
@@ -6663,7 +6664,8 @@ static int sysctl_min_slab_ratio_sysctl_handler(const struct ctl_table *table, i
 	if (rc)
 		return rc;
 
-	setup_min_slab_ratio();
+	if (write)
+		setup_min_slab_ratio();
 
 	return 0;
 }
Signature · 1 line
2.43.0
#1 lore raw

Friendly ping.

Any further feedback on this patch?

Thanks,
Jianlin

maintainer
#2 lore raw
In reply to Jianlin Shi
Quoted 10 lines · On Thu, 4 Jun 2026 12:01:38 +0800 Jianlin Shi <[email protected]> wrote:

The sysctl handlers for min_unmapped_ratio and min_slab_ratio invoke setup_min_unmapped_ratio() and setup_min_slab_ratio() unconditionally after proc_dointvec_minmax(), even for read operations.

These setup functions first zero all per-NUMA node thresholds (min_unmapped_pages and min_slab_pages) before recalculating them. Reading /proc sysctl entries therefore temporarily resets node reclaim thresholds to zero, which may disturb the behavior of __node_reclaim() and node_reclaim() during the recomputation.

Quoted 5 lines

Fix this by only calling the setup functions when the sysctl is actually written (write == 1), matching the behavior of existing sysctl handlers like min_free_kbytes and watermark_scale_factor.

This only affects systems with CONFIG_NUMA.

AI review points out that lowmem_reserve_ratio_sysctl_handler() has the same issue:

	https://sashiko.dev/#/patchset/[email protected]

All these changes are non-backward-compatible userspace API changes. It's really lame and somewhat unlikely, but we should give consideration to this. Perhaps there are systems out there which are dependent on the side-effects of reads from these files. We should be careful about these things.

So I suggest that these changes be proposed as two or three standalone patches (independently revertible if problems are discovered) and that each one contains a description of the worst-case regressions which such oddball userspace might encounter.

#3 lore raw
Quoted 11 lines · On Mon, 27 Jul 2026 15:51:38 -0700 Andrew Morton wrote:

AI review points out that lowmem_reserve_ratio_sysctl_handler() has the same issue:

	https://sashiko.dev/#/patchset/[email protected]

All these changes are non-backward-compatible userspace API changes. It's really lame and somewhat unlikely, but we should give consideration to this. Perhaps there are systems out there which are dependent on the side-effects of reads from these files. We should be careful about these things.

Quoted 4 lines

So I suggest that these changes be proposed as two or three standalone patches (independently revertible if problems are discovered) and that each one contains a description of the worst-case regressions which such oddball userspace might encounter.

Hi Andrew,

Thank you for taking another look, and for the careful note about possible userspace relying on read side-effects. That is a fair point; I had not considered it.

I believe the NUMA min_unmapped_ratio / min_slab_ratio change may already be present as 874611d193f2 ("mm/page_alloc: only update NUMA min ratios on sysctl write"). If I have that right, I will not resend that part.

I will send only the remaining lowmem_reserve_ratio fix as a standalone patch, with a worst-case userspace note as you suggested. Please let me know if I misunderstood the tree state.

Thanks,
Jianlin