From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753287AbdDCN2y (ORCPT ); Mon, 3 Apr 2017 09:28:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:33856 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752020AbdDCN2x (ORCPT ); Mon, 3 Apr 2017 09:28:53 -0400 Subject: Re: [PATCH] mm/zswap: fix potential deadlock in zswap_frontswap_store() To: Andrey Ryabinin , Michal Hocko , Shakeel Butt References: <20170331153009.11397-1-aryabinin@virtuozzo.com> <20170403084729.GG24661@dhcp22.suse.cz> Cc: Seth Jennings , Dan Streetman , Linux MM , LKML , Andrew Morton From: Vlastimil Babka Message-ID: <28e47653-96d7-288a-0c9b-e065b29d7c45@suse.cz> Date: Mon, 3 Apr 2017 15:28:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/03/2017 02:38 PM, Andrey Ryabinin wrote: > > > On 04/03/2017 03:37 PM, 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 >>>> 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: >> >> __alloc_pages_direct_compact(): >> ... >> current->flags |= PF_MEMALLOC; >> *compact_result = try_to_compact_pages(gfp_mask, order, alloc_flags, ac, >> prio); >> 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, >> &did_some_progress); >> > > > Seems it was broken by > > a8161d1ed6098506303c65b3701dedba876df42a > Author: Vlastimil Babka > Date: Thu Jul 28 15:49:19 2016 -0700 > > mm, page_alloc: restructure direct compaction handling in slowpath Yeah, looks like previously the code subtly relied on compaction being called only after the PF_MEMALLOC -> goto nopage check and I didn't notice it. Tell me if I should add a check or you plan to send a patch. Thanks! > -- > 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 >