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 D04F3C3ABB0 for ; Mon, 5 May 2025 10:09:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 173A86B0092; Mon, 5 May 2025 06:09:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 122F36B0093; Mon, 5 May 2025 06:09:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 012E56B0095; Mon, 5 May 2025 06:09:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D5CC56B0092 for ; Mon, 5 May 2025 06:09:28 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D70CC161E49 for ; Mon, 5 May 2025 10:09:29 +0000 (UTC) X-FDA: 83408432058.03.AF012DB Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf11.hostedemail.com (Postfix) with ESMTP id E1C594000F for ; Mon, 5 May 2025 10:09:27 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1746439768; 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; bh=6KGzOBPu59KHLrBki8/bZC2WuWtOj6IApiG01CuOBiQ=; b=XjmwZ78jZV2DJkqIMD6A5ZDXTMT0JcetM5ZZtDENj+PH8k7Vgp3mbVf0GH2YHCOroC19V2 Q3EWV0g/aA4KqeWQSjfCOwUY8fsQvtWmdfD8i8wPDYIYfYaFVHVWX8+xxYd8uvaToyQNZS neo4VaN2D72PT3/Yx1wFl05GnAX+WG4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1746439768; a=rsa-sha256; cv=none; b=TvWxhKHNgqasBZPLsV86W+59+fwLipYRxsfEuqpcDJv+JFvuI2IqMhqPxfvihihg22lYNr Zb/7+7kVum4UK5vgQowOL7kRCIQG3wN4Yv5r3GPcnoF2D5pwbuW7WEFDCZtkZVKVKkksAw aDGo3QLsMUVMD2h60Qdkqu6F0EalvGk= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A85761007; Mon, 5 May 2025 03:09:17 -0700 (PDT) Received: from [10.163.53.144] (unknown [10.163.53.144]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7DDD73F5A1; Mon, 5 May 2025 03:09:21 -0700 (PDT) Message-ID: <8e3ca5fc-dadc-4a0a-902e-d2522740cbce@arm.com> Date: Mon, 5 May 2025 15:39:17 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v4 1/5] mm/readahead: Honour new_order in page_cache_ra_order() To: Ryan Roberts , Andrew Morton , "Matthew Wilcox (Oracle)" , Alexander Viro , Christian Brauner , Jan Kara , David Hildenbrand , Dave Chinner , Catalin Marinas , Will Deacon , Kalesh Singh , Zi Yan Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org References: <20250430145920.3748738-1-ryan.roberts@arm.com> <20250430145920.3748738-2-ryan.roberts@arm.com> Content-Language: en-US From: Anshuman Khandual In-Reply-To: <20250430145920.3748738-2-ryan.roberts@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: ffmw3qh1kh1simkhk1dajajk6bjo1sgk X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E1C594000F X-Rspam-User: X-HE-Tag: 1746439767-798266 X-HE-Meta: U2FsdGVkX1++HOxahBSUGWYgkKK1NNtlMbRQ26EJ7NwYtjnwcrnBtdl5mlOauH7mvIKd5iT+f6RabSltt5DPIYwjZN+b1C0Vz+M5dWnH+/ro4F6hsMYIri3I1L/GUMjaM1os3+Q9MSSPz3hUhHcZQ1jU3zFBfP3I34aKwoGAeAYGRlDMuLlrzt2O1tmDIdNdUhVpxrkdCgvyRpRKTALHD76E0keI3cJW1ZZZyLF/J8hhSwnSKvcXegIxol6U9GkgaNXAVdDWTxrN1eM+J3heLTuHapv0LuGiPPRatxGDrXQzMWzOqCESmS5j0Ccebmi0EEXwHdtB9YPOEJdf2D2Ir79O12A3rWY4fWHtPgP/R8mCFdpShutv+qWvNU5nrODj274UpBcFuHxWIMYfrbbXSxEVcLSCldNFpPWF8bowRSzxdmcOepS8bBJ1LFpDdKzhUuwPPXxeESAAhKfeMudCDF1odpZ9aW9afSuHqqFwwbWz61ZndfwUhPoOgBvFUo8A7NcK9OL1Wbr+MBPu1zg1R4KzU/D0gbJlc2Ml68fZXrtTssOqgd4sEk+GNiSGBXbwUKSr/UeW4qt7F2GFa1tnCvkkyT/KthWPzIurESyDrUUR4rfKA0HBoaj7kDgA+mpcVxpjjweZGx+WolkU879ZlhF9pf6bo9pf3TCp9pVNaDBA+TvhOLu3Zu4cYWUOj/tM+gHP0pcvOdwpbcL2OuQwnaYdXOeGAdS6tnNIRrzRSVfn5wU5wApeEqrnXUMEWg6RIxyWy1NijzvCnOahQPYkDhesMx7jscVjVUdgV98vPAl/bi7WDPQf6AFiZHIt/kPuog/xQ0HpXP8Ka59GQHQJ7ANiLTWRLVU8DsrLARgmTxiRG1m+aqW+Qwn/HW2Ss0DtQkQjkoLPRqVmP0Lsvq+73A+NJrjlfKrUCKZOZcYc/OjhGNyJ0zv7SnsGWzTmmLQr+zU/pBaMaLY4N2KAMnL itVnpw5q FLsKQqq6wPvLVycbelAOYTWCcs22aa2Ybnl/oU5a0E0KMGzgImIcd9g2LzuhIML6EKk+r1Q5+GJDTWEZ3UghtASt/toeQs+BlbMlJNaDKv3xRrSJPwdoaQZf7pTQT1ogRtP5mYvbzrUnKxbJpa2rfDk2jEy6t+pLnf8qfdY1AznsfRfZbt29+RilsAELtgvDqV2/WUJ1+dXcEBSdWb0SagEZjlARbZPpnL8e/SVDn9pGs8duo3uJrshc8lA== 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 4/30/25 20:29, Ryan Roberts wrote: > page_cache_ra_order() takes a parameter called new_order, which is > intended to express the preferred order of the folios that will be > allocated for the readahead operation. Most callers indeed call this > with their preferred new order. But page_cache_async_ra() calls it with > the preferred order of the previous readahead request (actually the > order of the folio that had the readahead marker, which may be smaller > when alignment comes into play). > > And despite the parameter name, page_cache_ra_order() always treats it > at the old order, adding 2 to it on entry. As a result, a cold readahead > always starts with order-2 folios. > > Let's fix this behaviour by always passing in the *new* order. Makes sense. > > Worked example: > > Prior to the change, mmaping an 8MB file and touching each page > sequentially, resulted in the following, where we start with order-2 > folios for the first 128K then ramp up to order-4 for the next 128K, > then get clamped to order-5 for the rest of the file because pa_pages is > limited to 128K: > > TYPE STARTOFFS ENDOFFS SIZE STARTPG ENDPG NRPG ORDER > ----- ---------- ---------- --------- ------- ------- ----- ----- > FOLIO 0x00000000 0x00004000 16384 0 4 4 2 > FOLIO 0x00004000 0x00008000 16384 4 8 4 2 > FOLIO 0x00008000 0x0000c000 16384 8 12 4 2 > FOLIO 0x0000c000 0x00010000 16384 12 16 4 2 > FOLIO 0x00010000 0x00014000 16384 16 20 4 2 > FOLIO 0x00014000 0x00018000 16384 20 24 4 2 > FOLIO 0x00018000 0x0001c000 16384 24 28 4 2 > FOLIO 0x0001c000 0x00020000 16384 28 32 4 2 > FOLIO 0x00020000 0x00030000 65536 32 48 16 4 > FOLIO 0x00030000 0x00040000 65536 48 64 16 4 > FOLIO 0x00040000 0x00060000 131072 64 96 32 5 > FOLIO 0x00060000 0x00080000 131072 96 128 32 5 > FOLIO 0x00080000 0x000a0000 131072 128 160 32 5 > FOLIO 0x000a0000 0x000c0000 131072 160 192 32 5 > ... > > After the change, the same operation results in the first 128K being > order-0, then we start ramping up to order-2, -4, and finally get > clamped at order-5: > > TYPE STARTOFFS ENDOFFS SIZE STARTPG ENDPG NRPG ORDER > ----- ---------- ---------- --------- ------- ------- ----- ----- > FOLIO 0x00000000 0x00001000 4096 0 1 1 0 > FOLIO 0x00001000 0x00002000 4096 1 2 1 0 > FOLIO 0x00002000 0x00003000 4096 2 3 1 0 > FOLIO 0x00003000 0x00004000 4096 3 4 1 0 > FOLIO 0x00004000 0x00005000 4096 4 5 1 0 > FOLIO 0x00005000 0x00006000 4096 5 6 1 0 > FOLIO 0x00006000 0x00007000 4096 6 7 1 0 > FOLIO 0x00007000 0x00008000 4096 7 8 1 0 > FOLIO 0x00008000 0x00009000 4096 8 9 1 0 > FOLIO 0x00009000 0x0000a000 4096 9 10 1 0 > FOLIO 0x0000a000 0x0000b000 4096 10 11 1 0 > FOLIO 0x0000b000 0x0000c000 4096 11 12 1 0 > FOLIO 0x0000c000 0x0000d000 4096 12 13 1 0 > FOLIO 0x0000d000 0x0000e000 4096 13 14 1 0 > FOLIO 0x0000e000 0x0000f000 4096 14 15 1 0 > FOLIO 0x0000f000 0x00010000 4096 15 16 1 0 > FOLIO 0x00010000 0x00011000 4096 16 17 1 0 > FOLIO 0x00011000 0x00012000 4096 17 18 1 0 > FOLIO 0x00012000 0x00013000 4096 18 19 1 0 > FOLIO 0x00013000 0x00014000 4096 19 20 1 0 > FOLIO 0x00014000 0x00015000 4096 20 21 1 0 > FOLIO 0x00015000 0x00016000 4096 21 22 1 0 > FOLIO 0x00016000 0x00017000 4096 22 23 1 0 > FOLIO 0x00017000 0x00018000 4096 23 24 1 0 > FOLIO 0x00018000 0x00019000 4096 24 25 1 0 > FOLIO 0x00019000 0x0001a000 4096 25 26 1 0 > FOLIO 0x0001a000 0x0001b000 4096 26 27 1 0 > FOLIO 0x0001b000 0x0001c000 4096 27 28 1 0 > FOLIO 0x0001c000 0x0001d000 4096 28 29 1 0 > FOLIO 0x0001d000 0x0001e000 4096 29 30 1 0 > FOLIO 0x0001e000 0x0001f000 4096 30 31 1 0 > FOLIO 0x0001f000 0x00020000 4096 31 32 1 0 > FOLIO 0x00020000 0x00024000 16384 32 36 4 2 > FOLIO 0x00024000 0x00028000 16384 36 40 4 2 > FOLIO 0x00028000 0x0002c000 16384 40 44 4 2 > FOLIO 0x0002c000 0x00030000 16384 44 48 4 2 > FOLIO 0x00030000 0x00034000 16384 48 52 4 2 > FOLIO 0x00034000 0x00038000 16384 52 56 4 2 > FOLIO 0x00038000 0x0003c000 16384 56 60 4 2 > FOLIO 0x0003c000 0x00040000 16384 60 64 4 2 > FOLIO 0x00040000 0x00050000 65536 64 80 16 4 > FOLIO 0x00050000 0x00060000 65536 80 96 16 4 > FOLIO 0x00060000 0x00080000 131072 96 128 32 5 > FOLIO 0x00080000 0x000a0000 131072 128 160 32 5 > FOLIO 0x000a0000 0x000c0000 131072 160 192 32 5 > FOLIO 0x000c0000 0x000e0000 131072 192 224 32 5 I guess performance wise this will be worse than earlier ? Although it does fix the semantics for page_cache_ra_order() with respect to the parameter 'new_order'. > ... > > Signed-off-by: Ryan Roberts > --- > mm/readahead.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/mm/readahead.c b/mm/readahead.c > index 6a4e96b69702..8bb316f5a842 100644 > --- a/mm/readahead.c > +++ b/mm/readahead.c > @@ -479,9 +479,6 @@ void page_cache_ra_order(struct readahead_control *ractl, > > limit = min(limit, index + ra->size - 1); > > - if (new_order < mapping_max_folio_order(mapping)) > - new_order += 2; > - > new_order = min(mapping_max_folio_order(mapping), new_order); > new_order = min_t(unsigned int, new_order, ilog2(ra->size)); > new_order = max(new_order, min_order); > @@ -683,6 +680,7 @@ void page_cache_async_ra(struct readahead_control *ractl, > ra->size = get_next_ra_size(ra, max_pages); > ra->async_size = ra->size; > readit: Should not the earlier conditional check also be brought here before incrementing the order ? Just curious. if (new_order < mapping_max_folio_order(mapping)) > + order += 2; > ractl->_index = ra->start; > page_cache_ra_order(ractl, ra, order); > }