Skip to contentSkip to conversation

nfsd: more robust allocation failure handling in nfsd_file_cache_init

PATCH Superseded Amir Goldstein 3 participants 3 messages Feb 24, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfsd: more robust allocation failure handling in nfsd_file_cache_init

The nfsd file cache table can be pretty large and its allocation may require as many as 80 contigious pages.

Employ the same fix that was employed for similar issue that was reported for the reply cache hash table allocation several years ago by commit 8f97514b423a ("nfsd: more robust allocation failure handling in nfsd_reply_cache_init").

Fixes 65294c1f2c5e ("nfsd: add a new struct file caching facility to nfsd")
---
 fs/nfsd/filecache.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/nfsd/filecache.c +4 -2
index 8bc807c5fea4..b75cd6d1e331 100644
@@ -60,6 +60,9 @@ static struct fsnotify_group		*nfsd_file_fsnotify_group;
 static atomic_long_t			nfsd_filecache_count;
 static struct delayed_work		nfsd_filecache_laundrette;
 
+#define NFSD_FILE_HASHTBL_SIZE \
+	array_size(NFSD_FILE_HASH_SIZE, sizeof(*nfsd_file_hashtbl))
+
 static void nfsd_file_gc(void);
 
 static void
@@ -632,8 +635,7 @@ nfsd_file_cache_init(void)
 	if (!nfsd_filecache_wq)
 		goto out;
 
-	nfsd_file_hashtbl = kcalloc(NFSD_FILE_HASH_SIZE,
-				sizeof(*nfsd_file_hashtbl), GFP_KERNEL);
+	nfsd_file_hashtbl = kvzalloc(NFSD_FILE_HASHTBL_SIZE, GFP_KERNEL);
 	if (!nfsd_file_hashtbl) {
 		pr_err("nfsd: unable to allocate nfsd_file_hashtbl\n");
 		goto out_err;
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 31 lines · Amir Goldstein

The nfsd file cache table can be pretty large and its allocation may require as many as 80 contigious pages.

Employ the same fix that was employed for similar issue that was reported for the reply cache hash table allocation several years ago by commit 8f97514b423a ("nfsd: more robust allocation failure handling in nfsd_reply_cache_init").

Fixes 65294c1f2c5e ("nfsd: add a new struct file caching facility to nfsd")
---
 fs/nfsd/filecache.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/nfsd/filecache.c +3 -0
index 8bc807c5fea4..b75cd6d1e331 100644
@@ -60,6 +60,9 @@ static struct fsnotify_group		*nfsd_file_fsnotify_group;
 static atomic_long_t			nfsd_filecache_count;
 static struct delayed_work		nfsd_filecache_laundrette;
 
+#define NFSD_FILE_HASHTBL_SIZE \
+	array_size(NFSD_FILE_HASH_SIZE, sizeof(*nfsd_file_hashtbl))
+
 static void nfsd_file_gc(void);
 
 static void

fs/nfsd/filecache.c nfsd_file_cache_init(void) · line 641

Quoted 9 lines
fs/nfsd/filecache.c +1 -2
@@ -632,8 +635,7 @@ nfsd_file_cache_init(void)
 	if (!nfsd_filecache_wq)
 		goto out;
 
-	nfsd_file_hashtbl = kcalloc(NFSD_FILE_HASH_SIZE,
-				sizeof(*nfsd_file_hashtbl), GFP_KERNEL);
+	nfsd_file_hashtbl = kvzalloc(NFSD_FILE_HASHTBL_SIZE, GFP_KERNEL);
 	if (!nfsd_file_hashtbl) {
 		pr_err("nfsd: unable to allocate nfsd_file_hashtbl\n");
 		goto out_err;

You'd also need to change to kvfree(), in case it does end up being vmalloc'ed. Also, I don't see that the new constant adds anything -- you could just use kvcalloc().

Signature · 1 line
Jeff Layton <[email protected]>
#2 lore raw
In reply to Amir Goldstein

Hi Jeff, Amir -

Quoted 10 lines · Amir Goldstein

The nfsd file cache table can be pretty large and its allocation may require as many as 80 contigious pages.

Employ the same fix that was employed for similar issue that was reported for the reply cache hash table allocation several years ago by commit 8f97514b423a ("nfsd: more robust allocation failure handling in nfsd_reply_cache_init").

Quoted 4 lines
Fixes 65294c1f2c5e ("nfsd: add a new struct file caching facility to nfsd")

IMO, this approach is a band-aid, as was 8f97514b423a. I note that not as a rejection, but rather to point out that more work is needed in this area. Big hash tables are inflexible.

I'll go with this one because you provided a patch description ;-) But, as you noted, you need to fix up the kfree() paths too.

Quoted 31 lines

---
fs/nfsd/filecache.c | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)
fs/nfsd/filecache.c +3 -0
index 8bc807c5fea4..b75cd6d1e331 100644
@@ -60,6 +60,9 @@ static struct fsnotify_group		*nfsd_file_fsnotify_group;
 static atomic_long_t			nfsd_filecache_count;
 static struct delayed_work		nfsd_filecache_laundrette;
 
+#define NFSD_FILE_HASHTBL_SIZE \
+	array_size(NFSD_FILE_HASH_SIZE, sizeof(*nfsd_file_hashtbl))
+
 static void nfsd_file_gc(void);
 

static void

fs/nfsd/filecache.c +1 -2
@@ -632,8 +635,7 @@ nfsd_file_cache_init(void)
 	if (!nfsd_filecache_wq)
 		goto out;
 
-	nfsd_file_hashtbl = kcalloc(NFSD_FILE_HASH_SIZE,
-				sizeof(*nfsd_file_hashtbl), GFP_KERNEL);
+	nfsd_file_hashtbl = kvzalloc(NFSD_FILE_HASHTBL_SIZE, GFP_KERNEL);
 	if (!nfsd_file_hashtbl) {
 		pr_err("nfsd: unable to allocate nfsd_file_hashtbl\n");
 		goto out_err;
Signature · 1 line
2.25.1

--
Chuck Lever