From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFFAFC433E0 for ; Fri, 19 Jun 2020 06:01:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AAEE4207DD for ; Fri, 19 Jun 2020 06:01:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AAEE4207DD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=fromorbit.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 260D28D0076; Fri, 19 Jun 2020 02:01:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 210D48D0052; Fri, 19 Jun 2020 02:01:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 126308D0076; Fri, 19 Jun 2020 02:01:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0181.hostedemail.com [216.40.44.181]) by kanga.kvack.org (Postfix) with ESMTP id ECC478D0052 for ; Fri, 19 Jun 2020 02:01:05 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 85765181ACC80 for ; Fri, 19 Jun 2020 06:01:05 +0000 (UTC) X-FDA: 76944913290.23.chain96_3602b5426e16 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 51D2D37079 for ; Fri, 19 Jun 2020 06:01:05 +0000 (UTC) X-HE-Tag: chain96_3602b5426e16 X-Filterd-Recvd-Size: 4079 Received: from mail106.syd.optusnet.com.au (mail106.syd.optusnet.com.au [211.29.132.42]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Fri, 19 Jun 2020 06:01:04 +0000 (UTC) Received: from dread.disaster.area (unknown [49.180.124.177]) by mail106.syd.optusnet.com.au (Postfix) with ESMTPS id 54D5C5AE81A; Thu, 18 Jun 2020 10:34:30 +1000 (AEST) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1jliVf-0001VT-H7; Thu, 18 Jun 2020 10:34:27 +1000 Date: Thu, 18 Jun 2020 10:34:27 +1000 From: Dave Chinner To: Michal Hocko Cc: Yafang Shao , Christoph Hellwig , "Darrick J. Wong" , Andrew Morton , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, Linux MM Subject: Re: [PATCH v3] xfs: avoid deadlock when trigger memory reclaim in ->writepages Message-ID: <20200618003427.GZ2040@dread.disaster.area> References: <1592222181-9832-1-git-send-email-laoar.shao@gmail.com> <20200616081628.GC9499@dhcp22.suse.cz> <20200616092727.GD9499@dhcp22.suse.cz> <20200616104806.GE9499@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200616104806.GE9499@dhcp22.suse.cz> User-Agent: Mutt/1.10.1 (2018-07-13) X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.3 cv=QIgWuTDL c=1 sm=1 tr=0 a=k3aV/LVJup6ZGWgigO6cSA==:117 a=k3aV/LVJup6ZGWgigO6cSA==:17 a=kj9zAlcOel0A:10 a=nTHF0DUjJn0A:10 a=7-415B0cAAAA:8 a=RKaNVZAroByeIuNqgEYA:9 a=CjuIK1q_8ugA:10 a=biEYGPWJfzWAr4FL6Ov7:22 X-Rspamd-Queue-Id: 51D2D37079 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Jun 16, 2020 at 12:48:06PM +0200, Michal Hocko wrote: > On Tue 16-06-20 17:39:33, Yafang Shao wrote: > > The history is complicated, but it doesn't matter. > > Let's turn back to the upstream kernel now. As I explained in the commit log, > > xfs_vm_writepages > > -> iomap_writepages. > > -> write_cache_pages > > -> lock_page <<<< This page is locked. > > -> writepages ( which is iomap_do_writepage) > > -> xfs_map_blocks > > -> xfs_convert_blocks > > -> xfs_bmapi_convert_delalloc > > -> xfs_trans_alloc > > -> kmem_zone_zalloc //It should alloc page > > with GFP_NOFS > > > > If GFP_NOFS isn't set in xfs_trans_alloc(), the kmem_zone_zalloc() may > > trigger the memory reclaim then it may wait on the page locked in > > write_cache_pages() ... > > This cannot happen because the memory reclaim backs off on locked pages. ->writepages can hold a bio with multiple PageWriteback pages already attached to it. Direct GFP_KERNEL page reclaim can wait on them - if that happens the the bio will never be issued and so reclaim will deadlock waiting for the writeback state to clear... > > That means the ->writepages should be set with GFP_NOFS to avoid this > > recursive filesystem reclaim. Indeed. We already have parts of the IO submission path under PF_MEMALLOC_NOFS so we can do transaction allocation, etc. See xfs_prepare_ioend(), which is called from iomap via: iomap_submit_ioend() ->prepare_ioend() xfs_prepare_ioend() we can get there from: iomap_writepage() iomap_do_writepage() iomap_writepage_map() iomap_submit_ioend() iomap_submit_ioend() and: iomap_writepages() write_cache_pages() iomap_do_writepage() iomap_writepage_map() iomap_submit_ioend() iomap_submit_ioend() Which says that we really should be putting both iomap_writepage() and iomap_writepages() under PF_MEMALLOC_NOFS context so that filesystem callouts don't have to repeatedly enter and exit PF_MEMALLOC_NOFS context to avoid memory reclaim recursion... Cheers, Dave. -- Dave Chinner david@fromorbit.com