Skip to content

Commit 3eed034

Browse files
netoptimizertorvalds
authored andcommitted
slub: add support for kmem_cache_debug in bulk calls
Per request of Joonsoo Kim adding kmem debug support. I've tested that when debugging is disabled, then there is almost no performance impact as this code basically gets removed by the compiler. Need some guidance in enabling and testing this. bulk- PREVIOUS - THIS-PATCH 1 - 43 cycles(tsc) 10.811 ns - 44 cycles(tsc) 11.236 ns improved -2.3% 2 - 27 cycles(tsc) 6.867 ns - 28 cycles(tsc) 7.019 ns improved -3.7% 3 - 21 cycles(tsc) 5.496 ns - 22 cycles(tsc) 5.526 ns improved -4.8% 4 - 24 cycles(tsc) 6.038 ns - 19 cycles(tsc) 4.786 ns improved 20.8% 8 - 17 cycles(tsc) 4.280 ns - 18 cycles(tsc) 4.572 ns improved -5.9% 16 - 17 cycles(tsc) 4.483 ns - 18 cycles(tsc) 4.658 ns improved -5.9% 30 - 18 cycles(tsc) 4.531 ns - 18 cycles(tsc) 4.568 ns improved 0.0% 32 - 58 cycles(tsc) 14.586 ns - 65 cycles(tsc) 16.454 ns improved -12.1% 34 - 53 cycles(tsc) 13.391 ns - 63 cycles(tsc) 15.932 ns improved -18.9% 48 - 65 cycles(tsc) 16.268 ns - 50 cycles(tsc) 12.506 ns improved 23.1% 64 - 53 cycles(tsc) 13.440 ns - 63 cycles(tsc) 15.929 ns improved -18.9% 128 - 79 cycles(tsc) 19.899 ns - 86 cycles(tsc) 21.583 ns improved -8.9% 158 - 90 cycles(tsc) 22.732 ns - 90 cycles(tsc) 22.552 ns improved 0.0% 250 - 95 cycles(tsc) 23.916 ns - 98 cycles(tsc) 24.589 ns improved -3.2% Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> 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> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent fbd0263 commit 3eed034

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

mm/slub.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,19 +2757,20 @@ void kmem_cache_free_bulk(struct kmem_cache *s, size_t size, void **p)
27572757
struct page *page;
27582758
int i;
27592759

2760-
/* Debugging fallback to generic bulk */
2761-
if (kmem_cache_debug(s))
2762-
return __kmem_cache_free_bulk(s, size, p);
2763-
27642760
local_irq_disable();
27652761
c = this_cpu_ptr(s->cpu_slab);
27662762

27672763
for (i = 0; i < size; i++) {
27682764
void *object = p[i];
27692765

27702766
BUG_ON(!object);
2767+
/* kmem cache debug support */
2768+
s = cache_from_obj(s, object);
2769+
if (unlikely(!s))
2770+
goto exit;
2771+
slab_free_hook(s, object);
2772+
27712773
page = virt_to_head_page(object);
2772-
BUG_ON(s != page->slab_cache); /* Check if valid slab page */
27732774

27742775
if (c->page == page) {
27752776
/* Fastpath: local CPU free */
@@ -2784,6 +2785,7 @@ void kmem_cache_free_bulk(struct kmem_cache *s, size_t size, void **p)
27842785
c = this_cpu_ptr(s->cpu_slab);
27852786
}
27862787
}
2788+
exit:
27872789
c->tid = next_tid(c->tid);
27882790
local_irq_enable();
27892791
}
@@ -2796,10 +2798,6 @@ bool kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
27962798
struct kmem_cache_cpu *c;
27972799
int i;
27982800

2799-
/* Debugging fallback to generic bulk */
2800-
if (kmem_cache_debug(s))
2801-
return __kmem_cache_alloc_bulk(s, flags, size, p);
2802-
28032801
/*
28042802
* Drain objects in the per cpu slab, while disabling local
28052803
* IRQs, which protects against PREEMPT and interrupts
@@ -2828,8 +2826,20 @@ bool kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
28282826
continue; /* goto for-loop */
28292827
}
28302828

2829+
/* kmem_cache debug support */
2830+
s = slab_pre_alloc_hook(s, flags);
2831+
if (unlikely(!s)) {
2832+
__kmem_cache_free_bulk(s, i, p);
2833+
c->tid = next_tid(c->tid);
2834+
local_irq_enable();
2835+
return false;
2836+
}
2837+
28312838
c->freelist = get_freepointer(s, object);
28322839
p[i] = object;
2840+
2841+
/* kmem_cache debug support */
2842+
slab_post_alloc_hook(s, flags, object);
28332843
}
28342844
c->tid = next_tid(c->tid);
28352845
local_irq_enable();

0 commit comments

Comments
 (0)