nfsd: more robust allocation failure handling in nfsd_reply_cache_init
Subsystems (2)
PATCH v2 1/1 nfsd: more robust allocation failure handling in nfsd_reply_cache_init
Currently, we try to allocate the cache as a single, large chunk, which can fail if no big chunks of memory are available. We _do_ try to size it according to the amount of memory in the box, but if the server is started well after boot time, then the allocation can fail due to memory fragmentation.
Fall back to doing a vzalloc if the kcalloc fails, and switch the shutdown code to do a kvfree to handle freeing correctly.
--- fs/nfsd/nfscache.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
fs/nfsd/nfscache.c +8 -3
@@ -9,6 +9,7 @@*/ #include <linux/slab.h> +#include <linux/vmalloc.h> #include <linux/sunrpc/addr.h> #include <linux/highmem.h> #include <linux/log2.h>
@@ -174,8 +175,12 @@ int nfsd_reply_cache_init(void) goto out_nomem; drc_hashtbl =kcalloc (hashsize,sizeof (*drc_hashtbl),GFP_KERNEL ); -if (!drc_hashtbl) - goto out_nomem; +if (!drc_hashtbl) { + drc_hashtbl =vzalloc (hashsize *sizeof (*drc_hashtbl)); +if (!drc_hashtbl) + goto out_nomem; + } +for (i =0 ; i < hashsize; i++) {INIT_LIST_HEAD (&drc_hashtbl[i].lru_head);spin_lock_init (&drc_hashtbl[i].cache_lock);
@@ -204,7 +209,7 @@ void nfsd_reply_cache_shutdown(void) } } -kfree (drc_hashtbl); +kvfree (drc_hashtbl); drc_hashtbl =NULL ; drc_hashsize =0 ;
Signature · 1 line
2.7.4
Quoted 8 lines · Jeff Layton
Currently, we try to allocate the cache as a single, large chunk, which can fail if no big chunks of memory are available. We _do_ try to size it according to the amount of memory in the box, but if the server is started well after boot time, then the allocation can fail due to memory fragmentation.
Fall back to doing a vzalloc if the kcalloc fails, and switch the shutdown code to do a kvfree to handle freeing correctly.
Thanks, applying for 4.10.--b.
Quoted 46 lines
Reported-by Olaf Hering <[email protected]>Cc Linus Torvalds <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfscache.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)fs/nfsd/nfscache.c +8
-3@@ -9,6 +9,7 @@*/ #include <linux/slab.h> +#include <linux/vmalloc.h> #include <linux/sunrpc/addr.h> #include <linux/highmem.h> #include <linux/log2.h> @@ -174,8 +175,12 @@ int nfsd_reply_cache_init(void) goto out_nomem; drc_hashtbl =kcalloc (hashsize,sizeof (*drc_hashtbl),GFP_KERNEL ); -if (!drc_hashtbl) - goto out_nomem; +if (!drc_hashtbl) { + drc_hashtbl =vzalloc (hashsize *sizeof (*drc_hashtbl)); +if (!drc_hashtbl) + goto out_nomem; + } +for (i =0 ; i < hashsize; i++) {INIT_LIST_HEAD (&drc_hashtbl[i].lru_head);spin_lock_init (&drc_hashtbl[i].cache_lock);@@ -204,7 +209,7 @@ void nfsd_reply_cache_shutdown(void) } } -kfree (drc_hashtbl); +kvfree (drc_hashtbl); drc_hashtbl =NULL ; drc_hashsize =0 ;Signature · 1 line
2.7.4