nfsd: more robust allocation failure handling in nfsd_file_cache_init
Subsystems (2)
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").
--- fs/nfsd/filecache.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/nfsd/filecache.c +4 -2
@@ -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
Jeff Layton
maintainerQuoted 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 innfsd_reply_cache_init").Fixes 65294c1f2c5e ("nfsd: add a new struct file caching facility to nfsd")Suggested-by Jeff Layton <[email protected]>Signed-off-by Amir Goldstein <[email protected]>--- fs/nfsd/filecache.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/nfsd/filecache.c +3
-0@@ -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]>
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 innfsd_reply_cache_init").
Quoted 4 lines
Fixes 65294c1f2c5e ("nfsd: add a new struct file caching facility to nfsd")Suggested-by Jeff Layton <[email protected]>Signed-off-by Amir Goldstein <[email protected]>
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@@ -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