Commit ba6c496ed834a37a26fc6fc87fc9aecb0fa0014d

Authored by Glauber Costa
Committed by Linus Torvalds
1 parent d5bdae7d59

slab/slub: struct memcg_params

For the kmem slab controller, we need to record some extra information in
the kmem_cache structure.

Signed-off-by: Glauber Costa <glommer@parallels.com>
Signed-off-by: Suleiman Souhlal <suleiman@google.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Frederic Weisbecker <fweisbec@redhat.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: JoonSoo Kim <js1304@gmail.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Rik van Riel <riel@redhat.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 4 changed files with 43 additions and 0 deletions Side-by-side Diff

include/linux/slab.h
... ... @@ -177,6 +177,30 @@
177 177 #endif
178 178  
179 179 /*
  180 + * This is the main placeholder for memcg-related information in kmem caches.
  181 + * struct kmem_cache will hold a pointer to it, so the memory cost while
  182 + * disabled is 1 pointer. The runtime cost while enabled, gets bigger than it
  183 + * would otherwise be if that would be bundled in kmem_cache: we'll need an
  184 + * extra pointer chase. But the trade off clearly lays in favor of not
  185 + * penalizing non-users.
  186 + *
  187 + * Both the root cache and the child caches will have it. For the root cache,
  188 + * this will hold a dynamically allocated array large enough to hold
  189 + * information about the currently limited memcgs in the system.
  190 + *
  191 + * Child caches will hold extra metadata needed for its operation. Fields are:
  192 + *
  193 + * @memcg: pointer to the memcg this cache belongs to
  194 + */
  195 +struct memcg_cache_params {
  196 + bool is_root_cache;
  197 + union {
  198 + struct kmem_cache *memcg_caches[0];
  199 + struct mem_cgroup *memcg;
  200 + };
  201 +};
  202 +
  203 +/*
180 204 * Common kmalloc functions provided by all allocators
181 205 */
182 206 void * __must_check __krealloc(const void *, size_t, gfp_t);
include/linux/slab_def.h
... ... @@ -81,6 +81,9 @@
81 81 */
82 82 int obj_offset;
83 83 #endif /* CONFIG_DEBUG_SLAB */
  84 +#ifdef CONFIG_MEMCG_KMEM
  85 + struct memcg_cache_params *memcg_params;
  86 +#endif
84 87  
85 88 /* 6) per-cpu/per-node data, touched during every alloc/free */
86 89 /*
include/linux/slub_def.h
... ... @@ -101,6 +101,9 @@
101 101 #ifdef CONFIG_SYSFS
102 102 struct kobject kobj; /* For sysfs */
103 103 #endif
  104 +#ifdef CONFIG_MEMCG_KMEM
  105 + struct memcg_cache_params *memcg_params;
  106 +#endif
104 107  
105 108 #ifdef CONFIG_NUMA
106 109 /*
... ... @@ -100,5 +100,18 @@
100 100 void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *s);
101 101 ssize_t slabinfo_write(struct file *file, const char __user *buffer,
102 102 size_t count, loff_t *ppos);
  103 +
  104 +#ifdef CONFIG_MEMCG_KMEM
  105 +static inline bool is_root_cache(struct kmem_cache *s)
  106 +{
  107 + return !s->memcg_params || s->memcg_params->is_root_cache;
  108 +}
  109 +#else
  110 +static inline bool is_root_cache(struct kmem_cache *s)
  111 +{
  112 + return true;
  113 +}
  114 +
  115 +#endif
103 116 #endif