From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.52.48 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796141305; b=RohcEOuYBBJ0J4zt8cRAJZF1zjfOnklGeCA+0yBRJeNeTIwOfRx2OXaqTH3stn1qax91 xxpfjrtzoSYjaG80wHo197jMkCB+GsQ8afGsb5/LptNcbPOyJ17XuAskzfV8KyLh9v9Kz uDdBfSEA3+GXCg6yfj1rRNLy25CaXWpLOZIPLO4dxDTnhjYkIkltbRCe8A+pexcKOEXs2 6UwLM9BJum7jjKg9arZN4N+ApwFdDwqdcyk+XI1CZ15iy69Tg19sMszk8S/srEglNfMZ7 x1HBEyzDD5xyeOfNUgq/k+vM4Z9utmABE3sfg0TW+Re5qMm1Sxg/nzs+7aXUocUuLAg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796141305; h=DMARC-Filter:DKIM-Signature:Received:Received:Message-ID:Date: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-ClientProxiedBy:MIME-Version: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=+UBV4o84GyFvrpc1EdbLKtC9+OikWPChymj8dXu6cqY=; b=LAx1v8Q3dmXmXnNPwcdXJLNynYVWJrhWh6TiQRWM6Xh1pZro2mB5AKnzAgyLeEg4bOum B4D6rAVMChPM9X+K/FBBNoweeALmxBwvHn9WzhQH7tPB64Q1puJWHPYlbyQ4n5vM9dwBF 8pyJNa8auuk/5Glv2wIR3O4qi5+Gfb4a1CIPiKEufG82h30X56cLtX1zxhQolN455mpCV QfzioZMeGNGl8vC9kV38U1D+qztsgQadf3UG7YwpthV68JThi7KV4/y4fdZl2IKtQnNeZ ZZ8wWtK/rrtlSwsZodDtMT29A+H2dW2Y821ZeyM2rbaADbvgCDNeQdBmtoxxejjsMtQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=T+02DCpr; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.52.48 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011048.outbound.protection.outlook.com [52.101.52.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1F0F606A6AA; Tue, 1 Dec 2026 16:08:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D1F0F606A6AA Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=T+02DCpr ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Z1I0o+hP8CCZnuZY+5xHVE788PyypluMAbVqkrbQJN6IWu+4VJZwidsonY2yVkpxjbXYVlQhfHiihPvUA0JuKeOp5rIdsbwoyh1sFI5SEkhh6885N0mYlkFDY0X6SNJP5gy9ekfGnJSKu70vyQl5UaJevHqhnFkA5+Twltq2UfAvE87jn4DWNzn2xa+oQVrSk9mlmPcJHQU1NUhPL3S5+F2lVVB5ZSYnmj5mDAgR8URh1vVlKugQ80NscdNom1u2MB23Yps7UtHA9RuwWUhqKgYZqhJvL3x9KXNprue3/CBf/+XLqPxiy0Z0RCZpGOnD3dx2KC2SLJc01vnBd13ySw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+UBV4o84GyFvrpc1EdbLKtC9+OikWPChymj8dXu6cqY=; b=Wwq1a8NreQCcnUm3I17kZMFnkfbWjwOpPIOPMM5yKLvC7j8R8vXCK8gLLtDAWIkVjsx4JnbZF/kinuInoWyvTbE8qlYhsm4NClFtXJXNFswyD/OM/UdUcVNFZYWTlUfz/dtg+UeOxwy3leJD8JsZKr55RqmZmFAcUjL268iNsUqQyUR6PupNtUFX6NfW35gRPjrBprfWQIuJnJBKSndsyQK9O3d3KHscBzd/2fKuTNdtpFuZ+bnoOhbeLt4QeKb/WohtphK3SwKYeynnkxZjqVWQTlQAkoFZ9JObQAqAx6ja+cwGtvCL3lTdfyU02fQTfzjX952opP5N7ONwM4YB4w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+UBV4o84GyFvrpc1EdbLKtC9+OikWPChymj8dXu6cqY=; b=T+02DCprRgfVnLu20tWFQcjYzmTguKVX+3q6IXVqBkRX1YkNOWZ2SXvT2AzIPrvGwfu/cYCbaz8pQaen5YOi6rOIlvJf6XY3d4VRDMpLQrWlSocHNVsZ/8Ej9N24qHqSFdbpCJus4HhsZVMPn0L8TyV0xgUAqCtOTjxzsiaf03MgHDreleOsc2jxPo/u08orN3oO5yXf2qFHRDJhSqF0Om9kk45MVSZJdoRNbSK63MPQjw+Pdug2AosFJ01y/GMAY7VVOayHAnlMMEr17/3Bqz/jKk+pTFyABG3nR5rs1tOBZXBDzWeY6A0DOKy9njerPKLaXkqqnSIic62KOkE5mg== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from IA3PR12MB246477.namprd12.prod.outlook.com (2603:10b6:208:70e::7) by SN7PR12MB6714.namprd12.prod.outlook.com (2603:10b6:806:272::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.12; Tue, 1 Dec 2026 16:08:17 +0000 Received: from IA3PR12MB246477.namprd12.prod.outlook.com ([fe80::624e:d5ed:7112:bd07]) by IA3PR12MB246477.namprd12.prod.outlook.com ([fe80::624e:d5ed:7112:bd07%6]) with mapi id 15.21.0688.009; Tue, 1 Dec 2026 16:08:17 +0000 Message-ID: Date: Tue, 1 Dec 2026 10:08:14 -0600 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/filemap: bring a folio uptodate if all blocks below EOF are uptodate To: Andrew Morton Cc: willy@infradead.org, jack@suse.cz, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, John Hubbard References: <20261130181703.836051-1-csoto@nvidia.com> <20261130152437.b31acd84e6baabe58d23eb9e@linux-foundation.org> Content-Language: en-US From: Carol Soto In-Reply-To: <20261130152437.b31acd84e6baabe58d23eb9e@linux-foundation.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: MW4PR03CA0275.namprd03.prod.outlook.com (2603:10b6:303:b5::10) To IA3PR12MB246477.namprd12.prod.outlook.com (2603:10b6:208:70e::7) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: IA3PR12MB246477:EE_|SN7PR12MB6714:EE_ X-MS-Office365-Filtering-Correlation-Id: 2f4cb5ae-d24a-48ee-c6a5-08df4fc54f8c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|23010399003|1800799024|376014|261022113327099003|10067099003|56012099006|261026140227099003|261026121527099003|261028144727099003|261022075727099003|261022105027099003|261021121427099003|261102123227099003|18002099003|22082099003|11063799006|4143699003|6133799003; X-Microsoft-Antispam-Message-Info: S9KnU6y1MEo0GEnn7cNGBeXckVe7VCfoTX2uxrmwaZekpQJlK0f4LV4DNX8zSBBbehdumxDnou5FIsfK+2BC6/Ty8UcUXgx9ToDffwl/BvJYa++Eh0BJBgkL0rtj8zPQqJT0qXFmPUpRKpoEYlRxJUQMgy8tkcutC94rvyI1im5gj27wCWMXDSgLgtPuE2z4JAaIQw5PrQf2ldPR+tbTOCPQWkv2bDzMQC4WIZd4uwpBjQjsdT6fpZwvX8D4FRhHPBkQJa7GOmFjSJATqWL6z7R+hvJod8+6W8MPnznzxpBdV8hneNz9qDQZFWez/GzSK/d0Q+bc2M71IrnJTmDv4a69YCtHh7pAbHV16BE3pCxID14rKWXBTScfIWdiYncsjLn2c24k5UZmxWtaIakJ20qC73Ifms9oEkgfyWbfeg2qm721kP/R9T2hw7DaCB03kqMlYDRs2ZmdmRaNJPeyLePd/QqmYd4gr/u1t58puNl0ESZ4Nq1GjxbIj6/AwDjgKq8+DqFmnHES+8G7F+PQIE8YxWJFcUX5F9eTjjohJGZnlOgA0ZdNnrOVLoL18SmFSIbOE+GMJ7r19tPTGAF2N5kq+RHCLnQdOpg+BYlC0X6rSgsEtmxfOUvcupuyoBamOG2E8Zg+crZnV8T9AlCdx0Jn8+FNuCTn3liEYGsJCII= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:IA3PR12MB246477.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(23010399003)(1800799024)(376014)(261022113327099003)(10067099003)(56012099006)(261026140227099003)(261026121527099003)(261028144727099003)(261022075727099003)(261022105027099003)(261021121427099003)(261102123227099003)(18002099003)(22082099003)(11063799006)(4143699003)(6133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?d1dCOFEybHJUeWVoV2FrMmZOY0tFK1VQN2I3U3AwaTMyQklHMlNWcHFoR1NP?= =?utf-8?B?TG0yRnAvUWR1elByYWJrTjdzNlU4bTI1OEczclFDUEhhRnE0VmRIc056RGtB?= =?utf-8?B?RXM1WjV4NENueVFvTktsTm05dHBRZlRtTHR5bk5KMTNZcnZPV1JIWmc2U1Vl?= =?utf-8?B?cHp3Yk5SSDZPVVlYMFJsOVJOV1ZYT0ZPdlFpZ2ZRSFBnNlNyaWU3b3cxYW5n?= =?utf-8?B?VXhRbFRmaG9TbVZBZjZ3VTRMeEhDaDViSW54aVU3MzFOSDVJVXBsUm4wMER2?= =?utf-8?B?RTZhM2MvZktNdGw0SXVvVUpRc3FjR0ovR0h0VXliQzhXOHZpMXJucTNDTDhz?= =?utf-8?B?MVpESVp1K0Z2ZTBDb1ZIVXQrQWFKbWZWZTZ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blpQazNpSm56WXEybHpOREtkZUNnZlEzUWloYXhveXp4R2pE?= =?utf-8?B?WVoxV3RKWVpob3ZNcG5tdXNIWW45VFFWZFpkTStUajhmUXlPV3BJQWtVbWE5?= =?utf-8?B?RGdWWFhjbEFGUzZiV09xSlBFM0twait2OEk1dnhNZFY3c3VOTUczUT09?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f4cb5ae-d24a-48ee-c6a5-08df4fc54f8c X-MS-Exchange-CrossTenant-AuthSource: IA3PR12MB246477.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 16:08:17.2522 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DtGZpy2Cy+OJil7r8vq0ny6ehtIkFHYqVeVkOLxyE4r+bOHlvkAiReDbcHyY15w0XkSKiSy/h5bmfG/tlObZWQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6714 On 11/30/26 5:24 PM, Andrew Morton wrote: > 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? So far, we have observed this in the nginx benchmark described in the commit message; the reporter has not identified a separate production workload. The reporter found it while profiling folio-access costs and investigating discrepancies between machines with different configurations. The affected pattern is a short buffered write that leaves a partially uptodate folio cached, followed by concurrent reads of valid ranges. Those reads repeatedly acquire the folio lock. Other applications using that access pattern could encounter the same contention, but we do not currently have measurements beyond the benchmark. Evicting the file after fsync, or writing a full folio before truncating, avoids the slowdown in our tests. I’ll also incorporate your suggested comment and declaration changes in v2. > >> --- 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