From: Shakeel Butt <shakeelb@google.com>
To: "Michal Koutný" <mkoutny@suse.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Muchun Song <songmuchun@bytedance.com>,
Andrew Morton <akpm@linux-foundation.org>,
Cgroups <cgroups@vger.kernel.org>, Linux MM <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 3/3] memcg: reduce size of memcg vmstats structures
Date: Fri, 9 Sep 2022 10:14:35 -0700 [thread overview]
Message-ID: <CALvZod5XGH6MzMhqQfLPtD4zXdSNk_EptGN17Gmp-N8HM8Fjkw@mail.gmail.com> (raw)
In-Reply-To: <YxqHZtOx2+LUYZth@blackbook>
On Thu, Sep 8, 2022 at 5:23 PM Michal Koutný <mkoutny@suse.com> wrote:
>
> Hello.
>
> On Wed, Sep 07, 2022 at 04:35:37AM +0000, Shakeel Butt <shakeelb@google.com> wrote:
> > /* Subset of vm_event_item to report for memcg event stats */
> > static const unsigned int memcg_vm_event_stat[] = {
> > + PGPGIN,
> > + PGPGOUT,
> > PGSCAN_KSWAPD,
> > PGSCAN_DIRECT,
> > PGSTEAL_KSWAPD,
>
> What about adding a dummy entry at the beginning like:
>
> static const unsigned int memcg_vm_event_stat[] = {
> + NR_VM_EVENT_ITEMS,
> + PGPGIN,
> + PGPGOUT,
> PGSCAN_KSWAPD,
> PGSCAN_DIRECT,
>
>
> > @@ -692,14 +694,30 @@ static const unsigned int memcg_vm_event_stat[] = {
> > #endif
> > };
> >
> > +#define NR_MEMCG_EVENTS ARRAY_SIZE(memcg_vm_event_stat)
> > +static int mem_cgroup_events_index[NR_VM_EVENT_ITEMS] __read_mostly;
> > +
> > +static void init_memcg_events(void)
> > +{
> > + int i;
> > +
> > + for (i = 0; i < NR_MEMCG_EVENTS; ++i)
> > + mem_cgroup_events_index[memcg_vm_event_stat[i]] = i + 1;
>
> Start such loops from i = 1, save i to the table.
>
> > +}
> > +
> > +static inline int memcg_events_index(enum vm_event_item idx)
> > +{
> > + return mem_cgroup_events_index[idx] - 1;
> > +}
>
> And the there'd be no need for the reverse transforms -1.
>
> I.e. it might be just a negligible micro-optimization but since the
> event updates are on some fast (albeit longer) paths, it may be worth
> sacrificing one of the saved 8Bs in favor of no arithmetics.
>
> What do you think about this?
>
> > static unsigned long memcg_events(struct mem_cgroup *memcg, int event)
> > {
> > - return READ_ONCE(memcg->vmstats->events[event]);
> > + int index = memcg_events_index(event);
> > +
> > + if (index < 0)
> > + return 0;
>
> As a bonus these undefined maps could use the zero at the dummy location
> without branch (slow paths though).
>
>
> > @@ -5477,7 +5511,7 @@ static void mem_cgroup_css_rstat_flush(struct cgroup_subsys_state *css, int cpu)
> > parent->vmstats->state_pending[i] += delta;
> > }
> >
> > - for (i = 0; i < NR_VM_EVENT_ITEMS; i++) {
> > + for (i = 0; i < NR_MEMCG_EVENTS; i++) {
>
> I applaud this part :-)
>
>
Hi Michal,
Thanks for taking a look. Let me get back to you on this later. I am
at the moment rearranging struct mem_cgroup for better packing and
will be running some benchmarks. Later I will see if your suggestion
has any performance benefit or just more readable code then I will
follow up.
Shakeel
prev parent reply other threads:[~2022-09-09 17:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-07 4:35 [PATCH 0/3] memcg: reduce memory overhead of memory cgroups Shakeel Butt
2022-09-07 4:35 ` [PATCH 1/3] memcg: extract memcg_vmstats from struct mem_cgroup Shakeel Butt
2022-09-09 0:26 ` Michal Koutný
2022-09-09 16:11 ` Shakeel Butt
2022-09-07 4:35 ` [PATCH 2/3] memcg: rearrange code Shakeel Butt
2022-09-07 4:35 ` [PATCH 3/3] memcg: reduce size of memcg vmstats structures Shakeel Butt
2022-09-07 23:27 ` Roman Gushchin
2022-09-08 2:35 ` Shakeel Butt
2022-09-08 22:37 ` Andrew Morton
2022-09-09 0:23 ` Michal Koutný
2022-09-09 17:14 ` Shakeel Butt [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CALvZod5XGH6MzMhqQfLPtD4zXdSNk_EptGN17Gmp-N8HM8Fjkw@mail.gmail.com \
--to=shakeelb@google.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mkoutny@suse.com \
--cc=roman.gushchin@linux.dev \
--cc=songmuchun@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).