Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tools/testing: Add support for changes to slab for sheaves

The slab changes for sheaves requires more effort in the testing code.
Unite all the kmem_cache work into the tools/include slab header for
both the vma and maple tree testing.

The vma test code also requires importing more #defines to allow for
seamless use of the shared kmem_cache code.

This adds the pthread header to the slab header in the tools directory
to allow for the pthread_mutex in linux.c.

Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>

authored by

Liam R. Howlett and committed by
Vlastimil Babka
c4fb7f0a d09a61a3

+142 -114
+133 -4
tools/include/linux/slab.h
··· 4 4 5 5 #include <linux/types.h> 6 6 #include <linux/gfp.h> 7 + #include <pthread.h> 7 8 8 - #define SLAB_PANIC 2 9 9 #define SLAB_RECLAIM_ACCOUNT 0x00020000UL /* Objects are reclaimable */ 10 10 11 11 #define kzalloc_node(size, flags, node) kmalloc(size, flags) 12 + enum _slab_flag_bits { 13 + _SLAB_KMALLOC, 14 + _SLAB_HWCACHE_ALIGN, 15 + _SLAB_PANIC, 16 + _SLAB_TYPESAFE_BY_RCU, 17 + _SLAB_ACCOUNT, 18 + _SLAB_FLAGS_LAST_BIT 19 + }; 20 + 21 + #define __SLAB_FLAG_BIT(nr) ((unsigned int __force)(1U << (nr))) 22 + #define __SLAB_FLAG_UNUSED ((unsigned int __force)(0U)) 23 + 24 + #define SLAB_HWCACHE_ALIGN __SLAB_FLAG_BIT(_SLAB_HWCACHE_ALIGN) 25 + #define SLAB_PANIC __SLAB_FLAG_BIT(_SLAB_PANIC) 26 + #define SLAB_TYPESAFE_BY_RCU __SLAB_FLAG_BIT(_SLAB_TYPESAFE_BY_RCU) 27 + #ifdef CONFIG_MEMCG 28 + # define SLAB_ACCOUNT __SLAB_FLAG_BIT(_SLAB_ACCOUNT) 29 + #else 30 + # define SLAB_ACCOUNT __SLAB_FLAG_UNUSED 31 + #endif 12 32 13 33 void *kmalloc(size_t size, gfp_t gfp); 14 34 void kfree(void *p); ··· 41 21 PARTIAL, 42 22 UP, 43 23 FULL 24 + }; 25 + 26 + struct kmem_cache { 27 + pthread_mutex_t lock; 28 + unsigned int size; 29 + unsigned int align; 30 + unsigned int sheaf_capacity; 31 + int nr_objs; 32 + void *objs; 33 + void (*ctor)(void *); 34 + bool non_kernel_enabled; 35 + unsigned int non_kernel; 36 + unsigned long nr_allocated; 37 + unsigned long nr_tallocated; 38 + bool exec_callback; 39 + void (*callback)(void *); 40 + void *private; 41 + }; 42 + 43 + struct kmem_cache_args { 44 + /** 45 + * @align: The required alignment for the objects. 46 + * 47 + * %0 means no specific alignment is requested. 48 + */ 49 + unsigned int align; 50 + /** 51 + * @sheaf_capacity: The maximum size of the sheaf. 52 + */ 53 + unsigned int sheaf_capacity; 54 + /** 55 + * @useroffset: Usercopy region offset. 56 + * 57 + * %0 is a valid offset, when @usersize is non-%0 58 + */ 59 + unsigned int useroffset; 60 + /** 61 + * @usersize: Usercopy region size. 62 + * 63 + * %0 means no usercopy region is specified. 64 + */ 65 + unsigned int usersize; 66 + /** 67 + * @freeptr_offset: Custom offset for the free pointer 68 + * in &SLAB_TYPESAFE_BY_RCU caches 69 + * 70 + * By default &SLAB_TYPESAFE_BY_RCU caches place the free pointer 71 + * outside of the object. This might cause the object to grow in size. 72 + * Cache creators that have a reason to avoid this can specify a custom 73 + * free pointer offset in their struct where the free pointer will be 74 + * placed. 75 + * 76 + * Note that placing the free pointer inside the object requires the 77 + * caller to ensure that no fields are invalidated that are required to 78 + * guard against object recycling (See &SLAB_TYPESAFE_BY_RCU for 79 + * details). 80 + * 81 + * Using %0 as a value for @freeptr_offset is valid. If @freeptr_offset 82 + * is specified, %use_freeptr_offset must be set %true. 83 + * 84 + * Note that @ctor currently isn't supported with custom free pointers 85 + * as a @ctor requires an external free pointer. 86 + */ 87 + unsigned int freeptr_offset; 88 + /** 89 + * @use_freeptr_offset: Whether a @freeptr_offset is used. 90 + */ 91 + bool use_freeptr_offset; 92 + /** 93 + * @ctor: A constructor for the objects. 94 + * 95 + * The constructor is invoked for each object in a newly allocated slab 96 + * page. It is the cache user's responsibility to free object in the 97 + * same state as after calling the constructor, or deal appropriately 98 + * with any differences between a freshly constructed and a reallocated 99 + * object. 100 + * 101 + * %NULL means no constructor. 102 + */ 103 + void (*ctor)(void *); 44 104 }; 45 105 46 106 static inline void *kzalloc(size_t size, gfp_t gfp) ··· 137 37 } 138 38 void kmem_cache_free(struct kmem_cache *cachep, void *objp); 139 39 140 - struct kmem_cache *kmem_cache_create(const char *name, unsigned int size, 141 - unsigned int align, unsigned int flags, 142 - void (*ctor)(void *)); 40 + 41 + struct kmem_cache * 42 + __kmem_cache_create_args(const char *name, unsigned int size, 43 + struct kmem_cache_args *args, unsigned int flags); 44 + 45 + /* If NULL is passed for @args, use this variant with default arguments. */ 46 + static inline struct kmem_cache * 47 + __kmem_cache_default_args(const char *name, unsigned int size, 48 + struct kmem_cache_args *args, unsigned int flags) 49 + { 50 + struct kmem_cache_args kmem_default_args = {}; 51 + 52 + return __kmem_cache_create_args(name, size, &kmem_default_args, flags); 53 + } 54 + 55 + static inline struct kmem_cache * 56 + __kmem_cache_create(const char *name, unsigned int size, unsigned int align, 57 + unsigned int flags, void (*ctor)(void *)) 58 + { 59 + struct kmem_cache_args kmem_args = { 60 + .align = align, 61 + .ctor = ctor, 62 + }; 63 + 64 + return __kmem_cache_create_args(name, size, &kmem_args, flags); 65 + } 66 + 67 + #define kmem_cache_create(__name, __object_size, __args, ...) \ 68 + _Generic((__args), \ 69 + struct kmem_cache_args *: __kmem_cache_create_args, \ 70 + void *: __kmem_cache_default_args, \ 71 + default: __kmem_cache_create)(__name, __object_size, __args, __VA_ARGS__) 143 72 144 73 void kmem_cache_free_bulk(struct kmem_cache *cachep, size_t size, void **list); 145 74 int kmem_cache_alloc_bulk(struct kmem_cache *cachep, gfp_t gfp, size_t size,
+7 -19
tools/testing/shared/linux.c
··· 16 16 int preempt_count; 17 17 int test_verbose; 18 18 19 - struct kmem_cache { 20 - pthread_mutex_t lock; 21 - unsigned int size; 22 - unsigned int align; 23 - int nr_objs; 24 - void *objs; 25 - void (*ctor)(void *); 26 - unsigned int non_kernel; 27 - unsigned long nr_allocated; 28 - unsigned long nr_tallocated; 29 - bool exec_callback; 30 - void (*callback)(void *); 31 - void *private; 32 - }; 33 - 34 19 void kmem_cache_set_callback(struct kmem_cache *cachep, void (*callback)(void *)) 35 20 { 36 21 cachep->callback = callback; ··· 219 234 } 220 235 221 236 struct kmem_cache * 222 - kmem_cache_create(const char *name, unsigned int size, unsigned int align, 223 - unsigned int flags, void (*ctor)(void *)) 237 + __kmem_cache_create_args(const char *name, unsigned int size, 238 + struct kmem_cache_args *args, 239 + unsigned int flags) 224 240 { 225 241 struct kmem_cache *ret = malloc(sizeof(*ret)); 226 242 227 243 pthread_mutex_init(&ret->lock, NULL); 228 244 ret->size = size; 229 - ret->align = align; 245 + ret->align = args->align; 246 + ret->sheaf_capacity = args->sheaf_capacity; 230 247 ret->nr_objs = 0; 231 248 ret->nr_allocated = 0; 232 249 ret->nr_tallocated = 0; 233 250 ret->objs = NULL; 234 - ret->ctor = ctor; 251 + ret->ctor = args->ctor; 235 252 ret->non_kernel = 0; 236 253 ret->exec_callback = false; 237 254 ret->callback = NULL; 238 255 ret->private = NULL; 256 + 239 257 return ret; 240 258 } 241 259
+1
tools/testing/shared/maple-shim.c
··· 3 3 /* Very simple shim around the maple tree. */ 4 4 5 5 #include "maple-shared.h" 6 + #include <linux/slab.h> 6 7 7 8 #include "../../../lib/maple_tree.c"
+1 -91
tools/testing/vma/vma_internal.h
··· 26 26 #include <linux/mm.h> 27 27 #include <linux/rbtree.h> 28 28 #include <linux/refcount.h> 29 + #include <linux/slab.h> 29 30 30 31 extern unsigned long stack_guard_gap; 31 32 #ifdef CONFIG_MMU ··· 510 509 .len_in = len_, \ 511 510 } 512 511 513 - struct kmem_cache_args { 514 - /** 515 - * @align: The required alignment for the objects. 516 - * 517 - * %0 means no specific alignment is requested. 518 - */ 519 - unsigned int align; 520 - /** 521 - * @useroffset: Usercopy region offset. 522 - * 523 - * %0 is a valid offset, when @usersize is non-%0 524 - */ 525 - unsigned int useroffset; 526 - /** 527 - * @usersize: Usercopy region size. 528 - * 529 - * %0 means no usercopy region is specified. 530 - */ 531 - unsigned int usersize; 532 - /** 533 - * @freeptr_offset: Custom offset for the free pointer 534 - * in &SLAB_TYPESAFE_BY_RCU caches 535 - * 536 - * By default &SLAB_TYPESAFE_BY_RCU caches place the free pointer 537 - * outside of the object. This might cause the object to grow in size. 538 - * Cache creators that have a reason to avoid this can specify a custom 539 - * free pointer offset in their struct where the free pointer will be 540 - * placed. 541 - * 542 - * Note that placing the free pointer inside the object requires the 543 - * caller to ensure that no fields are invalidated that are required to 544 - * guard against object recycling (See &SLAB_TYPESAFE_BY_RCU for 545 - * details). 546 - * 547 - * Using %0 as a value for @freeptr_offset is valid. If @freeptr_offset 548 - * is specified, %use_freeptr_offset must be set %true. 549 - * 550 - * Note that @ctor currently isn't supported with custom free pointers 551 - * as a @ctor requires an external free pointer. 552 - */ 553 - unsigned int freeptr_offset; 554 - /** 555 - * @use_freeptr_offset: Whether a @freeptr_offset is used. 556 - */ 557 - bool use_freeptr_offset; 558 - /** 559 - * @ctor: A constructor for the objects. 560 - * 561 - * The constructor is invoked for each object in a newly allocated slab 562 - * page. It is the cache user's responsibility to free object in the 563 - * same state as after calling the constructor, or deal appropriately 564 - * with any differences between a freshly constructed and a reallocated 565 - * object. 566 - * 567 - * %NULL means no constructor. 568 - */ 569 - void (*ctor)(void *); 570 - }; 571 - 572 512 static inline void vma_iter_invalidate(struct vma_iterator *vmi) 573 513 { 574 514 mas_pause(&vmi->mas); ··· 592 650 vma->vm_ops = &vma_dummy_vm_ops; 593 651 INIT_LIST_HEAD(&vma->anon_vma_chain); 594 652 vma->vm_lock_seq = UINT_MAX; 595 - } 596 - 597 - struct kmem_cache { 598 - const char *name; 599 - size_t object_size; 600 - struct kmem_cache_args *args; 601 - }; 602 - 603 - static inline struct kmem_cache *__kmem_cache_create(const char *name, 604 - size_t object_size, 605 - struct kmem_cache_args *args) 606 - { 607 - struct kmem_cache *ret = malloc(sizeof(struct kmem_cache)); 608 - 609 - ret->name = name; 610 - ret->object_size = object_size; 611 - ret->args = args; 612 - 613 - return ret; 614 - } 615 - 616 - #define kmem_cache_create(__name, __object_size, __args, ...) \ 617 - __kmem_cache_create((__name), (__object_size), (__args)) 618 - 619 - static inline void *kmem_cache_alloc(struct kmem_cache *s, gfp_t gfpflags) 620 - { 621 - return calloc(1, s->object_size); 622 - } 623 - 624 - static inline void kmem_cache_free(struct kmem_cache *s, void *x) 625 - { 626 - free(x); 627 653 } 628 654 629 655 /*