From patchwork Tue Feb 13 09:37:05 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: 13554787 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 7C2C0C48260 for ; Tue, 13 Feb 2024 09:37:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 108358D0005; Tue, 13 Feb 2024 04:37:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BA9C8D0001; Tue, 13 Feb 2024 04:37:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4D1A8D0005; Tue, 13 Feb 2024 04:37:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C91918D0001 for ; Tue, 13 Feb 2024 04:37:44 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 903AE4036A for ; Tue, 13 Feb 2024 09:37:44 +0000 (UTC) X-FDA: 81786278448.27.FBF3D0C Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by imf07.hostedemail.com (Postfix) with ESMTP id EC75A40011 for ; Tue, 13 Feb 2024 09:37:42 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=x6CfVQAW; dmarc=none; spf=pass (imf07.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=1707817063; 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=s3+v+1l0sQIYfL9D8O6cM5bMDlwybIjei48bqSTyWjw=; b=0aQoHKC33dKMKk/fsyNJ1Ke+bRSp8OL5B5zVQIuhYt3l7xXsDhMWzzWX8c/CljwLfjwN1E S/oQwxzNT8o/wZtV5f0HYseNjFXQE7uaXmLCOrDfEy8q8o/FLr5DtAjPCl7Pu0lOKT/y2G eErosg+DkVAQZQICtx46TuSCs8a8sos= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=x6CfVQAW; dmarc=none; spf=pass (imf07.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=1707817063; a=rsa-sha256; cv=none; b=ugDuRiWfQySVdkjbfdN0+1cnwDG436kY8GzBAaXleluC1/kDO8ewKYVJQpcOHNu7471o2r gFdYi1tMoRvOjHhPaV2uAHHef8tlDNx1pG4o2NFqvrjN61q/nnAqf1wnRUgiYspJKMPUUD g0LnFH0jUhxn7GfOuN82YzGFWS/gOF4= Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4TYx7l4ntmz9t2m; Tue, 13 Feb 2024 10:37:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817059; 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=s3+v+1l0sQIYfL9D8O6cM5bMDlwybIjei48bqSTyWjw=; b=x6CfVQAW4rNsG3L+k95kHbFRenuHprAKwdKZE4SqzOwOs2L6aGmZ1ZQVD8/dJoBhJywTa7 6y8PrO1+vcd3D+x0Iqy3adhK62udO+kGv47JGmZGPVG7qqwA+gbeU/NJnY92pbJuF1EY0l JUstg7eTNj265zR9KXR68yLq9hPsVt7JMoLc8i9Yuiv2JGdztsLselFJepClTBB/njp9tI RG6HjSx+PGhFCUnsXbC9mYVgrbZ+ICPlPMhuKs9iRc8QUGmTUZSCWlB/fNXayyoq4+anHk uone6GAIEb5xnuUWMx9ouMcbT5CHsJzw8G3PIZcC8sKASsD5Z5GQy5wGcDz+jQ== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 06/14] readahead: rework loop in page_cache_ra_unbounded() Date: Tue, 13 Feb 2024 10:37:05 +0100 Message-ID: <20240213093713.1753368-7-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: EC75A40011 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: wsbp5fsqkt8k9pqsdunt5if1u11jdjsh X-HE-Tag: 1707817062-446886 X-HE-Meta: U2FsdGVkX19NVkrSM5+xdeZgxmqqBL5NT/2x9IsZ4Zy7S9aI9RlT43CHHqzgZaGzmTtvkJSRCQdFvoN4b8Lt7PD+Vk3IhZdMX8fIA6F28GjQWJQjfJawzBvxfO31cga1vskloQ/Te9Lv+tVj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pU0hXUTrJO+HsBAFUXQsSdgYiQbVQ2wJDAdCET10jyQXnl1bW4G9B6DuszPUh6nyH53e6QD/2ezV2n344L1i+3LsSs5GA608elJMQQ/6VUmCsCNSTJ5WZPUjyUT504CkK4TWOQ4OFMR5SgrTgpjIVZAz+k 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 5e1ec7705c78..13b62cbd3b79 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -213,7 +213,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 @@ -231,7 +231,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)) { @@ -244,8 +244,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; } @@ -257,13 +257,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); } /*