* [PATCH v2] nfsd: more robust allocation failure handling in nfsd_reply_cache_init
@ 2016-10-26 11:26 Jeff Layton
2016-10-26 19:37 ` J. Bruce Fields
0 siblings, 1 reply; 2+ messages in thread
From: Jeff Layton @ 2016-10-26 11:26 UTC (permalink / raw)
To: bfields; +Cc: olaf, torvalds, linux-nfs
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>
---
fs/nfsd/nfscache.c | 11 ++++++++---
1 file 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 @@
*/
#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;
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] nfsd: more robust allocation failure handling in nfsd_reply_cache_init
2016-10-26 11:26 [PATCH v2] nfsd: more robust allocation failure handling in nfsd_reply_cache_init Jeff Layton
@ 2016-10-26 19:37 ` J. Bruce Fields
0 siblings, 0 replies; 2+ messages in thread
From: J. Bruce Fields @ 2016-10-26 19:37 UTC (permalink / raw)
To: Jeff Layton; +Cc: olaf, torvalds, linux-nfs
On Wed, Oct 26, 2016 at 07:26:40AM -0400, Jeff Layton wrote:
> 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.
>
> Reported-by: Olaf Hering <olaf@aepfle.de>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Jeff Layton <jlayton@redhat.com>
> ---
> fs/nfsd/nfscache.c | 11 ++++++++---
> 1 file 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 @@
> */
>
> #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;
>
> --
> 2.7.4
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-10-26 19:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-26 11:26 [PATCH v2] nfsd: more robust allocation failure handling in nfsd_reply_cache_init Jeff Layton
2016-10-26 19:37 ` J. Bruce Fields
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).