radix tree test suite: Fix build

- Add an empty linux/compiler_types.h (now being included by kconfig.h)
 - Add __GFP_ZERO
 - Add kzalloc
 - Test __GFP_DIRECT_RECLAIM instead of __GFP_NOWARN

Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
This commit is contained in:
Matthew Wilcox 2018-02-25 06:00:11 -05:00
parent 3664ce2d93
commit 3d4d5d6186
4 changed files with 16 additions and 2 deletions

View File

@ -29,7 +29,7 @@ void *kmem_cache_alloc(struct kmem_cache *cachep, int flags)
{ {
struct radix_tree_node *node; struct radix_tree_node *node;
if (flags & __GFP_NOWARN) if (!(flags & __GFP_DIRECT_RECLAIM))
return NULL; return NULL;
pthread_mutex_lock(&cachep->lock); pthread_mutex_lock(&cachep->lock);
@ -73,10 +73,17 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp)
void *kmalloc(size_t size, gfp_t gfp) void *kmalloc(size_t size, gfp_t gfp)
{ {
void *ret = malloc(size); void *ret;
if (!(gfp & __GFP_DIRECT_RECLAIM))
return NULL;
ret = malloc(size);
uatomic_inc(&nr_allocated); uatomic_inc(&nr_allocated);
if (kmalloc_verbose) if (kmalloc_verbose)
printf("Allocating %p from malloc\n", ret); printf("Allocating %p from malloc\n", ret);
if (gfp & __GFP_ZERO)
memset(ret, 0, size);
return ret; return ret;
} }

View File

@ -11,6 +11,7 @@
#define __GFP_IO 0x40u #define __GFP_IO 0x40u
#define __GFP_FS 0x80u #define __GFP_FS 0x80u
#define __GFP_NOWARN 0x200u #define __GFP_NOWARN 0x200u
#define __GFP_ZERO 0x8000u
#define __GFP_ATOMIC 0x80000u #define __GFP_ATOMIC 0x80000u
#define __GFP_ACCOUNT 0x100000u #define __GFP_ACCOUNT 0x100000u
#define __GFP_DIRECT_RECLAIM 0x400000u #define __GFP_DIRECT_RECLAIM 0x400000u

View File

@ -3,6 +3,7 @@
#define SLAB_H #define SLAB_H
#include <linux/types.h> #include <linux/types.h>
#include <linux/gfp.h>
#define SLAB_HWCACHE_ALIGN 1 #define SLAB_HWCACHE_ALIGN 1
#define SLAB_PANIC 2 #define SLAB_PANIC 2
@ -11,6 +12,11 @@
void *kmalloc(size_t size, gfp_t); void *kmalloc(size_t size, gfp_t);
void kfree(void *); void kfree(void *);
static inline void *kzalloc(size_t size, gfp_t gfp)
{
return kmalloc(size, gfp | __GFP_ZERO);
}
void *kmem_cache_alloc(struct kmem_cache *cachep, int flags); void *kmem_cache_alloc(struct kmem_cache *cachep, int flags);
void kmem_cache_free(struct kmem_cache *cachep, void *objp); void kmem_cache_free(struct kmem_cache *cachep, void *objp);