From patchwork Mon Feb 26 09:49:30 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: 13571765 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 0A88DC48BF6 for ; Mon, 26 Feb 2024 09:50:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 911B2940021; Mon, 26 Feb 2024 04:50:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C0FE940014; Mon, 26 Feb 2024 04:50:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7891B940021; Mon, 26 Feb 2024 04:50:17 -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 68867940014 for ; Mon, 26 Feb 2024 04:50:17 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 4AB6D1C0868 for ; Mon, 26 Feb 2024 09:50:17 +0000 (UTC) X-FDA: 81833484474.13.9A90072 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf13.hostedemail.com (Postfix) with ESMTP id C334620013 for ; Mon, 26 Feb 2024 09:50:15 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=s1FvJLOV; dmarc=none; spf=pass (imf13.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 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=1708941016; 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=i9yxkr7ZYzLuGR2ramAYSlLdnRgu3ddqhwDDXgb/dQg=; b=lDkSvVr4EITWxAt0lfHCWqhW12uIBINhpBQuSEB+rXMa74jpKZrtZQEtkYNdGltCqi6L/g MTW7a9AkPRarT5xBVaC1xNXZJ/1q5I4BZvAIaEDkI+Rf8GUcOixVEHmYh69b81gIu/HLZR I7MWSShW3X+7cUtDyFIQJKBk+R7/a9I= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=s1FvJLOV; dmarc=none; spf=pass (imf13.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708941016; a=rsa-sha256; cv=none; b=7H3wo6LK3UdXBpgTNPSSLTyC08/o7XIEV6lOQMlOzqSgry0Yppa0h8rZxjcEHbRVHwulFs Ia8F0UNuKvj3L/BqWEF3rKhSvEK2hrdpIhDenPJqfB3SfdrMX7j9XGul3lv2r23EpSWf1d tIfwIwNSgmpptOdl/sqJTvenqyG8GUo= Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.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-202.mailbox.org (Postfix) with ESMTPS id 4TjwpD4yqgz9sQ6; Mon, 26 Feb 2024 10:50:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1708941012; 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=i9yxkr7ZYzLuGR2ramAYSlLdnRgu3ddqhwDDXgb/dQg=; b=s1FvJLOV6O9BDoEZy9rfAWAdOmTdsY69l/3r70AQ4MWdtRAAjRw8jrLMD2N1T8oH7bb3FE Zo5P5AF31/WRErUzGHULK/N/M18PaNHpCSVQ/5UjkSyvUBhL6ARcSVNtDNa7LFFihtGyuX zwLRbtKGFial2tfZRA/t6m9w4WUIikd/uSVFERTvKPvVNwLbAywF7r57ufmFDElaWknTj8 dQx12H3rSonr9IpI4qrobmgSjtp6J/VscSXIGgYelBUaxhicKdv9lyM5eovuOQEre1YR3i LWU2h+G8ukjtVd6mKiPDMISh406FjzorZrXGDipZ54XIyY/I6PB1osHX3sl0NA== 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 07/13] readahead: rework loop in page_cache_ra_unbounded() Date: Mon, 26 Feb 2024 10:49:30 +0100 Message-ID: <20240226094936.2677493-8-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-Stat-Signature: gfeym345i1ephyzyyqymfzetsj7m4pu6 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C334620013 X-HE-Tag: 1708941015-669087 X-HE-Meta: U2FsdGVkX18fRPqXLTjCvPfJD2u7pDu8ee3t+ODMrdR9UKclzBlHsHhYt1ivnr2/yrkst/borZdob4ejVNSLoibdcp/8s9Ik3LD1Sf360XHiAJExgiBSN9QrH6vdwED2tYG9vGRWRu4exleWGFCCAUuHHHfU00+BnNYNIC45zg0hAXn24oYjXwi6g6GF4w0RRSticPimnF2OuroV5MfxJUt8astYVYXinz1zTy9qzS0sdKaTnJSy9/MgIQxkuCzFCjZjp5y9I4P8NCn/MmwC/HS7Snc08KbYmbZ+RqLd/dAj3zuJDvCq3qOxP5P2wOMO7TH3gzuHxT6gPkp+g7af/rD4KD2W5dqUfCovngq9Ula/jH+OwyeKNRKjFUmq2m+W7Rxt2Lz2GpX2rifeudGAkTSRiyG472MBhtZUg+JNDWuPLcBXzUDWBPAAURazYhYBIqyl2gslair8IHejNy5eXeBjyGHrW9X3+dQbd+tjs6/nimaJjCqPMG619swb4p2qLdFOZSF1L7ckdokZXqQUxv/8+jBJCBNpOMwWZqWslowWjX76yGDVltjkpDhlULsTYR+Zzq4SDjjqrdzvbNp+SfZwdAJ7qsPTU+lFe7APNxrd71D1R5PgCs5Wjx5PrzZ9I9MtaAx1STT0llPS6c5RMjePd2EAsiUGlpzPbp8eashB1aEiR/PQJfR1LjjRsAJwhxsneJx4esOUyzbiuOtTsM1aUtVHfDHZnGouUgPJuZVX5bYRLVVPwmQPnbzm5Qid63d7kn/0o/S9vB44fUMKnNh533yqg0Z9V72F9BL9+ZDNTtQluNloAD/OrJOqsmQImpYfLZYHjQTxbhfeQMZQIfpWfaF3/uYWxeXmPiWZCkVtyzD8ILhJ9VeMpPqtrh9L3XUQW39qWEVhmnkv4+VWcC8x+aHK+5TBiqleNcfIouIhnaUM8oktImwBcktvkD7GHWk5E3cMFRnhB7AKzFG 0njrXUH2 pPSrUhht1SqkOcYWxHfhWoIsdO9VGI3bBc25zZKqqWkSZp4zNZt/x8XLofMEvIxix7glCQQw9w4WJobvPyd5BQTTKghZvjMgnW1vRczW9JzhKfLE= 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: Hannes Reinecke Rework the loop in page_cache_ra_unbounded() to advance with the number of pages in a folio instead of just one page at a time. Signed-off-by: Hannes Reinecke Co-developed-by: Pankaj Raghav Signed-off-by: Pankaj Raghav Acked-by: Darrick J. Wong --- mm/readahead.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 325a25e4ee3a..ef0004147952 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -212,7 +212,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, struct address_space *mapping = ractl->mapping; unsigned long index = readahead_index(ractl); gfp_t gfp_mask = readahead_gfp_mask(mapping); - unsigned long i; + unsigned long i = 0; /* * Partway through the readahead operation, we will have added @@ -230,7 +230,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, /* * Preallocate as many pages as we will need. */ - for (i = 0; i < nr_to_read; i++) { + while (i < nr_to_read) { struct folio *folio = xa_load(&mapping->i_pages, index + i); if (folio && !xa_is_value(folio)) { @@ -243,8 +243,8 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, * not worth getting one just for that. */ read_pages(ractl); - ractl->_index++; - i = ractl->_index + ractl->_nr_pages - index - 1; + ractl->_index += folio_nr_pages(folio); + i = ractl->_index + ractl->_nr_pages - index; continue; } @@ -256,13 +256,14 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, folio_put(folio); read_pages(ractl); ractl->_index++; - i = ractl->_index + ractl->_nr_pages - index - 1; + i = ractl->_index + ractl->_nr_pages - index; continue; } if (i == nr_to_read - lookahead_size) folio_set_readahead(folio); ractl->_workingset |= folio_test_workingset(folio); - ractl->_nr_pages++; + ractl->_nr_pages += folio_nr_pages(folio); + i += folio_nr_pages(folio); } /*