aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2016-10-26 07:26:40 -0400
committerJ. Bruce Fields <bfields@redhat.com>2016-11-01 15:47:43 -0400
commit8f97514b423a0983e4c600099882a9c6613142d2 (patch)
treeb16f551114bf911b4b5bd914ceedb94434226279
parentf46c445b79906a9da55c13e0a6f6b6a006b892fe (diff)
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. Reported-by: Olaf Hering <olaf@aepfle.de> Cc: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
-rw-r--r--fs/nfsd/nfscache.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index 54cde9a5864e..d6b97b424ad1 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/vmalloc.h>
12#include <linux/sunrpc/addr.h> 13#include <linux/sunrpc/addr.h>
13#include <linux/highmem.h> 14#include <linux/highmem.h>
14#include <linux/log2.h> 15#include <linux/log2.h>
@@ -174,8 +175,12 @@ int nfsd_reply_cache_init(void)
174 goto out_nomem; 175 goto out_nomem;
175 176
176 drc_hashtbl = kcalloc(hashsize, sizeof(*drc_hashtbl), GFP_KERNEL); 177 drc_hashtbl = kcalloc(hashsize, sizeof(*drc_hashtbl), GFP_KERNEL);
177 if (!drc_hashtbl) 178 if (!drc_hashtbl) {
178 goto out_nomem; 179 drc_hashtbl = vzalloc(hashsize * sizeof(*drc_hashtbl));
180 if (!drc_hashtbl)
181 goto out_nomem;
182 }
183
179 for (i = 0; i < hashsize; i++) { 184 for (i = 0; i < hashsize; i++) {
180 INIT_LIST_HEAD(&drc_hashtbl[i].lru_head); 185 INIT_LIST_HEAD(&drc_hashtbl[i].lru_head);
181 spin_lock_init(&drc_hashtbl[i].cache_lock); 186 spin_lock_init(&drc_hashtbl[i].cache_lock);
@@ -204,7 +209,7 @@ void nfsd_reply_cache_shutdown(void)
204 } 209 }
205 } 210 }
206 211
207 kfree (drc_hashtbl); 212 kvfree(drc_hashtbl);
208 drc_hashtbl = NULL; 213 drc_hashtbl = NULL;
209 drc_hashsize = 0; 214 drc_hashsize = 0;
210 215