@@ -72,8 +72,6 @@ struct thread_data {
72
72
struct test_obj * objs ;
73
73
};
74
74
75
- static struct test_obj array [MAX_ENTRIES ];
76
-
77
75
static struct rhashtable_params test_rht_params = {
78
76
.head_offset = offsetof(struct test_obj , node ),
79
77
.key_offset = offsetof(struct test_obj , value ),
@@ -85,15 +83,15 @@ static struct rhashtable_params test_rht_params = {
85
83
static struct semaphore prestart_sem ;
86
84
static struct semaphore startup_sem = __SEMAPHORE_INITIALIZER (startup_sem , 0 );
87
85
88
- static int insert_retry (struct rhashtable * ht , struct rhash_head * obj ,
86
+ static int insert_retry (struct rhashtable * ht , struct test_obj * obj ,
89
87
const struct rhashtable_params params )
90
88
{
91
89
int err , retries = -1 , enomem_retries = 0 ;
92
90
93
91
do {
94
92
retries ++ ;
95
93
cond_resched ();
96
- err = rhashtable_insert_fast (ht , obj , params );
94
+ err = rhashtable_insert_fast (ht , & obj -> node , params );
97
95
if (err == - ENOMEM && enomem_retry ) {
98
96
enomem_retries ++ ;
99
97
err = - EBUSY ;
@@ -107,7 +105,7 @@ static int insert_retry(struct rhashtable *ht, struct rhash_head *obj,
107
105
return err ? : retries ;
108
106
}
109
107
110
- static int __init test_rht_lookup (struct rhashtable * ht )
108
+ static int __init test_rht_lookup (struct rhashtable * ht , struct test_obj * array )
111
109
{
112
110
unsigned int i ;
113
111
@@ -186,7 +184,7 @@ static void test_bucket_stats(struct rhashtable *ht)
186
184
pr_warn ("Test failed: Total count mismatch ^^^" );
187
185
}
188
186
189
- static s64 __init test_rhashtable (struct rhashtable * ht )
187
+ static s64 __init test_rhashtable (struct rhashtable * ht , struct test_obj * array )
190
188
{
191
189
struct test_obj * obj ;
192
190
int err ;
@@ -203,7 +201,7 @@ static s64 __init test_rhashtable(struct rhashtable *ht)
203
201
struct test_obj * obj = & array [i ];
204
202
205
203
obj -> value .id = i * 2 ;
206
- err = insert_retry (ht , & obj -> node , test_rht_params );
204
+ err = insert_retry (ht , obj , test_rht_params );
207
205
if (err > 0 )
208
206
insert_retries += err ;
209
207
else if (err )
@@ -216,7 +214,7 @@ static s64 __init test_rhashtable(struct rhashtable *ht)
216
214
217
215
test_bucket_stats (ht );
218
216
rcu_read_lock ();
219
- test_rht_lookup (ht );
217
+ test_rht_lookup (ht , array );
220
218
rcu_read_unlock ();
221
219
222
220
test_bucket_stats (ht );
@@ -286,7 +284,7 @@ static int threadfunc(void *data)
286
284
for (i = 0 ; i < entries ; i ++ ) {
287
285
tdata -> objs [i ].value .id = i ;
288
286
tdata -> objs [i ].value .tid = tdata -> id ;
289
- err = insert_retry (& ht , & tdata -> objs [i ]. node , test_rht_params );
287
+ err = insert_retry (& ht , & tdata -> objs [i ], test_rht_params );
290
288
if (err > 0 ) {
291
289
insert_retries += err ;
292
290
} else if (err ) {
@@ -349,31 +347,38 @@ static int __init test_rht_init(void)
349
347
test_rht_params .max_size = max_size ? : roundup_pow_of_two (entries );
350
348
test_rht_params .nelem_hint = size ;
351
349
350
+ objs = vzalloc ((test_rht_params .max_size + 1 ) * sizeof (struct test_obj ));
351
+ if (!objs )
352
+ return - ENOMEM ;
353
+
352
354
pr_info ("Running rhashtable test nelem=%d, max_size=%d, shrinking=%d\n" ,
353
355
size , max_size , shrinking );
354
356
355
357
for (i = 0 ; i < runs ; i ++ ) {
356
358
s64 time ;
357
359
358
360
pr_info ("Test %02d:\n" , i );
359
- memset (& array , 0 , sizeof (array ));
361
+ memset (objs , 0 , test_rht_params .max_size * sizeof (struct test_obj ));
362
+
360
363
err = rhashtable_init (& ht , & test_rht_params );
361
364
if (err < 0 ) {
362
365
pr_warn ("Test failed: Unable to initialize hashtable: %d\n" ,
363
366
err );
364
367
continue ;
365
368
}
366
369
367
- time = test_rhashtable (& ht );
370
+ time = test_rhashtable (& ht , objs );
368
371
rhashtable_destroy (& ht );
369
372
if (time < 0 ) {
373
+ vfree (objs );
370
374
pr_warn ("Test failed: return code %lld\n" , time );
371
375
return - EINVAL ;
372
376
}
373
377
374
378
total_time += time ;
375
379
}
376
380
381
+ vfree (objs );
377
382
do_div (total_time , runs );
378
383
pr_info ("Average test time: %llu\n" , total_time );
379
384
0 commit comments