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

tools: Move gfp.h and slab.h from radix-tree to lib

Merge radix-tree definitions from gfp.h and slab.h with these
in tools/lib, so they can be used in other test suites.
Fix style issues in slab.h. Update radix-tree test files.

Signed-off-by: Karolina Drobnik <karolinadrobnik@gmail.com>
Signed-off-by: Mike Rapoport <rppt@kernel.org>
Link: https://lore.kernel.org/r/b76ddb8a12fdf9870b55c1401213e44f5e0d0da3.1643796665.git.karolinadrobnik@gmail.com

authored by

Karolina Drobnik and committed by
Mike Rapoport
aa0eab86 754e0b0e

+76 -68
+28
tools/include/linux/gfp.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 1 2 #ifndef _TOOLS_INCLUDE_LINUX_GFP_H 2 3 #define _TOOLS_INCLUDE_LINUX_GFP_H 4 + 5 + #include <linux/types.h> 6 + 7 + #define __GFP_BITS_SHIFT 26 8 + #define __GFP_BITS_MASK ((gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) 9 + 10 + #define __GFP_HIGH 0x20u 11 + #define __GFP_IO 0x40u 12 + #define __GFP_FS 0x80u 13 + #define __GFP_NOWARN 0x200u 14 + #define __GFP_ZERO 0x8000u 15 + #define __GFP_ATOMIC 0x80000u 16 + #define __GFP_ACCOUNT 0x100000u 17 + #define __GFP_DIRECT_RECLAIM 0x400000u 18 + #define __GFP_KSWAPD_RECLAIM 0x2000000u 19 + 20 + #define __GFP_RECLAIM (__GFP_DIRECT_RECLAIM | __GFP_KSWAPD_RECLAIM) 21 + 22 + #define GFP_ZONEMASK 0x0fu 23 + #define GFP_ATOMIC (__GFP_HIGH | __GFP_ATOMIC | __GFP_KSWAPD_RECLAIM) 24 + #define GFP_KERNEL (__GFP_RECLAIM | __GFP_IO | __GFP_FS) 25 + #define GFP_NOWAIT (__GFP_KSWAPD_RECLAIM) 26 + 27 + static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags) 28 + { 29 + return !!(gfp_flags & __GFP_DIRECT_RECLAIM); 30 + } 3 31 4 32 #endif /* _TOOLS_INCLUDE_LINUX_GFP_H */
+38
tools/lib/slab.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <stdio.h> 4 + #include <string.h> 5 + 6 + #include <urcu/uatomic.h> 7 + #include <linux/slab.h> 8 + #include <malloc.h> 9 + #include <linux/gfp.h> 10 + 11 + int kmalloc_nr_allocated; 12 + int kmalloc_verbose; 13 + 14 + void *kmalloc(size_t size, gfp_t gfp) 15 + { 16 + void *ret; 17 + 18 + if (!(gfp & __GFP_DIRECT_RECLAIM)) 19 + return NULL; 20 + 21 + ret = malloc(size); 22 + uatomic_inc(&kmalloc_nr_allocated); 23 + if (kmalloc_verbose) 24 + printf("Allocating %p from malloc\n", ret); 25 + if (gfp & __GFP_ZERO) 26 + memset(ret, 0, size); 27 + return ret; 28 + } 29 + 30 + void kfree(void *p) 31 + { 32 + if (!p) 33 + return; 34 + uatomic_dec(&kmalloc_nr_allocated); 35 + if (kmalloc_verbose) 36 + printf("Freeing %p to malloc\n", p); 37 + free(p); 38 + }
+2 -1
tools/testing/radix-tree/Makefile
··· 5 5 LDFLAGS += -fsanitize=address -fsanitize=undefined 6 6 LDLIBS+= -lpthread -lurcu 7 7 TARGETS = main idr-test multiorder xarray 8 - CORE_OFILES := xarray.o radix-tree.o idr.o linux.o test.o find_bit.o bitmap.o 8 + CORE_OFILES := xarray.o radix-tree.o idr.o linux.o test.o find_bit.o bitmap.o \ 9 + slab.o 9 10 OFILES = main.o $(CORE_OFILES) regression1.o regression2.o regression3.o \ 10 11 regression4.o tag_check.o multiorder.o idr-test.o iteration_check.o \ 11 12 iteration_check_2.o benchmark.o
-27
tools/testing/radix-tree/linux.c
··· 14 14 15 15 int nr_allocated; 16 16 int preempt_count; 17 - int kmalloc_verbose; 18 17 int test_verbose; 19 18 20 19 struct kmem_cache { ··· 75 76 cachep->objs = node; 76 77 } 77 78 pthread_mutex_unlock(&cachep->lock); 78 - } 79 - 80 - void *kmalloc(size_t size, gfp_t gfp) 81 - { 82 - void *ret; 83 - 84 - if (!(gfp & __GFP_DIRECT_RECLAIM)) 85 - return NULL; 86 - 87 - ret = malloc(size); 88 - uatomic_inc(&nr_allocated); 89 - if (kmalloc_verbose) 90 - printf("Allocating %p from malloc\n", ret); 91 - if (gfp & __GFP_ZERO) 92 - memset(ret, 0, size); 93 - return ret; 94 - } 95 - 96 - void kfree(void *p) 97 - { 98 - if (!p) 99 - return; 100 - uatomic_dec(&nr_allocated); 101 - if (kmalloc_verbose) 102 - printf("Freeing %p to malloc\n", p); 103 - free(p); 104 79 } 105 80 106 81 struct kmem_cache *
-33
tools/testing/radix-tree/linux/gfp.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _GFP_H 3 - #define _GFP_H 4 - 5 - #include <linux/types.h> 6 - 7 - #define __GFP_BITS_SHIFT 26 8 - #define __GFP_BITS_MASK ((gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) 9 - 10 - #define __GFP_HIGH 0x20u 11 - #define __GFP_IO 0x40u 12 - #define __GFP_FS 0x80u 13 - #define __GFP_NOWARN 0x200u 14 - #define __GFP_ZERO 0x8000u 15 - #define __GFP_ATOMIC 0x80000u 16 - #define __GFP_ACCOUNT 0x100000u 17 - #define __GFP_DIRECT_RECLAIM 0x400000u 18 - #define __GFP_KSWAPD_RECLAIM 0x2000000u 19 - 20 - #define __GFP_RECLAIM (__GFP_DIRECT_RECLAIM|__GFP_KSWAPD_RECLAIM) 21 - 22 - #define GFP_ZONEMASK 0x0fu 23 - #define GFP_ATOMIC (__GFP_HIGH|__GFP_ATOMIC|__GFP_KSWAPD_RECLAIM) 24 - #define GFP_KERNEL (__GFP_RECLAIM | __GFP_IO | __GFP_FS) 25 - #define GFP_NOWAIT (__GFP_KSWAPD_RECLAIM) 26 - 27 - 28 - static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags) 29 - { 30 - return !!(gfp_flags & __GFP_DIRECT_RECLAIM); 31 - } 32 - 33 - #endif
+8 -7
tools/testing/radix-tree/linux/slab.h tools/include/linux/slab.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef SLAB_H 3 - #define SLAB_H 2 + #ifndef _TOOLS_SLAB_H 3 + #define _TOOLS_SLAB_H 4 4 5 5 #include <linux/types.h> 6 6 #include <linux/gfp.h> 7 7 8 - #define SLAB_HWCACHE_ALIGN 1 9 8 #define SLAB_PANIC 2 10 9 #define SLAB_RECLAIM_ACCOUNT 0x00020000UL /* Objects are reclaimable */ 11 10 12 - void *kmalloc(size_t size, gfp_t); 13 - void kfree(void *); 11 + #define kzalloc_node(size, flags, node) kmalloc(size, flags) 12 + 13 + void *kmalloc(size_t size, gfp_t gfp); 14 + void kfree(void *p); 14 15 15 16 static inline void *kzalloc(size_t size, gfp_t gfp) 16 17 { 17 - return kmalloc(size, gfp | __GFP_ZERO); 18 + return kmalloc(size, gfp | __GFP_ZERO); 18 19 } 19 20 20 21 void *kmem_cache_alloc(struct kmem_cache *cachep, int flags); ··· 25 24 unsigned int align, unsigned int flags, 26 25 void (*ctor)(void *)); 27 26 28 - #endif /* SLAB_H */ 27 + #endif /* _TOOLS_SLAB_H */