Re: [PATCH 2/3] mm: memcg: add a helper for non-unified stats flushing

From: Yosry Ahmed
Date: Tue Aug 22 2023 - 12:00:47 EST


On Tue, Aug 22, 2023 at 6:01 AM Michal Koutný <mkoutny@xxxxxxxx> wrote:
>
> On Mon, Aug 21, 2023 at 08:54:57PM +0000, Yosry Ahmed <yosryahmed@xxxxxxxxxx> wrote:
> > +static void do_stats_flush(struct mem_cgroup *memcg)
> > +{
> > + cgroup_rstat_flush(memcg->css.cgroup);
> if(memcg == root_mem_cgroup)
> atomic_set(&stats_flush_threshold, 0);
> > +}
> > +
> > /*
> > * do_unified_stats_flush - do a unified flush of memory cgroup statistics
> > *
> > @@ -656,7 +667,7 @@ static void do_unified_stats_flush(void)
> >
> > WRITE_ONCE(flush_next_time, jiffies_64 + 2*FLUSH_TIME);
> >
> > - cgroup_rstat_flush(root_mem_cgroup->css.cgroup);
> > + do_stats_flush(root_mem_cgroup);
> >
> - atomic_set(&stats_flush_threshold, 0);
> > atomic_set(&stats_flush_ongoing, 0);
>
> You may reset stats_flush_threshold to save the unified flushers some
> work.

We can probably also kick FLUSH_TIME forward as well. Perhaps I can
move both into do_stats_flush() then. If I understand correctly this
is what you mean?

static void do_stats_flush(struct mem_cgroup *memcg)
{
if (mem_cgroup_is_root(memcg))
WRITE_ONCE(flush_next_time, jiffies_64 + 2*FLUSH_TIME);

cgroup_rstat_flush(memcg->css.cgroup);

if (mem_cgroup_is_root(memcg))
atomic_set(&stats_flush_threshold, 0);
}

static void do_unified_stats_flush(void)
{
if (atomic_read(&stats_flush_ongoing) ||
atomic_xchg(&stats_flush_ongoing, 1))
return;

do_stats_flush(root_mem_cgroup);
atomic_set(&stats_flush_ongoing, 0);
}

, or simplify it further by just resetting stats_flush_threshold
before we flush as well:

static void do_stats_flush(struct mem_cgroup *memcg)
{
/* for unified flushing, root non-unified flushing can help as well */
if (mem_cgroup_is_root(memcg)) {
WRITE_ONCE(flush_next_time, jiffies_64 + 2*FLUSH_TIME);
atomic_set(&stats_flush_threshold, 0);
}

cgroup_rstat_flush(memcg->css.cgroup);
}

static void do_unified_stats_flush(void)
{
if (atomic_read(&stats_flush_ongoing) ||
atomic_xchg(&stats_flush_ongoing, 1))
return;

do_stats_flush(root_mem_cgroup);
atomic_set(&stats_flush_ongoing, 0);
}


What do you think?