Re: [PATCH] mm: mempolicy: fix automatic numa balancing for shmem
From: Gregory Price
Date: Thu Jul 23 2026 - 13:53:05 EST
On Thu, Jul 23, 2026 at 01:07:04PM -0400, Johannes Weiner wrote:
> On Thu, Jul 23, 2026 at 11:58:27AM -0400, Gregory Price wrote:
> >
> > I lean towards Johannes' stance here that consistency is better, and if
> > KVM has a known-poor interaction with numa balancing, maybe KVM should
> > simply set a default policy (when none are present) to avoid this.
> >
> > That said, this is painful because MPOL_F_MOF / MPOL_F_MORON are already
> > a silently inherited policy on boot (added during init). This will be
> > confusing for users.
> >
> > This is not documented anywhere. Maybe this change should come with a
> > docs addition that says the default global policy is ACTUALLY:
> >
> > MPOL_LOCAL + (MPOL_F_MOF | MPOL_F_MORON)
> >
> > Instead of just MPOL_LOCAL and letting that silent implementation
> > detail bite people.
>
> Hm, where do you see "Instead of just MPOL_LOCAL"?
>
MPOL_LOCAL is effectively the default, that's what most people expect.
> Documentation/filesystems/tmpfs.rst says it defaults to "default" and
> points me to set_mempolicy(2). That in turn in general makes little
> mention of numa balancing and doesn't mention MPOL_F_MOF/MPOL_F_MORON.
> In fact these are documented as internal flags.
>
They're "internal" and generated by passing MPOL_F_NUMA_BALANCING...
which is basically shorthand for "use (F_MOF | F_MORON)". There is
no other user of MPOL_F_NUMA_BALANCING.
The internal/external state of uapi/linux/mempolicy.h is frustrating
to say the last.
> The numa_balancing entry in
> Documentation/admin-guide/sysctl/kernel.rst however DOES say plainly
> that enabling this feature will sample and migrate mapped process
> memory to where it's used, and that this has a performance penalty.
>
> It seems there is a general lack of documented interactions between
> user-requested policies and the system-wide numa-balancing behavior.
Agreed, that's basically what i'm pointing out.
This is what most think they're getting:
static struct mempolicy default_policy = {
.refcnt = ATOMIC_INIT(1), /* never free it */
.mode = MPOL_LOCAL,
};
This is what they're actually getting:
struct mempolicy *get_task_policy(struct task_struct *p)
{
...
pol = &preferred_node_policy[node];
/* preferred_node_policy is not initialised early in boot */
if (pol->mode)
return pol;
}
void __init numa_policy_init(void)
{
...
for_each_node(nid) {
preferred_node_policy[nid] = (struct mempolicy) {
.refcnt = ATOMIC_INIT(1),
.mode = MPOL_PREFERRED,
.flags = MPOL_F_MOF | MPOL_F_MORON,
.nodes = nodemask_of_node(nid),
};
}
}
So the default global mempolicy is effectively:
(MPOL_PREFERRED | (MPOL_F_MOF | MPOL_F_MORON)
which is just MPOL_F_NUMA_BALANCING without MPOL_F_NUMA_BALANCING.
The user can't actually see that - because the MOF/MORON flags get
stripped out when it's queried (because they're internal only).
Maybe we should just set MPOL_F_NUMA_BALANCING in the default/preferred
policies and document that the global preferred policy default-enables
MPOL_F_NUMA_BALANCING - and that if a user (KVM) doesn't want to be
affected by numa balancing it needs to set a policy to disable it.
~Gregory