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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B4FAC433F5 for ; Tue, 5 Oct 2021 02:58:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0488C61409 for ; Tue, 5 Oct 2021 02:58:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0488C61409 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 8AF656B006C; Mon, 4 Oct 2021 22:58:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 85FF8900002; Mon, 4 Oct 2021 22:58:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7266D6B0072; Mon, 4 Oct 2021 22:58:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0090.hostedemail.com [216.40.44.90]) by kanga.kvack.org (Postfix) with ESMTP id 5F0526B006C for ; Mon, 4 Oct 2021 22:58:14 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 0E4C032330 for ; Tue, 5 Oct 2021 02:58:14 +0000 (UTC) X-FDA: 78660874908.12.F8959BE Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) by imf08.hostedemail.com (Postfix) with ESMTP id BE9A43001873 for ; Tue, 5 Oct 2021 02:58:13 +0000 (UTC) Received: by mail-ot1-f44.google.com with SMTP id r43-20020a05683044ab00b0054716b40005so24138674otv.4 for ; Mon, 04 Oct 2021 19:58:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=L3EUZPK9K1Nv4X/t23Xigyl5ZGZm+PMO5vmnKob3qyk=; b=Zpongvaz1NjXcDn0gybFkNRbvYFnpGbnkya9dHm7ZPH1QZQ8VQzfO72CPFdDiZNxk6 cUt5bRncLzH6F2fgLMcngOkAwm7Kf/lLnE5mjvfR2c3Z7FnMdSgs5a7jkL4qhsBAreuO rb4nQBJFC+2lzhYvAoyDwC1GxSHqt4MYrRKga7OUGK9c9lpuXIc9FZpEXt0P0U6jnEYM wSJHf804fz3oH74cyeNcLDSqW5KzfAn4HtpE/aHPCQ5WUOtKLQRBVLZKvPPXt2cAZDMu fDtLdbckkbHV5+kaMpqJd96uY0VPzhBgTvPubTWk25DXnjPKOCVSb2YvLGUIwfVRvtWS r80A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=L3EUZPK9K1Nv4X/t23Xigyl5ZGZm+PMO5vmnKob3qyk=; b=cqqUD2yGVu4hXjM5vNo+p2BwvgOhnish+90B04evxGDoh4gaZSR5g+BoLVUD2IIG06 cFNfbpL0IzQ1iRchrLFLwSbX7Y1xgTSuVK1VgCXDlqfZGjJ1vvVNP1FHBTJz9Zi2sS1k CgFwX46cQxaDa9fCxITjzA3j8gRmt3nRe8KHhmApdbE9vwBEtziYJBJO6gXhJzxLTWtW e793RAXGkJiUb79Gl8RnundG91W0RWcLkpJMCDhgmBP6Vi5DkxKGxPrkeTSQoe3O2fbX lP3i0w+C/LPDh54ngG8pp7OLHPUHESGorixjqTX9u2GQTKsByk32Xl3bA7WV7bupZ/dT HuSw== X-Gm-Message-State: AOAM532pffPmzkHeeP0BIm4b1efqCQ/zHIQ4qLkGtotryL8cQBgOMKul QQ5Tu0I3Uzl/HoRXUMXsAFQwdg== X-Google-Smtp-Source: ABdhPJylDdet4eoQrG8ehs8f6OfgHk1DUVFd62qvlpu0tM77G2xgt2OIt4QsApR6Rzk6zIIBbzwaLA== X-Received: by 2002:a9d:6a17:: with SMTP id g23mr12355910otn.36.1633402692761; Mon, 04 Oct 2021 19:58:12 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id d14sm3289999otq.65.2021.10.04.19.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Oct 2021 19:58:11 -0700 (PDT) Date: Mon, 4 Oct 2021 19:58:10 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Rongwei Wang cc: Song Liu , Matthew Wilcox , Hugh Dickins , Andrew Morton , Linux MM , Linux Kernel Mailing List , William Kucharski Subject: Re: [PATCH v2 1/2] mm, thp: check page mapping when truncating page cache In-Reply-To: <8d8fb192-bd8d-8a08-498d-ca7204d4a716@linux.alibaba.com> Message-ID: References: <20210923194343.ca0f29e1c4d361170343a6f2@linux-foundation.org> <9e41661d-9919-d556-8c49-610dae157553@linux.alibaba.com> <68737431-01d2-e6e3-5131-7d7c731e49ae@linux.alibaba.com> <8d8fb192-bd8d-8a08-498d-ca7204d4a716@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: BE9A43001873 X-Stat-Signature: ukxujqzzrjoyepry5waqrcifq5q6cnhq Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Zpongvaz; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of hughd@google.com designates 209.85.210.44 as permitted sender) smtp.mailfrom=hughd@google.com X-HE-Tag: 1633402693-41318 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, 5 Oct 2021, Rongwei Wang wrote: > Hi, > I have run our cases these two days to stress test new Patch #1. The new Patch > #1 mainly add filemap_invalidate_{un}lock before and after > truncate_pagecache(), basing on original Patch #1. And the crash has not > happened. > > Now, I keep the original Patch #1, then adding the code below which suggested > by liu song (I'm not sure which one I should add in the next version, > Suggested-by or Signed-off-by? If you know, please remind me). > > - if (filemap_nr_thps(inode->i_mapping)) > + if (filemap_nr_thps(inode->i_mapping)) { > + filemap_invalidate_lock(inode->i_mapping); > truncate_pagecache(inode, 0); > + filemap_invalidate_unlock(inode->i_mapping); > + } I won't NAK that patch; but I still believe it's unnecessary, and don't see how it protects against all the races (collapse_file() does not use that lock, whereas collapse_file() does use page lock). And if you're hoping to fix 5.10, then you will have to backport those invalidate_lock patches there too (they're really intended to protect hole-punching). > > And the reason for keeping the original Patch #1 is mainly to fix the race > between collapse_file and truncate_pagecache. It seems necessary. Despite the > two-day test, I did not reproduce this race any more. > > In addition, I also test the below method: > > diff --git a/mm/truncate.c b/mm/truncate.c > index 3f47190f98a8..33604e4ce60a 100644 > --- a/mm/truncate.c > +++ b/mm/truncate.c > @@ -210,8 +210,6 @@ invalidate_complete_page(struct address_space *mapping, > struct page *page) > > int truncate_inode_page(struct address_space *mapping, struct page *page) > { > - VM_BUG_ON_PAGE(PageTail(page), page); > - > if (page->mapping != mapping) > return -EIO; > > I am not very sure this VM_BUG_ON_PAGE(PageTail) is what Hugh means. And > the test results show that only removing this VM_BUG_ON_PAGE(PageTail) has no > effect. So, I still keep the original Patch #1 to fix one race. Yes, that's exactly what I meant, and thank you for intending to try it. But if that patch had "no effect", then I think you were not running the kernel with that patch applied: because it deletes the BUG on line 213 of mm/truncate.c, which is what you reported in the first mail! Or, is line 213 of mm/truncate.c in your 5.10.46-hugetext+ kernel something else? I've been looking at 5.15-rc. But I wasn't proposing to delete it merely to hide the BUG: as I hope I explained, we could move it below the page->mapping check, but it wouldn't really be of any value there since tails have NULL page->mapping anyway (well, I didn't check first and second tails, maybe mapping gets reused for some compound page field in those). I was proposing to delete it because the page->mapping check then weeds out the racy case once we're holding page lock, without the need for adding anything special. Hugh