Whamcloud - gitweb
LU-6142 kernel: use kmem_cache_zalloc as appropriate. 39/38439/3
authorMr NeilBrown <neilb@suse.de>
Fri, 1 May 2020 05:11:59 +0000 (15:11 +1000)
committerOleg Drokin <green@whamcloud.com>
Wed, 20 May 2020 08:23:24 +0000 (08:23 +0000)
Rather than passing __GFP_ZERO to kmem_cache_alloc(), or calling
memset(0) after the allocation, use kmem_cache_zalloc().

Also update spelling.txt to encourage use of kmem_cache_zalloc().

kmem_cache_zalloc() has been part of Linux since 2.6.17.

Test-Parameters: trivial
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: Ic4ccbe0e223121e54699f7667e35db14d0f0da70
Reviewed-on: https://review.whamcloud.com/38439
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
contrib/scripts/spelling.txt
lnet/include/lnet/lib-lnet.h
lnet/klnds/gnilnd/gnilnd_cb.c
lnet/klnds/gnilnd/gnilnd_conn.c
lnet/lnet/lib-me.c
lustre/include/obd_support.h

index 008a87a..61ce449 100644 (file)
@@ -107,6 +107,7 @@ from_timer||cfs_from_timer
 f_dentry||f_path.dentry
 [^_]get_seconds||ktime_get_real_seconds
 GETSTRIPE||LFS getstripe
+kmem_cache_alloc.*GFP_ZERO||kmem_cache_zalloc
 ldebugfs_remove||debugfs_remove_recursive
 ldlm_appetite_t||enum ldlm_appetite
 ldlm_cancel_flags_t||enum ldlm_cancel_flags
index 6db8a5d..f27b5f0 100644 (file)
@@ -375,7 +375,7 @@ lnet_msg_alloc(void)
 {
        struct lnet_msg *msg;
 
-       msg = kmem_cache_alloc(lnet_msg_cachep, GFP_NOFS | __GFP_ZERO);
+       msg = kmem_cache_zalloc(lnet_msg_cachep, GFP_NOFS);
 
        return (msg);
 }
@@ -392,7 +392,7 @@ lnet_rspt_alloc(int cpt)
 {
        struct lnet_rsp_tracker *rspt;
 
-       rspt = kmem_cache_alloc(lnet_rspt_cachep, GFP_NOFS | __GFP_ZERO);
+       rspt = kmem_cache_zalloc(lnet_rspt_cachep, GFP_NOFS);
        if (rspt) {
                lnet_net_lock(cpt);
                the_lnet.ln_counters[cpt]->lct_health.lch_rst_alloc++;
index a4d8f50..36127bc 100644 (file)
@@ -277,7 +277,7 @@ kgnilnd_alloc_tx (void)
        if (CFS_FAIL_CHECK(CFS_FAIL_GNI_ALLOC_TX))
                return tx;
 
-       tx = kmem_cache_alloc(kgnilnd_data.kgn_tx_cache, GFP_ATOMIC);
+       tx = kmem_cache_zalloc(kgnilnd_data.kgn_tx_cache, GFP_ATOMIC);
        if (tx == NULL) {
                CERROR("failed to allocate tx\n");
                return NULL;
@@ -285,9 +285,6 @@ kgnilnd_alloc_tx (void)
        CDEBUG(D_MALLOC, "slab-alloced 'tx': %lu at %p.\n",
               sizeof(*tx), tx);
 
-       /* need this memset, cache alloc'd memory is not cleared */
-       memset(tx, 0, sizeof(*tx));
-
        /* setup everything here to minimize time under the lock */
        tx->tx_buftype = GNILND_BUF_NONE;
        tx->tx_msg.gnm_type = GNILND_MSG_NONE;
index cdd7310..12d16a3 100644 (file)
@@ -963,13 +963,10 @@ kgnilnd_alloc_dgram(kgn_dgram_t **dgramp, kgn_device_t *dev, kgn_dgram_type_t ty
 {
        kgn_dgram_t         *dgram;
 
-       dgram = kmem_cache_alloc(kgnilnd_data.kgn_dgram_cache, GFP_ATOMIC);
+       dgram = kmem_cache_zalloc(kgnilnd_data.kgn_dgram_cache, GFP_ATOMIC);
        if (dgram == NULL)
                return -ENOMEM;
 
-       /* cache alloc'd memory is not zeroed */
-       memset((void *)dgram, 0, sizeof(*dgram)) ;
-
        INIT_LIST_HEAD(&dgram->gndg_list);
        dgram->gndg_state = GNILND_DGRAM_USED;
        dgram->gndg_type = type;
index a87cf74..8dc8785 100644 (file)
@@ -85,7 +85,7 @@ LNetMEAttach(unsigned int portal,
        if (mtable == NULL) /* can't match portal type */
                return ERR_PTR(-EPERM);
 
-       me = kmem_cache_alloc(lnet_mes_cachep, GFP_NOFS | __GFP_ZERO);
+       me = kmem_cache_zalloc(lnet_mes_cachep, GFP_NOFS);
        if (me == NULL) {
                CDEBUG(D_MALLOC, "failed to allocate 'me'\n");
                return ERR_PTR(-ENOMEM);
index 74842e2..5130ca0 100644 (file)
@@ -913,7 +913,7 @@ do {                                                                              \
 do {                                                                         \
        LASSERT(ergo((type) != GFP_ATOMIC, !in_interrupt()));                 \
        (ptr) = (cptab) == NULL ?                                             \
-               kmem_cache_alloc(slab, (type) | __GFP_ZERO) :                 \
+               kmem_cache_zalloc(slab, (type)) :                             \
                cfs_mem_cache_cpt_alloc(slab, cptab, cpt, (type) | __GFP_ZERO); \
        if (likely((ptr)))                                                    \
                OBD_ALLOC_POST(ptr, size, "slab-alloced");                    \