* [PATCH 1/4] radix tree test suite: Add support for fallthrough attribute @ 2021-05-12 18:48 Liam Howlett 2021-05-12 18:48 ` [PATCH 2/4] radix tree test suite: Add __must_be_array() support Liam Howlett ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: Liam Howlett @ 2021-05-12 18:48 UTC (permalink / raw) To: linux-fsdevel, linux-kernel, Matthew Wilcox; +Cc: Liam Howlett Add support for fallthrough on case statements. Note this does *NOT* check for missing fallthrough, but does allow compiling of code with fallthrough in case statements. Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com> --- tools/testing/radix-tree/linux/kernel.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/testing/radix-tree/linux/kernel.h b/tools/testing/radix-tree/linux/kernel.h index 39867fd80c8f..c400a27e544a 100644 --- a/tools/testing/radix-tree/linux/kernel.h +++ b/tools/testing/radix-tree/linux/kernel.h @@ -23,4 +23,11 @@ #define __must_hold(x) #define EXPORT_PER_CPU_SYMBOL_GPL(x) + +#if __has_attribute(__fallthrough__) +# define fallthrough __attribute__((__fallthrough__)) +#else +# define fallthrough do {} while (0) /* fallthrough */ +#endif /* __has_attribute */ + #endif /* _KERNEL_H */ -- 2.30.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/4] radix tree test suite: Add __must_be_array() support 2021-05-12 18:48 [PATCH 1/4] radix tree test suite: Add support for fallthrough attribute Liam Howlett @ 2021-05-12 18:48 ` Liam Howlett 2021-05-12 21:46 ` Matthew Wilcox 2021-05-12 18:48 ` [PATCH 3/4] radix tree test suite: Add kmem_cache enhancements and pr_err Liam Howlett 2021-05-12 18:48 ` [PATCH 4/4] radix tree test suite: Add support for slab bulk APIs Liam Howlett 2 siblings, 1 reply; 6+ messages in thread From: Liam Howlett @ 2021-05-12 18:48 UTC (permalink / raw) To: linux-fsdevel, linux-kernel, Matthew Wilcox; +Cc: Liam Howlett Copy __must_be_array() define from include/linux/compiler.h for use in the radix tree test suite userspace compiles. Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com> --- tools/testing/radix-tree/linux/kernel.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/radix-tree/linux/kernel.h b/tools/testing/radix-tree/linux/kernel.h index c400a27e544a..2c3771fff2c0 100644 --- a/tools/testing/radix-tree/linux/kernel.h +++ b/tools/testing/radix-tree/linux/kernel.h @@ -30,4 +30,6 @@ # define fallthrough do {} while (0) /* fallthrough */ #endif /* __has_attribute */ +#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) + #endif /* _KERNEL_H */ -- 2.30.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/4] radix tree test suite: Add __must_be_array() support 2021-05-12 18:48 ` [PATCH 2/4] radix tree test suite: Add __must_be_array() support Liam Howlett @ 2021-05-12 21:46 ` Matthew Wilcox 2021-05-12 22:13 ` Liam Howlett 0 siblings, 1 reply; 6+ messages in thread From: Matthew Wilcox @ 2021-05-12 21:46 UTC (permalink / raw) To: Liam Howlett; +Cc: linux-fsdevel, linux-kernel On Wed, May 12, 2021 at 06:48:52PM +0000, Liam Howlett wrote: > Copy __must_be_array() define from include/linux/compiler.h for use in > the radix tree test suite userspace compiles. We needed this earlier, but see commit 7487de534dcbe143e6f41da751dd3ffcf93b00ee I bet if you revert this commit, it'll still build fine. Also, I bet patch 1/4 is the same -- I see a definition of fallthrough in tools/include/linux/compiler-gcc.h > Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com> > --- > tools/testing/radix-tree/linux/kernel.h | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/tools/testing/radix-tree/linux/kernel.h b/tools/testing/radix-tree/linux/kernel.h > index c400a27e544a..2c3771fff2c0 100644 > --- a/tools/testing/radix-tree/linux/kernel.h > +++ b/tools/testing/radix-tree/linux/kernel.h > @@ -30,4 +30,6 @@ > # define fallthrough do {} while (0) /* fallthrough */ > #endif /* __has_attribute */ > > +#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) > + > #endif /* _KERNEL_H */ > -- > 2.30.2 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/4] radix tree test suite: Add __must_be_array() support 2021-05-12 21:46 ` Matthew Wilcox @ 2021-05-12 22:13 ` Liam Howlett 0 siblings, 0 replies; 6+ messages in thread From: Liam Howlett @ 2021-05-12 22:13 UTC (permalink / raw) To: Matthew Wilcox; +Cc: linux-fsdevel, linux-kernel * Matthew Wilcox <willy@infradead.org> [210512 17:48]: > On Wed, May 12, 2021 at 06:48:52PM +0000, Liam Howlett wrote: > > Copy __must_be_array() define from include/linux/compiler.h for use in > > the radix tree test suite userspace compiles. > > We needed this earlier, but see commit > 7487de534dcbe143e6f41da751dd3ffcf93b00ee > > I bet if you revert this commit, it'll still build fine. > > Also, I bet patch 1/4 is the same -- I see a definition of > fallthrough in tools/include/linux/compiler-gcc.h You are correct. Please disregard patch 1 and 2. Thanks, Liam > > > Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com> > > --- > > tools/testing/radix-tree/linux/kernel.h | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/tools/testing/radix-tree/linux/kernel.h b/tools/testing/radix-tree/linux/kernel.h > > index c400a27e544a..2c3771fff2c0 100644 > > --- a/tools/testing/radix-tree/linux/kernel.h > > +++ b/tools/testing/radix-tree/linux/kernel.h > > @@ -30,4 +30,6 @@ > > # define fallthrough do {} while (0) /* fallthrough */ > > #endif /* __has_attribute */ > > > > +#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) > > + > > #endif /* _KERNEL_H */ > > -- > > 2.30.2 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/4] radix tree test suite: Add kmem_cache enhancements and pr_err 2021-05-12 18:48 [PATCH 1/4] radix tree test suite: Add support for fallthrough attribute Liam Howlett 2021-05-12 18:48 ` [PATCH 2/4] radix tree test suite: Add __must_be_array() support Liam Howlett @ 2021-05-12 18:48 ` Liam Howlett 2021-05-12 18:48 ` [PATCH 4/4] radix tree test suite: Add support for slab bulk APIs Liam Howlett 2 siblings, 0 replies; 6+ messages in thread From: Liam Howlett @ 2021-05-12 18:48 UTC (permalink / raw) To: linux-fsdevel, linux-kernel, Matthew Wilcox; +Cc: Liam Howlett Add kmem_cache_set_non_kernel(), a mechanism to allow a certain number of kmem_cache_alloc requests to succeed even when GFP_KERNEL is not set in the flags. Add kmem_cache_get_alloc() to see the size of the allocated kmem_cache. Add a define of pr_err to printk. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> --- tools/testing/radix-tree/linux.c | 20 ++++++++++++++++++-- tools/testing/radix-tree/linux/kernel.h | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tools/testing/radix-tree/linux.c b/tools/testing/radix-tree/linux.c index 2d9c59df60de..7225b5c46bb6 100644 --- a/tools/testing/radix-tree/linux.c +++ b/tools/testing/radix-tree/linux.c @@ -24,14 +24,29 @@ struct kmem_cache { int nr_objs; void *objs; void (*ctor)(void *); + unsigned int non_kernel; }; +void kmem_cache_set_non_kernel(struct kmem_cache *cachep, unsigned int val) +{ + cachep->non_kernel = val; +} + +unsigned long kmem_cache_get_alloc(struct kmem_cache *cachep) +{ + return cachep->size * nr_allocated; +} + void *kmem_cache_alloc(struct kmem_cache *cachep, int gfp) { void *p; - if (!(gfp & __GFP_DIRECT_RECLAIM)) - return NULL; + if (!(gfp & __GFP_DIRECT_RECLAIM)) { + if (!cachep->non_kernel) + return NULL; + + cachep->non_kernel--; + } pthread_mutex_lock(&cachep->lock); if (cachep->nr_objs) { @@ -116,5 +131,6 @@ kmem_cache_create(const char *name, unsigned int size, unsigned int align, ret->nr_objs = 0; ret->objs = NULL; ret->ctor = ctor; + ret->non_kernel = 0; return ret; } diff --git a/tools/testing/radix-tree/linux/kernel.h b/tools/testing/radix-tree/linux/kernel.h index 2c3771fff2c0..e44603a181da 100644 --- a/tools/testing/radix-tree/linux/kernel.h +++ b/tools/testing/radix-tree/linux/kernel.h @@ -14,6 +14,7 @@ #include "../../../include/linux/kconfig.h" #define printk printf +#define pr_err printk #define pr_info printk #define pr_debug printk #define pr_cont printk -- 2.30.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/4] radix tree test suite: Add support for slab bulk APIs 2021-05-12 18:48 [PATCH 1/4] radix tree test suite: Add support for fallthrough attribute Liam Howlett 2021-05-12 18:48 ` [PATCH 2/4] radix tree test suite: Add __must_be_array() support Liam Howlett 2021-05-12 18:48 ` [PATCH 3/4] radix tree test suite: Add kmem_cache enhancements and pr_err Liam Howlett @ 2021-05-12 18:48 ` Liam Howlett 2 siblings, 0 replies; 6+ messages in thread From: Liam Howlett @ 2021-05-12 18:48 UTC (permalink / raw) To: linux-fsdevel, linux-kernel, Matthew Wilcox; +Cc: Liam Howlett Add support for kmem_cache_free_bulk() and kmem_cache_alloc_bulk() to the radix tree test suite. Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com> --- tools/testing/radix-tree/linux.c | 61 +++++++++++++++++++++++++++ tools/testing/radix-tree/linux/slab.h | 3 ++ 2 files changed, 64 insertions(+) diff --git a/tools/testing/radix-tree/linux.c b/tools/testing/radix-tree/linux.c index 7225b5c46bb6..726407f934d3 100644 --- a/tools/testing/radix-tree/linux.c +++ b/tools/testing/radix-tree/linux.c @@ -93,6 +93,67 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp) pthread_mutex_unlock(&cachep->lock); } +void kmem_cache_free_bulk(struct kmem_cache *cachep, size_t size, void **list) +{ + if (kmalloc_verbose) + printk("Bulk free %p[0-%lu]\n", list, size - 1); + + for (int i = 0; i < size; i++) + kmem_cache_free(cachep, list[i]); +} + +int kmem_cache_alloc_bulk(struct kmem_cache *cachep, gfp_t gfp, size_t size, + void **p) +{ + size_t i; + + if (kmalloc_verbose) + printk("Bulk alloc %lu\n", size); + + if (!(gfp & __GFP_DIRECT_RECLAIM)) { + if (cachep->non_kernel < size) + return 0; + + cachep->non_kernel -= size; + } + + pthread_mutex_lock(&cachep->lock); + if (cachep->nr_objs >= size) { + struct radix_tree_node *node = cachep->objs; + + for (i = 0; i < size; i++) { + cachep->nr_objs--; + cachep->objs = node->parent; + p[i] = cachep->objs; + } + pthread_mutex_unlock(&cachep->lock); + node->parent = NULL; + } else { + pthread_mutex_unlock(&cachep->lock); + for (i = 0; i < size; i++) { + if (cachep->align) { + posix_memalign(&p[i], cachep->align, + cachep->size * size); + } else { + p[i] = malloc(cachep->size * size); + } + if (cachep->ctor) + cachep->ctor(p[i]); + else if (gfp & __GFP_ZERO) + memset(p[i], 0, cachep->size); + } + } + + for (i = 0; i < size; i++) { + uatomic_inc(&nr_allocated); + uatomic_inc(&nr_tallocated); + if (kmalloc_verbose) + printf("Allocating %p from slab\n", p[i]); + } + + return size; +} + void *kmalloc(size_t size, gfp_t gfp) { void *ret; diff --git a/tools/testing/radix-tree/linux/slab.h b/tools/testing/radix-tree/linux/slab.h index 2958830ce4d7..de3befdf14df 100644 --- a/tools/testing/radix-tree/linux/slab.h +++ b/tools/testing/radix-tree/linux/slab.h @@ -24,4 +24,7 @@ struct kmem_cache *kmem_cache_create(const char *name, unsigned int size, unsigned int align, unsigned int flags, void (*ctor)(void *)); +void kmem_cache_free_bulk(struct kmem_cache *cachep, size_t, void **); +int kmem_cache_alloc_bulk(struct kmem_cache *cachep, gfp_t, size_t, void **); + #endif /* SLAB_H */ -- 2.30.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-05-12 22:27 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-05-12 18:48 [PATCH 1/4] radix tree test suite: Add support for fallthrough attribute Liam Howlett 2021-05-12 18:48 ` [PATCH 2/4] radix tree test suite: Add __must_be_array() support Liam Howlett 2021-05-12 21:46 ` Matthew Wilcox 2021-05-12 22:13 ` Liam Howlett 2021-05-12 18:48 ` [PATCH 3/4] radix tree test suite: Add kmem_cache enhancements and pr_err Liam Howlett 2021-05-12 18:48 ` [PATCH 4/4] radix tree test suite: Add support for slab bulk APIs Liam Howlett
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).