* [PATCH] kmemcg: don't allocate extra memory for root memcg_cache_params
@ 2013-08-14 10:31 Andrey Vagin
[not found] ` <1376476281-26559-1-git-send-email-avagin-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Andrey Vagin @ 2013-08-14 10:31 UTC (permalink / raw)
To: linux-mm
Cc: cgroups, linux-kernel, Andrey Vagin, Glauber Costa,
Johannes Weiner, Michal Hocko, Balbir Singh, KAMEZAWA Hiroyuki,
Andrew Morton
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);
Cc: Glauber Costa <glommer@openvz.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Balbir Singh <bsingharora@gmail.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
---
mm/memcontrol.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index c5792a5..d69a10b 100644
--- 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));
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)
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread[parent not found: <1376476281-26559-1-git-send-email-avagin-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>]
* Re: [PATCH] kmemcg: don't allocate extra memory for root memcg_cache_params [not found] ` <1376476281-26559-1-git-send-email-avagin-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org> @ 2013-08-14 20:47 ` Andrew Morton 2013-08-15 5:13 ` Andrey Wagin 0 siblings, 1 reply; 3+ messages in thread From: Andrew Morton @ 2013-08-14 20:47 UTC (permalink / raw) To: Andrey Vagin Cc: linux-mm-Bw31MaZKKs3YtjvyW6yDsg, cgroups-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, Glauber Costa, Johannes Weiner, Michal Hocko, Balbir Singh, KAMEZAWA Hiroyuki 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) ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kmemcg: don't allocate extra memory for root memcg_cache_params 2013-08-14 20:47 ` Andrew Morton @ 2013-08-15 5:13 ` Andrey Wagin 0 siblings, 0 replies; 3+ messages in thread From: Andrey Wagin @ 2013-08-15 5:13 UTC (permalink / raw) To: Andrew Morton Cc: linux-mm, cgroups, LKML, Glauber Costa, Johannes Weiner, Michal Hocko, Balbir Singh, KAMEZAWA Hiroyuki [-- Attachment #1: Type: text/plain, Size: 2258 bytes --] 2013/8/15 Andrew Morton <akpm@linux-foundation.org> > On Wed, 14 Aug 2013 14:31:21 +0400 Andrey Vagin <avagin@openvz.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); > sizeof doesn't have to be here. I will resend this patch. Thanks. size += offsetof(struct memcg_cache_params, memcg_caches) > > 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) > > [-- Attachment #2: Type: text/html, Size: 3320 bytes --] ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-08-15 5:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2013-08-15 5:13 ` Andrey Wagin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox