Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

list_lru: introduce per-memcg lists

There are several FS shrinkers, including super_block::s_shrink, that
keep reclaimable objects in the list_lru structure. Hence to turn them
to memcg-aware shrinkers, it is enough to make list_lru per-memcg.

This patch does the trick. It adds an array of lru lists to the
list_lru_node structure (per-node part of the list_lru), one for each
kmem-active memcg, and dispatches every item addition or removal to the
list corresponding to the memcg which the item is accounted to. So now
the list_lru structure is not just per node, but per node and per memcg.

Not all list_lrus need this feature, so this patch also adds a new
method, list_lru_init_memcg, which initializes a list_lru as memcg
aware. Otherwise (i.e. if initialized with old list_lru_init), the
list_lru won't have per memcg lists.

Just like per memcg caches arrays, the arrays of per-memcg lists are
indexed by memcg_cache_id, so we must grow them whenever
memcg_nr_cache_ids is increased. So we introduce a callback,
memcg_update_all_list_lrus, invoked by memcg_alloc_cache_id if the id
space is full.

The locking is implemented in a manner similar to lruvecs, i.e. we have
one lock per node that protects all lists (both global and per cgroup) on
the node.

Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Greg Thelen <gthelen@google.com>
Cc: Glauber Costa <glommer@gmail.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
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>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Vladimir Davydov and committed by
Linus Torvalds
60d3fd32 c0a5b560

