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=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,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 7A902C388F7 for ; Wed, 21 Oct 2020 00:24:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9783522249 for ; Wed, 21 Oct 2020 00:24:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="c7ZEl1en" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9783522249 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9991C6B005C; Tue, 20 Oct 2020 20:23:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 949D06B0062; Tue, 20 Oct 2020 20:23:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EAC26B0068; Tue, 20 Oct 2020 20:23:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0193.hostedemail.com [216.40.44.193]) by kanga.kvack.org (Postfix) with ESMTP id 4E91A6B005C for ; Tue, 20 Oct 2020 20:23:59 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id EB09E3624 for ; Wed, 21 Oct 2020 00:23:58 +0000 (UTC) X-FDA: 77394034956.04.week03_5a0b10b27243 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id CD7F28007922 for ; Wed, 21 Oct 2020 00:23:58 +0000 (UTC) X-HE-Tag: week03_5a0b10b27243 X-Filterd-Recvd-Size: 4879 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Wed, 21 Oct 2020 00:23:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=OoXf9TqR/9/W/P0B/M4Uc8ZYoy2jtrMpXmMCh3pYwWI=; b=c7ZEl1enCdl4YFjo0BhLoBsdFa jn0npm4ZPMRIDhFYA8aJujKppTuN6Osom8GI+op55ZQ9O766MjXH3wolGlnJnfelIJ7iicDUecO44 ljL9SUQiIOPabKFWGPB3SYR7uP0dXDOc2EoUDV6b55jdOqe/MTWZErvQ19ZMnqnIzWF/PBgTglHKe S3HLxURDeBexVNk4RRlVcf1OfkcSlZijv8TXpqkBBFg+iIq7aoh0gnvPvbnivy607McQ48zA8YGRl 9h/MreNvdGDcpTvgRGvRl7uoVY5/CGeW3ujE6+aNRKXBTXb2HwBqWAEhQTcqaLbbbv0hhg7mwjhDX 3bsaVa8w==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kV1uy-00018W-H9; Wed, 21 Oct 2020 00:23:52 +0000 Date: Wed, 21 Oct 2020 01:23:52 +0100 From: Matthew Wilcox To: Chris Mason Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: Re: Splitting a THP beyond EOF Message-ID: <20201021002352.GF20115@casper.infradead.org> References: <20201020014357.GW20115@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: 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 Tue, Oct 20, 2020 at 10:32:59AM -0400, Chris Mason wrote: > On 19 Oct 2020, at 21:43, Matthew Wilcox wrote: > > This is a weird one ... which is good because it means the obvious > > ones have been fixed and now I'm just tripping over the weird cases. > > And fortunately, xfstests exercises the weird cases. > >=20 > > 1. The file is 0x3d000 bytes long. > > 2. A readahead allocates an order-2 THP for 0x3c000-0x3ffff > > 3. We simulate a read error for 0x3c000-0x3cfff > > 4. Userspace writes to 0x3d697 to 0x3dfaa > > 5. iomap_write_begin() gets the 0x3c page, sees it's THP and !Uptodat= e > > so it calls iomap_split_page() (passing page 0x3d) > > 6. iomap_split_page() calls split_huge_page() > > 7. split_huge_page() sees that page 0x3d is beyond EOF, so it removes= it > > from i_pages > > 8. iomap_write_actor() copies the data into page 0x3d >=20 > I=E2=80=99m guessing that iomap_write_begin() is still in charge of loc= king the > pages, and that iomap_split_page()->split_huge_page() is just reusing t= hat > lock? That's right -- iomap_write_begin() calls grab_cache_page_write_begin() which acquires the page lock. > It sounds like you=E2=80=99re missing a flag to iomap_split_page() that= says: I care > about range A->B, even if its beyond EOF. IOW, iomap_write_begin()=E2=80= =99s path > should be in charge of doing the right thing for the write, without rel= ying > on the rest of the kernel to avoid upsetting it. Yeah, the problem is that split_huge_page() doesn't have that functionality. I'd like to add it, but Kirill's not particularly keen. I'm also looking for a quick fix more than an intrusive change like that ... fortunately, I found one. And it's even something that was on my long-term todo list; I don't think we should be allocating THPs to cache beyond the end of the file. I mean, I could see the point in allocating a 2MB THP to cache a 1.9MB file tail, but allocating a 64kB page to cache a 3kB file tail is definitely wrong. > > Changing split_huge_page() to disregard i_size() is something I kind > > of want to be able to do long-term in order to make hole-punch more > > efficient, but that seems like a lot of work right now. > >=20 >=20 > The problem with trusting i_size is that it changes at surprising times= . > For this code inside split_huge_page(), end =3D=3D i_size_read() >=20 > for (i =3D HPAGE_PMD_NR - 1; i >=3D 1; i--) { > __split_huge_page_tail(head, i, lruvec, list); > /* Some pages can be beyond i_size: drop them from page > cache */ > if (head[i].index >=3D end) { > ClearPageDirty(head + i); >=20 > But, we actually change i_size after dropping all the page locks. In x= fs > this is xfs_setattr_size()->truncate_setsize(), all of which means that > dropping PageDirty seems unwise if this code is running concurrently wi= th an > expanding truncate. If i_size jumps past the page where you=E2=80=99re= clearing > dirty, it probably won=E2=80=99t be good. Ignore me if this is already= handled > differently, it just seems error prone in current Linus. Oh, but the next line is __delete_from_page_cache(). So a concurrent expanding truncate will never find this page, it's about to go back to the page allocator.