Skip to content

Commit 5dcc6a4

Browse files
committed
mm/mempolicy: Ignore runtime policy changes when set through cmdline
Some apps like linpack use numa_setpolicy to disable numa, but that tends to have a significant performance hit for us. If you have a cmdline.txt setting of numa_policy (to something other than default), then lets ignore runtime changes and stick with the cmdline.txt setting. Not specifying numa_setpolicy in cmdline, or setting numa_setpolicy=default(*) will allow runtime settings to work. (*) easier to do when numa_setpolicy=interleave is set in DT. Ignore logging for the first 40 seconds as there are some expected switches during boot. Signed-off-by: Dom Cobley <[email protected]>
1 parent 8d53a07 commit 5dcc6a4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

mm/mempolicy.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#include <linux/highmem.h>
8686
#include <linux/hugetlb.h>
8787
#include <linux/kernel.h>
88+
#include <linux/ktime.h>
8889
#include <linux/sched.h>
8990
#include <linux/sched/mm.h>
9091
#include <linux/sched/numa_balancing.h>
@@ -138,6 +139,7 @@ static struct mempolicy default_policy = {
138139
.refcnt = ATOMIC_INIT(1), /* never free it */
139140
.mode = MPOL_LOCAL,
140141
};
142+
static bool mempolicy_cmdline_set;
141143

142144
static struct mempolicy preferred_node_policy[MAX_NUMNODES];
143145

@@ -1629,6 +1631,15 @@ static long kernel_set_mempolicy(int mode, const unsigned long __user *nmask,
16291631
int err;
16301632

16311633
err = sanitize_mpol_flags(&lmode, &mode_flags);
1634+
1635+
if (mempolicy_cmdline_set) {
1636+
time64_t seconds_since_boot = ktime_get_boottime_seconds();
1637+
if (seconds_since_boot > 40)
1638+
pr_info("Request to set policy ignored (mode:%x lmode:%x flags:%x err:%d)\n",
1639+
mode, lmode, mode_flags, err);
1640+
return 0;
1641+
}
1642+
16321643
if (err)
16331644
return err;
16341645

@@ -3402,6 +3413,7 @@ static int __init setup_numapolicy(char *str)
34023413
default_policy = pol;
34033414
mpol_to_str(buf, sizeof(buf), &pol);
34043415
pr_info("NUMA default policy overridden to '%s'\n", buf);
3416+
mempolicy_cmdline_set = pol.mode != MPOL_DEFAULT;
34053417
} else {
34063418
pr_warn("Unable to parse numa_policy=\n");
34073419
}

0 commit comments

Comments
 (0)