aboutsummaryrefslogtreecommitdiffstats
path: root/mm/list_lru.c
diff options
context:
space:
mode:
authorVladimir Davydov <vdavydov@parallels.com>2015-02-12 17:59:38 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-12 21:54:10 -0500
commit2788cf0c401c268b4819c5407493a8769b7007aa (patch)
tree863ea244d6908bd6e8149e6cd81270389a9426a8 /mm/list_lru.c
parent3f97b163207c67a3b35931494ad3db1de66356f0 (diff)
memcg: reparent list_lrus and free kmemcg_id on css offline
Now, the only reason to keep kmemcg_id till css free is list_lru, which uses it to distribute elements between per-memcg lists. However, it can be easily sorted out - we only need to change kmemcg_id of an offline cgroup to its parent's id, making further list_lru_add()'s add elements to the parent's list, and then move all elements from the offline cgroup's list to the one of its parent. It will work, because a racing list_lru_del() does not need to know the list it is deleting the element from. It can decrement the wrong nr_items counter though, but the ongoing reparenting will fix it. After list_lru reparenting is done we are free to release kmemcg_id saving a valuable slot in a per-memcg array for new cgroups. Signed-off-by: Vladimir Davydov <vdavydov@parallels.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@suse.cz> Cc: Tejun Heo <tj@kernel.org> 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: Dave Chinner <david@fromorbit.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/list_lru.c')
-rw-r--r--mm/list_lru.c46
1 files changed, 43 insertions, 3 deletions
diff --git a/mm/list_lru.c b/mm/list_lru.c
index 8d9d168c6c38..909eca2c820e 100644
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -100,7 +100,6 @@ bool list_lru_add(struct list_lru *lru, struct list_head *item)
100 100
101 spin_lock(&nlru->lock); 101 spin_lock(&nlru->lock);
102 l = list_lru_from_kmem(nlru, item); 102 l = list_lru_from_kmem(nlru, item);
103 WARN_ON_ONCE(l->nr_items < 0);
104 if (list_empty(item)) { 103 if (list_empty(item)) {
105 list_add_tail(item, &l->list); 104 list_add_tail(item, &l->list);
106 l->nr_items++; 105 l->nr_items++;
@@ -123,7 +122,6 @@ bool list_lru_del(struct list_lru *lru, struct list_head *item)
123 if (!list_empty(item)) { 122 if (!list_empty(item)) {
124 list_del_init(item); 123 list_del_init(item);
125 l->nr_items--; 124 l->nr_items--;
126 WARN_ON_ONCE(l->nr_items < 0);
127 spin_unlock(&nlru->lock); 125 spin_unlock(&nlru->lock);
128 return true; 126 return true;
129 } 127 }
@@ -156,7 +154,6 @@ static unsigned long __list_lru_count_one(struct list_lru *lru,
156 154
157 spin_lock(&nlru->lock); 155 spin_lock(&nlru->lock);
158 l = list_lru_from_memcg_idx(nlru, memcg_idx); 156 l = list_lru_from_memcg_idx(nlru, memcg_idx);
159 WARN_ON_ONCE(l->nr_items < 0);
160 count = l->nr_items; 157 count = l->nr_items;
161 spin_unlock(&nlru->lock); 158 spin_unlock(&nlru->lock);
162 159
@@ -458,6 +455,49 @@ fail:
458 memcg_cancel_update_list_lru(lru, old_size, new_size); 455 memcg_cancel_update_list_lru(lru, old_size, new_size);
459 goto out; 456 goto out;
460} 457}
458
459static void memcg_drain_list_lru_node(struct list_lru_node *nlru,
460 int src_idx, int dst_idx)
461{
462 struct list_lru_one *src, *dst;
463
464 /*
465 * Since list_lru_{add,del} may be called under an IRQ-safe lock,
466 * we have to use IRQ-safe primitives here to avoid deadlock.
467 */
468 spin_lock_irq(&nlru->lock);
469
470 src = list_lru_from_memcg_idx(nlru, src_idx);
471 dst = list_lru_from_memcg_idx(nlru, dst_idx);
472
473 list_splice_init(&src->list, &dst->list);
474 dst->nr_items += src->nr_items;
475 src->nr_items = 0;
476
477 spin_unlock_irq(&nlru->lock);
478}
479
480static void memcg_drain_list_lru(struct list_lru *lru,
481 int src_idx, int dst_idx)
482{
483 int i;
484
485 if (!list_lru_memcg_aware(lru))
486 return;
487
488 for (i = 0; i < nr_node_ids; i++)
489 memcg_drain_list_lru_node(&lru->node[i], src_idx, dst_idx);
490}
491
492void memcg_drain_all_list_lrus(int src_idx, int dst_idx)
493{
494 struct list_lru *lru;
495
496 mutex_lock(&list_lrus_mutex);
497 list_for_each_entry(lru, &list_lrus, list)
498 memcg_drain_list_lru(lru, src_idx, dst_idx);
499 mutex_unlock(&list_lrus_mutex);
500}
461#else 501#else
462static int memcg_init_list_lru(struct list_lru *lru, bool memcg_aware) 502static int memcg_init_list_lru(struct list_lru *lru, bool memcg_aware)
463{ 503{