linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: Roman Gushchin <guro@fb.com>
Cc: "hannes@cmpxchg.org" <hannes@cmpxchg.org>,
	"mhocko@kernel.org" <mhocko@kernel.org>,
	 "vdavydov.dev@gmail.com" <vdavydov.dev@gmail.com>,
	 "akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>
Subject: Re: [PATCH] mm, memcg: reduce size of struct mem_cgroup by using bit field
Date: Sat, 28 Dec 2019 12:22:26 +0800	[thread overview]
Message-ID: <CALOAHbB4yZsCsqPAV8FQFXEpgaHBi+PsGRFgQCEsMNgR_6UR9Q@mail.gmail.com> (raw)
In-Reply-To: <20191227235537.GB6742@localhost.localdomain>

On Sat, Dec 28, 2019 at 7:55 AM Roman Gushchin <guro@fb.com> wrote:
>
> On Fri, Dec 27, 2019 at 07:43:52AM -0500, Yafang Shao wrote:
> > There are some members in struct mem_group can be either 0(false) or
> > 1(true), so we can define them using bit field to reduce size. With this
> > patch, the size of struct mem_cgroup can be reduced by 64 bytes in theory,
> > but as there're some MEMCG_PADDING()s, the real number may be different,
> > which is relate with the cacheline size. Anyway, this patch could reduce
> > the size of struct mem_cgroup more or less.
> >
> > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> > Cc: Roman Gushchin <guro@fb.com>
> > ---
> >  include/linux/memcontrol.h | 21 ++++++++++++---------
> >  1 file changed, 12 insertions(+), 9 deletions(-)
> >
> > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> > index a7a0a1a5..f68a9ef 100644
> > --- a/include/linux/memcontrol.h
> > +++ b/include/linux/memcontrol.h
> > @@ -229,20 +229,26 @@ struct mem_cgroup {
> >       /*
> >        * Should the accounting and control be hierarchical, per subtree?
> >        */
> > -     bool use_hierarchy;
> > +     unsigned int use_hierarchy : 1;
> > +
> > +     /* Legacy tcp memory accounting */
> > +     unsigned int tcpmem_active : 1;
> > +     unsigned int tcpmem_pressure : 1;
> >
> >       /*
> >        * Should the OOM killer kill all belonging tasks, had it kill one?
> >        */
> > -     bool oom_group;
> > +     unsigned int  oom_group : 1;
> >
> >       /* protected by memcg_oom_lock */
> > -     bool            oom_lock;
> > -     int             under_oom;
> > +     unsigned int oom_lock : 1;
>
> Hm, looking at the original code, it was clear that oom_lock
> and under_oom are protected with memcg_oom_lock; but not oom_kill_disable.
>
> This information seems to be lost.
>

Should add this comment. Thanks for pointing this out.

> Also, I'd look at the actual memory savings. Is it worth it?
> Or it's all eaten by the padding.
>

As explained in the commit log, the real size depends on the cacheline size,
and in the future we may introduce other new bool members.
I have verified it on my server with 64B-cacheline, and the saveing is 0.

Actually there's no strong reason to make this minor optimization.

> Thanks!
>
> >
> > -     int     swappiness;
> >       /* OOM-Killer disable */
> > -     int             oom_kill_disable;
> > +     unsigned int oom_kill_disable : 1;
> > +
> > +     int under_oom;
> > +
> > +     int     swappiness;
> >
> >       /* memory.events and memory.events.local */
> >       struct cgroup_file events_file;
> > @@ -297,9 +303,6 @@ struct mem_cgroup {
> >
> >       unsigned long           socket_pressure;
> >
> > -     /* Legacy tcp memory accounting */
> > -     bool                    tcpmem_active;
> > -     int                     tcpmem_pressure;
> >
> >  #ifdef CONFIG_MEMCG_KMEM
> >          /* Index in the kmem_cache->memcg_params.memcg_caches array */
> > --
> > 1.8.3.1
> >


  reply	other threads:[~2019-12-28  4:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-27 12:43 Yafang Shao
2019-12-27 12:43 ` [PATCH] mm, memcg: reset memcg's memory.{min, low} for reclaiming itself Yafang Shao
2019-12-27 23:49   ` Roman Gushchin
2019-12-28  1:45     ` Yafang Shao
2019-12-28  2:59       ` Roman Gushchin
2019-12-28  4:24         ` Yafang Shao
2019-12-27 23:55 ` [PATCH] mm, memcg: reduce size of struct mem_cgroup by using bit field Roman Gushchin
2019-12-28  4:22   ` Yafang Shao [this message]
2019-12-31 22:31 ` Andrew Morton
2020-01-02  5:43   ` Yafang Shao
2020-01-06 10:19 ` Michal Hocko

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=CALOAHbB4yZsCsqPAV8FQFXEpgaHBi+PsGRFgQCEsMNgR_6UR9Q@mail.gmail.com \
    --to=laoar.shao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=guro@fb.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=vdavydov.dev@gmail.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