Re: [PATCH] mm: mempolicy: fix automatic numa balancing for shmem

From: Gregory Price

Date: Wed Jul 01 2026 - 12:22:35 EST


On Wed, Jul 01, 2026 at 11:49:16AM -0400, Johannes Weiner wrote:
> On Wed, Jul 01, 2026 at 11:33:38AM -0400, Gregory Price wrote:
> >
> > I considered proposing MPOL_F_MOVABLE_ONLY to mean (roughly) "userland
> > memory only" - and then slowly trying to migrate numactl to make this
> > the default.
>
> Hm. Kernel allocations that are totally incidental like the stackdepot
> example above should not follow task policy. But there are kernel
> allocations (kernel stack, inodes, pipes) that are directly allocated
> on behalf of a process, and so probably SHOULD follow task policy.
>
> That's an annotation problem that I think we have solved already,
> because cgroups need the same distinction for what allocations to
> charge to the current task's cgroup context.
>
> We could rename __GFP_ACCOUNT / SLAB_ACCOUNT to __GFP_TASKPOLICY /
> SLAB_TASKPOLICY or something, and have mempolicy follow it too.
>
> There is still the whole "changing 20 year old behavior" aspect, but I
> think the polarity works in our favor: big important allocations have
> already been following the policy correctly. The behavior changes
> primarily for smaller, random allocations.

This seems like it would be a pretty trivial change.

something like:

static nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *pol,
pgoff_t ilx, int *nid)
{
nodemask_t *nodemask = NULL;

if (!(gfp & __GFP_TASKPOLICY))
/* don't do the task policy, numa_node_id()? */
... snip ...
}