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

Submitted by Oleg Babin on May 10, 2018, 5:09 p.m.

Details

Message ID 1525972194-231410-3-git-send-email-obabin@virtuozzo.com
State New
Series "nfsd: use kvzalloc() to allocate memory for drc_hashtbl"
Headers show

Commit Message

Oleg Babin May 10, 2018, 5:09 p.m.
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@virtuozzo.com>
---
 fs/nfsd/nfscache.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

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);

Comments

Andrey Ryabinin May 11, 2018, 9:25 a.m.
On 05/10/2018 08:09 PM, Oleg Babin wrote:
> 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@virtuozzo.com>

Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com>