Received: by 10.223.176.5 with SMTP id f5csp2770854wra; Mon, 29 Jan 2018 03:48:05 -0800 (PST) X-Google-Smtp-Source: AH8x2254Ft6Clk0YPrf+4x+WsXaGw6/0tHMAJBrZTA14Ax9Ja7yU8OjkV1ghn/QeIrwc11MIlZGV X-Received: by 2002:a17:902:4324:: with SMTP id i33-v6mr21432058pld.39.1517226485572; Mon, 29 Jan 2018 03:48:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517226485; cv=none; d=google.com; s=arc-20160816; b=Ut4ESPDitmfvL6BrkbcbeCAKY2RjgXC/g1f62a8dQC9gqpohFHE/Hz2zFRfl4tD4pa Gm1yKFN1XJbRZqYoFtUkc+SH6Vr33fk4s+9OhE9WB0vTxa3PglPPkb7UTBRMyMr5qcSh 0To6ZImHhAHc8YV1AhQWZcYj840DZzrYOdY0m9Ca7mJgGLkHcroXvWb7OKBxyFYhyDzc 5dU6Ij5YaS89f7otMKGjF1SRy+RIyzQ7RV+9wRaoNQMe4CuxPU5y7rPEP2LRw+xILgBd tfflDOMx+X8LC5yeRuC/gTjtEx9ywce7I5Fjk9XXdCco4OxsjutsB0qzDl4PvlfpllgU yuwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:date:message-id:in-reply-to :references:from:subject:cc:to:arc-authentication-results; bh=4UrhSwGodhOWFe0F1fJAnSRZBoADq5dAMbHjz1ST2mg=; b=th9dGj/mSckhU+SqjaGFS3pfUgJrzCG4U6nJe6OjY3QWcE/bOaEkGedlebrrMthZ3p DStaB4mfTXazsvfvOIUJMfPCFpgeVA3dxIsp68CPlLh/ZnoVTAq0JeqPaHQeVhfGUJ93 t1I8p9sALUK2gup8iPQlbNoU45XkhliSRwOiTVcv2nsHg24lJfy0MgnVBJRnWtv/fNFn ++voRBdGgwR/2RKG6RIKAA+wkoFtJzNdGO/Ng+Gwxf0UniOmcfNAFxFHxSGh10l6SUBl sGeEYQ8x2ns0592XXX/rKdT+tJyKziL5Ysnho1s7JhPc3YVU31EZ2p1chR3NIASduwvn pM0A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h67si7243138pgc.821.2018.01.29.03.47.51; Mon, 29 Jan 2018 03:48:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751733AbeA2LrZ (ORCPT + 99 others); Mon, 29 Jan 2018 06:47:25 -0500 Received: from www262.sakura.ne.jp ([202.181.97.72]:15729 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751360AbeA2LrY (ORCPT ); Mon, 29 Jan 2018 06:47:24 -0500 Received: from fsav402.sakura.ne.jp (fsav402.sakura.ne.jp [133.242.250.101]) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id w0TBlMYG068993; Mon, 29 Jan 2018 20:47:22 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav402.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav402.sakura.ne.jp); Mon, 29 Jan 2018 20:47:22 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav402.sakura.ne.jp) Received: from AQUA (softbank126074156036.bbtec.net [126.74.156.36]) (authenticated bits=0) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id w0TBlM46068987; Mon, 29 Jan 2018 20:47:22 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) To: peterz@infradead.org Cc: torvalds@linux-foundation.org, davej@codemonkey.org.uk, npiggin@gmail.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, mhocko@kernel.org Subject: Re: [4.15-rc9] fs_reclaim lockdep trace From: Tetsuo Handa References: <7771dd55-2655-d3a9-80ee-24c9ada7dbbe@I-love.SAKURA.ne.jp> <8f1c776d-b791-e0b9-1e5c-62b03dcd1d74@I-love.SAKURA.ne.jp> <20180129102746.GQ2269@hirez.programming.kicks-ass.net> In-Reply-To: <20180129102746.GQ2269@hirez.programming.kicks-ass.net> Message-Id: <201801292047.EHC05241.OHSQOJOVtFMFLF@I-love.SAKURA.ne.jp> X-Mailer: Winbiff [Version 2.51 PL2] X-Accept-Language: ja,en,zh Date: Mon, 29 Jan 2018 20:47:20 +0900 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Peter Zijlstra wrote: > On Sun, Jan 28, 2018 at 02:55:28PM +0900, Tetsuo Handa wrote: > > This warning seems to be caused by commit d92a8cfcb37ecd13 > > ("locking/lockdep: Rework FS_RECLAIM annotation") which moved the > > location of > > > > /* this guy won't enter reclaim */ > > if ((current->flags & PF_MEMALLOC) && !(gfp_mask & __GFP_NOMEMALLOC)) > > return false; > > > > check added by commit cf40bd16fdad42c0 ("lockdep: annotate reclaim context > > (__GFP_NOFS)"). > > I'm not entirly sure I get what you mean here. How did I move it? It was > part of lockdep_trace_alloc(), if __GFP_NOMEMALLOC was set, it would not > mark the lock as held. d92a8cfcb37ecd13 replaced lockdep_set_current_reclaim_state() with fs_reclaim_acquire(), and removed current->lockdep_recursion handling. ---------- # git show d92a8cfcb37ecd13 | grep recursion -# define INIT_LOCKDEP .lockdep_recursion = 0, .lockdep_reclaim_gfp = 0, +# define INIT_LOCKDEP .lockdep_recursion = 0, unsigned int lockdep_recursion; - if (unlikely(current->lockdep_recursion)) - current->lockdep_recursion = 1; - current->lockdep_recursion = 0; - * context checking code. This tests GFP_FS recursion (a lock taken ---------- > > The new code has it in fs_reclaim_acquire/release to the same effect, if > __GFP_NOMEMALLOC, we'll not acquire/release the lock. Excuse me, but I can't catch. We currently acquire/release __fs_reclaim_map if __GFP_NOMEMALLOC. ---------- +static bool __need_fs_reclaim(gfp_t gfp_mask) +{ (...snipped...) + /* this guy won't enter reclaim */ + if ((current->flags & PF_MEMALLOC) && !(gfp_mask & __GFP_NOMEMALLOC)) + return false; (...snipped...) +} ---------- > > > > Since __kmalloc_reserve() from __alloc_skb() adds > > __GFP_NOMEMALLOC | __GFP_NOWARN to gfp_mask, __need_fs_reclaim() is > > failing to return false despite PF_MEMALLOC context (and resulted in > > lockdep warning). > > But that's correct right, __GFP_NOMEMALLOC should negate PF_MEMALLOC. > That's what the name says. __GFP_NOMEMALLOC negates PF_MEMALLOC regarding what watermark that allocation request should use. ---------- static inline int __gfp_pfmemalloc_flags(gfp_t gfp_mask) { if (unlikely(gfp_mask & __GFP_NOMEMALLOC)) return 0; if (gfp_mask & __GFP_MEMALLOC) return ALLOC_NO_WATERMARKS; if (in_serving_softirq() && (current->flags & PF_MEMALLOC)) return ALLOC_NO_WATERMARKS; if (!in_interrupt()) { if (current->flags & PF_MEMALLOC) return ALLOC_NO_WATERMARKS; else if (oom_reserves_allowed(current)) return ALLOC_OOM; } return 0; } ---------- But at the same time, PF_MEMALLOC negates __GFP_DIRECT_RECLAIM. ---------- /* Attempt with potentially adjusted zonelist and alloc_flags */ page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac); if (page) goto got_pg; /* Caller is not willing to reclaim, we can't balance anything */ if (!can_direct_reclaim) goto nopage; /* Avoid recursion of direct reclaim */ if (current->flags & PF_MEMALLOC) goto nopage; /* Try direct reclaim and then allocating */ page = __alloc_pages_direct_reclaim(gfp_mask, order, alloc_flags, ac, &did_some_progress); if (page) goto got_pg; /* Try direct compaction and then allocating */ page = __alloc_pages_direct_compact(gfp_mask, order, alloc_flags, ac, compact_priority, &compact_result); if (page) goto got_pg; /* Do not loop if specifically requested */ if (gfp_mask & __GFP_NORETRY) goto nopage; ---------- Then, how can fs_reclaim contribute to deadlock? > > > Since there was no PF_MEMALLOC safeguard as of cf40bd16fdad42c0, checking > > __GFP_NOMEMALLOC might make sense. But since this safeguard was added by > > commit 341ce06f69abfafa ("page allocator: calculate the alloc_flags for > > allocation only once"), checking __GFP_NOMEMALLOC no longer makes sense. > > Thus, let's remove __GFP_NOMEMALLOC check and allow __need_fs_reclaim() to > > return false. > > This does not in fact explain what's going on, it just points to > 'random' patches. > > Are you talking about this: > > + /* Avoid recursion of direct reclaim */ > + if (p->flags & PF_MEMALLOC) > + goto nopage; > > bit? Yes. > > > Reported-by: Dave Jones > > Signed-off-by: Tetsuo Handa > > Cc: Peter Zijlstra > > Cc: Nick Piggin > > --- > > mm/page_alloc.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > index 76c9688..7804b0e 100644 > > --- a/mm/page_alloc.c > > +++ b/mm/page_alloc.c > > @@ -3583,7 +3583,7 @@ static bool __need_fs_reclaim(gfp_t gfp_mask) > > return false; > > > > /* this guy won't enter reclaim */ > > - if ((current->flags & PF_MEMALLOC) && !(gfp_mask & __GFP_NOMEMALLOC)) > > + if (current->flags & PF_MEMALLOC) > > return false; > > I'm _really_ uncomfortable doing that. Esp. without a solid explanation > of how this raelly can't possibly lead to trouble. Which the above semi > incoherent rambling is not. > > Your backtrace shows the btrfs shrinker doing an allocation, that's the > exact kind of thing we need to be extremely careful with. > If btrfs is already holding some lock (and thus __GFP_FS is not safe), that lock must be printed at 2 locks held by sshd/24800: #0: (sk_lock-AF_INET6){+.+.}, at: [<000000001a069652>] tcp_sendmsg+0x19/0x40 #1: (fs_reclaim){+.+.}, at: [<0000000084f438c2>] fs_reclaim_acquire.part.102+0x5/0x30 doesn't it? But sk_lock-AF_INET6 is not a FS lock, and fs_reclaim does not actually lock something.