From 3ceed00b0458dec68ceff4068dcaadd34a71c664 Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Fri, 1 May 2020 15:11:59 +1000 Subject: [PATCH] LU-6142 kernel: use kmem_cache_zalloc as appropriate. 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 Change-Id: Ic4ccbe0e223121e54699f7667e35db14d0f0da70 Reviewed-on: https://review.whamcloud.com/38439 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Chris Horn Reviewed-by: Oleg Drokin --- contrib/scripts/spelling.txt | 1 + lnet/include/lnet/lib-lnet.h | 4 ++-- lnet/klnds/gnilnd/gnilnd_cb.c | 5 +---- lnet/klnds/gnilnd/gnilnd_conn.c | 5 +---- lnet/lnet/lib-me.c | 2 +- lustre/include/obd_support.h | 2 +- 6 files changed, 7 insertions(+), 12 deletions(-) diff --git a/contrib/scripts/spelling.txt b/contrib/scripts/spelling.txt index 008a87a..61ce449 100644 --- a/contrib/scripts/spelling.txt +++ b/contrib/scripts/spelling.txt @@ -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 diff --git a/lnet/include/lnet/lib-lnet.h b/lnet/include/lnet/lib-lnet.h index 6db8a5d..f27b5f0 100644 --- a/lnet/include/lnet/lib-lnet.h +++ b/lnet/include/lnet/lib-lnet.h @@ -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++; diff --git a/lnet/klnds/gnilnd/gnilnd_cb.c b/lnet/klnds/gnilnd/gnilnd_cb.c index a4d8f50..36127bc 100644 --- a/lnet/klnds/gnilnd/gnilnd_cb.c +++ b/lnet/klnds/gnilnd/gnilnd_cb.c @@ -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; diff --git a/lnet/klnds/gnilnd/gnilnd_conn.c b/lnet/klnds/gnilnd/gnilnd_conn.c index cdd7310..12d16a3 100644 --- a/lnet/klnds/gnilnd/gnilnd_conn.c +++ b/lnet/klnds/gnilnd/gnilnd_conn.c @@ -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; diff --git a/lnet/lnet/lib-me.c b/lnet/lnet/lib-me.c index a87cf74..8dc8785 100644 --- a/lnet/lnet/lib-me.c +++ b/lnet/lnet/lib-me.c @@ -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); diff --git a/lustre/include/obd_support.h b/lustre/include/obd_support.h index 74842e2..5130ca0 100644 --- a/lustre/include/obd_support.h +++ b/lustre/include/obd_support.h @@ -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"); \ -- 1.8.3.1