From nobody Thu Feb 12 20:26:01 2026 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b="ZakUtY0e" 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: quoted-printable X-Rspamd-Queue-Id: 4Vwkqm0Pjmz9snP Content-Type: text/plain; charset="utf-8" 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 =3D ractl->mapping; unsigned long index =3D readahead_index(ractl); gfp_t gfp_mask =3D readahead_gfp_mask(mapping); - unsigned long i; + unsigned long i =3D 0; =20 /* * 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 =3D 0; i < nr_to_read; i++) { + while (i < nr_to_read) { struct folio *folio =3D xa_load(&mapping->i_pages, index + i); int ret; =20 @@ -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 =3D ractl->_index + ractl->_nr_pages - index - 1; + ractl->_index +=3D folio_nr_pages(folio); + i =3D ractl->_index + ractl->_nr_pages - index; continue; } =20 @@ -256,13 +256,14 @@ void page_cache_ra_unbounded(struct readahead_control= *ractl, break; read_pages(ractl); ractl->_index++; - i =3D ractl->_index + ractl->_nr_pages - index - 1; + i =3D ractl->_index + ractl->_nr_pages - index; continue; } if (i =3D=3D nr_to_read - lookahead_size) folio_set_readahead(folio); ractl->_workingset |=3D folio_test_workingset(folio); - ractl->_nr_pages++; + ractl->_nr_pages +=3D folio_nr_pages(folio); + i +=3D folio_nr_pages(folio); } =20 /* --=20 2.44.1