Skip to content

Commit 8a5b20a

Browse files
JoonsooKimtorvalds
authored andcommitted
slub: fix off by one in number of slab tests
min_partial means minimum number of slab cached in node partial list. So, if nr_partial is less than it, we keep newly empty slab on node partial list rather than freeing it. But if nr_partial is equal or greater than it, it means that we have enough partial slabs so should free newly empty slab. Current implementation missed the equal case so if we set min_partial is 0, then, at least one slab could be cached. This is critical problem to kmemcg destroying logic because it doesn't works properly if some slabs is cached. This patch fixes this problem. Fixes 91cb69620284 ("slub: make dead memcg caches discard free slabs immediately"). Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com> Acked-by: Vladimir Davydov <vdavydov@parallels.com> Cc: Christoph Lameter <cl@linux.com> Cc: Pekka Enberg <penberg@kernel.org> Acked-by: David Rientjes <rientjes@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent dc78327 commit 8a5b20a

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎mm/slub.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
18811881

18821882
new.frozen = 0;
18831883

1884-
if (!new.inuse && n->nr_partial > s->min_partial)
1884+
if (!new.inuse && n->nr_partial >= s->min_partial)
18851885
m = M_FREE;
18861886
else if (new.freelist) {
18871887
m = M_PARTIAL;
@@ -1992,7 +1992,7 @@ static void unfreeze_partials(struct kmem_cache *s,
19921992
new.freelist, new.counters,
19931993
"unfreezing slab"));
19941994

1995-
if (unlikely(!new.inuse && n->nr_partial > s->min_partial)) {
1995+
if (unlikely(!new.inuse && n->nr_partial >= s->min_partial)) {
19961996
page->next = discard_page;
19971997
discard_page = page;
19981998
} else {
@@ -2620,7 +2620,7 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
26202620
return;
26212621
}
26222622

2623-
if (unlikely(!new.inuse && n->nr_partial > s->min_partial))
2623+
if (unlikely(!new.inuse && n->nr_partial >= s->min_partial))
26242624
goto slab_empty;
26252625

26262626
/*

0 commit comments

Comments
 (0)