From patchwork Fri Sep 15 18:38:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13387477 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 E22D2EED61E for ; Fri, 15 Sep 2023 18:39:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4ED546B03D4; Fri, 15 Sep 2023 14:39:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 381C46B03D0; Fri, 15 Sep 2023 14:39:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F9A26B03D2; Fri, 15 Sep 2023 14:39:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B72BC6B03D0 for ; Fri, 15 Sep 2023 14:39:47 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8E13980762 for ; Fri, 15 Sep 2023 18:39:47 +0000 (UTC) X-FDA: 81239695614.26.8B04829 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by imf28.hostedemail.com (Postfix) with ESMTP id C0A88C0015 for ; Fri, 15 Sep 2023 18:39:45 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=sPBj7+lP; spf=pass (imf28.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694803186; 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=LywLEuPyM84LvnszU9bu3yYyFXSjfbQxmSaZo0Anuqo=; b=bwVAsO6HLLpVgoEWE4vdhhm5U+b7+7BNVuyEqK+BFcl6KG5F6PlpBO+jqpGNRN+8Fu25Vg zpFvBQfVS75zZDkl0gqNqszJWDB+eBhcwRMkZlqA1v8LuTjJRvPn1YeYCeqlPDInc5zmnV S85DEV32mcrD7Pmm5b1noFZKe7AWGEI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694803186; a=rsa-sha256; cv=none; b=cKV7Vu7e1xPVx88F+XXNQqxz4CtTZrIfkXGl+9xauoMGy6Q58ZFlm3siVC3GWygBeQzf/p CldJ0fAqi1KzRVX6LngjLcA9hmabG4siXOtHVu8xRP6o8kL/6wbXDWX3amUOWqyZ/+c8k0 pnVTlzd1kBuYvyUwmHUSITNhLXmcB8Y= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=sPBj7+lP; spf=pass (imf28.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none 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 ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4RnNJt60W1z9sTy; Fri, 15 Sep 2023 20:39:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1694803182; 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=LywLEuPyM84LvnszU9bu3yYyFXSjfbQxmSaZo0Anuqo=; b=sPBj7+lPJjN1O52TPN3bPIvCgfHWewlpa4lD2gPArpjJc42qjZjYB0ivxNzVoPtgWUV2X9 baXqoaVEy427TKtHRyh9CuvB1dGk4UoKPWdumhCVK/Zj7hjnyV/9B5lvcIJez7O/RYML7a 7BbpTXkSIEysivDSIn8uG2RYC8Ka8TO0B9P19XqbBg8Pj8JfaNqqdtPoeNMsD2lb4sD0eY cFRHPxdkrbiSJb37sUgM291kELuaAdt9gvlmR97ZVvHYeejas3FF4Zlhd05N2OYrwNWsrp 2xibhXY+ahHHlr/15+T/ltQEQlsnkfS5en8VhTucFA1GfYp0wjO7bbHAmSHM9Q== From: Pankaj Raghav To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: p.raghav@samsung.com, david@fromorbit.com, da.gomez@samsung.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, willy@infradead.org, djwong@kernel.org, linux-mm@kvack.org, chandan.babu@oracle.com, mcgrof@kernel.org, gost.dev@samsung.com Subject: [RFC 18/23] readahead: align ra start and size to mapping_min_order in ondemand_ra() Date: Fri, 15 Sep 2023 20:38:43 +0200 Message-Id: <20230915183848.1018717-19-kernel@pankajraghav.com> In-Reply-To: <20230915183848.1018717-1-kernel@pankajraghav.com> References: <20230915183848.1018717-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: C0A88C0015 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: z5k13rjrps4ebbar54rzn1okpowj7hdf X-HE-Tag: 1694803185-510320 X-HE-Meta: U2FsdGVkX19yKALya4Ii925+8FSPtKP5tqpMoeeb/OBeU700wwyJVp6zcs6M+F8tl2yfscscDyS21h7cUjx15JpgwSM6CeYGx1AqRsBcTOcr+Ke6ZjjlGzREVEQacerLdHcfcBSx8A9uDWQqRluV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jPmyfPafAExjpcM/iIwQy6f1bTjHyDpupf0V+PA/KAU/QGU6iE6+A/d6ORW4REavS/zu6lKsFCuE/meuIj8DlFppKqxRBaM/Y705Ka50BoZ7ZGZSCw9s9uh0V53zv67MOp+jr67/4fc93O0G+bWll8RnzCVcFuDecAL0iJ/0Z25u3BX0ogTkE1awl1uylgtK/Z 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: From: Luis Chamberlain Align the ra->start and ra->size to mapping_min_order in ondemand_readahead(). This will ensure the folios added to the page_cache will be aligned to mapping_min_order number of pages. Signed-off-by: Luis Chamberlain --- mm/readahead.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 7c2660815a01..03fa6f6c8145 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -605,7 +605,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 = 1UL << min_order; + unsigned int order = folio ? folio_order(folio) : min_order; + + VM_BUG_ON(ractl->_index & (min_nrpages - 1)); /* * If the request exceeds the readahead window, allow the read to @@ -627,9 +631,13 @@ static void ondemand_readahead(struct readahead_control *ractl, expected = round_up(ra->start + ra->size - ra->async_size, 1UL << order); if (index == expected || index == (ra->start + ra->size)) { - ra->start += ra->size; - ra->size = get_next_ra_size(ra, max_pages); + ra->start += round_down(ra->size, min_nrpages); + ra->size = get_next_ra_size(ra, min_order, max_pages); ra->async_size = ra->size; + + VM_BUG_ON(ra->size & ((1UL << min_order) - 1)); + VM_BUG_ON(ra->start & ((1UL << min_order) - 1)); + goto readit; } @@ -647,13 +655,19 @@ static void ondemand_readahead(struct readahead_control *ractl, max_pages); rcu_read_unlock(); + start = round_down(start, min_nrpages); + + VM_BUG_ON(start & (min_nrpages - 1)); + VM_BUG_ON(folio->index & (folio_nr_pages(folio) - 1)); + if (!start || start - index > max_pages) return; ra->start = start; ra->size = start - index; /* old async_size */ - ra->size += req_size; - ra->size = get_next_ra_size(ra, max_pages); + VM_BUG_ON(ra->size & (min_nrpages - 1)); + ra->size += round_up(req_size, min_nrpages); + ra->size = get_next_ra_size(ra, min_order, max_pages); ra->async_size = ra->size; goto readit; } @@ -690,7 +704,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 = get_init_ra_size(req_size, min_order, max_pages); ra->async_size = ra->size > req_size ? ra->size - req_size : ra->size; readit: @@ -701,7 +715,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 = get_next_ra_size(ra, min_order, max_pages); if (ra->size + add_pages <= max_pages) { ra->async_size = add_pages; ra->size += add_pages; @@ -712,6 +726,7 @@ static void ondemand_readahead(struct readahead_control *ractl, } ractl->_index = ra->start; + VM_BUG_ON(ractl->_index & (min_nrpages - 1)); page_cache_ra_order(ractl, ra, order); }