Skip to content

Commit da4fc00

Browse files
urezkipaulmckrcu
authored andcommitted
lib/test_vmalloc.c: Add test cases for kvfree_rcu()
Introduce four new test cases for testing the kvfree_rcu() interface. Two of them belong to single argument functionality and another two for 2-argument functionality. The aim is to stress and check how kvfree_rcu() behaves under different load and memory conditions and analyze its performance throughput. Reviewed-by: Joel Fernandes (Google) <[email protected]> Signed-off-by: Uladzislau Rezki (Sony) <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 1835f47 commit da4fc00

File tree

1 file changed

+95
-8
lines changed

1 file changed

+95
-8
lines changed

lib/test_vmalloc.c

Lines changed: 95 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <linux/delay.h>
1616
#include <linux/rwsem.h>
1717
#include <linux/mm.h>
18+
#include <linux/rcupdate.h>
19+
#include <linux/slab.h>
1820

1921
#define __param(type, name, init, msg) \
2022
static type name = init; \
@@ -35,14 +37,18 @@ __param(int, test_loop_count, 1000000,
3537

3638
__param(int, run_test_mask, INT_MAX,
3739
"Set tests specified in the mask.\n\n"
38-
"\t\tid: 1, name: fix_size_alloc_test\n"
39-
"\t\tid: 2, name: full_fit_alloc_test\n"
40-
"\t\tid: 4, name: long_busy_list_alloc_test\n"
41-
"\t\tid: 8, name: random_size_alloc_test\n"
42-
"\t\tid: 16, name: fix_align_alloc_test\n"
43-
"\t\tid: 32, name: random_size_align_alloc_test\n"
44-
"\t\tid: 64, name: align_shift_alloc_test\n"
45-
"\t\tid: 128, name: pcpu_alloc_test\n"
40+
"\t\tid: 1, name: fix_size_alloc_test\n"
41+
"\t\tid: 2, name: full_fit_alloc_test\n"
42+
"\t\tid: 4, name: long_busy_list_alloc_test\n"
43+
"\t\tid: 8, name: random_size_alloc_test\n"
44+
"\t\tid: 16, name: fix_align_alloc_test\n"
45+
"\t\tid: 32, name: random_size_align_alloc_test\n"
46+
"\t\tid: 64, name: align_shift_alloc_test\n"
47+
"\t\tid: 128, name: pcpu_alloc_test\n"
48+
"\t\tid: 256, name: kvfree_rcu_1_arg_vmalloc_test\n"
49+
"\t\tid: 512, name: kvfree_rcu_2_arg_vmalloc_test\n"
50+
"\t\tid: 1024, name: kvfree_rcu_1_arg_slab_test\n"
51+
"\t\tid: 2048, name: kvfree_rcu_2_arg_slab_test\n"
4652
/* Add a new test case description here. */
4753
);
4854

@@ -316,6 +322,83 @@ pcpu_alloc_test(void)
316322
return rv;
317323
}
318324

325+
struct test_kvfree_rcu {
326+
struct rcu_head rcu;
327+
unsigned char array[20];
328+
};
329+
330+
static int
331+
kvfree_rcu_1_arg_vmalloc_test(void)
332+
{
333+
struct test_kvfree_rcu *p;
334+
int i;
335+
336+
for (i = 0; i < test_loop_count; i++) {
337+
p = vmalloc(1 * PAGE_SIZE);
338+
if (!p)
339+
return -1;
340+
341+
p->array[0] = 'a';
342+
kvfree_rcu(p);
343+
}
344+
345+
return 0;
346+
}
347+
348+
static int
349+
kvfree_rcu_2_arg_vmalloc_test(void)
350+
{
351+
struct test_kvfree_rcu *p;
352+
int i;
353+
354+
for (i = 0; i < test_loop_count; i++) {
355+
p = vmalloc(1 * PAGE_SIZE);
356+
if (!p)
357+
return -1;
358+
359+
p->array[0] = 'a';
360+
kvfree_rcu(p, rcu);
361+
}
362+
363+
return 0;
364+
}
365+
366+
static int
367+
kvfree_rcu_1_arg_slab_test(void)
368+
{
369+
struct test_kvfree_rcu *p;
370+
int i;
371+
372+
for (i = 0; i < test_loop_count; i++) {
373+
p = kmalloc(sizeof(*p), GFP_KERNEL);
374+
if (!p)
375+
return -1;
376+
377+
p->array[0] = 'a';
378+
kvfree_rcu(p);
379+
}
380+
381+
return 0;
382+
}
383+
384+
static int
385+
kvfree_rcu_2_arg_slab_test(void)
386+
{
387+
struct test_kvfree_rcu *p;
388+
int i;
389+
390+
for (i = 0; i < test_loop_count; i++) {
391+
p = kmalloc(sizeof(*p), GFP_KERNEL);
392+
if (!p)
393+
return -1;
394+
395+
p->array[0] = 'a';
396+
kvfree_rcu(p, rcu);
397+
}
398+
399+
return 0;
400+
}
401+
319402
struct test_case_desc {
320403
const char *test_name;
321404
int (*test_func)(void);
@@ -330,6 +413,10 @@ static struct test_case_desc test_case_array[] = {
330413
{ "random_size_align_alloc_test", random_size_align_alloc_test },
331414
{ "align_shift_alloc_test", align_shift_alloc_test },
332415
{ "pcpu_alloc_test", pcpu_alloc_test },
416+
{ "kvfree_rcu_1_arg_vmalloc_test", kvfree_rcu_1_arg_vmalloc_test },
417+
{ "kvfree_rcu_2_arg_vmalloc_test", kvfree_rcu_2_arg_vmalloc_test },
418+
{ "kvfree_rcu_1_arg_slab_test", kvfree_rcu_1_arg_slab_test },
419+
{ "kvfree_rcu_2_arg_slab_test", kvfree_rcu_2_arg_slab_test },
333420
/* Add a new test case here. */
334421
};
335422

0 commit comments

Comments
 (0)