+424 -36
+40 -12
include/linux/list_lru.h
··· 11 11 #include <linux/nodemask.h> 12 12 #include <linux/shrinker.h> 13 13 14 + struct mem_cgroup; 15 + 14 16 /* list_lru_walk_cb has to always return one of those */ 15 17 enum lru_status { 16 18 LRU_REMOVED, /* item removed from list */ ··· 24 22 internally, but has to return locked. */ 25 23 }; 26 24 27 - struct list_lru_node { 28 - spinlock_t lock; 25 + struct list_lru_one { 29 26 struct list_head list; 30 27 /* kept as signed so we can catch imbalance bugs */ 31 28 long nr_items; 29 + }; 30 + 31 + struct list_lru_memcg { 32 + /* array of per cgroup lists, indexed by memcg_cache_id */ 33 + struct list_lru_one *lru[0]; 34 + }; 35 + 36 + struct list_lru_node { 37 + /* protects all lists on the node, including per cgroup */ 38 + spinlock_t lock; 39 + /* global list, used for the root cgroup in cgroup aware lrus */ 40 + struct list_lru_one lru; 41 + #ifdef CONFIG_MEMCG_KMEM 42 + /* for cgroup aware lrus points to per cgroup lists, otherwise NULL */ 43 + struct list_lru_memcg *memcg_lrus; 44 + #endif 32 45 } ____cacheline_aligned_in_smp; 33 46 34 47 struct list_lru { ··· 54 37 }; 55 38 56 39 void list_lru_destroy(struct list_lru *lru); 57 - int list_lru_init_key(struct list_lru *lru, struct lock_class_key *key); 58 - static inline int list_lru_init(struct list_lru *lru) 59 - { 60 - return list_lru_init_key(lru, NULL); 61 - } 40 + int __list_lru_init(struct list_lru *lru, bool memcg_aware, 41 + struct lock_class_key *key); 42 + 43 + #define list_lru_init(lru) __list_lru_init((lru), false, NULL) 44 + #define list_lru_init_key(lru, key) __list_lru_init((lru), false, (key)) 45 + #define list_lru_init_memcg(lru) __list_lru_init((lru), true, NULL) 46 + 47 + int memcg_update_all_list_lrus(int num_memcgs); 62 48 63 49 /** 64 50 * list_lru_add: add an element to the lru list's tail ··· 95 75 bool list_lru_del(struct list_lru *lru, struct list_head *item); 96 76 97 77 /** 98 - * list_lru_count_node: return the number of objects currently held by @lru 78 + * list_lru_count_one: return the number of objects currently held by @lru 99 79 * @lru: the lru pointer. 100 80 * @nid: the node id to count from. 81 + * @memcg: the cgroup to count from. 101 82 * 102 83 * Always return a non-negative number, 0 for empty lists. There is no 103 84 * guarantee that the list is not updated while the count is being computed. 104 85 * Callers that want such a guarantee need to provide an outer lock. 105 86 */ 87 + unsigned long list_lru_count_one(struct list_lru *lru, 88 + int nid, struct mem_cgroup *memcg); 106 89 unsigned long list_lru_count_node(struct list_lru *lru, int nid); 107 90 108 91 static inline unsigned long list_lru_shrink_count(struct list_lru *lru, 109 92 struct shrink_control *sc) 110 93 { 111 - return list_lru_count_node(lru, sc->nid); 94 + return list_lru_count_one(lru, sc->nid, sc->memcg); 112 95 } 113 96 114 97 static inline unsigned long list_lru_count(struct list_lru *lru) ··· 128 105 typedef enum lru_status 129 106 (*list_lru_walk_cb)(struct list_head *item, spinlock_t *lock, void *cb_arg); 130 107 /** 131 - * list_lru_walk_node: walk a list_lru, isolating and disposing freeable items. 108 + * list_lru_walk_one: walk a list_lru, isolating and disposing freeable items. 132 109 * @lru: the lru pointer. 133 110 * @nid: the node id to scan from. 111 + * @memcg: the cgroup to scan from. 134 112 * @isolate: callback function that is resposible for deciding what to do with 135 113 * the item currently being scanned 136 114 * @cb_arg: opaque type that will be passed to @isolate ··· 149 125 * 150 126 * Return value: the number of objects effectively removed from the LRU. 151 127 */ 128 + unsigned long list_lru_walk_one(struct list_lru *lru, 129 + int nid, struct mem_cgroup *memcg, 130 + list_lru_walk_cb isolate, void *cb_arg, 131 + unsigned long *nr_to_walk); 152 132 unsigned long list_lru_walk_node(struct list_lru *lru, int nid, 153 133 list_lru_walk_cb isolate, void *cb_arg, 154 134 unsigned long *nr_to_walk); ··· 161 133 list_lru_shrink_walk(struct list_lru *lru, struct shrink_control *sc, 162 134 list_lru_walk_cb isolate, void *cb_arg) 163 135 { 164 - return list_lru_walk_node(lru, sc->nid, isolate, cb_arg, 165 - &sc->nr_to_scan); 136 + return list_lru_walk_one(lru, sc->nid, sc->memcg, isolate, cb_arg, 137 + &sc->nr_to_scan); 166 138 } 167 139 168 140 static inline unsigned long
+14
include/linux/memcontrol.h
··· 439 439 struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep); 440 440 void __memcg_kmem_put_cache(struct kmem_cache *cachep); 441 441 442 + struct mem_cgroup *__mem_cgroup_from_kmem(void *ptr); 443 + 442 444 int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp, 443 445 unsigned long nr_pages); 444 446 void memcg_uncharge_kmem(struct mem_cgroup *memcg, unsigned long nr_pages); ··· 537 535 if (memcg_kmem_enabled()) 538 536 __memcg_kmem_put_cache(cachep); 539 537 } 538 + 539 + static __always_inline struct mem_cgroup *mem_cgroup_from_kmem(void *ptr) 540 + { 541 + if (!memcg_kmem_enabled()) 542 + return NULL; 543 + return __mem_cgroup_from_kmem(ptr); 544 + } 540 545 #else 541 546 #define for_each_memcg_cache_index(_idx) \ 542 547 for (; NULL; ) ··· 594 585 595 586 static inline void memcg_kmem_put_cache(struct kmem_cache *cachep) 596 587 { 588 + } 589 + 590 + static inline struct mem_cgroup *mem_cgroup_from_kmem(void *ptr) 591 + { 592 + return NULL; 597 593 } 598 594 #endif /* CONFIG_MEMCG_KMEM */ 599 595 #endif /* _LINUX_MEMCONTROL_H */
+350 -24
mm/list_lru.c
··· 10 10 #include <linux/list_lru.h> 11 11 #include <linux/slab.h> 12 12 #include <linux/mutex.h> 13 + #include <linux/memcontrol.h> 13 14 14 15 #ifdef CONFIG_MEMCG_KMEM 15 16 static LIST_HEAD(list_lrus); ··· 39 38 } 40 39 #endif /* CONFIG_MEMCG_KMEM */ 41 40 41 + #ifdef CONFIG_MEMCG_KMEM 42 + static inline bool list_lru_memcg_aware(struct list_lru *lru) 43 + { 44 + return !!lru->node[0].memcg_lrus; 45 + } 46 + 47 + static inline struct list_lru_one * 48 + list_lru_from_memcg_idx(struct list_lru_node *nlru, int idx) 49 + { 50 + /* 51 + * The lock protects the array of per cgroup lists from relocation 52 + * (see memcg_update_list_lru_node). 53 + */ 54 + lockdep_assert_held(&nlru->lock); 55 + if (nlru->memcg_lrus && idx >= 0) 56 + return nlru->memcg_lrus->lru[idx]; 57 + 58 + return &nlru->lru; 59 + } 60 + 61 + static inline struct list_lru_one * 62 + list_lru_from_kmem(struct list_lru_node *nlru, void *ptr) 63 + { 64 + struct mem_cgroup *memcg; 65 + 66 + if (!nlru->memcg_lrus) 67 + return &nlru->lru; 68 + 69 + memcg = mem_cgroup_from_kmem(ptr); 70 + if (!memcg) 71 + return &nlru->lru; 72 + 73 + return list_lru_from_memcg_idx(nlru, memcg_cache_id(memcg)); 74 + } 75 + #else 76 + static inline bool list_lru_memcg_aware(struct list_lru *lru) 77 + { 78 + return false; 79 + } 80 + 81 + static inline struct list_lru_one * 82 + list_lru_from_memcg_idx(struct list_lru_node *nlru, int idx) 83 + { 84 + return &nlru->lru; 85 + } 86 + 87 + static inline struct list_lru_one * 88 + list_lru_from_kmem(struct list_lru_node *nlru, void *ptr) 89 + { 90 + return &nlru->lru; 91 + } 92 + #endif /* CONFIG_MEMCG_KMEM */ 93 + 42 94 bool list_lru_add(struct list_lru *lru, struct list_head *item) 43 95 { 44 96 int nid = page_to_nid(virt_to_page(item)); 45 97 struct list_lru_node *nlru = &lru->node[nid]; 98 + struct list_lru_one *l; 46 99 47 100 spin_lock(&nlru->lock); 48 - WARN_ON_ONCE(nlru->nr_items < 0); 101 + l = list_lru_from_kmem(nlru, item); 102 + WARN_ON_ONCE(l->nr_items < 0); 49 103 if (list_empty(item)) { 50 - list_add_tail(item, &nlru->list); 51 - nlru->nr_items++; 104 + list_add_tail(item, &l->list); 105 + l->nr_items++; 52 106 spin_unlock(&nlru->lock); 53 107 return true; 54 108 } ··· 116 60 { 117 61 int nid = page_to_nid(virt_to_page(item)); 118 62 struct list_lru_node *nlru = &lru->node[nid]; 63 + struct list_lru_one *l; 119 64 120 65 spin_lock(&nlru->lock); 66 + l = list_lru_from_kmem(nlru, item); 121 67 if (!list_empty(item)) { 122 68 list_del_init(item); 123 - nlru->nr_items--; 124 - WARN_ON_ONCE(nlru->nr_items < 0); 69 + l->nr_items--; 70 + WARN_ON_ONCE(l->nr_items < 0); 125 71 spin_unlock(&nlru->lock); 126 72 return true; 127 73 } ··· 132 74 } 133 75 EXPORT_SYMBOL_GPL(list_lru_del); 134 76 135 - unsigned long 136 - list_lru_count_node(struct list_lru *lru, int nid) 77 + static unsigned long __list_lru_count_one(struct list_lru *lru, 78 + int nid, int memcg_idx) 137 79 { 138 - unsigned long count = 0; 139 80 struct list_lru_node *nlru = &lru->node[nid]; 81 + struct list_lru_one *l; 82 + unsigned long count; 140 83 141 84 spin_lock(&nlru->lock); 142 - WARN_ON_ONCE(nlru->nr_items < 0); 143 - count += nlru->nr_items; 85 + l = list_lru_from_memcg_idx(nlru, memcg_idx); 86 + WARN_ON_ONCE(l->nr_items < 0); 87 + count = l->nr_items; 144 88 spin_unlock(&nlru->lock); 145 89 146 90 return count; 147 91 } 92 + 93 + unsigned long list_lru_count_one(struct list_lru *lru, 94 + int nid, struct mem_cgroup *memcg) 95 + { 96 + return __list_lru_count_one(lru, nid, memcg_cache_id(memcg)); 97 + } 98 + EXPORT_SYMBOL_GPL(list_lru_count_one); 99 + 100 + unsigned long list_lru_count_node(struct list_lru *lru, int nid) 101 + { 102 + long count = 0; 103 + int memcg_idx; 104 + 105 + count += __list_lru_count_one(lru, nid, -1); 106 + if (list_lru_memcg_aware(lru)) { 107 + for_each_memcg_cache_index(memcg_idx) 108 + count += __list_lru_count_one(lru, nid, memcg_idx); 109 + } 110 + return count; 111 + } 148 112 EXPORT_SYMBOL_GPL(list_lru_count_node); 149 113 150 - unsigned long 151 - list_lru_walk_node(struct list_lru *lru, int nid, list_lru_walk_cb isolate, 152 - void *cb_arg, unsigned long *nr_to_walk) 114 + static unsigned long 115 + __list_lru_walk_one(struct list_lru *lru, int nid, int memcg_idx, 116 + list_lru_walk_cb isolate, void *cb_arg, 117 + unsigned long *nr_to_walk) 153 118 { 154 119 155 - struct list_lru_node *nlru = &lru->node[nid]; 120 + struct list_lru_node *nlru = &lru->node[nid]; 121 + struct list_lru_one *l; 156 122 struct list_head *item, *n; 157 123 unsigned long isolated = 0; 158 124 159 125 spin_lock(&nlru->lock); 126 + l = list_lru_from_memcg_idx(nlru, memcg_idx); 160 127 restart: 161 - list_for_each_safe(item, n, &nlru->list) { 128 + list_for_each_safe(item, n, &l->list) { 162 129 enum lru_status ret; 163 130 164 131 /* ··· 199 116 case LRU_REMOVED_RETRY: 200 117 assert_spin_locked(&nlru->lock); 201 118 case LRU_REMOVED: 202 - nlru->nr_items--; 203 - WARN_ON_ONCE(nlru->nr_items < 0); 119 + l->nr_items--; 120 + WARN_ON_ONCE(l->nr_items < 0); 204 121 isolated++; 205 122 /* 206 123 * If the lru lock has been dropped, our list ··· 211 128 goto restart; 212 129 break; 213 130 case LRU_ROTATE: 214 - list_move_tail(item, &nlru->list); 131 + list_move_tail(item, &l->list); 215 132 break; 216 133 case LRU_SKIP: 217 134 break; ··· 230 147 spin_unlock(&nlru->lock); 231 148 return isolated; 232 149 } 150 + 151 + unsigned long 152 + list_lru_walk_one(struct list_lru *lru, int nid, struct mem_cgroup *memcg, 153 + list_lru_walk_cb isolate, void *cb_arg, 154 + unsigned long *nr_to_walk) 155 + { 156 + return __list_lru_walk_one(lru, nid, memcg_cache_id(memcg), 157 + isolate, cb_arg, nr_to_walk); 158 + } 159 + EXPORT_SYMBOL_GPL(list_lru_walk_one); 160 + 161 + unsigned long list_lru_walk_node(struct list_lru *lru, int nid, 162 + list_lru_walk_cb isolate, void *cb_arg, 163 + unsigned long *nr_to_walk) 164 + { 165 + long isolated = 0; 166 + int memcg_idx; 167 + 168 + isolated += __list_lru_walk_one(lru, nid, -1, isolate, cb_arg, 169 + nr_to_walk); 170 + if (*nr_to_walk > 0 && list_lru_memcg_aware(lru)) { 171 + for_each_memcg_cache_index(memcg_idx) { 172 + isolated += __list_lru_walk_one(lru, nid, memcg_idx, 173 + isolate, cb_arg, nr_to_walk); 174 + if (*nr_to_walk <= 0) 175 + break; 176 + } 177 + } 178 + return isolated; 179 + } 233 180 EXPORT_SYMBOL_GPL(list_lru_walk_node); 234 181 235 - int list_lru_init_key(struct list_lru *lru, struct lock_class_key *key) 182 + static void init_one_lru(struct list_lru_one *l) 183 + { 184 + INIT_LIST_HEAD(&l->list); 185 + l->nr_items = 0; 186 + } 187 + 188 + #ifdef CONFIG_MEMCG_KMEM 189 + static void __memcg_destroy_list_lru_node(struct list_lru_memcg *memcg_lrus, 190 + int begin, int end) 191 + { 192 + int i; 193 + 194 + for (i = begin; i < end; i++) 195 + kfree(memcg_lrus->lru[i]); 196 + } 197 + 198 + static int __memcg_init_list_lru_node(struct list_lru_memcg *memcg_lrus, 199 + int begin, int end) 200 + { 201 + int i; 202 + 203 + for (i = begin; i < end; i++) { 204 + struct list_lru_one *l; 205 + 206 + l = kmalloc(sizeof(struct list_lru_one), GFP_KERNEL); 207 + if (!l) 208 + goto fail; 209 + 210 + init_one_lru(l); 211 + memcg_lrus->lru[i] = l; 212 + } 213 + return 0; 214 + fail: 215 + __memcg_destroy_list_lru_node(memcg_lrus, begin, i - 1); 216 + return -ENOMEM; 217 + } 218 + 219 + static int memcg_init_list_lru_node(struct list_lru_node *nlru) 220 + { 221 + int size = memcg_nr_cache_ids; 222 + 223 + nlru->memcg_lrus = kmalloc(size * sizeof(void *), GFP_KERNEL); 224 + if (!nlru->memcg_lrus) 225 + return -ENOMEM; 226 + 227 + if (__memcg_init_list_lru_node(nlru->memcg_lrus, 0, size)) { 228 + kfree(nlru->memcg_lrus); 229 + return -ENOMEM; 230 + } 231 + 232 + return 0; 233 + } 234 + 235 + static void memcg_destroy_list_lru_node(struct list_lru_node *nlru) 236 + { 237 + __memcg_destroy_list_lru_node(nlru->memcg_lrus, 0, memcg_nr_cache_ids); 238 + kfree(nlru->memcg_lrus); 239 + } 240 + 241 + static int memcg_update_list_lru_node(struct list_lru_node *nlru, 242 + int old_size, int new_size) 243 + { 244 + struct list_lru_memcg *old, *new; 245 + 246 + BUG_ON(old_size > new_size); 247 + 248 + old = nlru->memcg_lrus; 249 + new = kmalloc(new_size * sizeof(void *), GFP_KERNEL); 250 + if (!new) 251 + return -ENOMEM; 252 + 253 + if (__memcg_init_list_lru_node(new, old_size, new_size)) { 254 + kfree(new); 255 + return -ENOMEM; 256 + } 257 + 258 + memcpy(new, old, old_size * sizeof(void *)); 259 + 260 + /* 261 + * The lock guarantees that we won't race with a reader 262 + * (see list_lru_from_memcg_idx). 263 + * 264 + * Since list_lru_{add,del} may be called under an IRQ-safe lock, 265 + * we have to use IRQ-safe primitives here to avoid deadlock. 266 + */ 267 + spin_lock_irq(&nlru->lock); 268 + nlru->memcg_lrus = new; 269 + spin_unlock_irq(&nlru->lock); 270 + 271 + kfree(old); 272 + return 0; 273 + } 274 + 275 + static void memcg_cancel_update_list_lru_node(struct list_lru_node *nlru, 276 + int old_size, int new_size) 277 + { 278 + /* do not bother shrinking the array back to the old size, because we 279 + * cannot handle allocation failures here */ 280 + __memcg_destroy_list_lru_node(nlru->memcg_lrus, old_size, new_size); 281 + } 282 + 283 + static int memcg_init_list_lru(struct list_lru *lru, bool memcg_aware) 284 + { 285 + int i; 286 + 287 + for (i = 0; i < nr_node_ids; i++) { 288 + if (!memcg_aware) 289 + lru->node[i].memcg_lrus = NULL; 290 + else if (memcg_init_list_lru_node(&lru->node[i])) 291 + goto fail; 292 + } 293 + return 0; 294 + fail: 295 + for (i = i - 1; i >= 0; i--) 296 + memcg_destroy_list_lru_node(&lru->node[i]); 297 + return -ENOMEM; 298 + } 299 + 300 + static void memcg_destroy_list_lru(struct list_lru *lru) 301 + { 302 + int i; 303 + 304 + if (!list_lru_memcg_aware(lru)) 305 + return; 306 + 307 + for (i = 0; i < nr_node_ids; i++) 308 + memcg_destroy_list_lru_node(&lru->node[i]); 309 + } 310 + 311 + static int memcg_update_list_lru(struct list_lru *lru, 312 + int old_size, int new_size) 313 + { 314 + int i; 315 + 316 + if (!list_lru_memcg_aware(lru)) 317 + return 0; 318 + 319 + for (i = 0; i < nr_node_ids; i++) { 320 + if (memcg_update_list_lru_node(&lru->node[i], 321 + old_size, new_size)) 322 + goto fail; 323 + } 324 + return 0; 325 + fail: 326 + for (i = i - 1; i >= 0; i--) 327 + memcg_cancel_update_list_lru_node(&lru->node[i], 328 + old_size, new_size); 329 + return -ENOMEM; 330 + } 331 + 332 + static void memcg_cancel_update_list_lru(struct list_lru *lru, 333 + int old_size, int new_size) 334 + { 335 + int i; 336 + 337 + if (!list_lru_memcg_aware(lru)) 338 + return; 339 + 340 + for (i = 0; i < nr_node_ids; i++) 341 + memcg_cancel_update_list_lru_node(&lru->node[i], 342 + old_size, new_size); 343 + } 344 + 345 + int memcg_update_all_list_lrus(int new_size) 346 + { 347 + int ret = 0; 348 + struct list_lru *lru; 349 + int old_size = memcg_nr_cache_ids; 350 + 351 + mutex_lock(&list_lrus_mutex); 352 + list_for_each_entry(lru, &list_lrus, list) { 353 + ret = memcg_update_list_lru(lru, old_size, new_size); 354 + if (ret) 355 + goto fail; 356 + } 357 + out: 358 + mutex_unlock(&list_lrus_mutex); 359 + return ret; 360 + fail: 361 + list_for_each_entry_continue_reverse(lru, &list_lrus, list) 362 + memcg_cancel_update_list_lru(lru, old_size, new_size); 363 + goto out; 364 + } 365 + #else 366 + static int memcg_init_list_lru(struct list_lru *lru, bool memcg_aware) 367 + { 368 + return 0; 369 + } 370 + 371 + static void memcg_destroy_list_lru(struct list_lru *lru) 372 + { 373 + } 374 + #endif /* CONFIG_MEMCG_KMEM */ 375 + 376 + int __list_lru_init(struct list_lru *lru, bool memcg_aware, 377 + struct lock_class_key *key) 236 378 { 237 379 int i; 238 380 size_t size = sizeof(*lru->node) * nr_node_ids; 381 + int err = -ENOMEM; 382 + 383 + memcg_get_cache_ids(); 239 384 240 385 lru->node = kzalloc(size, GFP_KERNEL); 241 386 if (!lru->node) 242 - return -ENOMEM; 387 + goto out; 243 388 244 389 for (i = 0; i < nr_node_ids; i++) { 245 390 spin_lock_init(&lru->node[i].lock); 246 391 if (key) 247 392 lockdep_set_class(&lru->node[i].lock, key); 248 - INIT_LIST_HEAD(&lru->node[i].list); 249 - lru->node[i].nr_items = 0; 393 + init_one_lru(&lru->node[i].lru); 250 394 } 395 + 396 + err = memcg_init_list_lru(lru, memcg_aware); 397 + if (err) { 398 + kfree(lru->node); 399 + goto out; 400 + } 401 + 251 402 list_lru_register(lru); 252 - return 0; 403 + out: 404 + memcg_put_cache_ids(); 405 + return err; 253 406 } 254 - EXPORT_SYMBOL_GPL(list_lru_init_key); 407 + EXPORT_SYMBOL_GPL(__list_lru_init); 255 408 256 409 void list_lru_destroy(struct list_lru *lru) 257 410 { 258 411 /* Already destroyed or not yet initialized? */ 259 412 if (!lru->node) 260 413 return; 414 + 415 + memcg_get_cache_ids(); 416 + 261 417 list_lru_unregister(lru); 418 + 419 + memcg_destroy_list_lru(lru); 262 420 kfree(lru->node); 263 421 lru->node = NULL; 422 + 423 + memcg_put_cache_ids(); 264 424 } 265 425 EXPORT_SYMBOL_GPL(list_lru_destroy);
+20
mm/memcontrol.c
··· 2572 2572 2573 2573 err = memcg_update_all_caches(size); 2574 2574 if (!err) 2575 + err = memcg_update_all_list_lrus(size); 2576 + if (!err) 2575 2577 memcg_nr_cache_ids = size; 2576 2578 2577 2579 up_write(&memcg_cache_ids_sem); ··· 2766 2764 2767 2765 memcg_uncharge_kmem(memcg, 1 << order); 2768 2766 page->mem_cgroup = NULL; 2767 + } 2768 + 2769 + struct mem_cgroup *__mem_cgroup_from_kmem(void *ptr) 2770 + { 2771 + struct mem_cgroup *memcg = NULL; 2772 + struct kmem_cache *cachep; 2773 + struct page *page; 2774 + 2775 + page = virt_to_head_page(ptr); 2776 + if (PageSlab(page)) { 2777 + cachep = page->slab_cache; 2778 + if (!is_root_cache(cachep)) 2779 + memcg = cachep->memcg_params->memcg; 2780 + } else 2781 + /* page allocated by alloc_kmem_pages */ 2782 + memcg = page->mem_cgroup; 2783 + 2784 + return memcg; 2769 2785 } 2770 2786 #endif /* CONFIG_MEMCG_KMEM */ 2771 2787