From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Reply-To: "Hillf Danton" From: "Hillf Danton" To: "'Vlastimil Babka'" , "'Andrew Morton'" Cc: , , "'Michal Hocko'" , "'Mel Gorman'" , "'Johannes Weiner'" , , , , , , , "'Andrey Ryabinin'" References: <20170405074700.29871-1-vbabka@suse.cz> <20170405074700.29871-2-vbabka@suse.cz> In-Reply-To: <20170405074700.29871-2-vbabka@suse.cz> Subject: Re: [PATCH 1/4] mm: prevent potential recursive reclaim due to clearing PF_MEMALLOC Date: Fri, 07 Apr 2017 15:33:03 +0800 Message-ID: <092301d2af71$31c97fe0$955c7fa0$@alibaba-inc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Sender: linux-scsi-owner@vger.kernel.org List-ID: On April 05, 2017 3:47 PM Vlastimil Babka wrote: > > The function __alloc_pages_direct_compact() sets PF_MEMALLOC to prevent > deadlock during page migration by lock_page() (see the comment in > __unmap_and_move()). Then it unconditionally clears the flag, which can clear a > pre-existing PF_MEMALLOC flag and result in recursive reclaim. This was not a > problem until commit a8161d1ed609 ("mm, page_alloc: restructure direct > compaction handling in slowpath"), because direct compation was called only > after direct reclaim, which was skipped when PF_MEMALLOC flag was set. > > Even now it's only a theoretical issue, as the new callsite of > __alloc_pages_direct_compact() is reached only for costly orders and when > gfp_pfmemalloc_allowed() is true, which means either __GFP_NOMEMALLOC is in > gfp_flags or in_interrupt() is true. There is no such known context, but let's > play it safe and make __alloc_pages_direct_compact() robust for cases where > PF_MEMALLOC is already set. > > Fixes: a8161d1ed609 ("mm, page_alloc: restructure direct compaction handling in slowpath") > Reported-by: Andrey Ryabinin > Signed-off-by: Vlastimil Babka > Cc: > --- Acked-by: Hillf Danton > mm/page_alloc.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 3589f8be53be..b84e6ffbe756 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -3288,6 +3288,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, > enum compact_priority prio, enum compact_result *compact_result) > { > struct page *page; > + unsigned int noreclaim_flag = current->flags & PF_MEMALLOC; > > if (!order) > return NULL; > @@ -3295,7 +3296,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, > current->flags |= PF_MEMALLOC; > *compact_result = try_to_compact_pages(gfp_mask, order, alloc_flags, ac, > prio); > - current->flags &= ~PF_MEMALLOC; > + current->flags = (current->flags & ~PF_MEMALLOC) | noreclaim_flag; > > if (*compact_result <= COMPACT_INACTIVE) > return NULL; > -- > 2.12.2 From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Hillf Danton" Subject: Re: [PATCH 1/4] mm: prevent potential recursive reclaim due to clearing PF_MEMALLOC Date: Fri, 07 Apr 2017 15:33:03 +0800 Message-ID: <092301d2af71$31c97fe0$955c7fa0$@alibaba-inc.com> References: <20170405074700.29871-1-vbabka@suse.cz> <20170405074700.29871-2-vbabka@suse.cz> Reply-To: "Hillf Danton" Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: , , "'Michal Hocko'" , "'Mel Gorman'" , "'Johannes Weiner'" , , , , , , , "'Andrey Ryabinin'" To: "'Vlastimil Babka'" , "'Andrew Morton'" Return-path: In-Reply-To: <20170405074700.29871-2-vbabka@suse.cz> Content-Language: zh-cn Sender: owner-linux-mm@kvack.org List-Id: netdev.vger.kernel.org On April 05, 2017 3:47 PM Vlastimil Babka wrote: > > The function __alloc_pages_direct_compact() sets PF_MEMALLOC to prevent > deadlock during page migration by lock_page() (see the comment in > __unmap_and_move()). Then it unconditionally clears the flag, which can clear a > pre-existing PF_MEMALLOC flag and result in recursive reclaim. This was not a > problem until commit a8161d1ed609 ("mm, page_alloc: restructure direct > compaction handling in slowpath"), because direct compation was called only > after direct reclaim, which was skipped when PF_MEMALLOC flag was set. > > Even now it's only a theoretical issue, as the new callsite of > __alloc_pages_direct_compact() is reached only for costly orders and when > gfp_pfmemalloc_allowed() is true, which means either __GFP_NOMEMALLOC is in > gfp_flags or in_interrupt() is true. There is no such known context, but let's > play it safe and make __alloc_pages_direct_compact() robust for cases where > PF_MEMALLOC is already set. > > Fixes: a8161d1ed609 ("mm, page_alloc: restructure direct compaction handling in slowpath") > Reported-by: Andrey Ryabinin > Signed-off-by: Vlastimil Babka > Cc: > --- Acked-by: Hillf Danton > mm/page_alloc.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 3589f8be53be..b84e6ffbe756 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -3288,6 +3288,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, > enum compact_priority prio, enum compact_result *compact_result) > { > struct page *page; > + unsigned int noreclaim_flag = current->flags & PF_MEMALLOC; > > if (!order) > return NULL; > @@ -3295,7 +3296,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, > current->flags |= PF_MEMALLOC; > *compact_result = try_to_compact_pages(gfp_mask, order, alloc_flags, ac, > prio); > - current->flags &= ~PF_MEMALLOC; > + current->flags = (current->flags & ~PF_MEMALLOC) | noreclaim_flag; > > if (*compact_result <= COMPACT_INACTIVE) > return NULL; > -- > 2.12.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Hillf Danton" Subject: Re: [PATCH 1/4] mm: prevent potential recursive reclaim due to clearing PF_MEMALLOC Date: Fri, 07 Apr 2017 15:33:03 +0800 Message-ID: <092301d2af71$31c97fe0$955c7fa0$@alibaba-inc.com> References: <20170405074700.29871-1-vbabka@suse.cz> <20170405074700.29871-2-vbabka@suse.cz> Reply-To: "Hillf Danton" Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20170405074700.29871-2-vbabka@suse.cz> Content-Language: zh-cn Sender: owner-linux-mm@kvack.org To: 'Vlastimil Babka' , 'Andrew Morton' Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, 'Michal Hocko' , 'Mel Gorman' , 'Johannes Weiner' , linux-block@vger.kernel.org, nbd-general@lists.sourceforge.net, open-iscsi@googlegroups.com, linux-scsi@vger.kernel.org, netdev@vger.kernel.org, stable@vger.kernel.org, 'Andrey Ryabinin' List-Id: linux-scsi@vger.kernel.org On April 05, 2017 3:47 PM Vlastimil Babka wrote: > > The function __alloc_pages_direct_compact() sets PF_MEMALLOC to prevent > deadlock during page migration by lock_page() (see the comment in > __unmap_and_move()). Then it unconditionally clears the flag, which can clear a > pre-existing PF_MEMALLOC flag and result in recursive reclaim. This was not a > problem until commit a8161d1ed609 ("mm, page_alloc: restructure direct > compaction handling in slowpath"), because direct compation was called only > after direct reclaim, which was skipped when PF_MEMALLOC flag was set. > > Even now it's only a theoretical issue, as the new callsite of > __alloc_pages_direct_compact() is reached only for costly orders and when > gfp_pfmemalloc_allowed() is true, which means either __GFP_NOMEMALLOC is in > gfp_flags or in_interrupt() is true. There is no such known context, but let's > play it safe and make __alloc_pages_direct_compact() robust for cases where > PF_MEMALLOC is already set. > > Fixes: a8161d1ed609 ("mm, page_alloc: restructure direct compaction handling in slowpath") > Reported-by: Andrey Ryabinin > Signed-off-by: Vlastimil Babka > Cc: > --- Acked-by: Hillf Danton > mm/page_alloc.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 3589f8be53be..b84e6ffbe756 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -3288,6 +3288,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, > enum compact_priority prio, enum compact_result *compact_result) > { > struct page *page; > + unsigned int noreclaim_flag = current->flags & PF_MEMALLOC; > > if (!order) > return NULL; > @@ -3295,7 +3296,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, > current->flags |= PF_MEMALLOC; > *compact_result = try_to_compact_pages(gfp_mask, order, alloc_flags, ac, > prio); > - current->flags &= ~PF_MEMALLOC; > + current->flags = (current->flags & ~PF_MEMALLOC) | noreclaim_flag; > > if (*compact_result <= COMPACT_INACTIVE) > return NULL; > -- > 2.12.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org