Whamcloud - gitweb
LU-5304: use kzalloc/vzalloc instead of [kv]malloc+memset 29/11029/4
authorFrank Zago <fzago@cray.com>
Wed, 9 Jul 2014 16:58:11 +0000 (11:58 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 15 Jul 2014 04:00:46 +0000 (04:00 +0000)
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 <fzago@cray.com>
Reviewed-on: http://review.whamcloud.com/11029
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Tested-by: Jenkins
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
libcfs/include/libcfs/libcfs_private.h
libcfs/include/libcfs/linux/linux-mem.h
libcfs/libcfs/linux/linux-mem.c
lustre/include/obd_support.h

index 4afb764..d9e7ad4 100644 (file)
@@ -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)
 
index ce20cb8..0ad0e6f 100644 (file)
@@ -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);
index 05c160d..8cdf07d 100644 (file)
@@ -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)
index 0044fb7..cc3e2c4 100644 (file)
@@ -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__