Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1098898lqt; Fri, 7 Jun 2024 08:01:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWVVsKsLrmOLXwsJqNZ1a62c3U7DAJ54pxzIfN9rW9mRguxX1htfJaNbGG7O+9jv20/DHrmDFkflOX8SYD57BB3Cd6yWDxZRQNdNpEQuA== X-Google-Smtp-Source: AGHT+IFcaTI3j85jvqLQb3jyZp+guYOkKpQiPTEqubkwXz1+foK/y2EnpEPFU+Dh9uW4+eGJt45l X-Received: by 2002:a50:8e49:0:b0:57c:5cfc:3824 with SMTP id 4fb4d7f45d1cf-57c5cfc3bccmr1096765a12.8.1717772506889; Fri, 07 Jun 2024 08:01:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717772506; cv=pass; d=google.com; s=arc-20160816; b=yjWNBRfFhfi0HqHIjYxDOO6qNUI2NMn3AVClg3xfRFiiB4fVOZQcoe0YWw1J76nvZJ iZDn0utg1I//etx/MKg05SdJykmDD8V1h2/V+Mx3uISHeZIEc4G6r+4YB/5gEapx46Aw xmyHnJTSbFBCClf0nM0611hivpsHbPhpJzEZIJD0sLaENtvgX7jPhPmPddnUNqXA7dCn /BF2ouRLcbbI047mtwTdU8ZpZxZcCsegR34tKLqWF/SX+6NojBy0VQlLs7jqNU5l4zB/ tgtILRMb25X8sTShbvTqmr+D++KsuB83LsedbwWfl/ScE3ya/Ks8WnvgjGE3Rie8QX3q TsXA== 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=BFnh1b+RXQDGMofoFIGxG63YkPABCa7aRyrJNKKzJxw=; fh=pqFiGWrwOnMOz7J5JEcls+uL5JrBxW7q4gBZg6HAuoA=; b=nLBvh3bnzIg0mj4IP5FEy0uHLgXHsQInI8SM3XusqBv34oK8bAY+VwUls3HN21vzk7 EZkgpUz6b6LH7IiDnZttk8uPvQGP5cAp9oQKUtH/k+YhAaCLc3AnSrzMWvRVuOOhNTct 4X7uYxoGYCrERefb04CIHfqMa/rbDZ0GTwgbkyJ9QL9XXAd1JodmrrMs7UJjU7ds/g/u tFuBSl0pT0EdB6e7hsh79hbY5xvEQyf/gyx1CwdO9udp18qryiUKdWBiVz2rJjb+qer+ dvvoI8bJ9SJhWZdAMENmzOzB/lp1WvwBspvig+LcKwIiHdf5SEw4OOi1eh4jiORoVnL/ sV0w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=ZakUtY0e; 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-206330-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206330-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. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57aae22863esi1862504a12.367.2024.06.07.08.01.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 08:01:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206330-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=ZakUtY0e; 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-206330-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206330-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 99CCF1F23967 for ; Fri, 7 Jun 2024 15:01:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1717319AA75; Fri, 7 Jun 2024 14:59:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b="ZakUtY0e" Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) (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 92F1A199E9C; Fri, 7 Jun 2024 14:59:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.151 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717772367; cv=none; b=BEHbHOLcJmU3cLA6HaQWEHqPIZ2TKjUCeVUasWgSyg/J6ppmcOcufiftCi1xJvZ9ss3K80aEYN55UuRK+2e2wX70s39rxuTJrzk5Ds2gC8F2VuEAiQSS7okFH76rU1i4gPrRiQtGGxIBBQK3ZoKtpBezLyf31QO9mBEwDgi1jPg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717772367; c=relaxed/simple; bh=MCWRpI8kEOSYRtDZngyFAk5dmZlPhSoEWzJfPKvHNaw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b3+XkbVQdG7oIxANszUAblLt1rZvhDAbPgtwM+lhiBTgU/tcGCt8NZEUwf5z8hEsGZSv6dSR4gne0yOmboRhh4ULXNmTEJncXFBY0Q4q/hd5p+bjDr0iPHNi8PVto9nfyAddnDKiZ2Ng5EFPqlloidrNVE8soBSZG4vEA5yo+AY= 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=ZakUtY0e; arc=none smtp.client-ip=80.241.56.151 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 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4Vwkqm0Pjmz9snP 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.44.1