From patchwork Wed May 29 13:44:59 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: 13678904 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 51461C27C43 for ; Wed, 29 May 2024 13:45:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9EA456B0092; Wed, 29 May 2024 09:45:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 972276B009E; Wed, 29 May 2024 09:45:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EC4C6B009F; Wed, 29 May 2024 09:45:29 -0400 (EDT) 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 59F906B0092 for ; Wed, 29 May 2024 09:45:29 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 10F031C03B3 for ; Wed, 29 May 2024 13:45:29 +0000 (UTC) X-FDA: 82171555578.12.5C5A31A Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf22.hostedemail.com (Postfix) with ESMTP id 4F442C0023 for ; Wed, 29 May 2024 13:45:26 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=K5BDc8k6; spf=pass (imf22.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 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=1716990326; 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=vyE4Fmym59OtmjhKpB7hb2ndo0HifAVPGXvfWnGUe04=; b=jumW7ZECXV1dcHsjfFTCaQkQzeCToJCzoDyp+j4gVWztYLIiQ+M1XFRfM0PxRQOxS81XNQ zGN+jMKqP5OIAV4ICBb+w5Fp/BzbqG17acx9/7he0dk+e/Pe3XX4tzIJ7fwvTeANJAkCWF Y+PVIulbMc33vkrqo1D5Xkake8WWmzQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716990326; a=rsa-sha256; cv=none; b=qgZJH4TvqkYIlACIwZOSO+qJp5NVI9GJNsqdTKgoj1U5NwQ9c3SKbvMGJDTuIMnaKQ39xy CU68MR0Zt79xT36TKCW+iTVwAniqN9R9ENlySd41ed89ihN41HwKLIFQPprLS+Uh3XyWom kB4a0XfZ8dpjDdBE0fJqp7LCAsFX8CE= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=K5BDc8k6; spf=pass (imf22.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (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 4Vq9cf2FK2z9spd; Wed, 29 May 2024 15:45:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1716990322; 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=vyE4Fmym59OtmjhKpB7hb2ndo0HifAVPGXvfWnGUe04=; b=K5BDc8k6JS74gk5nZ9S3ftaf1bczhFlSfvZUdxetoUfU00BgRFBVYNz9TZyB75a+jyKRcK +rEokZRXyNksoG16gNoeXEEtUg7tI23QP5/aFBofdmGcfKacI5XSBpC3haBSH1ikEVw+Cp JLar43Zxvmd/8EYuFal/LtLzVKvZAopFHMR74IU/8tt5ac7AMO3BnBiW7DZzJsFGjzleai pgB6m2CPlRrfCFGiSH7j6BbSCxH8SierAl/HSCY9WsLuB0UYZh6TaD9dXsdm4WuODNMNNJ sB960inXvVAiv0lcaR7D9b9DlBiDLRzBNqn44+S5wT4T3/+Ruk1cbMo3mRA6Ow== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, chandan.babu@oracle.com, akpm@linux-foundation.org, brauner@kernel.org, willy@infradead.org, djwong@kernel.org Cc: linux-kernel@vger.kernel.org, hare@suse.de, john.g.garry@oracle.com, gost.dev@samsung.com, yang@os.amperecomputing.com, p.raghav@samsung.com, cl@os.amperecomputing.com, linux-xfs@vger.kernel.org, hch@lst.de, mcgrof@kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v6 01/11] readahead: rework loop in page_cache_ra_unbounded() Date: Wed, 29 May 2024 15:44:59 +0200 Message-Id: <20240529134509.120826-2-kernel@pankajraghav.com> In-Reply-To: <20240529134509.120826-1-kernel@pankajraghav.com> References: <20240529134509.120826-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 4F442C0023 X-Rspam-User: X-Stat-Signature: 1m3z5sy5w5zzqgscksynqshh33mdpitc X-HE-Tag: 1716990326-941700 X-HE-Meta: U2FsdGVkX19TLGrez2J/JcG5TBlMCBeJdlPrrrY1+1zDxFDg04npq9ztir3UpY/1YY4Iwn9WYDX0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GlTNEeIt/ULi8cxenSmeFf+TxeKpFayrXtml6xunn4OT+hGByBIF6Raq1EsjWVOHVT04rUo3HpcYvSdOn4qId8tsuyD9E7qF32aSK8l+pRoFYY2OIGgbpVvce8MvRuR2/Jpo0ESRjmQMB6WnnQ= 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); } /*