From: Frank Zago Date: Wed, 9 Jul 2014 16:58:11 +0000 (-0500) Subject: LU-5304: use kzalloc/vzalloc instead of [kv]malloc+memset X-Git-Tag: 2.6.51~95 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=refs%2Fchanges%2F29%2F11029%2F4;hp=b29c9945aba485cf8e895cbafdb894f8da2375b7;p=fs%2Flustre-release.git LU-5304: use kzalloc/vzalloc instead of [kv]malloc+memset Changed __OBD_VMALLOC_VERBOSE to use vzalloc instead of vmalloc + memset. Changed LIBCFS_ALLOC_GFP / LIBCFS_ALLOC_POST to use kzalloc or vzalloc, instead of the regular kmalloc/vmalloc followed by a memset. Fixed a minor typo (VEROBSE->VERBOSE) in the vicinity. Change-Id: Ie8ef6036c24bc4557a88d1aa04f34f6ec0c13109 Signed-off-by: Frank Zago Reviewed-on: http://review.whamcloud.com/11029 Reviewed-by: James Simmons Tested-by: Jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Dmitry Eremin --- diff --git a/libcfs/include/libcfs/libcfs_private.h b/libcfs/include/libcfs/libcfs_private.h index 4afb764..d9e7ad4 100644 --- a/libcfs/include/libcfs/libcfs_private.h +++ b/libcfs/include/libcfs/libcfs_private.h @@ -172,7 +172,6 @@ do { \ CERROR("LNET: %d total bytes allocated by lnet\n", \ libcfs_kmem_read()); \ } else { \ - memset((ptr), 0, (size)); \ libcfs_kmem_inc((ptr), (size)); \ CDEBUG(D_MALLOC, "alloc '" #ptr "': %d at %p (tot %d).\n", \ (int)(size), (ptr), libcfs_kmem_read()); \ @@ -181,12 +180,13 @@ do { \ /** * allocate memory with GFP flags @mask + * The allocated memory is zeroed-out. */ #define LIBCFS_ALLOC_GFP(ptr, size, mask) \ do { \ LIBCFS_ALLOC_PRE((size), (mask)); \ (ptr) = (size) <= LIBCFS_VMALLOC_SIZE ? \ - kmalloc((size), (mask)) : vmalloc(size); \ + kzalloc((size), (mask)) : vzalloc(size); \ LIBCFS_ALLOC_POST((ptr), (size)); \ } while (0) @@ -206,13 +206,14 @@ do { \ * allocate memory for specified CPU partition * \a cptab != NULL, \a cpt is CPU partition id of \a cptab * \a cptab == NULL, \a cpt is HW NUMA node id + * The allocated memory is zeroed-out. */ #define LIBCFS_CPT_ALLOC_GFP(ptr, cptab, cpt, size, mask) \ do { \ LIBCFS_ALLOC_PRE((size), (mask)); \ (ptr) = (size) <= LIBCFS_VMALLOC_SIZE ? \ - cfs_cpt_malloc((cptab), (cpt), (size), (mask)) : \ - cfs_cpt_vmalloc((cptab), (cpt), (size)); \ + cfs_cpt_malloc((cptab), (cpt), (size), (mask) | __GFP_ZERO) : \ + cfs_cpt_vzalloc((cptab), (cpt), (size)); \ LIBCFS_ALLOC_POST((ptr), (size)); \ } while (0) diff --git a/libcfs/include/libcfs/linux/linux-mem.h b/libcfs/include/libcfs/linux/linux-mem.h index ce20cb8..0ad0e6f 100644 --- a/libcfs/include/libcfs/linux/linux-mem.h +++ b/libcfs/include/libcfs/linux/linux-mem.h @@ -97,7 +97,7 @@ extern void *cfs_cpt_malloc(struct cfs_cpt_table *cptab, int cpt, size_t nr_bytes, unsigned int flags); -extern void *cfs_cpt_vmalloc(struct cfs_cpt_table *cptab, int cpt, +extern void *cfs_cpt_vzalloc(struct cfs_cpt_table *cptab, int cpt, size_t nr_bytes); extern struct page *cfs_page_cpt_alloc(struct cfs_cpt_table *cptab, int cpt, unsigned int flags); diff --git a/libcfs/libcfs/linux/linux-mem.c b/libcfs/libcfs/linux/linux-mem.c index 05c160d..8cdf07d 100644 --- a/libcfs/libcfs/linux/linux-mem.c +++ b/libcfs/libcfs/linux/linux-mem.c @@ -51,11 +51,11 @@ cfs_cpt_malloc(struct cfs_cpt_table *cptab, int cpt, EXPORT_SYMBOL(cfs_cpt_malloc); void * -cfs_cpt_vmalloc(struct cfs_cpt_table *cptab, int cpt, size_t nr_bytes) +cfs_cpt_vzalloc(struct cfs_cpt_table *cptab, int cpt, size_t nr_bytes) { - return vmalloc_node(nr_bytes, cfs_cpt_spread_node(cptab, cpt)); + return vzalloc_node(nr_bytes, cfs_cpt_spread_node(cptab, cpt)); } -EXPORT_SYMBOL(cfs_cpt_vmalloc); +EXPORT_SYMBOL(cfs_cpt_vzalloc); struct page * cfs_page_cpt_alloc(struct cfs_cpt_table *cptab, int cpt, unsigned int flags) diff --git a/lustre/include/obd_support.h b/lustre/include/obd_support.h index 0044fb7a..cc3e2c4 100644 --- a/lustre/include/obd_support.h +++ b/lustre/include/obd_support.h @@ -703,26 +703,25 @@ do { \ #define OBD_CPT_ALLOC_PTR(ptr, cptab, cpt) \ OBD_CPT_ALLOC(ptr, cptab, cpt, sizeof *(ptr)) -# define __OBD_VMALLOC_VEROBSE(ptr, cptab, cpt, size) \ +# define __OBD_VMALLOC_VERBOSE(ptr, cptab, cpt, size) \ do { \ (ptr) = cptab == NULL ? \ - vmalloc(size) : \ - cfs_cpt_vmalloc(cptab, cpt, size); \ + vzalloc(size) : \ + cfs_cpt_vzalloc(cptab, cpt, size); \ if (unlikely((ptr) == NULL)) { \ CERROR("vmalloc of '" #ptr "' (%d bytes) failed\n", \ (int)(size)); \ CERROR(LPU64" total bytes allocated by Lustre, %d by LNET\n", \ obd_memory_sum(), atomic_read(&libcfs_kmemory)); \ } else { \ - memset(ptr, 0, size); \ OBD_ALLOC_POST(ptr, size, "vmalloced"); \ } \ } while(0) # define OBD_VMALLOC(ptr, size) \ - __OBD_VMALLOC_VEROBSE(ptr, NULL, 0, size) + __OBD_VMALLOC_VERBOSE(ptr, NULL, 0, size) # define OBD_CPT_VMALLOC(ptr, cptab, cpt, size) \ - __OBD_VMALLOC_VEROBSE(ptr, cptab, cpt, size) + __OBD_VMALLOC_VERBOSE(ptr, cptab, cpt, size) #ifdef __KERNEL__