From patchwork Mon Feb 26 09:49:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13571764 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 20D2EC48BF6 for ; Mon, 26 Feb 2024 09:50:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A23FC940020; Mon, 26 Feb 2024 04:50:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 98373940014; Mon, 26 Feb 2024 04:50:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82523940020; Mon, 26 Feb 2024 04:50:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6F3CC940014 for ; Mon, 26 Feb 2024 04:50:12 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 502CFA074F for ; Mon, 26 Feb 2024 09:50:12 +0000 (UTC) X-FDA: 81833484264.11.9FA2745 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by imf25.hostedemail.com (Postfix) with ESMTP id A98A0A0002 for ; Mon, 26 Feb 2024 09:50:10 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="LK4xL/zq"; dmarc=none; spf=pass (imf25.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708941011; a=rsa-sha256; cv=none; b=rVQgLTDwLBYapyhZnfSnUv8B8TFsb6MQdk2+7MZyWEXX12EE1MWSekd7/o8LNLNmXjb19T iCFLO0/gwAhnTIiXTRZO+IghiOHUBfpQl4/+3XKh2M+2x1cIlfaP6qY1J7IFs/HKYlcRGf rFQIUMP5rzokVI9UhTcibiIZg7yJ2ic= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="LK4xL/zq"; dmarc=none; spf=pass (imf25.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708941011; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/iWtDtcsIIVhWdsgAPg59nbWoOxmbwnUSiPp0I9sy7c=; b=ACzmBcAijC7SHagHG2hpuZOFUxo4ItlRZ/FiNL3nLbo6ABYN+FLhz56YWECD9gDE6Zf6cb gF22CF40kBDcaapSfpIC8OXzMGXKDP7OMhgob6hrY7jHqo2aN3f497YFI9N907lN14gjTX L09lUw1fRf3yowpHFjskArThxJyTWA0= Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4Tjwp748Vjz9sp7; Mon, 26 Feb 2024 10:50:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1708941007; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/iWtDtcsIIVhWdsgAPg59nbWoOxmbwnUSiPp0I9sy7c=; b=LK4xL/zqaOcK2C5cLdqWnyrsWrnOSrjd9JTjUKcDU36GVSLc7/PAhmIrSGgJHHPVt8jyaA CgAzmkvPxMIBSBLcmcHaWd47UtkpWFQwiVv9/6AbPdnMxLve7raB9+Dk0fDTKnmm9LKncR ofaxnSbT+9OLB0DXuaRe+tj1SBO/0HueXcK5qRpFENHtJ8B/WVgvHro2xe4XGQ1OM6o+cT 9QBmPtxoMmp7aubJY+9oya4KZl1IXYuPch7eyw8l+I6AeRy0I0d//IH87DD6EgY948jKob VEkkuCR9FEEG3hCVfOsWiirFMc8BLEn1q7pwYRWY0o9sYRQnlRp1e5YWUsfuDg== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, david@fromorbit.com, chandan.babu@oracle.com, akpm@linux-foundation.org, mcgrof@kernel.org, ziy@nvidia.com, hare@suse.de, djwong@kernel.org, gost.dev@samsung.com, linux-mm@kvack.org, willy@infradead.org, Pankaj Raghav Subject: [PATCH 06/13] readahead: align index to mapping_min_order in ondemand_ra and force_ra Date: Mon, 26 Feb 2024 10:49:29 +0100 Message-ID: <20240226094936.2677493-7-kernel@pankajraghav.com> In-Reply-To: <20240226094936.2677493-1-kernel@pankajraghav.com> References: <20240226094936.2677493-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A98A0A0002 X-Stat-Signature: us4daa3cy3wnh6k6bn5xzy74x3xcmsqx X-HE-Tag: 1708941010-614464 X-HE-Meta: U2FsdGVkX1+E3Bs1tZfxlNhsGPGYrKn13TSticYgkTihwkkfspju90+DpATdDopo7RFu8NTb5KWRHvAgT+PgpQ1vZDSf9no7m1+K0uTF/YmAqez1Pqp+a9R9GKqWHdklGwakBSDFweQlxr9Mqbtt8/4VOppAzAmbrW2zBDN3sgiVoNQAeyV9rI/DK2m0nJbZfjb5DmGItdVB3XS3w8vVSpYxPiM3YmC2I09IIL049Wpq9sSbHRPiTG8p5OWmYl4z1DrGBpDyF8mUOrJGeIon9Fqk52SS7u8sthIfDhPUhuZo+n6ywH9REgGEIg6KUKc+2xaoYLzqkG/47UJRbWWB99HVK7mi0Vcbs/3vFf/7VwnDihnT5XflhFFupH+3lgUCUmkQIS6MI+euIQP5RIeKahk3U6Ec0F3UdBzLwIItD4P/4j/X3j17Sgo9IHu5AqrQ+deyt68kDU74lmjMO5BKkS9hA4P14i3zg7cb2+OBKKmpnrG9cJsLnSDnp1rtCcq+OSvQJyVd9Gfuq1ruQmnOlMOPHH6+Dznf/uNnkEh6kdutfx5e9mJZw4hO2YEKnN6YqpdWOWVvDOw3fQqqixCygwI9SldKJNB87KISt5MOx0wuxBaGEBZC08v5D+vvTtV4g4ixk+ezRFRFTH66kNAZe9demEe+betam7ZS+1y8JWVvvmufn7Rv5ZFaCPsYKsjE3cacUh/VfW+Ug0RcT2V90Q/BFdXfQpO7+5aK75oMl/l3hhu/MUrFfQwhCqWwdE46rlM3CAVMIp9N1iAG3xsgcVASwvtEISUvb1SNJgqrmdSu6CtN+sMEGYVCozSOitkgDUvKOi3P9a8NbIDCPfv/M+ECrIqonqVwkunFStSxaj683aTl0ldI9CjEMfEODKlG5w8BzQAiX4C/xxBp/aC7lGHLFCVOn+y/zla9EF8C6RPQji+ZW7hJjs4ouKQCgCBwUeYTj8LRagGXBzDZQws 1ADR1mol sJSyMui3t6SzE/1buWQw2YKHMTeEncNp7+JdKMLdtxheNrUOz5nFupgPX3jk7F9efQvX4yFl/t5KVIaeVJKZn++XRHkssPNnVfrTe+NLgzZZ9gDc= 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: From: Luis Chamberlain Align the ra->start and ra->size to mapping_min_order in ondemand_readahead(), and align the index to mapping_min_order in force_page_cache_ra(). This will ensure that the folios allocated for readahead that are added to the page cache are aligned to mapping_min_order. Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- mm/readahead.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 8a610b78d94b..325a25e4ee3a 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -313,7 +313,9 @@ void force_page_cache_ra(struct readahead_control *ractl, struct address_space *mapping = ractl->mapping; struct file_ra_state *ra = ractl->ra; struct backing_dev_info *bdi = inode_to_bdi(mapping->host); - unsigned long max_pages, index; + unsigned long max_pages; + pgoff_t index, new_index; + unsigned long min_nrpages = mapping_min_folio_nrpages(mapping); if (unlikely(!mapping->a_ops->read_folio && !mapping->a_ops->readahead)) return; @@ -323,7 +325,14 @@ void force_page_cache_ra(struct readahead_control *ractl, * be up to the optimal hardware IO size */ index = readahead_index(ractl); + new_index = mapping_align_start_index(mapping, index); + if (new_index != index) { + nr_to_read += index - new_index; + index = new_index; + } + max_pages = max_t(unsigned long, bdi->io_pages, ra->ra_pages); + max_pages = max_t(unsigned long, max_pages, min_nrpages); nr_to_read = min_t(unsigned long, nr_to_read, max_pages); while (nr_to_read) { unsigned long this_chunk = (2 * 1024 * 1024) / PAGE_SIZE; @@ -331,6 +340,7 @@ void force_page_cache_ra(struct readahead_control *ractl, if (this_chunk > nr_to_read) this_chunk = nr_to_read; ractl->_index = index; + VM_BUG_ON(!IS_ALIGNED(index, min_nrpages)); do_page_cache_ra(ractl, this_chunk, 0); index += this_chunk; @@ -557,8 +567,11 @@ static void ondemand_readahead(struct readahead_control *ractl, unsigned long add_pages; pgoff_t index = readahead_index(ractl); pgoff_t expected, prev_index; - unsigned int order = folio ? folio_order(folio) : 0; + unsigned int min_order = mapping_min_folio_order(ractl->mapping); + unsigned int min_nrpages = mapping_min_folio_nrpages(ractl->mapping); + unsigned int order = folio ? folio_order(folio) : min_order; + VM_BUG_ON(!IS_ALIGNED(index, min_nrpages)); /* * If the request exceeds the readahead window, allow the read to * be up to the optimal hardware IO size @@ -580,7 +593,7 @@ static void ondemand_readahead(struct readahead_control *ractl, 1UL << order); if (index == expected || index == (ra->start + ra->size)) { ra->start += ra->size; - ra->size = get_next_ra_size(ra, max_pages); + ra->size = max(get_next_ra_size(ra, max_pages), min_nrpages); ra->async_size = ra->size; goto readit; } @@ -605,7 +618,7 @@ static void ondemand_readahead(struct readahead_control *ractl, ra->start = start; ra->size = start - index; /* old async_size */ ra->size += req_size; - ra->size = get_next_ra_size(ra, max_pages); + ra->size = max(get_next_ra_size(ra, max_pages), min_nrpages); ra->async_size = ra->size; goto readit; } @@ -642,7 +655,7 @@ static void ondemand_readahead(struct readahead_control *ractl, initial_readahead: ra->start = index; - ra->size = get_init_ra_size(req_size, max_pages); + ra->size = max(min_nrpages, get_init_ra_size(req_size, max_pages)); ra->async_size = ra->size > req_size ? ra->size - req_size : ra->size; readit: @@ -653,7 +666,7 @@ static void ondemand_readahead(struct readahead_control *ractl, * Take care of maximum IO pages as above. */ if (index == ra->start && ra->size == ra->async_size) { - add_pages = get_next_ra_size(ra, max_pages); + add_pages = max(get_next_ra_size(ra, max_pages), min_nrpages); if (ra->size + add_pages <= max_pages) { ra->async_size = add_pages; ra->size += add_pages; @@ -663,7 +676,7 @@ static void ondemand_readahead(struct readahead_control *ractl, } } - ractl->_index = ra->start; + ractl->_index = mapping_align_start_index(ractl->mapping, ra->start); page_cache_ra_order(ractl, ra, order); }