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=-4.0 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 90EBAC433E1 for ; Mon, 15 Jun 2020 14:53:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5A43C206D7 for ; Mon, 15 Jun 2020 14:53:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5A43C206D7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E4ECE6B000D; Mon, 15 Jun 2020 10:53:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E25FE6B000E; Mon, 15 Jun 2020 10:53:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D61FA6B0010; Mon, 15 Jun 2020 10:53:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id BBF096B000D for ; Mon, 15 Jun 2020 10:53:41 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 43D9C181ABE8D for ; Mon, 15 Jun 2020 14:53:41 +0000 (UTC) X-FDA: 76931740242.14.shop74_371576226df7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 648131802C674 for ; Mon, 15 Jun 2020 14:53:35 +0000 (UTC) X-HE-Tag: shop74_371576226df7 X-Filterd-Recvd-Size: 4647 Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Mon, 15 Jun 2020 14:53:34 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id y20so15141029wmi.2 for ; Mon, 15 Jun 2020 07:53:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=bVlgLw5K9ZgRrPe2t+yOf/onVI5NsVTfDFdGR/zdJbs=; b=FiICpHcX1YG2MtSp6w8hW4nZh+hBEit2KblialBqhBgh1o+Xe1BFfcVsMi3+7uPtB7 tZP0qBpEmtf7JIUWk3vRUZ7YXCBMeg8et771iFNDrEqvr+5YA62Y2MBqyn+YTo1fG21P GfjoX0wEBTnC7kghOc1fz3n/y3giqr5+JXNzxp7QsnucLQado8qIU2UWBSIJJTh0QItq BHhD+J3u99iq8DmIxzxY6lX5vk5RpCVWZ2Cf6ywQkIYVBIqJ+K81Uy/yIredF9dyH60I HI9Z+4RvGvUd7trIXFKTKfb43VZz0obrbRV0r5SQkalYL0xKpadW6sYqjGu+Sp2Sl7TK H0GQ== X-Gm-Message-State: AOAM533m+VtfNao4tdgPuOf2vLuhkAXUKgb2kz0lvFMkPn0Zb0dEc5ik 1RbWkvuy9ppQlJS1F2uAfB4= X-Google-Smtp-Source: ABdhPJyVv5tx/nm/l6AJJBZvJxROTg39Cgylcu/qLDQNBjikfDW9tkcfO8tIgnrH24kXjyv4lpb1BA== X-Received: by 2002:a7b:cd94:: with SMTP id y20mr13023943wmj.87.1592232813795; Mon, 15 Jun 2020 07:53:33 -0700 (PDT) Received: from localhost (ip-37-188-174-201.eurotel.cz. [37.188.174.201]) by smtp.gmail.com with ESMTPSA id r12sm26167608wrc.22.2020.06.15.07.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2020 07:53:32 -0700 (PDT) Date: Mon, 15 Jun 2020 16:53:31 +0200 From: Michal Hocko To: Holger =?iso-8859-1?Q?Hoffst=E4tte?= Cc: Yafang Shao , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v3] xfs: avoid deadlock when trigger memory reclaim in ->writepages Message-ID: <20200615145331.GK25296@dhcp22.suse.cz> References: <1592222181-9832-1-git-send-email-laoar.shao@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 648131802C674 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 Content-Transfer-Encoding: quoted-printable 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 Mon 15-06-20 16:25:52, Holger Hoffst=E4tte wrote: > On 2020-06-15 13:56, Yafang Shao wrote: [...] > > diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c > > index b356118..1ccfbf2 100644 > > --- a/fs/xfs/xfs_aops.c > > +++ b/fs/xfs/xfs_aops.c > > @@ -573,9 +573,21 @@ static inline bool xfs_ioend_needs_workqueue(str= uct iomap_ioend *ioend) > > struct writeback_control *wbc) > > { > > struct xfs_writepage_ctx wpc =3D { }; > > + unsigned int nofs_flag; > > + int ret; > > xfs_iflags_clear(XFS_I(mapping->host), XFS_ITRUNCATED); > > - return iomap_writepages(mapping, wbc, &wpc.ctx, &xfs_writeback_ops)= ; > > + > > + /* > > + * We can allocate memory here while doing writeback on behalf of > > + * memory reclaim. To avoid memory allocation deadlocks set the > > + * task-wide nofs context for the following operations. > > + */ > > + nofs_flag =3D memalloc_nofs_save(); > > + ret =3D iomap_writepages(mapping, wbc, &wpc.ctx, &xfs_writeback_ops= ); > > + memalloc_nofs_restore(nofs_flag); > > + > > + return ret; > > } > > STATIC int > >=20 >=20 > Not sure if I did something wrong, but while the previous version of th= is patch > worked fine, this one gave me (with v2 removed obviously): >=20 > [ +0.000004] WARNING: CPU: 0 PID: 2811 at fs/iomap/buffered-io.c:1544 = iomap_do_writepage+0x6b4/0x780 This corresponds to /* * Given that we do not allow direct reclaim to call us, we shoul= d * never be called in a recursive filesystem reclaim context. */ if (WARN_ON_ONCE(current->flags & PF_MEMALLOC_NOFS)) goto redirty; which effectivelly says that memalloc_nofs_save/restore cannot be used for that code path. Your stack trace doesn't point to a reclaim path which shows that this path is shared and also underlines that this is not really an intended use of the api. Please refer to Documentation/core-api/gfp_mask-from-fs-io.rst for more details but shortly the API should be used at the layer which defines a context which shouldn't allow to recurse. E.g. a lock which would be problematic in the reclaim recursion path. --=20 Michal Hocko SUSE Labs