[SRU,X,1/1] NFS: Use GFP_NOIO for two allocations in writeback

Message ID 20180508063443.6507-2-dja@axtens.net
State New
Headers show
Series
  • LP: #1750038 - stuck in D state in NFS op
Related show

Commit Message

Daniel Axtens May 8, 2018, 6:34 a.m.
From: Benjamin Coddington <bcodding@redhat.com>

BugLink: https://bugs.launchpad.net/bugs/1750038

Prevent a deadlock that can occur if we wait on allocations
that try to write back our pages.

Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Fixes: 00bfa30abe869 ("NFS: Create a common pgio_alloc and pgio_release...")
Cc: stable@vger.kernel.org # 3.16+
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
(backported from commit ae97aa524ef495b6276fd26f5d5449fb22975d7c)
Signed-off-by: Daniel Axtens <daniel.axtens@canonical.com>
---
 fs/nfs/pagelist.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Juerg Haefliger May 8, 2018, 7:07 a.m. | #1
On 05/08/2018 08:34 AM, Daniel Axtens wrote:
> From: Benjamin Coddington <bcodding@redhat.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1750038
> 
> Prevent a deadlock that can occur if we wait on allocations
> that try to write back our pages.
> 
> Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
> Fixes: 00bfa30abe869 ("NFS: Create a common pgio_alloc and pgio_release...")
> Cc: stable@vger.kernel.org # 3.16+
> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
> (backported from commit ae97aa524ef495b6276fd26f5d5449fb22975d7c)
> Signed-off-by: Daniel Axtens <daniel.axtens@canonical.com>

Looks reasonable.

Acked-by: Juerg Haefliger <juergh@canonical.com>


