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


Groups > linux.kernel > #1615195

Re: [PATCH] mm/zswap: fix potential deadlock in zswap_frontswap_store()

From Michal Hocko <mhocko@kernel.org>
Newsgroups linux.kernel
Subject Re: [PATCH] mm/zswap: fix potential deadlock in zswap_frontswap_store()
Date 2017-04-03 15:30 +0200
Message-ID <tsadr-7pt-3@gated-at.bofh.it> (permalink)
References (1 earlier) <tr8dI-7tj-9@gated-at.bofh.it> <ts5Qt-4uN-7@gated-at.bofh.it> <ts9AK-6V6-27@gated-at.bofh.it> <ts9AK-6V6-25@gated-at.bofh.it> <tsadr-7pt-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon 03-04-17 16:14:51, Andrey Ryabinin wrote:
> 
> 
> On 04/03/2017 03:45 PM, Michal Hocko wrote:
> > On Mon 03-04-17 15:37:07, Andrey Ryabinin wrote:
> >>
> >>
> >> On 04/03/2017 11:47 AM, Michal Hocko wrote:
> >>> On Fri 31-03-17 10:00:30, Shakeel Butt wrote:
> >>>> On Fri, Mar 31, 2017 at 8:30 AM, Andrey Ryabinin
> >>>> <aryabinin@virtuozzo.com> wrote:
> >>>>> zswap_frontswap_store() is called during memory reclaim from
> >>>>> __frontswap_store() from swap_writepage() from shrink_page_list().
> >>>>> This may happen in NOFS context, thus zswap shouldn't use __GFP_FS,
> >>>>> otherwise we may renter into fs code and deadlock.
> >>>>> zswap_frontswap_store() also shouldn't use __GFP_IO to avoid recursion
> >>>>> into itself.
> >>>>>
> >>>>
> >>>> Is it possible to enter fs code (or IO) from zswap_frontswap_store()
> >>>> other than recursive memory reclaim? However recursive memory reclaim
> >>>> is protected through PF_MEMALLOC task flag. The change seems fine but
> >>>> IMHO reasoning needs an update. Adding Michal for expert opinion.
> >>>
> >>> Yes this is true. 
> >>
> >> Actually, no. I think we have a bug in allocator which may lead to
> >> recursive direct reclaim.
> >>
> >> E.g. for costly order allocations (or order > 0 &&
> >> ac->migratetype != MIGRATE_MOVABLE) with __GFP_NOMEMALLOC
> >> (gfp_pfmemalloc_allowed() returns false) __alloc_pages_slowpath()
> >> may call __alloc_pages_direct_compact() and unconditionally clear
> >> PF_MEMALLOC:
> > 
> > Not sure what is the bug here. __GFP_NOMEMALLOC is supposed to inhibit
> > PF_MEMALLOC. And we do not recurse to the reclaim path. We only do the
> > compaction. Or what am I missing?
> > 
> 
> The bug here is that __alloc_pages_direct_compact() will
> *unconditionally* clear PF_MEMALLOC.  So if we already
> under direct reclaim (so PF_MEMALLOC was already set)
> __alloc_pages_direct_compact() will clear that PF_MEMALLOC. If
> compaction failed we may go into direct reclaim again because the
> following following if in __alloc_pages_slowpath() is false:

Ohh, I see what you mean. Yes this is true but I guess we do not
have any real costly order __GFP_NOMEMALLOC users (not sure about
MIGRATE_MOVABLE branch) so nobody has noticed this.  Still worth fixing
I guess. I already have a plan to change direct PF_MEMALLOC to use
memalloc_noreclaim_{save,restore} API on my todo list. Just didn't get
to it yet. Care to send a patch?
-- 
Michal Hocko
SUSE Labs

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


Thread

Re: [PATCH] mm/zswap: fix potential deadlock in zswap_frontswap_store() Shakeel Butt <shakeelb@google.com> - 2017-03-31 19:10 +0200
  Re: [PATCH] mm/zswap: fix potential deadlock in  zswap_frontswap_store() Michal Hocko <mhocko@kernel.org> - 2017-04-03 10:50 +0200
    Re: [PATCH] mm/zswap: fix potential deadlock in  zswap_frontswap_store() Michal Hocko <mhocko@kernel.org> - 2017-04-03 14:30 +0200
    Re: [PATCH] mm/zswap: fix potential deadlock in  zswap_frontswap_store() Michal Hocko <mhocko@kernel.org> - 2017-04-03 14:50 +0200
      Re: [PATCH] mm/zswap: fix potential deadlock in  zswap_frontswap_store() Michal Hocko <mhocko@kernel.org> - 2017-04-03 15:30 +0200
    Re: [PATCH] mm/zswap: fix potential deadlock in  zswap_frontswap_store() Vlastimil Babka <vbabka@suse.cz> - 2017-04-03 15:30 +0200

csiph-web