Re: [PATCH v2] mm/mempolicy: track page allocations per mempolicy
From: Johannes Weiner
Date: Wed Mar 11 2026 - 14:06:44 EST
On Sun, Mar 08, 2026 at 08:30:47PM -0700, JP Kobryn (Meta) wrote:
> On 3/8/26 12:24 PM, Usama Arif wrote:
> > On Fri, 6 Mar 2026 20:55:20 -0800 "JP Kobryn (Meta)" <jp.kobryn@xxxxxxxxx> wrote:
> [...]
> >> +static void mpol_count_numa_alloc(struct mempolicy *pol, int intended_nid,
> >> + struct page *page, unsigned int order)
> >> +{
> >> + int actual_nid = page_to_nid(page);
> >> + long nr_pages = 1L << order;
> >> + enum node_stat_item hit_idx;
> >> + struct mem_cgroup *memcg;
> >> + struct lruvec *lruvec;
> >> + bool is_hit;
> >> +
> >> + if (!root_mem_cgroup || mem_cgroup_disabled())
> >> + return;
> >
> > Hello JP!
> >
> > The stats are exposed via /proc/vmstat and are guarded by CONFIG_NUMA, not
> > CONFIG_MEMCG. Early returning overhere would make it inaccuate. Does
> > it make sense to use mod_node_page_state if memcg is not available,
> > so that these global counters work regardless of cgroup configuration.
> >
>
> Good call. I can instead do:
>
> if (!mem_cgroup_disabled() && root_mem_cgroup) {
> struct mem_cgroup *memcg;
> struct lruvec *lruvec;
> /* use lruvec for updating stats */
> } else {
> /* use node for updating stats */
> }
>
> This should also take care of the bot warning on mem_cgroup_from_task()
> not being available.
mem_cgroup_lruvec() and mod_lruvec_state() already do the right thing
for !CONFIG_MEMCG. Add a dummy for mem_cgroup_from_task() and you can
do a single, shared sequence for both configs.