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 <[email protected]> Suggested-by: Tejun Heo <[email protected]> Acked-by: Johannes Weiner <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: Greg Thelen <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: Pekka Enberg <[email protected]> Cc: David Rientjes <[email protected]> Cc: Joonsoo Kim <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> (cherry picked from commit 230e9fc2860450fbb1f33bdcf9093d92d7d91f5b) Signed-off-by: Vladimir Davydov <[email protected]> Conflicts: include/linux/memcontrol.h mm/memcontrol.c mm/slab_common.c --- include/linux/memcontrol.h | 2 -- include/linux/slab.h | 5 +++++ mm/memcontrol.c | 6 ++++++ mm/slab.h | 5 +++-- mm/slub.c | 4 +++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 628b23dadd1d..d90f6c77dc69 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -637,8 +637,6 @@ memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp) { if (!memcg_kmem_enabled()) return cachep; - if (!(gfp & __GFP_ACCOUNT)) - return cachep; if (gfp & __GFP_NOFAIL) return cachep; if (in_interrupt() || (!current->mm) || (current->flags & PF_KTHREAD)) diff --git a/include/linux/slab.h b/include/linux/slab.h index ef8760bb034c..f454fcd2ad18 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -79,6 +79,11 @@ #else # define SLAB_FAILSLAB 0x00000000UL #endif +#ifdef CONFIG_MEMCG_KMEM +# define SLAB_ACCOUNT 0x04000000UL /* Account to memcg */ +#else +# define SLAB_ACCOUNT 0x00000000UL +#endif /* The following flags affect the page allocator grouping pages by mobility */ #define SLAB_RECLAIM_ACCOUNT 0x00020000UL /* Objects are reclaimable */ diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9ccc8080c2e0..f617423a3ade 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3446,6 +3446,12 @@ struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep, VM_BUG_ON(!is_root_cache(cachep)); + if (cachep->flags & SLAB_ACCOUNT) + gfp |= __GFP_ACCOUNT; + + if (!(gfp & __GFP_ACCOUNT)) + return cachep; + if (!current->mm || current->memcg_kmem_skip_account) return cachep; diff --git a/mm/slab.h b/mm/slab.h index 57de63f5bf46..66257a427e9c 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -114,10 +114,11 @@ __kmem_cache_alias(const char *name, size_t size, size_t align, #if defined(CONFIG_SLAB) #define SLAB_CACHE_FLAGS (SLAB_MEM_SPREAD | SLAB_NOLEAKTRACE | \ - SLAB_RECLAIM_ACCOUNT | SLAB_TEMPORARY | SLAB_NOTRACK) + SLAB_RECLAIM_ACCOUNT | SLAB_TEMPORARY | \ + SLAB_NOTRACK | SLAB_ACCOUNT) #elif defined(CONFIG_SLUB) #define SLAB_CACHE_FLAGS (SLAB_NOLEAKTRACE | SLAB_RECLAIM_ACCOUNT | \ - SLAB_TEMPORARY | SLAB_NOTRACK) + SLAB_TEMPORARY | SLAB_NOTRACK | SLAB_ACCOUNT) #else #define SLAB_CACHE_FLAGS (0) #endif diff --git a/mm/slub.c b/mm/slub.c index 80c7b79c5b8c..c62e38188a79 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -169,7 +169,7 @@ static inline int kmem_cache_debug(struct kmem_cache *s) SLAB_FAILSLAB) #define SLUB_MERGE_SAME (SLAB_DEBUG_FREE | SLAB_RECLAIM_ACCOUNT | \ - SLAB_CACHE_DMA | SLAB_NOTRACK) + SLAB_CACHE_DMA | SLAB_NOTRACK | SLAB_ACCOUNT) #define OO_SHIFT 16 #define OO_MASK ((1 << OO_SHIFT) - 1) @@ -5228,6 +5228,8 @@ static char *create_unique_id(struct kmem_cache *s) *p++ = 'F'; if (!(s->flags & SLAB_NOTRACK)) *p++ = 't'; + if (s->flags & SLAB_ACCOUNT) + *p++ = 'A'; if (p != name + 1) *p++ = '-'; p += sprintf(p, "%07d", s->size); -- 2.1.4 _______________________________________________ Devel mailing list [email protected] https://lists.openvz.org/mailman/listinfo/devel
