~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/lib/test_vmalloc.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /lib/test_vmalloc.c (Version linux-6.11-rc3) and /lib/test_vmalloc.c (Version linux-6.3.13)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2                                                     2 
  3 /*                                                  3 /*
  4  * Test module for stress and analyze performa      4  * Test module for stress and analyze performance of vmalloc allocator.
  5  * (C) 2018 Uladzislau Rezki (Sony) <urezki@gm      5  * (C) 2018 Uladzislau Rezki (Sony) <urezki@gmail.com>
  6  */                                                 6  */
  7 #include <linux/init.h>                             7 #include <linux/init.h>
  8 #include <linux/kernel.h>                           8 #include <linux/kernel.h>
  9 #include <linux/module.h>                           9 #include <linux/module.h>
 10 #include <linux/vmalloc.h>                         10 #include <linux/vmalloc.h>
 11 #include <linux/random.h>                          11 #include <linux/random.h>
 12 #include <linux/kthread.h>                         12 #include <linux/kthread.h>
 13 #include <linux/moduleparam.h>                     13 #include <linux/moduleparam.h>
 14 #include <linux/completion.h>                      14 #include <linux/completion.h>
 15 #include <linux/delay.h>                           15 #include <linux/delay.h>
 16 #include <linux/rwsem.h>                           16 #include <linux/rwsem.h>
 17 #include <linux/mm.h>                              17 #include <linux/mm.h>
 18 #include <linux/rcupdate.h>                        18 #include <linux/rcupdate.h>
 19 #include <linux/slab.h>                            19 #include <linux/slab.h>
 20                                                    20 
 21 #define __param(type, name, init, msg)             21 #define __param(type, name, init, msg)          \
 22         static type name = init;                   22         static type name = init;                                \
 23         module_param(name, type, 0444);            23         module_param(name, type, 0444);                 \
 24         MODULE_PARM_DESC(name, msg)                24         MODULE_PARM_DESC(name, msg)                             \
 25                                                    25 
 26 __param(int, nr_threads, 0,                        26 __param(int, nr_threads, 0,
 27         "Number of workers to perform tests(mi     27         "Number of workers to perform tests(min: 1 max: USHRT_MAX)");
 28                                                    28 
 29 __param(bool, sequential_test_order, false,        29 __param(bool, sequential_test_order, false,
 30         "Use sequential stress tests order");      30         "Use sequential stress tests order");
 31                                                    31 
 32 __param(int, test_repeat_count, 1,                 32 __param(int, test_repeat_count, 1,
 33         "Set test repeat counter");                33         "Set test repeat counter");
 34                                                    34 
 35 __param(int, test_loop_count, 1000000,             35 __param(int, test_loop_count, 1000000,
 36         "Set test loop counter");                  36         "Set test loop counter");
 37                                                    37 
 38 __param(int, nr_pages, 0,                          38 __param(int, nr_pages, 0,
 39         "Set number of pages for fix_size_allo     39         "Set number of pages for fix_size_alloc_test(default: 1)");
 40                                                    40 
 41 __param(bool, use_huge, false,                     41 __param(bool, use_huge, false,
 42         "Use vmalloc_huge in fix_size_alloc_te     42         "Use vmalloc_huge in fix_size_alloc_test");
 43                                                    43 
 44 __param(int, run_test_mask, INT_MAX,               44 __param(int, run_test_mask, INT_MAX,
 45         "Set tests specified in the mask.\n\n"     45         "Set tests specified in the mask.\n\n"
 46                 "\t\tid: 1,    name: fix_size_     46                 "\t\tid: 1,    name: fix_size_alloc_test\n"
 47                 "\t\tid: 2,    name: full_fit_     47                 "\t\tid: 2,    name: full_fit_alloc_test\n"
 48                 "\t\tid: 4,    name: long_busy     48                 "\t\tid: 4,    name: long_busy_list_alloc_test\n"
 49                 "\t\tid: 8,    name: random_si     49                 "\t\tid: 8,    name: random_size_alloc_test\n"
 50                 "\t\tid: 16,   name: fix_align     50                 "\t\tid: 16,   name: fix_align_alloc_test\n"
 51                 "\t\tid: 32,   name: random_si     51                 "\t\tid: 32,   name: random_size_align_alloc_test\n"
 52                 "\t\tid: 64,   name: align_shi     52                 "\t\tid: 64,   name: align_shift_alloc_test\n"
 53                 "\t\tid: 128,  name: pcpu_allo     53                 "\t\tid: 128,  name: pcpu_alloc_test\n"
 54                 "\t\tid: 256,  name: kvfree_rc     54                 "\t\tid: 256,  name: kvfree_rcu_1_arg_vmalloc_test\n"
 55                 "\t\tid: 512,  name: kvfree_rc     55                 "\t\tid: 512,  name: kvfree_rcu_2_arg_vmalloc_test\n"
 56                 "\t\tid: 1024, name: vm_map_ra << 
 57                 /* Add a new test case descrip     56                 /* Add a new test case description here. */
 58 );                                                 57 );
 59                                                    58 
 60 /*                                                 59 /*
 61  * Read write semaphore for synchronization of     60  * Read write semaphore for synchronization of setup
 62  * phase that is done in main thread and worke     61  * phase that is done in main thread and workers.
 63  */                                                62  */
 64 static DECLARE_RWSEM(prepare_for_test_rwsem);      63 static DECLARE_RWSEM(prepare_for_test_rwsem);
 65                                                    64 
 66 /*                                                 65 /*
 67  * Completion tracking for worker threads.         66  * Completion tracking for worker threads.
 68  */                                                67  */
 69 static DECLARE_COMPLETION(test_all_done_comp);     68 static DECLARE_COMPLETION(test_all_done_comp);
 70 static atomic_t test_n_undone = ATOMIC_INIT(0)     69 static atomic_t test_n_undone = ATOMIC_INIT(0);
 71                                                    70 
 72 static inline void                                 71 static inline void
 73 test_report_one_done(void)                         72 test_report_one_done(void)
 74 {                                                  73 {
 75         if (atomic_dec_and_test(&test_n_undone     74         if (atomic_dec_and_test(&test_n_undone))
 76                 complete(&test_all_done_comp);     75                 complete(&test_all_done_comp);
 77 }                                                  76 }
 78                                                    77 
 79 static int random_size_align_alloc_test(void)      78 static int random_size_align_alloc_test(void)
 80 {                                                  79 {
 81         unsigned long size, align;                 80         unsigned long size, align;
 82         unsigned int rnd;                          81         unsigned int rnd;
 83         void *ptr;                                 82         void *ptr;
 84         int i;                                     83         int i;
 85                                                    84 
 86         for (i = 0; i < test_loop_count; i++)      85         for (i = 0; i < test_loop_count; i++) {
 87                 rnd = get_random_u8();             86                 rnd = get_random_u8();
 88                                                    87 
 89                 /*                                 88                 /*
 90                  * Maximum 1024 pages, if PAGE     89                  * Maximum 1024 pages, if PAGE_SIZE is 4096.
 91                  */                                90                  */
 92                 align = 1 << (rnd % 23);           91                 align = 1 << (rnd % 23);
 93                                                    92 
 94                 /*                                 93                 /*
 95                  * Maximum 10 pages.               94                  * Maximum 10 pages.
 96                  */                                95                  */
 97                 size = ((rnd % 10) + 1) * PAGE     96                 size = ((rnd % 10) + 1) * PAGE_SIZE;
 98                                                    97 
 99                 ptr = __vmalloc_node(size, ali     98                 ptr = __vmalloc_node(size, align, GFP_KERNEL | __GFP_ZERO, 0,
100                                 __builtin_retu     99                                 __builtin_return_address(0));
101                 if (!ptr)                         100                 if (!ptr)
102                         return -1;                101                         return -1;
103                                                   102 
104                 vfree(ptr);                       103                 vfree(ptr);
105         }                                         104         }
106                                                   105 
107         return 0;                                 106         return 0;
108 }                                                 107 }
109                                                   108 
110 /*                                                109 /*
111  * This test case is supposed to be failed.       110  * This test case is supposed to be failed.
112  */                                               111  */
113 static int align_shift_alloc_test(void)           112 static int align_shift_alloc_test(void)
114 {                                                 113 {
115         unsigned long align;                      114         unsigned long align;
116         void *ptr;                                115         void *ptr;
117         int i;                                    116         int i;
118                                                   117 
119         for (i = 0; i < BITS_PER_LONG; i++) {     118         for (i = 0; i < BITS_PER_LONG; i++) {
120                 align = 1UL << i;              !! 119                 align = ((unsigned long) 1) << i;
121                                                   120 
122                 ptr = __vmalloc_node(PAGE_SIZE    121                 ptr = __vmalloc_node(PAGE_SIZE, align, GFP_KERNEL|__GFP_ZERO, 0,
123                                 __builtin_retu    122                                 __builtin_return_address(0));
124                 if (!ptr)                         123                 if (!ptr)
125                         return -1;                124                         return -1;
126                                                   125 
127                 vfree(ptr);                       126                 vfree(ptr);
128         }                                         127         }
129                                                   128 
130         return 0;                                 129         return 0;
131 }                                                 130 }
132                                                   131 
133 static int fix_align_alloc_test(void)             132 static int fix_align_alloc_test(void)
134 {                                                 133 {
135         void *ptr;                                134         void *ptr;
136         int i;                                    135         int i;
137                                                   136 
138         for (i = 0; i < test_loop_count; i++)     137         for (i = 0; i < test_loop_count; i++) {
139                 ptr = __vmalloc_node(5 * PAGE_    138                 ptr = __vmalloc_node(5 * PAGE_SIZE, THREAD_ALIGN << 1,
140                                 GFP_KERNEL | _    139                                 GFP_KERNEL | __GFP_ZERO, 0,
141                                 __builtin_retu    140                                 __builtin_return_address(0));
142                 if (!ptr)                         141                 if (!ptr)
143                         return -1;                142                         return -1;
144                                                   143 
145                 vfree(ptr);                       144                 vfree(ptr);
146         }                                         145         }
147                                                   146 
148         return 0;                                 147         return 0;
149 }                                                 148 }
150                                                   149 
151 static int random_size_alloc_test(void)           150 static int random_size_alloc_test(void)
152 {                                                 151 {
153         unsigned int n;                           152         unsigned int n;
154         void *p;                                  153         void *p;
155         int i;                                    154         int i;
156                                                   155 
157         for (i = 0; i < test_loop_count; i++)     156         for (i = 0; i < test_loop_count; i++) {
158                 n = get_random_u32_inclusive(1    157                 n = get_random_u32_inclusive(1, 100);
159                 p = vmalloc(n * PAGE_SIZE);       158                 p = vmalloc(n * PAGE_SIZE);
160                                                   159 
161                 if (!p)                           160                 if (!p)
162                         return -1;                161                         return -1;
163                                                   162 
164                 *((__u8 *)p) = 1;                 163                 *((__u8 *)p) = 1;
165                 vfree(p);                         164                 vfree(p);
166         }                                         165         }
167                                                   166 
168         return 0;                                 167         return 0;
169 }                                                 168 }
170                                                   169 
171 static int long_busy_list_alloc_test(void)        170 static int long_busy_list_alloc_test(void)
172 {                                                 171 {
173         void *ptr_1, *ptr_2;                      172         void *ptr_1, *ptr_2;
174         void **ptr;                               173         void **ptr;
175         int rv = -1;                              174         int rv = -1;
176         int i;                                    175         int i;
177                                                   176 
178         ptr = vmalloc(sizeof(void *) * 15000);    177         ptr = vmalloc(sizeof(void *) * 15000);
179         if (!ptr)                                 178         if (!ptr)
180                 return rv;                        179                 return rv;
181                                                   180 
182         for (i = 0; i < 15000; i++)               181         for (i = 0; i < 15000; i++)
183                 ptr[i] = vmalloc(1 * PAGE_SIZE    182                 ptr[i] = vmalloc(1 * PAGE_SIZE);
184                                                   183 
185         for (i = 0; i < test_loop_count; i++)     184         for (i = 0; i < test_loop_count; i++) {
186                 ptr_1 = vmalloc(100 * PAGE_SIZ    185                 ptr_1 = vmalloc(100 * PAGE_SIZE);
187                 if (!ptr_1)                       186                 if (!ptr_1)
188                         goto leave;               187                         goto leave;
189                                                   188 
190                 ptr_2 = vmalloc(1 * PAGE_SIZE)    189                 ptr_2 = vmalloc(1 * PAGE_SIZE);
191                 if (!ptr_2) {                     190                 if (!ptr_2) {
192                         vfree(ptr_1);             191                         vfree(ptr_1);
193                         goto leave;               192                         goto leave;
194                 }                                 193                 }
195                                                   194 
196                 *((__u8 *)ptr_1) = 0;             195                 *((__u8 *)ptr_1) = 0;
197                 *((__u8 *)ptr_2) = 1;             196                 *((__u8 *)ptr_2) = 1;
198                                                   197 
199                 vfree(ptr_1);                     198                 vfree(ptr_1);
200                 vfree(ptr_2);                     199                 vfree(ptr_2);
201         }                                         200         }
202                                                   201 
203         /*  Success */                            202         /*  Success */
204         rv = 0;                                   203         rv = 0;
205                                                   204 
206 leave:                                            205 leave:
207         for (i = 0; i < 15000; i++)               206         for (i = 0; i < 15000; i++)
208                 vfree(ptr[i]);                    207                 vfree(ptr[i]);
209                                                   208 
210         vfree(ptr);                               209         vfree(ptr);
211         return rv;                                210         return rv;
212 }                                                 211 }
213                                                   212 
214 static int full_fit_alloc_test(void)              213 static int full_fit_alloc_test(void)
215 {                                                 214 {
216         void **ptr, **junk_ptr, *tmp;             215         void **ptr, **junk_ptr, *tmp;
217         int junk_length;                          216         int junk_length;
218         int rv = -1;                              217         int rv = -1;
219         int i;                                    218         int i;
220                                                   219 
221         junk_length = fls(num_online_cpus());     220         junk_length = fls(num_online_cpus());
222         junk_length *= (32 * 1024 * 1024 / PAG    221         junk_length *= (32 * 1024 * 1024 / PAGE_SIZE);
223                                                   222 
224         ptr = vmalloc(sizeof(void *) * junk_le    223         ptr = vmalloc(sizeof(void *) * junk_length);
225         if (!ptr)                                 224         if (!ptr)
226                 return rv;                        225                 return rv;
227                                                   226 
228         junk_ptr = vmalloc(sizeof(void *) * ju    227         junk_ptr = vmalloc(sizeof(void *) * junk_length);
229         if (!junk_ptr) {                          228         if (!junk_ptr) {
230                 vfree(ptr);                       229                 vfree(ptr);
231                 return rv;                        230                 return rv;
232         }                                         231         }
233                                                   232 
234         for (i = 0; i < junk_length; i++) {       233         for (i = 0; i < junk_length; i++) {
235                 ptr[i] = vmalloc(1 * PAGE_SIZE    234                 ptr[i] = vmalloc(1 * PAGE_SIZE);
236                 junk_ptr[i] = vmalloc(1 * PAGE    235                 junk_ptr[i] = vmalloc(1 * PAGE_SIZE);
237         }                                         236         }
238                                                   237 
239         for (i = 0; i < junk_length; i++)         238         for (i = 0; i < junk_length; i++)
240                 vfree(junk_ptr[i]);               239                 vfree(junk_ptr[i]);
241                                                   240 
242         for (i = 0; i < test_loop_count; i++)     241         for (i = 0; i < test_loop_count; i++) {
243                 tmp = vmalloc(1 * PAGE_SIZE);     242                 tmp = vmalloc(1 * PAGE_SIZE);
244                                                   243 
245                 if (!tmp)                         244                 if (!tmp)
246                         goto error;               245                         goto error;
247                                                   246 
248                 *((__u8 *)tmp) = 1;               247                 *((__u8 *)tmp) = 1;
249                 vfree(tmp);                       248                 vfree(tmp);
250         }                                         249         }
251                                                   250 
252         /* Success */                             251         /* Success */
253         rv = 0;                                   252         rv = 0;
254                                                   253 
255 error:                                            254 error:
256         for (i = 0; i < junk_length; i++)         255         for (i = 0; i < junk_length; i++)
257                 vfree(ptr[i]);                    256                 vfree(ptr[i]);
258                                                   257 
259         vfree(ptr);                               258         vfree(ptr);
260         vfree(junk_ptr);                          259         vfree(junk_ptr);
261                                                   260 
262         return rv;                                261         return rv;
263 }                                                 262 }
264                                                   263 
265 static int fix_size_alloc_test(void)              264 static int fix_size_alloc_test(void)
266 {                                                 265 {
267         void *ptr;                                266         void *ptr;
268         int i;                                    267         int i;
269                                                   268 
270         for (i = 0; i < test_loop_count; i++)     269         for (i = 0; i < test_loop_count; i++) {
271                 if (use_huge)                     270                 if (use_huge)
272                         ptr = vmalloc_huge((nr    271                         ptr = vmalloc_huge((nr_pages > 0 ? nr_pages:1) * PAGE_SIZE, GFP_KERNEL);
273                 else                              272                 else
274                         ptr = vmalloc((nr_page    273                         ptr = vmalloc((nr_pages > 0 ? nr_pages:1) * PAGE_SIZE);
275                                                   274 
276                 if (!ptr)                         275                 if (!ptr)
277                         return -1;                276                         return -1;
278                                                   277 
279                 *((__u8 *)ptr) = 0;               278                 *((__u8 *)ptr) = 0;
280                                                   279 
281                 vfree(ptr);                       280                 vfree(ptr);
282         }                                         281         }
283                                                   282 
284         return 0;                                 283         return 0;
285 }                                                 284 }
286                                                   285 
287 static int                                        286 static int
288 pcpu_alloc_test(void)                             287 pcpu_alloc_test(void)
289 {                                                 288 {
290         int rv = 0;                               289         int rv = 0;
291 #ifndef CONFIG_NEED_PER_CPU_KM                    290 #ifndef CONFIG_NEED_PER_CPU_KM
292         void __percpu **pcpu;                     291         void __percpu **pcpu;
293         size_t size, align;                       292         size_t size, align;
294         int i;                                    293         int i;
295                                                   294 
296         pcpu = vmalloc(sizeof(void __percpu *)    295         pcpu = vmalloc(sizeof(void __percpu *) * 35000);
297         if (!pcpu)                                296         if (!pcpu)
298                 return -1;                        297                 return -1;
299                                                   298 
300         for (i = 0; i < 35000; i++) {             299         for (i = 0; i < 35000; i++) {
301                 size = get_random_u32_inclusiv    300                 size = get_random_u32_inclusive(1, PAGE_SIZE / 4);
302                                                   301 
303                 /*                                302                 /*
304                  * Maximum PAGE_SIZE              303                  * Maximum PAGE_SIZE
305                  */                               304                  */
306                 align = 1 << get_random_u32_in    305                 align = 1 << get_random_u32_inclusive(1, 11);
307                                                   306 
308                 pcpu[i] = __alloc_percpu(size,    307                 pcpu[i] = __alloc_percpu(size, align);
309                 if (!pcpu[i])                     308                 if (!pcpu[i])
310                         rv = -1;                  309                         rv = -1;
311         }                                         310         }
312                                                   311 
313         for (i = 0; i < 35000; i++)               312         for (i = 0; i < 35000; i++)
314                 free_percpu(pcpu[i]);             313                 free_percpu(pcpu[i]);
315                                                   314 
316         vfree(pcpu);                              315         vfree(pcpu);
317 #endif                                            316 #endif
318         return rv;                                317         return rv;
319 }                                                 318 }
320                                                   319 
321 struct test_kvfree_rcu {                          320 struct test_kvfree_rcu {
322         struct rcu_head rcu;                      321         struct rcu_head rcu;
323         unsigned char array[20];                  322         unsigned char array[20];
324 };                                                323 };
325                                                   324 
326 static int                                        325 static int
327 kvfree_rcu_1_arg_vmalloc_test(void)               326 kvfree_rcu_1_arg_vmalloc_test(void)
328 {                                                 327 {
329         struct test_kvfree_rcu *p;                328         struct test_kvfree_rcu *p;
330         int i;                                    329         int i;
331                                                   330 
332         for (i = 0; i < test_loop_count; i++)     331         for (i = 0; i < test_loop_count; i++) {
333                 p = vmalloc(1 * PAGE_SIZE);       332                 p = vmalloc(1 * PAGE_SIZE);
334                 if (!p)                           333                 if (!p)
335                         return -1;                334                         return -1;
336                                                   335 
337                 p->array[0] = 'a';                336                 p->array[0] = 'a';
338                 kvfree_rcu_mightsleep(p);      !! 337                 kvfree_rcu(p);
339         }                                         338         }
340                                                   339 
341         return 0;                                 340         return 0;
342 }                                                 341 }
343                                                   342 
344 static int                                        343 static int
345 kvfree_rcu_2_arg_vmalloc_test(void)               344 kvfree_rcu_2_arg_vmalloc_test(void)
346 {                                                 345 {
347         struct test_kvfree_rcu *p;                346         struct test_kvfree_rcu *p;
348         int i;                                    347         int i;
349                                                   348 
350         for (i = 0; i < test_loop_count; i++)     349         for (i = 0; i < test_loop_count; i++) {
351                 p = vmalloc(1 * PAGE_SIZE);       350                 p = vmalloc(1 * PAGE_SIZE);
352                 if (!p)                           351                 if (!p)
353                         return -1;                352                         return -1;
354                                                   353 
355                 p->array[0] = 'a';                354                 p->array[0] = 'a';
356                 kvfree_rcu(p, rcu);               355                 kvfree_rcu(p, rcu);
357         }                                         356         }
358                                                   357 
359         return 0;                                 358         return 0;
360 }                                                 359 }
361                                                   360 
362 static int                                     << 
363 vm_map_ram_test(void)                          << 
364 {                                              << 
365         unsigned long nr_allocated;            << 
366         unsigned int map_nr_pages;             << 
367         unsigned char *v_ptr;                  << 
368         struct page **pages;                   << 
369         int i;                                 << 
370                                                << 
371         map_nr_pages = nr_pages > 0 ? nr_pages << 
372         pages = kcalloc(map_nr_pages, sizeof(s << 
373         if (!pages)                            << 
374                 return -1;                     << 
375                                                << 
376         nr_allocated = alloc_pages_bulk_array( << 
377         if (nr_allocated != map_nr_pages)      << 
378                 goto cleanup;                  << 
379                                                << 
380         /* Run the test loop. */               << 
381         for (i = 0; i < test_loop_count; i++)  << 
382                 v_ptr = vm_map_ram(pages, map_ << 
383                 *v_ptr = 'a';                  << 
384                 vm_unmap_ram(v_ptr, map_nr_pag << 
385         }                                      << 
386                                                << 
387 cleanup:                                       << 
388         for (i = 0; i < nr_allocated; i++)     << 
389                 __free_page(pages[i]);         << 
390                                                << 
391         kfree(pages);                          << 
392                                                << 
393         /* 0 indicates success. */             << 
394         return nr_allocated != map_nr_pages;   << 
395 }                                              << 
396                                                << 
397 struct test_case_desc {                           361 struct test_case_desc {
398         const char *test_name;                    362         const char *test_name;
399         int (*test_func)(void);                   363         int (*test_func)(void);
400 };                                                364 };
401                                                   365 
402 static struct test_case_desc test_case_array[]    366 static struct test_case_desc test_case_array[] = {
403         { "fix_size_alloc_test", fix_size_allo    367         { "fix_size_alloc_test", fix_size_alloc_test },
404         { "full_fit_alloc_test", full_fit_allo    368         { "full_fit_alloc_test", full_fit_alloc_test },
405         { "long_busy_list_alloc_test", long_bu    369         { "long_busy_list_alloc_test", long_busy_list_alloc_test },
406         { "random_size_alloc_test", random_siz    370         { "random_size_alloc_test", random_size_alloc_test },
407         { "fix_align_alloc_test", fix_align_al    371         { "fix_align_alloc_test", fix_align_alloc_test },
408         { "random_size_align_alloc_test", rand    372         { "random_size_align_alloc_test", random_size_align_alloc_test },
409         { "align_shift_alloc_test", align_shif    373         { "align_shift_alloc_test", align_shift_alloc_test },
410         { "pcpu_alloc_test", pcpu_alloc_test }    374         { "pcpu_alloc_test", pcpu_alloc_test },
411         { "kvfree_rcu_1_arg_vmalloc_test", kvf    375         { "kvfree_rcu_1_arg_vmalloc_test", kvfree_rcu_1_arg_vmalloc_test },
412         { "kvfree_rcu_2_arg_vmalloc_test", kvf    376         { "kvfree_rcu_2_arg_vmalloc_test", kvfree_rcu_2_arg_vmalloc_test },
413         { "vm_map_ram_test", vm_map_ram_test } << 
414         /* Add a new test case here. */           377         /* Add a new test case here. */
415 };                                                378 };
416                                                   379 
417 struct test_case_data {                           380 struct test_case_data {
418         int test_failed;                          381         int test_failed;
419         int test_passed;                          382         int test_passed;
420         u64 time;                                 383         u64 time;
421 };                                                384 };
422                                                   385 
423 static struct test_driver {                       386 static struct test_driver {
424         struct task_struct *task;                 387         struct task_struct *task;
425         struct test_case_data data[ARRAY_SIZE(    388         struct test_case_data data[ARRAY_SIZE(test_case_array)];
426                                                   389 
427         unsigned long start;                      390         unsigned long start;
428         unsigned long stop;                       391         unsigned long stop;
429 } *tdriver;                                       392 } *tdriver;
430                                                   393 
431 static void shuffle_array(int *arr, int n)        394 static void shuffle_array(int *arr, int n)
432 {                                                 395 {
433         int i, j;                                 396         int i, j;
434                                                   397 
435         for (i = n - 1; i > 0; i--)  {            398         for (i = n - 1; i > 0; i--)  {
436                 /* Cut the range. */              399                 /* Cut the range. */
437                 j = get_random_u32_below(i);      400                 j = get_random_u32_below(i);
438                                                   401 
439                 /* Swap indexes. */               402                 /* Swap indexes. */
440                 swap(arr[i], arr[j]);             403                 swap(arr[i], arr[j]);
441         }                                         404         }
442 }                                                 405 }
443                                                   406 
444 static int test_func(void *private)               407 static int test_func(void *private)
445 {                                                 408 {
446         struct test_driver *t = private;          409         struct test_driver *t = private;
447         int random_array[ARRAY_SIZE(test_case_    410         int random_array[ARRAY_SIZE(test_case_array)];
448         int index, i, j;                          411         int index, i, j;
449         ktime_t kt;                               412         ktime_t kt;
450         u64 delta;                                413         u64 delta;
451                                                   414 
452         for (i = 0; i < ARRAY_SIZE(test_case_a    415         for (i = 0; i < ARRAY_SIZE(test_case_array); i++)
453                 random_array[i] = i;              416                 random_array[i] = i;
454                                                   417 
455         if (!sequential_test_order)               418         if (!sequential_test_order)
456                 shuffle_array(random_array, AR    419                 shuffle_array(random_array, ARRAY_SIZE(test_case_array));
457                                                   420 
458         /*                                        421         /*
459          * Block until initialization is done.    422          * Block until initialization is done.
460          */                                       423          */
461         down_read(&prepare_for_test_rwsem);       424         down_read(&prepare_for_test_rwsem);
462                                                   425 
463         t->start = get_cycles();                  426         t->start = get_cycles();
464         for (i = 0; i < ARRAY_SIZE(test_case_a    427         for (i = 0; i < ARRAY_SIZE(test_case_array); i++) {
465                 index = random_array[i];          428                 index = random_array[i];
466                                                   429 
467                 /*                                430                 /*
468                  * Skip tests if run_test_mask    431                  * Skip tests if run_test_mask has been specified.
469                  */                               432                  */
470                 if (!((run_test_mask & (1 << i    433                 if (!((run_test_mask & (1 << index)) >> index))
471                         continue;                 434                         continue;
472                                                   435 
473                 kt = ktime_get();                 436                 kt = ktime_get();
474                 for (j = 0; j < test_repeat_co    437                 for (j = 0; j < test_repeat_count; j++) {
475                         if (!test_case_array[i    438                         if (!test_case_array[index].test_func())
476                                 t->data[index]    439                                 t->data[index].test_passed++;
477                         else                      440                         else
478                                 t->data[index]    441                                 t->data[index].test_failed++;
479                 }                                 442                 }
480                                                   443 
481                 /*                                444                 /*
482                  * Take an average time that t    445                  * Take an average time that test took.
483                  */                               446                  */
484                 delta = (u64) ktime_us_delta(k    447                 delta = (u64) ktime_us_delta(ktime_get(), kt);
485                 do_div(delta, (u32) test_repea    448                 do_div(delta, (u32) test_repeat_count);
486                                                   449 
487                 t->data[index].time = delta;      450                 t->data[index].time = delta;
488         }                                         451         }
489         t->stop = get_cycles();                   452         t->stop = get_cycles();
490                                                   453 
491         up_read(&prepare_for_test_rwsem);         454         up_read(&prepare_for_test_rwsem);
492         test_report_one_done();                   455         test_report_one_done();
493                                                   456 
494         /*                                        457         /*
495          * Wait for the kthread_stop() call.      458          * Wait for the kthread_stop() call.
496          */                                       459          */
497         while (!kthread_should_stop())            460         while (!kthread_should_stop())
498                 msleep(10);                       461                 msleep(10);
499                                                   462 
500         return 0;                                 463         return 0;
501 }                                                 464 }
502                                                   465 
503 static int                                        466 static int
504 init_test_configuration(void)                  !! 467 init_test_configurtion(void)
505 {                                                 468 {
506         /*                                        469         /*
507          * A maximum number of workers is defi    470          * A maximum number of workers is defined as hard-coded
508          * value and set to USHRT_MAX. We add     471          * value and set to USHRT_MAX. We add such gap just in
509          * case and for potential heavy stress    472          * case and for potential heavy stressing.
510          */                                       473          */
511         nr_threads = clamp(nr_threads, 1, (int    474         nr_threads = clamp(nr_threads, 1, (int) USHRT_MAX);
512                                                   475 
513         /* Allocate the space for test instanc    476         /* Allocate the space for test instances. */
514         tdriver = kvcalloc(nr_threads, sizeof(    477         tdriver = kvcalloc(nr_threads, sizeof(*tdriver), GFP_KERNEL);
515         if (tdriver == NULL)                      478         if (tdriver == NULL)
516                 return -1;                        479                 return -1;
517                                                   480 
518         if (test_repeat_count <= 0)               481         if (test_repeat_count <= 0)
519                 test_repeat_count = 1;            482                 test_repeat_count = 1;
520                                                   483 
521         if (test_loop_count <= 0)                 484         if (test_loop_count <= 0)
522                 test_loop_count = 1;              485                 test_loop_count = 1;
523                                                   486 
524         return 0;                                 487         return 0;
525 }                                                 488 }
526                                                   489 
527 static void do_concurrent_test(void)              490 static void do_concurrent_test(void)
528 {                                                 491 {
529         int i, ret;                               492         int i, ret;
530                                                   493 
531         /*                                        494         /*
532          * Set some basic configurations plus     495          * Set some basic configurations plus sanity check.
533          */                                       496          */
534         ret = init_test_configuration();       !! 497         ret = init_test_configurtion();
535         if (ret < 0)                              498         if (ret < 0)
536                 return;                           499                 return;
537                                                   500 
538         /*                                        501         /*
539          * Put on hold all workers.               502          * Put on hold all workers.
540          */                                       503          */
541         down_write(&prepare_for_test_rwsem);      504         down_write(&prepare_for_test_rwsem);
542                                                   505 
543         for (i = 0; i < nr_threads; i++) {        506         for (i = 0; i < nr_threads; i++) {
544                 struct test_driver *t = &tdriv    507                 struct test_driver *t = &tdriver[i];
545                                                   508 
546                 t->task = kthread_run(test_fun    509                 t->task = kthread_run(test_func, t, "vmalloc_test/%d", i);
547                                                   510 
548                 if (!IS_ERR(t->task))             511                 if (!IS_ERR(t->task))
549                         /* Success. */            512                         /* Success. */
550                         atomic_inc(&test_n_und    513                         atomic_inc(&test_n_undone);
551                 else                              514                 else
552                         pr_err("Failed to star    515                         pr_err("Failed to start %d kthread\n", i);
553         }                                         516         }
554                                                   517 
555         /*                                        518         /*
556          * Now let the workers do their job.      519          * Now let the workers do their job.
557          */                                       520          */
558         up_write(&prepare_for_test_rwsem);        521         up_write(&prepare_for_test_rwsem);
559                                                   522 
560         /*                                        523         /*
561          * Sleep quiet until all workers are d    524          * Sleep quiet until all workers are done with 1 second
562          * interval. Since the test can take a    525          * interval. Since the test can take a lot of time we
563          * can run into a stack trace of the h    526          * can run into a stack trace of the hung task. That is
564          * why we go with completion_timeout a    527          * why we go with completion_timeout and HZ value.
565          */                                       528          */
566         do {                                      529         do {
567                 ret = wait_for_completion_time    530                 ret = wait_for_completion_timeout(&test_all_done_comp, HZ);
568         } while (!ret);                           531         } while (!ret);
569                                                   532 
570         for (i = 0; i < nr_threads; i++) {        533         for (i = 0; i < nr_threads; i++) {
571                 struct test_driver *t = &tdriv    534                 struct test_driver *t = &tdriver[i];
572                 int j;                            535                 int j;
573                                                   536 
574                 if (!IS_ERR(t->task))             537                 if (!IS_ERR(t->task))
575                         kthread_stop(t->task);    538                         kthread_stop(t->task);
576                                                   539 
577                 for (j = 0; j < ARRAY_SIZE(tes    540                 for (j = 0; j < ARRAY_SIZE(test_case_array); j++) {
578                         if (!((run_test_mask &    541                         if (!((run_test_mask & (1 << j)) >> j))
579                                 continue;         542                                 continue;
580                                                   543 
581                         pr_info(                  544                         pr_info(
582                                 "Summary: %s p    545                                 "Summary: %s passed: %d failed: %d repeat: %d loops: %d avg: %llu usec\n",
583                                 test_case_arra    546                                 test_case_array[j].test_name,
584                                 t->data[j].tes    547                                 t->data[j].test_passed,
585                                 t->data[j].tes    548                                 t->data[j].test_failed,
586                                 test_repeat_co    549                                 test_repeat_count, test_loop_count,
587                                 t->data[j].tim    550                                 t->data[j].time);
588                 }                                 551                 }
589                                                   552 
590                 pr_info("All test took worker%    553                 pr_info("All test took worker%d=%lu cycles\n",
591                         i, t->stop - t->start)    554                         i, t->stop - t->start);
592         }                                         555         }
593                                                   556 
594         kvfree(tdriver);                          557         kvfree(tdriver);
595 }                                                 558 }
596                                                   559 
597 static int vmalloc_test_init(void)                560 static int vmalloc_test_init(void)
598 {                                                 561 {
599         do_concurrent_test();                     562         do_concurrent_test();
600         return -EAGAIN; /* Fail will directly     563         return -EAGAIN; /* Fail will directly unload the module */
601 }                                                 564 }
602                                                   565 
                                                   >> 566 static void vmalloc_test_exit(void)
                                                   >> 567 {
                                                   >> 568 }
                                                   >> 569 
603 module_init(vmalloc_test_init)                    570 module_init(vmalloc_test_init)
                                                   >> 571 module_exit(vmalloc_test_exit)
604                                                   572 
605 MODULE_LICENSE("GPL");                            573 MODULE_LICENSE("GPL");
606 MODULE_AUTHOR("Uladzislau Rezki");                574 MODULE_AUTHOR("Uladzislau Rezki");
607 MODULE_DESCRIPTION("vmalloc test module");        575 MODULE_DESCRIPTION("vmalloc test module");
608                                                   576 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php