Skip to content

Commit dc5c5ad

Browse files
labbotttorvalds
authored andcommitted
lib/test_meminit.c: add bulk alloc/free tests
kmem_cache_alloc_bulk/kmem_cache_free_bulk are used to make multiple allocations of the same size to avoid the overhead of multiple kmalloc/kfree calls. Extend the kmem_cache tests to make some calls to these APIs. Link: http://lkml.kernel.org/r/20191107191447.23058-1-labbott@redhat.com Signed-off-by: Laura Abbott <labbott@redhat.com> Reviewed-by: Kees Cook <keescook@chromium.org> Tested-by: Alexander Potapenko <glider@google.com> Cc: Laura Abbott <labbott@redhat.com> Cc: Christoph Lameter <cl@linux.com> Cc: Nick Desaulniers <ndesaulniers@google.com> Cc: Kostya Serebryany <kcc@google.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Sandeep Patil <sspatil@android.com> Cc: Jann Horn <jannh@google.com> Cc: Marco Elver <elver@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8b7569a commit dc5c5ad

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎lib/test_meminit.c‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ static bool __init check_buf(void *buf, int size, bool want_ctor,
183183
return fail;
184184
}
185185

186+
#define BULK_SIZE 100
187+
static void *bulk_array[BULK_SIZE];
188+
186189
/*
187190
* Test kmem_cache with given parameters:
188191
* want_ctor - use a constructor;
@@ -203,9 +206,24 @@ static int __init do_kmem_cache_size(size_t size, bool want_ctor,
203206
want_rcu ? SLAB_TYPESAFE_BY_RCU : 0,
204207
want_ctor ? test_ctor : NULL);
205208
for (iter = 0; iter < 10; iter++) {
209+
/* Do a test of bulk allocations */
210+
if (!want_rcu && !want_ctor) {
211+
int ret;
212+
213+
ret = kmem_cache_alloc_bulk(c, alloc_mask, BULK_SIZE, bulk_array);
214+
if (!ret) {
215+
fail = true;
216+
} else {
217+
int i;
218+
for (i = 0; i < ret; i++)
219+
fail |= check_buf(bulk_array[i], size, want_ctor, want_rcu, want_zero);
220+
kmem_cache_free_bulk(c, ret, bulk_array);
221+
}
222+
}
223+
206224
buf = kmem_cache_alloc(c, alloc_mask);
207225
/* Check that buf is zeroed, if it must be. */
208-
fail = check_buf(buf, size, want_ctor, want_rcu, want_zero);
226+
fail |= check_buf(buf, size, want_ctor, want_rcu, want_zero);
209227
fill_with_garbage_skip(buf, size, want_ctor ? CTOR_BYTES : 0);
210228

211229
if (!want_rcu) {

0 commit comments

Comments
 (0)