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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7291AC3DA49 for ; Sun, 28 Jul 2024 21:46:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6C0E6B007B; Sun, 28 Jul 2024 17:46:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A1BF16B0083; Sun, 28 Jul 2024 17:46:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E3E26B0085; Sun, 28 Jul 2024 17:46:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7045D6B007B for ; Sun, 28 Jul 2024 17:46:35 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1E111C01D6 for ; Sun, 28 Jul 2024 21:46:35 +0000 (UTC) X-FDA: 82390495950.12.54736B4 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf21.hostedemail.com (Postfix) with ESMTP id 8C41C1C000D for ; Sun, 28 Jul 2024 21:46:33 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="Jq4D1qR/"; spf=none (imf21.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722203152; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ee35UQdGzo/TjoqV+FGBExRMBQy4PRf/ou1hv4n6+Zo=; b=WyTP+onD2xLx9tdu4kehsDkggj5C62nDIBrW8Ei+DDyy7ezYOO9zWLj5SkRO0+rim9eVEP BtJ3pF4pqSB9kbOGe/J67zHrQUOuqsQuTI5CJYoriXnPAoypX253fPsme/R+6sTR6EIDIv LqX1rdcEe9nTe3x1vnMGB+wnOUnoOnM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="Jq4D1qR/"; spf=none (imf21.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722203152; a=rsa-sha256; cv=none; b=U+6m5qjw1OIAY+BIOiWLuzRle41mx9pIO8y9jrvatxrZ3rsZdGv2jw6n76XFq/saK4fkr8 Zj4UrfZHEDxo3N3mrQy4dEfpfIm8kmZYjZ5z8xxDnoxzQfJC9t+7aPTANGVw6JalT3twDD Tj6wTNes931NmZBi/HVvvRujBLU0Ryc= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Ee35UQdGzo/TjoqV+FGBExRMBQy4PRf/ou1hv4n6+Zo=; b=Jq4D1qR/ke08I1MT3ewwS/H+eC TaPqwwCWfzTkJYmfMnK5G8wY1mRY+RK8jEuUEcCEK40Fl4fht/d6C9QZoENWOswFIv0KOGb1vX3mn gJTFMXHxBDW0gA2EHMPtnNgqejsyerbe03OVAiCN953gNvL434BssfVDd4Zki+Nbu7fvjPp2dim5K jqXuZes4HAi0Y2F2enRs3F/Ce+kWjPiPeYDGAgH3WWOf/coJQtV9NKuXFnaGwQhu89YcUlR/mFu2v esP2tynMspdtn7syuVsw3Sq5ng7h+vEMgcjZ/rYgXZNn1lw4tpycDyQdkWIh48hqkMXbnGIDZYil5 ELeu1t4A==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYBio-0000000CqUE-0RtE; Sun, 28 Jul 2024 21:46:30 +0000 Date: Sun, 28 Jul 2024 22:46:29 +0100 From: Matthew Wilcox To: Gao Xiang Cc: Andrew Morton , Huang Ying , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/migrate: fix deadlock in migrate_pages_batch() on large folios Message-ID: References: <20240728154913.4023977-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240728154913.4023977-1-hsiangkao@linux.alibaba.com> X-Stat-Signature: cqwih3qyx4f7nzxfj4459fh5uyjwrqd7 X-Rspam-User: X-Rspamd-Queue-Id: 8C41C1C000D X-Rspamd-Server: rspam02 X-HE-Tag: 1722203193-226279 X-HE-Meta: U2FsdGVkX19fvD/f0DZ5gnXPPlI5YsrAltjbR1VOe+KP3dBChRc1WsS46S8wvs9xs2s2nXyYvYo6jOlBv5LwahQsq5TITZF/BomNICMXS0gNEjSRmPr1veOmMmE46k3uw8SfHJj3m2Smbn2tqdpV2woVs4/Emk8Lz2ITL4hmahxeUnvcR6lcz/BabDFGEtIXLjF1Xfex6mFFDZ2XOogTAO1dDTDuWX/Lfd7kYKzrTg+X5TAJKsmGLMtQ/PMoWjy36sS9Kk9XtJb5cmnKnu6Bd4/8GMNy7GGkmQp7xRywr0iGdLficqjEuTRGObTmAEVN2VXttLp0h3soWq+hkxtir9YN3mWecgAjhFfjQMcDJDPuywar3km4LUiZKsucq1jscd1lB20LKBBUjwD0l3cbfKw9nfrebnRhAQ2J2fuycJ+vZXRZCci4IeJR6IcYgV0inx43qC2QUuoY1NJCSRKu5NvKbz8BL96I0JawucVzun6b2qEWVb4qoMfDX1TlFCDtSMfWBhbU92jl09/8HdLwkTpsvMLdAsVqCDOF/f7n7PrK0NTYe4bnS3MpQe0viexvBVMSL3+fVuKXs/rXBRckl+C12FTBDX2u3BdAdRKvyyCbZ4vJkrjbrxY944z+yxsV8CnblYYuS5ns6kDbIRVyLAD8K27BgbRatqT+9sqjuRCMv7uIOSw60pgcF836Z7z9YSmwm3Mh1Qt6HUpJdtSuycYFCt1vVJv4KY38SmbzWjdPMhjxCNK/hMyfLdtOKGKiLOhfbSPQQ9es6PCR9jR2Ta+Or5kF29DGZCc/cDDxoqnjmM1tqLtR27ZcKDbQQG8gRCRlmySOHH/7tFwgn4xonUcHxtWyjYAi2qkdFmChmoLOgbEL6ryr23jUyqHH2yth+hwsZhPVSLEVTyGreCgbC38i95Cn12dwGOEHbJKJy79vPc48wV3Hb+MczJT4t16F0AjOQro/Cmw3fRfnEyA DAMp9Cxc 1RpC+BlAwOz6giQif0Y42trYKUzNF/xKnxih3LC5Sc0YZCiImYEQ+mHSbTH7EFyDhdtYpCnSbIoLn9CKS9PB/gWvhq/c16WI386TRHC/bP4PADJvTp2UFZLeBEqE3wteeQBdrJ/BJELx1WNnNZ6ZdSTQzHIeFUyH/uKtD16jEnrNBF0tj6XGcJGSeDCcj88Dzw2trJkqFEEVXHu07zB//YxTPZcE06racV6INMeb6xgiDQViQ2r578cOQKb+G1DnDefbq 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: List-Subscribe: List-Unsubscribe: On Sun, Jul 28, 2024 at 11:49:13PM +0800, Gao Xiang wrote: > It was found by compaction stress test when I explicitly enable EROFS > compressed files to use large folios, which case I cannot reproduce with > the same workload if large folio support is off (current mainline). > Typically, filesystem reads (with locked file-backed folios) could use > another bdev/meta inode to load some other I/Os (e.g. inode extent > metadata or caching compressed data), so the locking order will be: Umm. That is a new constraint to me. We have two other places which take the folio lock in a particular order. Writeback takes locks on folios belonging to the same inode in ascending ->index order. It submits all the folios for write before moving on to lock other inodes, so it does not conflict with this new constraint you're proposing. The other place is remap_file_range(). Both inodes in that case must be regular files, if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode)) return -EINVAL; so this new rule is fine. Does anybody know of any _other_ ordering constraints on folio locks? I'm willing to write them down ... > diff --git a/mm/migrate.c b/mm/migrate.c > index 20cb9f5f7446..a912e4b83228 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -1483,7 +1483,8 @@ static inline int try_split_folio(struct folio *folio, struct list_head *split_f > { > int rc; > > - folio_lock(folio); > + if (!folio_trylock(folio)) > + return -EAGAIN; > rc = split_folio_to_list(folio, split_folios); > folio_unlock(folio); > if (!rc) This feels like the best quick fix to me since migration is going to walk the folios in a different order from writeback. I'm surprised this hasn't already bitten us, to be honest. (ie I don't think this is even necessarily connected to the new ordering constraint; I think migration and writeback can already deadlock)