summaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorVladimir Davydov <vdavydov@virtuozzo.com>2016-01-14 18:18:15 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-14 19:00:49 -0500
commit230e9fc2860450fbb1f33bdcf9093d92d7d91f5b (patch)
treed0cb29d821cc5c3ca49066f0ca5d9149066b157f /mm
parenta9bb7e620efdfd29b6d1c238041173e411670996 (diff)
slab: add SLAB_ACCOUNT flag
Currently, if we want to account all objects of a particular kmem cache, we have to pass __GFP_ACCOUNT to each kmem_cache_alloc call, which is inconvenient. This patch introduces SLAB_ACCOUNT flag which if passed to kmem_cache_create will force accounting for every allocation from this cache even if __GFP_ACCOUNT is not passed. This patch does not make any of the existing caches use this flag - it will be done later in the series. Note, a cache with SLAB_ACCOUNT cannot be merged with a cache w/o SLAB_ACCOUNT, because merged caches share the same kmem_cache struct and hence cannot have different sets of SLAB_* flags. Thus using this flag will probably reduce the number of merged slabs even if kmem accounting is not used (only compiled in). Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com> Suggested-by: Tejun Heo <tj@kernel.org> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Greg Thelen <gthelen@google.com> Cc: Christoph Lameter <cl@linux.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: David Rientjes <rientjes@google.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/memcontrol.c8
-rw-r--r--mm/slab.h5
-rw-r--r--mm/slab_common.c3
-rw-r--r--mm/slub.c2
4 files changed, 14 insertions, 4 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 14cb1db4c52b..4bd6c4513393 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2356,7 +2356,7 @@ static void memcg_schedule_kmem_cache_create(struct mem_cgroup *memcg,
2356 * Can't be called in interrupt context or from kernel threads. 2356 * Can't be called in interrupt context or from kernel threads.
2357 * This function needs to be called with rcu_read_lock() held. 2357 * This function needs to be called with rcu_read_lock() held.
2358 */ 2358 */
2359struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep) 2359struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp)
2360{ 2360{
2361 struct mem_cgroup *memcg; 2361 struct mem_cgroup *memcg;
2362 struct kmem_cache *memcg_cachep; 2362 struct kmem_cache *memcg_cachep;
@@ -2364,6 +2364,12 @@ struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep)
2364 2364
2365 VM_BUG_ON(!is_root_cache(cachep)); 2365 VM_BUG_ON(!is_root_cache(cachep));
2366 2366
2367 if (cachep->flags & SLAB_ACCOUNT)
2368 gfp |= __GFP_ACCOUNT;
2369
2370 if (!(gfp & __GFP_ACCOUNT))
2371 return cachep;
2372
2367 if (current->memcg_kmem_skip_account) 2373 if (current->memcg_kmem_skip_account)
2368 return cachep; 2374 return cachep;
2369 2375
diff --git a/mm/slab.h b/mm/slab.h
index 7b6087197997..c63b8699cfa3 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -128,10 +128,11 @@ static inline unsigned long kmem_cache_flags(unsigned long object_size,
128 128
129#if defined(CONFIG_SLAB) 129#if defined(CONFIG_SLAB)
130#define SLAB_CACHE_FLAGS (SLAB_MEM_SPREAD | SLAB_NOLEAKTRACE | \ 130#define SLAB_CACHE_FLAGS (SLAB_MEM_SPREAD | SLAB_NOLEAKTRACE | \
131 SLAB_RECLAIM_ACCOUNT | SLAB_TEMPORARY | SLAB_NOTRACK) 131 SLAB_RECLAIM_ACCOUNT | SLAB_TEMPORARY | \
132 SLAB_NOTRACK | SLAB_ACCOUNT)
132#elif defined(CONFIG_SLUB) 133#elif defined(CONFIG_SLUB)
133#define SLAB_CACHE_FLAGS (SLAB_NOLEAKTRACE | SLAB_RECLAIM_ACCOUNT | \ 134#define SLAB_CACHE_FLAGS (SLAB_NOLEAKTRACE | SLAB_RECLAIM_ACCOUNT | \
134 SLAB_TEMPORARY | SLAB_NOTRACK) 135 SLAB_TEMPORARY | SLAB_NOTRACK | SLAB_ACCOUNT)
135#else 136#else
136#define SLAB_CACHE_FLAGS (0) 137#define SLAB_CACHE_FLAGS (0)
137#endif 138#endif
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 3c6a86b4ec25..e016178063e1 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -37,7 +37,8 @@ struct kmem_cache *kmem_cache;
37 SLAB_TRACE | SLAB_DESTROY_BY_RCU | SLAB_NOLEAKTRACE | \ 37 SLAB_TRACE | SLAB_DESTROY_BY_RCU | SLAB_NOLEAKTRACE | \
38 SLAB_FAILSLAB) 38 SLAB_FAILSLAB)
39 39
40#define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | SLAB_NOTRACK) 40#define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \
41 SLAB_NOTRACK | SLAB_ACCOUNT)
41 42
42/* 43/*
43 * Merge control. If this is set then no merging of slab caches will occur. 44 * Merge control. If this is set then no merging of slab caches will occur.
diff --git a/mm/slub.c b/mm/slub.c
index 46997517406e..2d0e610d195a 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -5362,6 +5362,8 @@ static char *create_unique_id(struct kmem_cache *s)
5362 *p++ = 'F'; 5362 *p++ = 'F';
5363 if (!(s->flags & SLAB_NOTRACK)) 5363 if (!(s->flags & SLAB_NOTRACK))
5364 *p++ = 't'; 5364 *p++ = 't';
5365 if (s->flags & SLAB_ACCOUNT)
5366 *p++ = 'A';
5365 if (p != name + 1) 5367 if (p != name + 1)
5366 *p++ = '-'; 5368 *p++ = '-';
5367 p += sprintf(p, "%07d", s->size); 5369 p += sprintf(p, "%07d", s->size);