[Devel] [PATCH RHEL7 COMMIT] nfsd: use kvzalloc() to allocate memory for drc_hashtbl

Konstantin Khorenko khorenko at virtuozzo.com
Wed May 16 11:18:13 MSK 2018


The commit is pushed to "branch-rh7-3.10.0-693.21.1.vz7.47.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-693.21.1.vz7.47.6
------>
commit b57f616135d1e25506f84cbf3637ec369c510d08
Author: Oleg Babin <obabin at virtuozzo.com>
Date:   Wed May 16 11:18:13 2018 +0300

    nfsd: use kvzalloc() to allocate memory for drc_hashtbl
    
    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>
    Reviewed-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
    
    ===========================================
    Patchset description:
    nfsd: use kvzalloc() to allocate memory for drc_hashtbl
    
    The size of drc_hashtbl depends on totalram_pages and totalhigh_pages
    mm variables and limited to 96k which means 5th memory order.
    
    Use kvzalloc() for drc_hashtbl allocation to fallback to vmalloc()
    in case of high order page is not available at the moment.
    
    https://jira.sw.ru/browse/PSBM-84234
    
    v2: Make use of the mainstream patch which partially fixes the problem.
    
    Jeff Layton (1):
      nfsd: more robust allocation failure handling in nfsd_reply_cache_init
    
    Oleg Babin (1):
      nfsd: use kvzalloc() to allocate memory for drc_hashtbl
---
 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 b5c25eaeaae2..f65090a5e7d7 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);


More information about the Devel mailing list