public inbox for cgroups@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
To: Andrey Vagin <avagin-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
Cc: linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org,
	cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Glauber Costa <glommer-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>,
	Johannes Weiner <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>,
	Michal Hocko <mhocko-AlSwsSmVLrQ@public.gmane.org>,
	Balbir Singh
	<bsingharora-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	KAMEZAWA Hiroyuki
	<kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
Subject: Re: [PATCH] kmemcg: don't allocate extra memory for root memcg_cache_params
Date: Wed, 14 Aug 2013 13:47:10 -0700	[thread overview]
Message-ID: <20130814134710.ff123b0ea802efa7261d7e26@linux-foundation.org> (raw)
In-Reply-To: <1376476281-26559-1-git-send-email-avagin-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>

On Wed, 14 Aug 2013 14:31:21 +0400 Andrey Vagin <avagin-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org> wrote:

> The memcg_cache_params structure contains the common part and the union,
> which represents two different types of data: one for root cashes and
> another for child caches.
> 
> The size of child data is fixed. The size of the memcg_caches array is
> calculated in runtime.
> 
> Currently the size of memcg_cache_params for root caches is calculated
> incorrectly, because it includes the size of parameters for child caches.
> 
> ssize_t size = memcg_caches_array_size(num_groups);
> size *= sizeof(void *);
> 
> size += sizeof(struct memcg_cache_params);
> 
> ...
>
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3140,7 +3140,7 @@ int memcg_update_cache_size(struct kmem_cache *s, int num_groups)
>  		ssize_t size = memcg_caches_array_size(num_groups);
>  
>  		size *= sizeof(void *);
> -		size += sizeof(struct memcg_cache_params);
> +		size += sizeof(offsetof(struct memcg_cache_params, memcg_caches));

This looks wrong. offsetof() returns size_t, so this is equivalent to

		size += sizeof(size_t);

>  		s->memcg_params = kzalloc(size, GFP_KERNEL);
>  		if (!s->memcg_params) {
> @@ -3183,13 +3183,16 @@ int memcg_update_cache_size(struct kmem_cache *s, int num_groups)
>  int memcg_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s,
>  			 struct kmem_cache *root_cache)
>  {
> -	size_t size = sizeof(struct memcg_cache_params);
> +	size_t size;
>  
>  	if (!memcg_kmem_enabled())
>  		return 0;
>  
> -	if (!memcg)
> +	if (!memcg) {
> +		size = offsetof(struct memcg_cache_params, memcg_caches);
>  		size += memcg_limited_groups_array_size * sizeof(void *);
> +	} else
> +		size = sizeof(struct memcg_cache_params);
>  
>  	s->memcg_params = kzalloc(size, GFP_KERNEL);
>  	if (!s->memcg_params)

  parent reply	other threads:[~2013-08-14 20:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-14 10:31 [PATCH] kmemcg: don't allocate extra memory for root memcg_cache_params Andrey Vagin
     [not found] ` <1376476281-26559-1-git-send-email-avagin-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2013-08-14 20:47   ` Andrew Morton [this message]
2013-08-15  5:13     ` Andrey Wagin

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=20130814134710.ff123b0ea802efa7261d7e26@linux-foundation.org \
    --to=akpm-de/tnxtf+jlsfhdxvbkv3wd2fqjk+8+b@public.gmane.org \
    --cc=avagin-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org \
    --cc=bsingharora-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=glommer-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org \
    --cc=hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org \
    --cc=kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org \
    --cc=mhocko-AlSwsSmVLrQ@public.gmane.org \
    /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