> ---
>  fs/nfs/pagelist.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
> index 8ebfdd00044b..1dc47d1aa7ce 100644
> --- a/fs/nfs/pagelist.c
> +++ b/fs/nfs/pagelist.c
> @@ -29,13 +29,14 @@
>  static struct kmem_cache *nfs_page_cachep;
>  static const struct rpc_call_ops nfs_pgio_common_ops;
>  
> -static bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount)
> +static bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount,
> +					gfp_t gfp_flags)
>  {
>  	p->npages = pagecount;
>  	if (pagecount <= ARRAY_SIZE(p->page_array))
>  		p->pagevec = p->page_array;
>  	else {
> -		p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_KERNEL);
> +		p->pagevec = kcalloc(pagecount, sizeof(struct page *), gfp_flags);
>  		if (!p->pagevec)
>  			p->npages = 0;
>  	}
> @@ -722,6 +723,7 @@ void nfs_pageio_init(struct nfs_pageio_descriptor *desc,
>  {
>  	struct nfs_pgio_mirror *new;
>  	int i;
> +	gfp_t gfp_flags = GFP_KERNEL;
>  
>  	desc->pg_moreio = 0;
>  	desc->pg_inode = inode;
> @@ -741,8 +743,10 @@ void nfs_pageio_init(struct nfs_pageio_descriptor *desc,
>  	if (pg_ops->pg_get_mirror_count) {
>  		/* until we have a request, we don't have an lseg and no
>  		 * idea how many mirrors there will be */
> +		if (desc->pg_rw_ops->rw_mode == FMODE_WRITE)
> +			gfp_flags = GFP_NOIO;
>  		new = kcalloc(NFS_PAGEIO_DESCRIPTOR_MIRROR_MAX,
> -			      sizeof(struct nfs_pgio_mirror), GFP_KERNEL);
> +			      sizeof(struct nfs_pgio_mirror), gfp_flags);
>  		desc->pg_mirrors_dynamic = new;
>  		desc->pg_mirrors = new;
>  
> @@ -796,10 +800,14 @@ int nfs_generic_pgio(struct nfs_pageio_descriptor *desc,
>  	struct list_head *head = &mirror->pg_list;
>  	struct nfs_commit_info cinfo;
>  	unsigned int pagecount, pageused;
> +	gfp_t gfp_flags = GFP_KERNEL;
>  
>  	pagecount = nfs_page_array_len(mirror->pg_base, mirror->pg_count);
> -	if (!nfs_pgarray_set(&hdr->page_array, pagecount))
> +	if (desc->pg_rw_ops->rw_mode == FMODE_WRITE)
> +		gfp_flags = GFP_NOIO;
> +	if (!nfs_pgarray_set(&hdr->page_array, pagecount, gfp_flags)) {
>  		return nfs_pgio_error(desc, hdr);
> +	}
>  
>  	nfs_init_cinfo(&cinfo, desc->pg_inode, desc->pg_dreq);
>  	pages = hdr->page_array.pagevec;
>
Kleber Souza May 11, 2018, 2:25 p.m. | #2
On 05/08/18 08:34, Daniel Axtens wrote:
> From: Benjamin Coddington <bcodding@redhat.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1750038
> 
> Prevent a deadlock that can occur if we wait on allocations
> that try to write back our pages.
> 
> Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
> Fixes: 00bfa30abe869 ("NFS: Create a common pgio_alloc and pgio_release...")
> Cc: stable@vger.kernel.org # 3.16+
> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
> (backported from commit ae97aa524ef495b6276fd26f5d5449fb22975d7c)
> Signed-off-by: Daniel Axtens <daniel.axtens@canonical.com>

Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>

> ---
>  fs/nfs/pagelist.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
> index 8ebfdd00044b..1dc47d1aa7ce 100644
> --- a/fs/nfs/pagelist.c
> +++ b/fs/nfs/pagelist.c
> @@ -29,13 +29,14 @@
>  static struct kmem_cache *nfs_page_cachep;
>  static const struct rpc_call_ops nfs_pgio_common_ops;
>  
> -static bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount)
> +static bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount,
> +					gfp_t gfp_flags)
>  {
>  	p->npages = pagecount;
>  	if (pagecount <= ARRAY_SIZE(p->page_array))
>  		p->pagevec = p->page_array;
>  	else {
> -		p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_KERNEL);
> +		p->pagevec = kcalloc(pagecount, sizeof(struct page *), gfp_flags);
>  		if (!p->pagevec)
>  			p->npages = 0;
>  	}
> @@ -722,6 +723,7 @@ void nfs_pageio_init(struct nfs_pageio_descriptor *desc,
>  {
>  	struct nfs_pgio_mirror *new;
>  	int i;
> +	gfp_t gfp_flags = GFP_KERNEL;
>  
>  	desc->pg_moreio = 0;
>  	desc->pg_inode = inode;
> @@ -741,8 +743,10 @@ void nfs_pageio_init(struct nfs_pageio_descriptor *desc,
>  	if (pg_ops->pg_get_mirror_count) {
>  		/* until we have a request, we don't have an lseg and no
>  		 * idea how many mirrors there will be */
> +		if (desc->pg_rw_ops->rw_mode == FMODE_WRITE)
> +			gfp_flags = GFP_NOIO;
>  		new = kcalloc(NFS_PAGEIO_DESCRIPTOR_MIRROR_MAX,
> -			      sizeof(struct nfs_pgio_mirror), GFP_KERNEL);
> +			      sizeof(struct nfs_pgio_mirror), gfp_flags);
>  		desc->pg_mirrors_dynamic = new;
>  		desc->pg_mirrors = new;
>  
> @@ -796,10 +800,14 @@ int nfs_generic_pgio(struct nfs_pageio_descriptor *desc,
>  	struct list_head *head = &mirror->pg_list;
>  	struct nfs_commit_info cinfo;
>  	unsigned int pagecount, pageused;
> +	gfp_t gfp_flags = GFP_KERNEL;
>  
>  	pagecount = nfs_page_array_len(mirror->pg_base, mirror->pg_count);
> -	if (!nfs_pgarray_set(&hdr->page_array, pagecount))
> +	if (desc->pg_rw_ops->rw_mode == FMODE_WRITE)
> +		gfp_flags = GFP_NOIO;
> +	if (!nfs_pgarray_set(&hdr->page_array, pagecount, gfp_flags)) {
>  		return nfs_pgio_error(desc, hdr);
> +	}
>  
>  	nfs_init_cinfo(&cinfo, desc->pg_inode, desc->pg_dreq);
>  	pages = hdr->page_array.pagevec;
>

Patch

diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index 8ebfdd00044b..1dc47d1aa7ce 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -29,13 +29,14 @@ 
 static struct kmem_cache *nfs_page_cachep;
 static const struct rpc_call_ops nfs_pgio_common_ops;
 
-static bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount)
+static bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount,
+					gfp_t gfp_flags)
 {
 	p->npages = pagecount;
 	if (pagecount <= ARRAY_SIZE(p->page_array))
 		p->pagevec = p->page_array;
 	else {
-		p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_KERNEL);
+		p->pagevec = kcalloc(pagecount, sizeof(struct page *), gfp_flags);
 		if (!p->pagevec)
 			p->npages = 0;
 	}
@@ -722,6 +723,7 @@  void nfs_pageio_init(struct nfs_pageio_descriptor *desc,
 {
 	struct nfs_pgio_mirror *new;
 	int i;
+	gfp_t gfp_flags = GFP_KERNEL;
 
 	desc->pg_moreio = 0;
 	desc->pg_inode = inode;
@@ -741,8 +743,10 @@  void nfs_pageio_init(struct nfs_pageio_descriptor *desc,
 	if (pg_ops->pg_get_mirror_count) {
 		/* until we have a request, we don't have an lseg and no
 		 * idea how many mirrors there will be */
+		if (desc->pg_rw_ops->rw_mode == FMODE_WRITE)
+			gfp_flags = GFP_NOIO;
 		new = kcalloc(NFS_PAGEIO_DESCRIPTOR_MIRROR_MAX,
-			      sizeof(struct nfs_pgio_mirror), GFP_KERNEL);
+			      sizeof(struct nfs_pgio_mirror), gfp_flags);
 		desc->pg_mirrors_dynamic = new;
 		desc->pg_mirrors = new;
 
@@ -796,10 +800,14 @@  int nfs_generic_pgio(struct nfs_pageio_descriptor *desc,
 	struct list_head *head = &mirror->pg_list;
 	struct nfs_commit_info cinfo;
 	unsigned int pagecount, pageused;
+	gfp_t gfp_flags = GFP_KERNEL;
 
 	pagecount = nfs_page_array_len(mirror->pg_base, mirror->pg_count);
-	if (!nfs_pgarray_set(&hdr->page_array, pagecount))
+	if (desc->pg_rw_ops->rw_mode == FMODE_WRITE)
+		gfp_flags = GFP_NOIO;
+	if (!nfs_pgarray_set(&hdr->page_array, pagecount, gfp_flags)) {
 		return nfs_pgio_error(desc, hdr);
+	}
 
 	nfs_init_cinfo(&cinfo, desc->pg_inode, desc->pg_dreq);
 	pages = hdr->page_array.pagevec;