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 <popcornmix@gmail.com>

Show process name in set_mempolicy() ignored message

Signed-off-by: Trevor Man <tman_github@trejan.com>
This commit is contained in:
Dom Cobley
2025-02-05 12:08:46 +00:00
parent 3a32ad19d9
commit 1e35dabbe0

View File

@@ -85,6 +85,7 @@
#include <linux/highmem.h>
#include <linux/hugetlb.h>
#include <linux/kernel.h>
#include <linux/ktime.h>
#include <linux/sched.h>
#include <linux/sched/mm.h>
#include <linux/sched/numa_balancing.h>
@@ -140,6 +141,7 @@ static struct mempolicy default_policy = {
.refcnt = ATOMIC_INIT(1), /* never free it */
.mode = MPOL_LOCAL,
};
static bool mempolicy_cmdline_set;
static struct mempolicy preferred_node_policy[MAX_NUMNODES];
@@ -1768,12 +1770,21 @@ SYSCALL_DEFINE6(mbind, unsigned long, start, unsigned long, len,
static long kernel_set_mempolicy(int mode, const unsigned long __user *nmask,
unsigned long maxnode)
{
char name[sizeof(current->comm)];
unsigned short mode_flags;
nodemask_t nodes;
int lmode = mode;
int err;
err = sanitize_mpol_flags(&lmode, &mode_flags);
if (mempolicy_cmdline_set) {
// ignore messages during boot which are expected
if (ktime_get_boottime_seconds() > 40)
pr_info("Request by '%s' to set policy to %d ignored\n", get_task_comm(name, current), mode);
return 0;
}
if (err)
return err;
@@ -3566,6 +3577,7 @@ static int __init setup_numapolicy(char *str)
default_policy = pol;
mpol_to_str(buf, sizeof(buf), &pol);
pr_info("NUMA default policy overridden to '%s'\n", buf);
mempolicy_cmdline_set = pol.mode != MPOL_DEFAULT;
} else {
pr_warn("Unable to parse numa_policy=\n");
}