Re: [PATCH v7 13/13] vmstat: add pcp remote node draining via cpu_vm_stats_fold

From: Marcelo Tosatti
Date: Tue Mar 21 2023 - 21:25:11 EST


On Mon, Mar 20, 2023 at 01:43:09PM -0700, Tim Chen wrote:
> On Mon, 2023-03-20 at 15:03 -0300, Marcelo Tosatti wrote:
> >
> > +
> > + if (do_pagesets) {
> > + cond_resched();
> > + /*
> > + * Deal with draining the remote pageset of a
> > + * processor
> > + *
> > + * Check if there are pages remaining in this pageset
> > + * if not then there is nothing to expire.
> > + */
> > + if (!pcp->expire || !pcp->count)
> > + continue;refresh_cpu_vm_stats
> > +
> > + /*
> > + * We never drain zones local to this processor.
> > + */
> > + if (zone_to_nid(zone) == cpu_to_node(cpu)) {
> > + pcp->expire = 0;
> > + continue;
> > + }
> > +
> > + WARN_ON(pcp->expire < 0);
> > + /*
> > + * pcp->expire is only accessed from vmstat_shepherd context,
> > + * therefore no locking is required.
> > + */
> > + if (--pcp->expire)
> > + continue;
> > +
> > + if (pcp->count)
> > + drain_zone_pages(zone, pcp);
> > + }
>
> This logic is the same to that for the do_pagesets portion of code in refresh_cpu_vm_stats().
> Is it possible to consolidate to avoid replicating the logic across two functions?
>
> Tim

Tim,

One of the versions is for remote access, the other version is for local
access (thats why merging the two is not so simple).

I suppose the next logical step would be ensure that the current
!CONFIG_HAVE_CMPXCHG_LOCAL also uses the cmpxchg remotely (then
refresh_cpu_vm_stats can be removed).