summaryrefslogtreecommitdiff
path: root/mm/slub.c
diff options
context:
space:
mode:
authorVladimir Davydov <vdavydov@parallels.com>2014-07-10 10:25:31 +1000
committerStephen Rothwell <sfr@canb.auug.org.au>2014-07-10 10:25:31 +1000
commit42f01560b64a26b4d662cc441310d3c96555ca04 (patch)
treec643d19183a1659e24fddf9589b93c83e619c929 /mm/slub.c
parentecb4bcdcf3751d17dc200ac2a8d6c1a390131b93 (diff)
slub: don't fail kmem_cache_shrink if slab placement optimization fails
SLUB's kmem_cache_shrink not only removes empty slabs from the cache, but also sorts slabs by the number of objects in-use to cope with fragmentation. To achieve that, it tries to allocate a temporary array. If it fails, it will abort the whole procedure. This is unacceptable for kmemcg, where we want to be sure that all empty slabs are removed from the cache on memcg offline, so let's just skip the slab placement optimization step if the allocation fails, but still get rid of empty slabs. Signed-off-by: Vladimir Davydov <vdavydov@parallels.com> Acked-by: Christoph Lameter <cl@linux.com> Cc: Michal Hocko <mhocko@suse.cz> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Pekka Enberg <penberg@kernel.org> Cc: David Rientjes <rientjes@google.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm/slub.c')
-rw-r--r--mm/slub.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/mm/slub.c b/mm/slub.c
index 92d8139c556d..d4130db7c918 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3367,12 +3367,20 @@ int __kmem_cache_shrink(struct kmem_cache *s)
struct page *page;
struct page *t;
int objects = oo_objects(s->max);
+ struct list_head empty_slabs;
struct list_head *slabs_by_inuse =
kmalloc(sizeof(struct list_head) * objects, GFP_KERNEL);
unsigned long flags;
- if (!slabs_by_inuse)
- return -ENOMEM;
+ if (!slabs_by_inuse) {
+ /*
+ * Do not fail shrinking empty slabs if allocation of the
+ * temporary array failed. Just skip the slab placement
+ * optimization then.
+ */
+ slabs_by_inuse = &empty_slabs;
+ objects = 1;
+ }
flush_all(s);
for_each_kmem_cache_node(s, node, n) {
@@ -3391,7 +3399,9 @@ int __kmem_cache_shrink(struct kmem_cache *s)
* list_lock. page->inuse here is the upper limit.
*/
list_for_each_entry_safe(page, t, &n->partial, lru) {
- list_move(&page->lru, slabs_by_inuse + page->inuse);
+ if (page->inuse < objects)
+ list_move(&page->lru,
+ slabs_by_inuse + page->inuse);
if (!page->inuse)
n->nr_partial--;
}
@@ -3410,7 +3420,8 @@ int __kmem_cache_shrink(struct kmem_cache *s)
discard_slab(s, page);
}
- kfree(slabs_by_inuse);
+ if (slabs_by_inuse != &empty_slabs)
+ kfree(slabs_by_inuse);
return 0;
}