[Devel] [PATCH RH8] silence nfscache allocation warnings with kvzalloc

Evgenii Shatokhin eshatokhin at virtuozzo.com
Wed May 5 17:08:06 MSK 2021


From: Rik van Riel <riel at surriel.com>

Currently nfsd_reply_cache_init attempts hash table allocation through
kmalloc, and manually falls back to vzalloc if that fails. This makes
the code a little larger than needed, and creates a significant amount
of serial console spam if you have enough systems.

Switching to kvzalloc gets rid of the allocation warnings, and makes
the code a little cleaner too as a side effect.

Freeing of nn->drc_hashtbl is already done using kvfree currently.

Signed-off-by: Rik van Riel <riel at surriel.com>
Signed-off-by: J. Bruce Fields <bfields at redhat.com>

eshatokhin@:
This patch from mainline kernel (commit 8c38b705b4f4) addresses the same
issue as the commit fb1f6c63b271 "nfsd: use kvzalloc() to allocate memory
for drc_hashtbl" in VZ7, prepared by Oleg Babin in the scope of
https://jira.sw.ru/browse/PSBM-84234. That patch did not make it into
the mainline kernel for some reason, so I picked the fix from mainline
instead.

>From the description of commit fb1f6c63b271 in VZ7:
=============
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.

[...]

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.
=============

Done in the scope of https://jira.sw.ru/browse/PSBM-127830.

Signed-off-by: Evgenii Shatokhin <eshatokhin at virtuozzo.com>
---
 fs/nfsd/nfscache.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index f3595fcead23..3bacc9f82f57 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -173,14 +173,10 @@ int nfsd_reply_cache_init(struct nfsd_net *nn)
 	if (status)
 		goto out_nomem;
 
-	nn->drc_hashtbl = kcalloc(hashsize,
-				sizeof(*nn->drc_hashtbl), GFP_KERNEL);
-	if (!nn->drc_hashtbl) {
-		nn->drc_hashtbl = vzalloc(array_size(hashsize,
-						 sizeof(*nn->drc_hashtbl)));
-		if (!nn->drc_hashtbl)
-			goto out_shrinker;
-	}
+	nn->drc_hashtbl = kvzalloc(array_size(hashsize,
+				sizeof(*nn->drc_hashtbl)), GFP_KERNEL);
+	if (!nn->drc_hashtbl)
+		goto out_shrinker;
 
 	for (i = 0; i < hashsize; i++) {
 		INIT_LIST_HEAD(&nn->drc_hashtbl[i].lru_head);
-- 
2.29.0



More information about the Devel mailing list