diff options
author | Vladimir Davydov <vdavydov.dev@gmail.com> | 2016-12-12 19:41:29 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-04-21 03:31:23 -0400 |
commit | 754ae7efb383690785265c8e9b032fda63be00ce (patch) | |
tree | 78f3b450fcab4641dd4426bc62ccd1e67da2baf0 /mm | |
parent | b1574caf96642113d1507ec637cc986acc4b61af (diff) |
mm: memcontrol: use special workqueue for creating per-memcg caches
commit 13583c3d3224508582ec03d881d0b68dd3ee8e10 upstream.
Creating a lot of cgroups at the same time might stall all worker
threads with kmem cache creation works, because kmem cache creation is
done with the slab_mutex held. The problem was amplified by commits
801faf0db894 ("mm/slab: lockless decision to grow cache") in case of
SLAB and 81ae6d03952c ("mm/slub.c: replace kick_all_cpus_sync() with
synchronize_sched() in kmem_cache_shrink()") in case of SLUB, which
increased the maximal time the slab_mutex can be held.
To prevent that from happening, let's use a special ordered single
threaded workqueue for kmem cache creation. This shouldn't introduce
any functional changes regarding how kmem caches are created, as the
work function holds the global slab_mutex during its whole runtime
anyway, making it impossible to run more than one work at a time. By
using a single threaded workqueue, we just avoid creating a thread per
each work. Ordering is required to avoid a situation when a cgroup's
work is put off indefinitely because there are other cgroups to serve,
in other words to guarantee fairness.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=172981
Link: http://lkml.kernel.org/r/20161004131417.GC1862@esperanza
Signed-off-by: Vladimir Davydov <vdavydov.dev@gmail.com>
Reported-by: Doug Smythies <dsmythies@telus.net>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/memcontrol.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 0de26691f0f5..47559cc0cdcc 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -2152,6 +2152,8 @@ struct memcg_kmem_cache_create_work { | |||
2152 | struct work_struct work; | 2152 | struct work_struct work; |
2153 | }; | 2153 | }; |
2154 | 2154 | ||
2155 | static struct workqueue_struct *memcg_kmem_cache_create_wq; | ||
2156 | |||
2155 | static void memcg_kmem_cache_create_func(struct work_struct *w) | 2157 | static void memcg_kmem_cache_create_func(struct work_struct *w) |
2156 | { | 2158 | { |
2157 | struct memcg_kmem_cache_create_work *cw = | 2159 | struct memcg_kmem_cache_create_work *cw = |
@@ -2183,7 +2185,7 @@ static void __memcg_schedule_kmem_cache_create(struct mem_cgroup *memcg, | |||
2183 | cw->cachep = cachep; | 2185 | cw->cachep = cachep; |
2184 | INIT_WORK(&cw->work, memcg_kmem_cache_create_func); | 2186 | INIT_WORK(&cw->work, memcg_kmem_cache_create_func); |
2185 | 2187 | ||
2186 | schedule_work(&cw->work); | 2188 | queue_work(memcg_kmem_cache_create_wq, &cw->work); |
2187 | } | 2189 | } |
2188 | 2190 | ||
2189 | static void memcg_schedule_kmem_cache_create(struct mem_cgroup *memcg, | 2191 | static void memcg_schedule_kmem_cache_create(struct mem_cgroup *memcg, |
@@ -5786,6 +5788,17 @@ static int __init mem_cgroup_init(void) | |||
5786 | { | 5788 | { |
5787 | int cpu, node; | 5789 | int cpu, node; |
5788 | 5790 | ||
5791 | #ifndef CONFIG_SLOB | ||
5792 | /* | ||
5793 | * Kmem cache creation is mostly done with the slab_mutex held, | ||
5794 | * so use a special workqueue to avoid stalling all worker | ||
5795 | * threads in case lots of cgroups are created simultaneously. | ||
5796 | */ | ||
5797 | memcg_kmem_cache_create_wq = | ||
5798 | alloc_ordered_workqueue("memcg_kmem_cache_create", 0); | ||
5799 | BUG_ON(!memcg_kmem_cache_create_wq); | ||
5800 | #endif | ||
5801 | |||
5789 | hotcpu_notifier(memcg_cpu_hotplug_callback, 0); | 5802 | hotcpu_notifier(memcg_cpu_hotplug_callback, 0); |
5790 | 5803 | ||
5791 | for_each_possible_cpu(cpu) | 5804 | for_each_possible_cpu(cpu) |