From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ACC51606A32C for ; Mon, 30 Nov 2026 23:24:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=LzKjtbmf Received: by kanga.kvack.org (Postfix) id 803A86B00EF; Mon, 30 Nov 2026 18:24:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B3FF6B05B1; Mon, 30 Nov 2026 18:24:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CA966B05B2; Mon, 30 Nov 2026 18:24:42 -0500 (EST) 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 353926B00EF for ; Mon, 30 Nov 2026 18:24:42 -0500 (EST) Received: from smtpin20.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 634A7A0ACB for ; Mon, 30 Nov 2026 23:24:41 +0000 (UTC) X-FDA: 85493367162.20.D7AA44F Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf12.hostedemail.com (Postfix) with ESMTP id 842084000A for ; Mon, 30 Nov 2026 23:24:39 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=LzKjtbmf; dmarc=none; spf=pass (imf12.hostedemail.com: domain of akpm@linux-foundation.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796081079; b=ycB5lYBcbTi1vFTzRk5ivurc8K6KXFo9GqUr1uZfRmb1OctyrkNAKcK2cNbgghhUxMaWUC 0Rk0W/qvLIcEmvdDnjXo6BpQgjCtHMUZQDUbdHAZ5JlCfIqhcrhdMU8NybtXyCKxac+gjV 7RglDGBeW4skzp2ErXih0wkUFeWa6Po= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796081079; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zRBfKxGBk5jO4Qh+3d8OUeihElXJaRA0Tt3EmWf5qV0=; b=m7GEWK31g4ZznNI2Q4cZsrSAsLALIbdPfMz4WsQr+37szMTMpUbH5WqybUsJK6ReGu1F5u 5tCeY9OvGT+0vLy8LwQT0H7nn/eg/FXRHu8XxQvFRhhNhs3JxCuCGZ4J0iXassodEIPPBy aMgSOJUGXGJjPBR2sVArHNCG5jB8BBU= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=LzKjtbmf; dmarc=none; spf=pass (imf12.hostedemail.com: domain of akpm@linux-foundation.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id ABCA54193F; Mon, 30 Nov 2026 23:24:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E2241F00898; Mon, 30 Nov 2026 23:24:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796081078; bh=zRBfKxGBk5jO4Qh+3d8OUeihElXJaRA0Tt3EmWf5qV0=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=LzKjtbmfIkcQNCfnlED/fbZnIX/2l4x7VtNX7M91lFX8IBH/qexv8rad31qirqLxG bgqNjWXn7QGgSTerDVLJugv0QeGdsN7gU3if13S4xLD2uGe4+z8v5YoBLvvmhkzLEp khQI8I65Hf0y/w14TNYyeg60MCqKkIjZwLjn+n4g= Date: Mon, 30 Nov 2026 15:24:37 -0800 From: Andrew Morton To: Carol L Soto Cc: willy@infradead.org, jack@suse.cz, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, John Hubbard Subject: Re: [PATCH] mm/filemap: bring a folio uptodate if all blocks below EOF are uptodate Message-Id: <20261130152437.b31acd84e6baabe58d23eb9e@linux-foundation.org> In-Reply-To: <20261130181703.836051-1-csoto@nvidia.com> References: <20261130181703.836051-1-csoto@nvidia.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Archived-By: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Stat-Signature: yubys1yp4ybenqtk16nh1ehnwjmm9uso X-Rspamd-Queue-Id: 842084000A X-Rspam-User: X-Rspamd-Server: rspam05 X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796081079-843953 X-HE-Meta: U2FsdGVkX18Gc7RNPrLGY6qUmt9b6DKJ0mM+LazAJXdP4+tWK4/RrcYL/j0f3m8iLcbf3K2VUBQ9ZBtaHJqZOF+elXc6ER4q1k1OgvaJHUaPJgscHRtTN7bW91LfGuNX9vy5AvFOircRKgTjgNwlYfuQMFuWrRzdIGS5fzrxAtbYXkzeZXNmHEZ7yTAiDrnVdIsS3DF/PsA6KoQoP515RsWKPKSNlD/72E9DcCbOEC/DqrRIA+Akfe4WUtRcGVK9JQOmoiJK8aONsGIfYBTZWnXPITMs5QVdHLYn4ah8gYBTAYIM97pNeMxlddEEqlpK4z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I/lhzQGKpMw4D051Kyujc7fQPnM4QcCywleOUpfUY/W1iYKDH4= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Mon, 30 Nov 2026 10:17:03 -0800 Carol L Soto wrote: > When a filesystem block is smaller than a folio, a write that ends > before the last block of a new folio leaves the folio partially > uptodate. The write marks its own blocks uptodate and leaves PG_uptodate > clear. With 64 KiB pages and 4 KiB blocks, a 1280-byte write to a new > file is such a write. So the write which makes all blocks which are inside EOF uptodate doesn't bring the whole folio uptodate because the parts which are outside EOF haven't been zeroed? > A read of that folio takes the folio lock and checks the blocks in the > range that the caller asked for. If one of those blocks is not uptodate, > the read calls ->read_folio(), which brings the whole folio uptodate. > If, on the other hand, all of those blocks are uptodate, then the read > copies its data and leaves PG_uptodate clear. But does that read zero out the outside-EOF page contents? Seems not. > For the 1280-byte file, an > 8 KiB request is the first case and a 1280-byte request is the second. > > A reader whose requests are all in the second case never brings the > folio uptodate, so every one of its reads takes the folio lock. > Concurrent readers of a small, newly written file therefore end up being > serialized on the folio lock. > > Fix this by making a blocking read bring the folio uptodate in the > second case as well. If every block of the folio below EOF is uptodate, > the read calls ->read_folio(), as in the first case. The call does not > issue any I/O for the blocks below EOF, because they are already > uptodate. The filesystem zeroes each block beyond EOF, ah, there it is. > or reads a block > that holds fsverity metadata, and sets PG_uptodate. Every later read > then finds PG_uptodate set, so it does not take the folio lock. > > The read path calls ->read_folio() and does not zero the folio itself, > because only the filesystem knows whether a block beyond EOF is zero. > The filesystem also keeps an uptodate state for each block, and iomap > requires that state to agree with PG_uptodate. > > A read with IOCB_NOWAIT, IOCB_NOIO or IOCB_WAITQ set is not allowed to > start I/O and wait for it to complete. A ->read_folio() call may do > both, so the read path never makes that call for such a read. The fix > keeps that rule, so such a read still takes the folio lock, as before. > > The fix provides a 4.32x speed-up for the test case, which runs 48 nginx > workers on one 1280-byte file. The test ran on v7.4-rc1, on arm64 with > 64 KiB pages and ext4 with 4 KiB blocks: three nginx instances of 16 > workers each served the file over HTTPS to 16 wrk threads per instance. > Each figure is the median of three 90-second runs, in million requests > per second: > > How the file was created Before After > 1280-byte write 1.255 5.417 > 1280-byte write, fsync, FADV_DONTNEED 5.041 5.169 > 64 KiB write, truncate to 1280 bytes 5.369 4.949 > > In the last two rows, the reads never find a partially uptodate folio, > so the fix does not apply. OK. Seems a rare case - is any real workload known to be affected? > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -2535,8 +2535,10 @@ static int filemap_read_folio(struct file *file, filler_t filler, > > static bool filemap_range_uptodate(struct address_space *mapping, > loff_t pos, size_t count, struct folio *folio, > - bool need_uptodate) > + bool need_uptodate, bool can_read) > { > + loff_t isize; > + > if (folio_test_uptodate(folio)) > return true; > /* pipes can't handle partially uptodate pages */ > @@ -2557,6 +2559,18 @@ static bool filemap_range_uptodate(struct address_space *mapping, > if (pos == 0 && count >= folio_size(folio)) > return false; > > + /* > + * If only blocks beyond i_size are not uptodate, have a caller that can > + * read the folio bring it uptodate, so that later reads do not have to > + * take the lock. > + */ "a caller that can read the folio" is a head-scratcher. How about /* * If all blocks below i_size are uptodate, complete the folio now * so later reads need not take the folio lock. */ > + isize = i_size_read(mapping->host); > + if (can_read && isize > folio_pos(folio) && > + isize < folio_next_pos(folio) && > + mapping->a_ops->is_partially_uptodate(folio, 0, > + isize - folio_pos(folio))) > + return false; > + > return mapping->a_ops->is_partially_uptodate(folio, pos, count); > } > > @@ -2564,6 +2578,8 @@ static int filemap_update_page(struct kiocb *iocb, > struct address_space *mapping, size_t count, > struct folio *folio, bool need_uptodate) > { > + bool can_read = !(iocb->ki_flags & > + (IOCB_NOIO | IOCB_NOWAIT | IOCB_WAITQ)); > int error; nit: bool can_read; int error; can_read = !(iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT | IOCB_WAITQ)); avoids the 80-col party tricks and creates a convenient place for adding an explanatory comment (not that I think one is needed in this case). > if (iocb->ki_flags & IOCB_NOWAIT) { > @@ -2597,11 +2613,11 @@ static int filemap_update_page(struct kiocb *iocb, > > error = 0; > if (filemap_range_uptodate(mapping, iocb->ki_pos, count, folio, > - need_uptodate)) > + need_uptodate, can_read)) > goto unlock; > > error = -EAGAIN; > - if (iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT | IOCB_WAITQ)) > + if (!can_read) > goto unlock; > > error = filemap_read_folio(iocb->ki_filp, mapping->a_ops->read_folio, > -- > 2.56.1