Skip to content

Commit

Permalink
xfs: simplify kmem_{zone_}zalloc
Browse files Browse the repository at this point in the history
Introduce flag KM_ZERO which is used to alloc zeroed entry, and convert
kmem_{zone_}zalloc to call kmem_{zone_}alloc() with KM_ZERO directly,
in order to avoid the setting to zero step. 
And following Dave's suggestion, make kmem_{zone_}zalloc static inline
into kmem.h as they're now just a simple wrapper.

V2:
  Make kmem_{zone_}zalloc static inline into kmem.h as Dave suggested.

Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
  • Loading branch information
Gu Zheng authored and Ben Myers committed Nov 6, 2013
1 parent d123031 commit 359d992
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
22 changes: 0 additions & 22 deletions fs/xfs/kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@ kmem_alloc(size_t size, xfs_km_flags_t flags)
} while (1);
}

void *
kmem_zalloc(size_t size, xfs_km_flags_t flags)
{
void *ptr;

ptr = kmem_alloc(size, flags);
if (ptr)
memset((char *)ptr, 0, (int)size);
return ptr;
}

void *
kmem_zalloc_large(size_t size, xfs_km_flags_t flags)
{
Expand Down Expand Up @@ -128,14 +117,3 @@ kmem_zone_alloc(kmem_zone_t *zone, xfs_km_flags_t flags)
congestion_wait(BLK_RW_ASYNC, HZ/50);
} while (1);
}

void *
kmem_zone_zalloc(kmem_zone_t *zone, xfs_km_flags_t flags)
{
void *ptr;

ptr = kmem_zone_alloc(zone, flags);
if (ptr)
memset((char *)ptr, 0, kmem_cache_size(zone));
return ptr;
}
21 changes: 18 additions & 3 deletions fs/xfs/kmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef unsigned __bitwise xfs_km_flags_t;
#define KM_NOSLEEP ((__force xfs_km_flags_t)0x0002u)
#define KM_NOFS ((__force xfs_km_flags_t)0x0004u)
#define KM_MAYFAIL ((__force xfs_km_flags_t)0x0008u)
#define KM_ZERO ((__force xfs_km_flags_t)0x0010u)

/*
* We use a special process flag to avoid recursive callbacks into
Expand All @@ -43,7 +44,7 @@ kmem_flags_convert(xfs_km_flags_t flags)
{
gfp_t lflags;

BUG_ON(flags & ~(KM_SLEEP|KM_NOSLEEP|KM_NOFS|KM_MAYFAIL));
BUG_ON(flags & ~(KM_SLEEP|KM_NOSLEEP|KM_NOFS|KM_MAYFAIL|KM_ZERO));

if (flags & KM_NOSLEEP) {
lflags = GFP_ATOMIC | __GFP_NOWARN;
Expand All @@ -52,18 +53,27 @@ kmem_flags_convert(xfs_km_flags_t flags)
if ((current->flags & PF_FSTRANS) || (flags & KM_NOFS))
lflags &= ~__GFP_FS;
}

if (flags & KM_ZERO)
lflags |= __GFP_ZERO;

return lflags;
}

extern void *kmem_alloc(size_t, xfs_km_flags_t);
extern void *kmem_zalloc(size_t, xfs_km_flags_t);
extern void *kmem_zalloc_large(size_t size, xfs_km_flags_t);
extern void *kmem_realloc(const void *, size_t, size_t, xfs_km_flags_t);
extern void kmem_free(const void *);


extern void *kmem_zalloc_greedy(size_t *, size_t, size_t);

static inline void *
kmem_zalloc(size_t size, xfs_km_flags_t flags)
{
return kmem_alloc(size, flags | KM_ZERO);
}

/*
* Zone interfaces
*/
Expand Down Expand Up @@ -102,6 +112,11 @@ kmem_zone_destroy(kmem_zone_t *zone)
}

extern void *kmem_zone_alloc(kmem_zone_t *, xfs_km_flags_t);
extern void *kmem_zone_zalloc(kmem_zone_t *, xfs_km_flags_t);

static inline void *
kmem_zone_zalloc(kmem_zone_t *zone, xfs_km_flags_t flags)
{
return kmem_zone_alloc(zone, flags | KM_ZERO);
}

#endif /* __XFS_SUPPORT_KMEM_H__ */

0 comments on commit 359d992

Please sign in to comment.