[lkml]   [2017]   [Apr]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH] mm/zswap: fix potential deadlock in zswap_frontswap_store()

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
>> <> 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:

current->flags |= PF_MEMALLOC;
*compact_result = try_to_compact_pages(gfp_mask, order, alloc_flags, ac,
current->flags &= ~PF_MEMALLOC;

And later in __alloc_pages_slowpath():

/* Avoid recursion of direct reclaim */
if (current->flags & PF_MEMALLOC) <=== false
goto nopage;

/* Try direct reclaim and then allocating */
page = __alloc_pages_direct_reclaim(gfp_mask, order, alloc_flags, ac,

 \ /
  Last update: 2017-04-03 14:36    [W:0.055 / U:1.860 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site