[Devel] [PATCH vz7 v2 2/2] nfsd: use kvzalloc() to allocate memory for drc_hashtbl

Oleg Babin obabin at virtuozzo.com
Thu May 10 20:09:54 MSK 2018


The original code uses vzalloc() directly as a fallback path if
the allocation with kcalloc() failed. But in this case a warning
about memory allocation failure will be generated even in case
when the fallback path succeeds. Also kcalloc() can involve retries
and OOM killer which is undesireable.

kvzalloc() handles all these aspects properly.

https://jira.sw.ru/browse/PSBM-84234

Signed-off-by: Oleg Babin <obabin at virtuozzo.com>
---
 fs/nfsd/nfscache.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index b5c25ea..f65090a 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -178,12 +178,9 @@ int nfsd_reply_cache_init(void)
 	if (!drc_slab)
 		goto out_nomem;
 
-	drc_hashtbl = kcalloc(hashsize, sizeof(*drc_hashtbl), GFP_KERNEL);
-	if (!drc_hashtbl) {
-		drc_hashtbl = vzalloc(hashsize * sizeof(*drc_hashtbl));
-		if (!drc_hashtbl)
-			goto out_nomem;
-	}
+	drc_hashtbl = kvzalloc(hashsize * sizeof(*drc_hashtbl), GFP_KERNEL);
+	if (!drc_hashtbl)
+		goto out_nomem;
 
 	for (i = 0; i < hashsize; i++) {
 		INIT_LIST_HEAD(&drc_hashtbl[i].lru_head);
-- 
1.8.3.1



More information about the Devel mailing list