[RFC PATCH 11/12] mm/cma: rebalance CMA when changing cma_first_limit

Frank van der Linden posted 12 patches 2 weeks, 2 days ago
[RFC PATCH 11/12] mm/cma: rebalance CMA when changing cma_first_limit
Posted by Frank van der Linden 2 weeks, 2 days ago
To keep things consistent, rebalance CMA when changing the
cma_first_limit sysctl.

Signed-off-by: Frank van der Linden <fvdl@google.com>
---
 mm/page_alloc.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index dc59aaa63ae6..da1cab63995c 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -6640,6 +6640,24 @@ static int percpu_pagelist_high_fraction_sysctl_handler(const struct ctl_table *
 	return ret;
 }
 
+#ifdef CONFIG_CMA
+static int cma_first_limit_sysctl_handler(const struct ctl_table *table,
+				int write, void *buffer, size_t *length,
+				loff_t *ppos)
+{
+	int ret, nid;
+
+	ret = proc_dointvec_minmax(table, write, buffer, length, ppos);
+	if (ret || !write)
+		return ret;
+
+	for_each_node_state(nid, N_MEMORY)
+		balance_node_cma(nid, NULL);
+
+	return 0;
+}
+#endif
+
 static const struct ctl_table page_alloc_sysctl_table[] = {
 	{
 		.procname	= "min_free_kbytes",
@@ -6723,7 +6741,7 @@ static const struct ctl_table page_alloc_sysctl_table[] = {
 		.data		= &cma_first_limit,
 		.maxlen		= sizeof(cma_first_limit),
 		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
+		.proc_handler	= cma_first_limit_sysctl_handler,
 		.extra1		= SYSCTL_ZERO,
 		.extra2		= SYSCTL_ONE_HUNDRED,
 	},
-- 
2.51.0.384.g4c02a37b29-goog
Re: [RFC PATCH 11/12] mm/cma: rebalance CMA when changing cma_first_limit
Posted by Rik van Riel 2 weeks ago
On Mon, 2025-09-15 at 19:51 +0000, Frank van der Linden wrote:
> To keep things consistent, rebalance CMA when changing the
> cma_first_limit sysctl.
> 
> Signed-off-by: Frank van der Linden <fvdl@google.com>
> 
Reviewed-by: Rik van Riel <riel@surriel.com>


-- 
All Rights Reversed.