From patchwork Fri Mar 1 16:44:38 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: 13578745 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 D792FC5478C for ; Fri, 1 Mar 2024 16:45:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 708D36B0096; Fri, 1 Mar 2024 11:45:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 693CD940007; Fri, 1 Mar 2024 11:45:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 517C96B0096; Fri, 1 Mar 2024 11:45:18 -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 3DF3A6B0096 for ; Fri, 1 Mar 2024 11:45:18 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CC11E1C1761 for ; Fri, 1 Mar 2024 16:45:17 +0000 (UTC) X-FDA: 81849045474.28.B2657C0 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf13.hostedemail.com (Postfix) with ESMTP id 34A392002C for ; Fri, 1 Mar 2024 16:45:15 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=VkAMxpfa; spf=pass (imf13.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709311516; 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=467JnvYp6xZwSrqHVz6JwGG/B+XhREWQAJ9IMIxeQus=; b=TMN/zKQhcDaAuln2QiNBsxcTR4pgkF+z/paP50OQcGGAJzGptqkfP9z9Z3ZK6RIxGy0F8p /sfxIBxv6dZG8IFEm7Ix6j1het0G3+iZmCHMqXwUvtYF3aZ+Xqk/k7K/AXQDyGswXN1Rt6 nPvqYpLp+ec3Krqo4M8rFZ+YzqxRPJg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311516; a=rsa-sha256; cv=none; b=1qi8HG0Kv1e7SxbDKJNRdnIRtP1vvea2SCXXYA9a7XtNiadiq59BQnFKsVDLxk86NKrDi7 g36mKk8YDbRlxOeRgpbTfMagW8YLaaauUoNd4frtZAg6qELb5KuR0zt6fTkxst0UwRqTtg P8PCpIdMA2y1HsiSnLLyjYlhh4NFaQA= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=VkAMxpfa; spf=pass (imf13.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com 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-202.mailbox.org (Postfix) with ESMTPS id 4TmYqF1lVsz9tWG; Fri, 1 Mar 2024 17:45:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311513; 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=467JnvYp6xZwSrqHVz6JwGG/B+XhREWQAJ9IMIxeQus=; b=VkAMxpfaEVmgbBcyuWtw1txdyYcbaIt4sqlGeJGp4avK/yPIQcy8to9fJZZ3qScgjLTMG0 zZ9hNEFp/oojel/WDhiyAb0dUct7HpNi+jJfzLbKNIueuEmbxVJyZbUht4rQxyC5lh8sMS HT6uu3rN9e8yCRwtkb60yJuBlBx8yoAQTlAbKLMMQDdxFUhoa6mKOfD0v3iZ/6pYAYxmVe Lb60kYjxTwQ5MKjEw4kbxCiUHOFuNB1Ojc9L6Jm6wAx5rq7lhFCLV8t0rmZZF8lVDx9g6W 5GNu5Ozk7Sxh5HXX22l8nX0Ko7gEP5moqmlTnADLEs0uHQPFY4rDTa4vNBGg7A== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 07/13] readahead: rework loop in page_cache_ra_unbounded() Date: Fri, 1 Mar 2024 17:44:38 +0100 Message-ID: <20240301164444.3799288-8-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: r7zqsnucbyehgxu1475ewwr45xop414z X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 34A392002C X-Rspam-User: X-HE-Tag: 1709311515-778042 X-HE-Meta: U2FsdGVkX1+r7tisKHQx3PPVZCImnsRH0mCatLbnzv6bxxfNrO5nWLTXHVLnn1nQQH94QuT9fRIbxxKnmauv7twNEoHF8QdiFL6iQYy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aBIxoMT92/JvYYlyLn9KNcvKE08HuZkGfA== 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 0197cb91cf85..65fbb9e78615 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -209,7 +209,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 @@ -227,7 +227,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)) { @@ -240,8 +240,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; } @@ -253,13 +253,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); } /*