radix tree test suite: allow GFP_ATOMIC allocations to fail
authorMatthew Wilcox <willy@linux.intel.com>
Wed, 14 Dec 2016 23:07:59 +0000 (15:07 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 15 Dec 2016 00:04:09 +0000 (16:04 -0800)
In order to test the preload code, it is necessary to fail GFP_ATOMIC
allocations, which requires defining GFP_KERNEL and GFP_ATOMIC properly.
Remove the obsolete __GFP_WAIT and copy the definitions of the __GFP
flags which are used from the kernel include files.  We also need the
real definition of gfpflags_allow_blocking() to persuade the radix tree
to actually use its preallocated nodes.

Link: http://lkml.kernel.org/r/1480369871-5271-38-git-send-email-mawilcox@linuxonhyperv.com
Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
Tested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
tools/testing/radix-tree/linux.c
tools/testing/radix-tree/linux/gfp.h
tools/testing/radix-tree/linux/slab.h

index 154823737b20d35f90d0b2e8e4b60f99795d81e0..3cfb04e98e2f3eaea845fc25bc7aa132ee52f945 100644 (file)
@@ -33,7 +33,12 @@ mempool_t *mempool_create(int min_nr, mempool_alloc_t *alloc_fn,
 
 void *kmem_cache_alloc(struct kmem_cache *cachep, int flags)
 {
-       void *ret = malloc(cachep->size);
+       void *ret;
+
+       if (flags & __GFP_NOWARN)
+               return NULL;
+
+       ret = malloc(cachep->size);
        if (cachep->ctor)
                cachep->ctor(ret);
        uatomic_inc(&nr_allocated);
index 5201b915f631fc9df916e9aa476735323c6d9e62..5b09b2ce6c33ad0e732a70e65347258e00f5a741 100644 (file)
@@ -3,8 +3,24 @@
 
 #define __GFP_BITS_SHIFT 26
 #define __GFP_BITS_MASK ((gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
-#define __GFP_WAIT 1
-#define __GFP_ACCOUNT 0
-#define __GFP_NOWARN 0
+
+#define __GFP_HIGH             0x20u
+#define __GFP_IO               0x40u
+#define __GFP_FS               0x80u
+#define __GFP_NOWARN           0x200u
+#define __GFP_ATOMIC           0x80000u
+#define __GFP_ACCOUNT          0x100000u
+#define __GFP_DIRECT_RECLAIM   0x400000u
+#define __GFP_KSWAPD_RECLAIM   0x2000000u
+
+#define __GFP_RECLAIM          (__GFP_DIRECT_RECLAIM|__GFP_KSWAPD_RECLAIM)
+
+#define GFP_ATOMIC             (__GFP_HIGH|__GFP_ATOMIC|__GFP_KSWAPD_RECLAIM)
+#define GFP_KERNEL             (__GFP_RECLAIM | __GFP_IO | __GFP_FS)
+
+static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags)
+{
+       return !!(gfp_flags & __GFP_DIRECT_RECLAIM);
+}
 
 #endif
index 6d5a34770fd43c589d7bdc3438e8f42552e7e016..452e2bf502e3e4515d34d59adbc68c1c894025ad 100644 (file)
@@ -7,11 +7,6 @@
 #define SLAB_PANIC 2
 #define SLAB_RECLAIM_ACCOUNT    0x00020000UL            /* Objects are reclaimable */
 
-static inline int gfpflags_allow_blocking(gfp_t mask)
-{
-       return 1;
-}
-
 struct kmem_cache {
        int size;
        void (*ctor)(void *);