Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp643877lqb; Wed, 29 May 2024 06:45:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVXgc0LKBkYfp+PouVXwr8MgACEi/gG2BfbNdJfOtZhjEgGQDFFJzHh4yfQD2/0qcBRsPij52H7q+Y9pSdcx3Aba5USP/23tFa05Wv29g== X-Google-Smtp-Source: AGHT+IGowetL7+zrCDPUgw9N7rvi+TjSzL5Ox59wQMXsSscXM528WzCNHXV022GrTc0SCRVrXkr3 X-Received: by 2002:a17:906:7b86:b0:a59:aa7a:3b16 with SMTP id a640c23a62f3a-a642d2787b8mr202340566b.4.1716990351089; Wed, 29 May 2024 06:45:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716990351; cv=pass; d=google.com; s=arc-20160816; b=XdTaWEa5PziHHAwoaZR6lbZYRq1tTN1bQLEuJ4PjUbIZDEdpZ6VIV9Oyt12ttSX49q 3jm9bwoUs+MJMpJj1sE36v2jnx0FWVzOwCo+Q5XfEJJGPhBopAoMYr9B24IqhDy0Rvk1 IiUQqnURMr25gZp8L1az2mPo/UG7N2hIB3M3bZwlsax1p9y82SGYSC330hp1rR5CERC1 TwA16p/cIAD1jRLhWGmX1zsuOb6c6QCeOgzlbArWxIsA2cYvo3RoyLO00gnxAlR6vJg3 4/Bx5rgWdb3LG61bUY4AhnZgAG6yF8V+Bjfy/G/ayT2DMVmo3bHYH+mK3HwvuycVZUaG HH2g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=vyE4Fmym59OtmjhKpB7hb2ndo0HifAVPGXvfWnGUe04=; fh=ZWBvF269YfmsGtLAEyLGw1eEKCt1wojF+D2dyuWPubY=; b=OdwS5Fnp8vMfnQrXbzZfD+FSN2UEgcOp6H/PJTa4LC9k0jFC/SF32q94bNDBESdcU4 +xvVhKfL50kQAC3cOrzGkzPKy1wXTp+w7OwpT54Q9WLqy1drjDe8t4QztY/QdW5e3uEw ADy1BaWGr8Wjb4DKd0d1/kwX8perAvmWkMxm2ECME4cajnSkkigqWjhtH04HMZFvxzPH mASyDqWhACuhd7xslLxA/GQkqkT4wqxNXPhk6xsmuwSi9JK7DZngiZBT+6VJorugRifo 4ISHcvn1Zlg1cx1XyaUqLA+fUAT16Ls07K2gF3NrWNGQGNl3kv+5lfybxPqV5xBYKCYb 1m2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=K5BDc8k6; arc=pass (i=1 spf=pass spfdomain=pankajraghav.com dkim=pass dkdomain=pankajraghav.com dmarc=pass fromdomain=pankajraghav.com); spf=pass (google.com: domain of linux-kernel+bounces-194192-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194192-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pankajraghav.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a626c918eeesi639600166b.259.2024.05.29.06.45.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 06:45:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194192-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=K5BDc8k6; arc=pass (i=1 spf=pass spfdomain=pankajraghav.com dkim=pass dkdomain=pankajraghav.com dmarc=pass fromdomain=pankajraghav.com); spf=pass (google.com: domain of linux-kernel+bounces-194192-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194192-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pankajraghav.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CB3321F25C76 for ; Wed, 29 May 2024 13:45:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C34E21CA84; Wed, 29 May 2024 13:45:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b="K5BDc8k6" Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA5FC18E1F; Wed, 29 May 2024 13:45:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716990328; cv=none; b=s0D98HsburS1QTpcIzzF7QhtJ7m8b4+PJWuokNNYeqWaymgLZgR0SfBmwiA29I1N4IaoWlMckPbW2tMsRkm86t8bKqAez8M6GcnnR/dINjVDku+UmPvAv3v1kMHcQlqMzItRYqkttumxaU89a2YrDJLD9mCNPHbR3nTpukj8tGw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716990328; c=relaxed/simple; bh=K6PQOvY3KVLVdcZPpwKLuofLviARqNOkUNcm1nj4Ik8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TdQHZ2nIX4HKPEjDnuZT4uqpWBXuY06dzK6oA4UQNhjk8xD/+CFWZ/UIRmhff2qsYgJHXY8bA2cRPAMf+WeewiMbJlvSPyy36WUX0nOJXZBcReCSr6aJzKOeQGvZlTiWJi7GGtEJt8i75Eru0TU2ut+G+0f+O7+Ug7ehNmmZY8s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pankajraghav.com; spf=pass smtp.mailfrom=pankajraghav.com; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b=K5BDc8k6; arc=none smtp.client-ip=80.241.56.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pankajraghav.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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); } /* -- 2.34.1