From patchwork Fri Jun 7 14:58:52 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: 13690327 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 5BA34C27C5F for ; Fri, 7 Jun 2024 14:59:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE0086B0095; Fri, 7 Jun 2024 10:59:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C90806B0098; Fri, 7 Jun 2024 10:59:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B30A96B009A; Fri, 7 Jun 2024 10:59:23 -0400 (EDT) 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 8B5DF6B0095 for ; Fri, 7 Jun 2024 10:59:23 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2C42B1403A3 for ; Fri, 7 Jun 2024 14:59:23 +0000 (UTC) X-FDA: 82204401006.24.5A95371 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf26.hostedemail.com (Postfix) with ESMTP id 5FC2A14000D for ; Fri, 7 Jun 2024 14:59:20 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=ZakUtY0e; spf=pass (imf26.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=kernel@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=1717772360; 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=BFnh1b+RXQDGMofoFIGxG63YkPABCa7aRyrJNKKzJxw=; b=1Oj1dqRhPT5Hx7Jcc3CrPNCT9xkdyQ07kzDXm1V4jZAAN58CcLfdks6LFLGlYr6zo37VNj zG9t8dzXEPcN8GrkwH/mQymmGFcoEI8T1PTzsKcJqiE7GminRLyYA867DqgLxjGXX4oY09 PkWa2NEKY18E22zLFK83mryDKrzmJ3s= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=ZakUtY0e; spf=pass (imf26.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717772360; a=rsa-sha256; cv=none; b=emdhrk/QGe8bBhGoqIYu3by9J5tUnJrQ8XfbcqssNhWMUDzqPi7tZldQUG3enkoDc7Jm/T nTdrptyIoJWVEyChtw+1yASDs6fKKiZTHLUjSuoCVoYB9/3m3nH36w9wXQStBdB7mUf0Vm MNWMqJDKEsciph9/pP1c9NO5X5ZxdjA= 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-101.mailbox.org (Postfix) with ESMTPS id 4Vwkqm0Pjmz9snP; Fri, 7 Jun 2024 16:59:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1717772356; 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=BFnh1b+RXQDGMofoFIGxG63YkPABCa7aRyrJNKKzJxw=; b=ZakUtY0escrvE06apDRyPD+1UovYO/TCH/gEKA5f4SUTvP6JxD64cPXtsGhIjM+jrRM9lq QXWUzDK/c6MGMaqvT2CA7TxTC9qF7ZoZnM3yBIYS48l9zppDElgFuUjmthaKpMe9dxK2aL Qs4y/kQxPz+XcJzDud9EP/FaiL9kmlb9SqPI0uOHzGwIT90s5/4aoiNKypyjSc6uAGgq/+ 5cnkgbVHYIMHETJVDlYEUT1j1K1/mWw2+640NJ36SVzwawc1zfww8hjo+B7Xx2RcCf1Kst cSL4JhZNXPk4joWl9bagi2zOUzySYMklsOAGyWrSmtRLsWEJlS3imCE+/Nb2dw== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, djwong@kernel.org, chandan.babu@oracle.com, brauner@kernel.org, akpm@linux-foundation.org, willy@infradead.org Cc: mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, linux-kernel@vger.kernel.org, yang@os.amperecomputing.com, Zi Yan , linux-xfs@vger.kernel.org, p.raghav@samsung.com, linux-fsdevel@vger.kernel.org, kernel@pankajraghav.com, hch@lst.de, gost.dev@samsung.com, cl@os.amperecomputing.com, john.g.garry@oracle.com Subject: [PATCH v7 01/11] readahead: rework loop in page_cache_ra_unbounded() Date: Fri, 7 Jun 2024 14:58:52 +0000 Message-ID: <20240607145902.1137853-2-kernel@pankajraghav.com> In-Reply-To: <20240607145902.1137853-1-kernel@pankajraghav.com> References: <20240607145902.1137853-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 5FC2A14000D X-Stat-Signature: qf3pzsi8wrup4d7o7cpxngf76j5hbroe X-Rspam-User: X-HE-Tag: 1717772360-578656 X-HE-Meta: U2FsdGVkX1/h/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A22kTfSnd9rz8TiQ+sdNK03HUdKt3DD2KIKVFpAVuCOxFCLJIsmZMXONFTLdnX7qyGl9wSqE7Oa5PLoq0G2DGpyNfXT0JmK5924toNSr3tLESE/3ziw7Z92b8JU91Y4Ziv8cxsJF4nCbC0vPZ21kr4Mis7Du+hmHZmRfoAI6FMCJIKKeuTLyn3KCT3k1wxBOdWDaKvmBmT4uGd83MSlJ9I0= 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. Note that the index is incremented by 1 if filemap_add_folio() fails because the size of the folio we are trying to add is 1 (order 0). Signed-off-by: Hannes Reinecke Co-developed-by: Pankaj Raghav Acked-by: Darrick J. Wong Signed-off-by: Pankaj Raghav --- mm/readahead.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index c1b23989d9ca..75e934a1fd78 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -208,7 +208,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 @@ -226,7 +226,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); int ret; @@ -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; } @@ -256,13 +256,14 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, break; 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); } /*