Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1616663

[PATCH 1/4] mm: prevent potential recursive reclaim due to clearing PF_MEMALLOC

From Vlastimil Babka <vbabka@suse.cz>
Newsgroups linux.kernel
Subject [PATCH 1/4] mm: prevent potential recursive reclaim due to clearing PF_MEMALLOC
Date 2017-04-05 09:50 +0200
Message-ID <tsNRv-89c-11@gated-at.bofh.it> (permalink)
References <tsNRv-89c-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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 <aryabinin@virtuozzo.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Cc: <stable@vger.kernel.org>
---
 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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/4] more robust PF_MEMALLOC handling Vlastimil Babka <vbabka@suse.cz> - 2017-04-05 09:50 +0200
  [PATCH 3/4] treewide: convert PF_MEMALLOC manipulations to new helpers Vlastimil Babka <vbabka@suse.cz> - 2017-04-05 09:50 +0200
    Re: [PATCH 3/4] treewide: convert PF_MEMALLOC manipulations to new  helpers Michal Hocko <mhocko@kernel.org> - 2017-04-05 13:40 +0200
      Re: [Nbd] [PATCH 3/4] treewide: convert PF_MEMALLOC manipulations to  new helpers Wouter Verhelst <w@uter.be> - 2017-04-06 09:00 +0200
        Re: [Nbd] [PATCH 3/4] treewide: convert PF_MEMALLOC manipulations to  new helpers Mel Gorman <mgorman@techsingularity.net> - 2017-04-06 13:30 +0200
  [PATCH 1/4] mm: prevent potential recursive reclaim due to clearing PF_MEMALLOC Vlastimil Babka <vbabka@suse.cz> - 2017-04-05 09:50 +0200
    Re: [PATCH 1/4] mm: prevent potential recursive reclaim due to  clearing PF_MEMALLOC Michal Hocko <mhocko@kernel.org> - 2017-04-05 13:30 +0200
    Re: [PATCH 1/4] mm: prevent potential recursive reclaim due to clearing PF_MEMALLOC "Hillf Danton" <hillf.zj@alibaba-inc.com> - 2017-04-07 09:40 +0200
    Re: [PATCH 1/4] mm: prevent potential recursive reclaim due to  clearing PF_MEMALLOC Vlastimil Babka <vbabka@suse.cz> - 2017-04-07 11:30 +0200
  [PATCH 4/4] mtd: nand: nandsim: convert to memalloc_noreclaim_*() Vlastimil Babka <vbabka@suse.cz> - 2017-04-05 09:50 +0200
    Re: [PATCH 4/4] mtd: nand: nandsim: convert to memalloc_noreclaim_*() Vlastimil Babka <vbabka@suse.cz> - 2017-04-05 13:40 +0200
      Re: [PATCH 4/4] mtd: nand: nandsim: convert to memalloc_noreclaim_*() Michal Hocko <mhocko@kernel.org> - 2017-04-05 14:20 +0200
      Re: [PATCH 4/4] mtd: nand: nandsim: convert to memalloc_noreclaim_*() Adrian Hunter <adrian.hunter@intel.com> - 2017-04-06 08:50 +0200
        Re: [PATCH 4/4] mtd: nand: nandsim: convert to memalloc_noreclaim_*() Michal Hocko <mhocko@kernel.org> - 2017-04-06 09:30 +0200
    Re: [PATCH 4/4] mtd: nand: nandsim: convert to memalloc_noreclaim_*() Michal Hocko <mhocko@kernel.org> - 2017-04-05 13:40 +0200
      Re: [PATCH 4/4] mtd: nand: nandsim: convert to memalloc_noreclaim_*() Richard Weinberger <richard@nod.at> - 2017-04-05 13:40 +0200

csiph-web