linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Yafang Shao <laoar.shao@gmail.com>
Cc: guro@fb.com, hannes@cmpxchg.org, mhocko@kernel.org,
	vdavydov.dev@gmail.com, linux-mm@kvack.org
Subject: Re: [PATCH] mm, memcg: reduce size of struct mem_cgroup by using bit field
Date: Tue, 31 Dec 2019 14:31:39 -0800	[thread overview]
Message-ID: <20191231143139.20a912b3386548062343a5b2@linux-foundation.org> (raw)
In-Reply-To: <1577450633-2098-1-git-send-email-laoar.shao@gmail.com>

On Fri, 27 Dec 2019 07:43:52 -0500 Yafang Shao <laoar.shao@gmail.com> 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.
> 
> ...
>
> --- 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;

Kernel coding style for this is normally no-spaces:

	bool foo:1;



More significantly...  Now that these fields share the same word of
memory, what prevents races when two CPUs do read-modify-write
operations on adjacent bitfields?

This:

struct foo {
	int a;
	int b;
};

doesn't need locking to prevent modifications of `a' from scribbling on
`b'.  But with this:

struct foo {
	int a:1;
	int b:1;
}

a simple `a = 1' on CPU1 could race with a `b = 1' on CPU2.

I think.  Maybe the compiler can take care of this in some fashion, but
it would require atomic bitops and I doubt if gcc does that for us?




  parent reply	other threads:[~2019-12-31 22:31 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
2019-12-31 22:31 ` Andrew Morton [this message]
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=20191231143139.20a912b3386548062343a5b2@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=guro@fb.com \
    --cc=hannes@cmpxchg.org \
    --cc=laoar.shao@gmail.com \
    --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