From nobody Mon Dec 1 20:53:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1777924A06D for ; Mon, 1 Dec 2025 19:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764616789; cv=none; b=WW71BHlJsOnprRpKO3Spo9UUK0xacrwAD+WcUXhnTBRp7jgqlvJn0CDGt/zlP8OPqBKCaBYqnGnJoO5/1cNo/gG/qaio0VkXbRpErHnrCgbxE4WxN0mIaRIp8NsTe0xEig1RAKGIN7dt5x+SPcJew8l90QM1tdwF4T3C/b7xF2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764616789; c=relaxed/simple; bh=SO/r1v05KSnDyaLwHJa1g/Jekz+lB9PhrclLWdtWnjo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qGsE0MC+2qWkYgL1loQ+4fCKsIIaXk1oUsdZTsr+Hy7TmMyxIpHutrWvSTrER/Y1B+6pucOJa4/lQIC/e2PCM1hW9G+VzKp8Of0o/ftDMAqX/S7dxZsFiIA7RaUIMmAe+ofAd6WJa/g+AV+SnOSNTkC/cAo2Exf5rzjwIuZgRNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gDZwOpI3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gDZwOpI3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8A98C4CEF1; Mon, 1 Dec 2025 19:19:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764616786; bh=SO/r1v05KSnDyaLwHJa1g/Jekz+lB9PhrclLWdtWnjo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gDZwOpI3jV+iaqgiMSTCzGNGvPDFIMKwMr7104bIwDV4v12JskWj70R6yj/bAxqgk Kz3QD+OgiAzOqf8YdUL8uK0c+ZzgVcL4OWDG8EqAFjsrRXoVRNDDSMAQsUAWGVyWsM OpZETwlgObpofA8tf8HYgK5w7442PmkgGfxTvCQna1ZoVop0Ug2Rs7bU6jQRPBizSX sEpr3E9J/onaUGY1puDsnbfRfwNS63agNNcujnia3QmNmPWEjML5vZ8SQKx1n7afWB dlisWT7qJfarpaIzfDXgBi3elOTudXvBzHt2joiRb4JlY4HwXrM62NPTIsitPdSyB7 ox3D3nMcOfIQA== From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim Subject: [PATCH 1/4] mm/readahead: fix the broken readahead for POSIX_FADV_WILLNEED Date: Mon, 1 Dec 2025 19:16:13 +0000 Message-ID: <20251201191940.883657-2-jaegeuk@kernel.org> X-Mailer: git-send-email 2.52.0.107.ga0afd4fd5b-goog In-Reply-To: <20251201191940.883657-1-jaegeuk@kernel.org> References: <20251201191940.883657-1-jaegeuk@kernel.org> 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 Content-Type: text/plain; charset="utf-8" This patch fixes the broken readahead flow for POSIX_FADV_WILLNEED, where the problem is, in force_page_cache_ra(nr_to_read), nr_to_read is cut by the below code. max_pages =3D max_t(unsigned long, bdi->io_pages, ra->ra_pages); nr_to_read =3D min_t(unsigned long, nr_to_read, max_pages); IOWs, we are not able to read ahead larger than the above max_pages which is most likely the range of 2MB and 16MB. Note, it doesn't make sense to set ra->ra_pages to the entire file size. Instead, let's fix this logic. Before: f2fs_fadvise: dev =3D (252,16), ino =3D 14, i_size =3D 4294967296 offset:0,= len:4294967296, advise:3 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D0 nr_to_read=3D512 lo= okahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D512 nr_to_read=3D512 = lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D1024 nr_to_read=3D512= lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D1536 nr_to_read=3D512= lookahead_size=3D0 After: f2fs_fadvise: dev =3D (252,16), ino =3D 14, i_size =3D 4294967296 offset:0,= len:4294967296, advise:3 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D0 nr_to_read=3D2048 l= ookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D2048 nr_to_read=3D204= 8 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D4096 nr_to_read=3D204= 8 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D6144 nr_to_read=3D204= 8 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D8192 nr_to_read=3D204= 8 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D10240 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D12288 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D14336 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D16384 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D18432 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D20480 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D22528 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D24576 nr_to_read=3D20= 48 lookahead_size=3D0 ... page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D1042432 nr_to_read=3D= 2048 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D1044480 nr_to_read=3D= 2048 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D1046528 nr_to_read=3D= 2048 lookahead_size=3D0 Signed-off-by: Jaegeuk Kim Reviewed-by: Chao Yu --- mm/readahead.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 3a4b5d58eeb6..c0db049a5b7b 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -311,7 +311,7 @@ EXPORT_SYMBOL_GPL(page_cache_ra_unbounded); * behaviour which would occur if page allocations are causing VM writebac= k. * We really don't want to intermingle reads and writes like that. */ -static void do_page_cache_ra(struct readahead_control *ractl, +static int do_page_cache_ra(struct readahead_control *ractl, unsigned long nr_to_read, unsigned long lookahead_size) { struct inode *inode =3D ractl->mapping->host; @@ -320,45 +320,42 @@ static void do_page_cache_ra(struct readahead_control= *ractl, pgoff_t end_index; /* The last page we want to read */ =20 if (isize =3D=3D 0) - return; + return -EINVAL; =20 end_index =3D (isize - 1) >> PAGE_SHIFT; if (index > end_index) - return; + return -EINVAL; /* Don't read past the page containing the last byte of the file */ if (nr_to_read > end_index - index) nr_to_read =3D end_index - index + 1; =20 page_cache_ra_unbounded(ractl, nr_to_read, lookahead_size); + return 0; } =20 /* - * Chunk the readahead into 2 megabyte units, so that we don't pin too much - * memory at once. + * Chunk the readahead per the block device capacity, and read all nr_to_r= ead. */ void force_page_cache_ra(struct readahead_control *ractl, unsigned long nr_to_read) { struct address_space *mapping =3D ractl->mapping; - struct file_ra_state *ra =3D ractl->ra; struct backing_dev_info *bdi =3D inode_to_bdi(mapping->host); - unsigned long max_pages; + unsigned long this_chunk; =20 if (unlikely(!mapping->a_ops->read_folio && !mapping->a_ops->readahead)) return; =20 /* - * If the request exceeds the readahead window, allow the read to - * be up to the optimal hardware IO size + * Consier the optimal hardware IO size for readahead chunk. */ - max_pages =3D max_t(unsigned long, bdi->io_pages, ra->ra_pages); - nr_to_read =3D min_t(unsigned long, nr_to_read, max_pages); + this_chunk =3D max_t(unsigned long, bdi->io_pages, ractl->ra->ra_pages); + while (nr_to_read) { - unsigned long this_chunk =3D (2 * 1024 * 1024) / PAGE_SIZE; + this_chunk =3D min_t(unsigned long, this_chunk, nr_to_read); =20 - if (this_chunk > nr_to_read) - this_chunk =3D nr_to_read; - do_page_cache_ra(ractl, this_chunk, 0); + if (do_page_cache_ra(ractl, this_chunk, 0)) + break; =20 nr_to_read -=3D this_chunk; } --=20 2.52.0.107.ga0afd4fd5b-goog From nobody Mon Dec 1 20:53:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 EFA152417C2 for ; Mon, 1 Dec 2025 19:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764616788; cv=none; b=kr+9pczzB9ybauFeDIVigg2C2/41WbwbjsE1MimDa43BfykMrdCJWve8xX5dnNleokZm0p6IZO3fBJ4wCvddRB7GsC2wZZ1FHVS8Y8CiXnCSDliRtF+eSiMTNmkztrkbO9cRNLv/l3755NbkABHiC3w7FMpToT0DM1ws8zpCcS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764616788; c=relaxed/simple; bh=qPAgh3J2+RQx0JuEOkYRh0szxr3XonhjB1XnpF8XRmE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bU79ksqDPixZ8fWADT0NXoU+O8a/GXJcVR0kPVKkncbEWrrAUf0ZJV60mYQzUUfO+3BHaa5GDw7ues4T0Y/Y+2UHR/GhNzkd3F/HhPxDkzxBY7Z5WjxvuT7SsDYdkK8s8AVtO+xDx+W4ntjsGVydEz9ZsQuNI1tq8lS2ZPvPETw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FxJaniuq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FxJaniuq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCB5CC19422; Mon, 1 Dec 2025 19:19:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764616787; bh=qPAgh3J2+RQx0JuEOkYRh0szxr3XonhjB1XnpF8XRmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FxJaniuqA9QxNGSqyD2DrWMHT6htzxZK4J2vWD4y+hGzmr7vAu75sPgGC8O9481WJ jK7t09I0XMT5GwYWRM0+yqcJQvFWV+IzvLVtsOhRV8ZYHSYHPGvmw6UvW5/vlBNa5L 6Nwvlo31jCzHIhNDoHaWls+scv50p/bvE6qb0y1/iwyFQwEajSuYGYsLSQ9TVzf6du iOFft850BkTsn+XY/qm5fydvCZmpOnrXW98M33HjwC1zm45OBLKHQMqm1jlXPyyfP9 keLhAHbwqG7Iz5oAiZRCXFTHPpfjkUG+CeLuA91FopZlUcO9bDB6Cn4S1D892CBo6a x7TFfM6+sM/xA== From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim Subject: [PATCH 2/4] mm/readahead: use page_cache_sync_ra for FADVISE_FAV_WILLNEED Date: Mon, 1 Dec 2025 19:16:14 +0000 Message-ID: <20251201191940.883657-3-jaegeuk@kernel.org> X-Mailer: git-send-email 2.52.0.107.ga0afd4fd5b-goog In-Reply-To: <20251201191940.883657-1-jaegeuk@kernel.org> References: <20251201191940.883657-1-jaegeuk@kernel.org> 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 Content-Type: text/plain; charset="utf-8" Given we have a_ops->folio_order which passes the desired folio order, let'= s use page_cache_sync_ra in fadvise(FADVISE_FAV_WILLNEED) to get large folios. Before: f2fs_fadvise: dev =3D (252,16), ino =3D 14, i_size =3D 4294967296 offset:0= , len:4294967296, advise:3 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D0 nr_to_read=3D2048 = lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D2048 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D4096 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D6144 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D8192 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D10240 nr_to_read=3D2= 048 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D12288 nr_to_read=3D2= 048 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D14336 nr_to_read=3D2= 048 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D16384 nr_to_read=3D2= 048 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D18432 nr_to_read=3D2= 048 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D20480 nr_to_read=3D2= 048 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D22528 nr_to_read=3D2= 048 lookahead_size=3D0 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D24576 nr_to_read=3D2= 048 lookahead_size=3D0 ... page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D1042432 nr_to_read= =3D2048 lookahead_size=3D0 This is all zero-order page allocation. After (order=3D0 by default): f2fs_fadvise: dev =3D (252,16), ino =3D 14, i_size =3D 4294967296 offset:0= , len:4294967296, advise:3 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D0 req_count=3D2048 order= =3D0 size=3D0 async_size=3D0 ra_pages=3D2048 mmap_miss=3D0 prev_pos=3D-1 page_cache_ra_order: dev=3D252:16 ino=3De index=3D0 order=3D0 size=3D2048 = async_size=3D1024 ra_pages=3D2048 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D2048 req_count=3D2048 ord= er=3D0 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_pos= =3D-1 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D2048 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D4096 req_count=3D2048 ord= er=3D0 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_pos= =3D-1 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D4096 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D6144 req_count=3D2048 ord= er=3D0 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_pos= =3D-1 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D6144 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D8192 req_count=3D2048 ord= er=3D0 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_pos= =3D-1 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D8192 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D10240 req_count=3D2048 or= der=3D0 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_po= s=3D-1 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D10240 nr_to_read=3D2= 048 lookahead_size=3D0 ... page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D1042432 nr_to_read= =3D2048 lookahead_size=3D0 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D1044480 req_count=3D2048 = order=3D0 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_= pos=3D-1 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D1044480 nr_to_read= =3D2048 lookahead_size=3D0 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D1046528 req_count=3D2048 = order=3D0 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_= pos=3D-1 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D1046528 nr_to_read= =3D2048 lookahead_size=3D0 Signed-off-by: Jaegeuk Kim --- mm/readahead.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index c0db049a5b7b..5beaf7803554 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -340,6 +340,7 @@ void force_page_cache_ra(struct readahead_control *ract= l, unsigned long nr_to_read) { struct address_space *mapping =3D ractl->mapping; + struct inode *inode =3D mapping->host; struct backing_dev_info *bdi =3D inode_to_bdi(mapping->host); unsigned long this_chunk; =20 @@ -352,11 +353,19 @@ void force_page_cache_ra(struct readahead_control *ra= ctl, this_chunk =3D max_t(unsigned long, bdi->io_pages, ractl->ra->ra_pages); =20 while (nr_to_read) { - this_chunk =3D min_t(unsigned long, this_chunk, nr_to_read); + unsigned long index =3D readahead_index(ractl); + pgoff_t end_index =3D (i_size_read(inode) - 1) >> PAGE_SHIFT; =20 - if (do_page_cache_ra(ractl, this_chunk, 0)) + if (index > end_index) break; =20 + if (nr_to_read > end_index - index) + nr_to_read =3D end_index - index + 1; + + this_chunk =3D min_t(unsigned long, this_chunk, nr_to_read); + + page_cache_sync_ra(ractl, this_chunk); + nr_to_read -=3D this_chunk; } } @@ -573,7 +582,7 @@ void page_cache_sync_ra(struct readahead_control *ractl, =20 /* be dumb */ if (do_forced_ra) { - force_page_cache_ra(ractl, req_count); + do_page_cache_ra(ractl, req_count, 0); return; } =20 --=20 2.52.0.107.ga0afd4fd5b-goog From nobody Mon Dec 1 20:53:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1770824A063 for ; Mon, 1 Dec 2025 19:19:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764616789; cv=none; b=b18lKmutF0Vk3nfpBzwDZg35Hb8d7amUL/qooqPFMNmziwbidzgWT0rVYn1lnj4+vRLhCtpTlUVHzLduPD6mQHup4mDqLEYTLAGppsnLyDAVOy/qqipWTVgEk0f1d2vldMdwvlCT6O0/yMJwg018Rkrp4pn89YiZoo3mbwWY3e0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764616789; c=relaxed/simple; bh=hLiZPx00tRWaVP/AA9DfLW8w9fvFgdJ/7VwS1ejjbNc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XeG4ajjEGGRmEhcYxx5/C6iDJQpOh/XQOwvv0YNOKceKOdH5+EWoxywxPh6FTez5PINjqIfp3BpWHyHTtm7kBdV3emfK4cr5QXu9WqqgnD4SroQIfeN9Ob2lAZJyTRnlFxx3ToGisrLl1l56fHbFeI/7NDyQNfa40JkxTnS8RFc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t3I9vyYS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="t3I9vyYS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7681C116C6; Mon, 1 Dec 2025 19:19:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764616788; bh=hLiZPx00tRWaVP/AA9DfLW8w9fvFgdJ/7VwS1ejjbNc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t3I9vyYSRB2Ap/OdoeOwNfg/bFwkto2/sQ4mMFGbpeFFBK5l7AqXrc3U/BjB3g7GW a+LJk8jQPfq+//ojKRZxSmhSMkYVdVhUxPNQSPG8goZPnm0NYjQpqIeGW0ZbFWYSPa 86OAPZR1UMd1kaoC8fViWo6k3XVz3g9z9BpKtPi6qAsRqiyMkqKQqsx5gTpLk85VQE h7aL6lIpZR08zRB42nPm/aDutjUIobYvjQrUiYmBHIVnumg4DjftlJXAIVXSu+0wxG l6YScH5QxW0mRxc8WXneKazp7w12nz60ErXHxbTvkhHRf0d0tI/955WWPcMHW3o7iW 7++/UQqcIUlfA== From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim Subject: [PATCH 3/4] mm/readahead: add a_ops->ra_folio_order to get a desired folio order Date: Mon, 1 Dec 2025 19:16:15 +0000 Message-ID: <20251201191940.883657-4-jaegeuk@kernel.org> X-Mailer: git-send-email 2.52.0.107.ga0afd4fd5b-goog In-Reply-To: <20251201191940.883657-1-jaegeuk@kernel.org> References: <20251201191940.883657-1-jaegeuk@kernel.org> 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 Content-Type: text/plain; charset="utf-8" This patch introduces a new address operation, a_ops->ra_folio_order(), whi= ch proposes a new folio order based on the adjusted order for page_cache_sync_= ra. Hence, each filesystem can set the desired minimum order of folio allocation when requesting fadvise(POSIX_FADV_WILLNEED). Signed-off-by: Jaegeuk Kim --- include/linux/fs.h | 4 ++++ include/linux/pagemap.h | 12 ++++++++++++ mm/readahead.c | 6 ++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index c895146c1444..ddab68b7e03b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -472,6 +472,10 @@ struct address_space_operations { void (*is_dirty_writeback) (struct folio *, bool *dirty, bool *wb); int (*error_remove_folio)(struct address_space *, struct folio *); =20 + /* Min folio order to allocate pages. */ + unsigned int (*ra_folio_order)(struct address_space *mapping, + unsigned int order); + /* swapfile support */ int (*swap_activate)(struct swap_info_struct *sis, struct file *file, sector_t *span); diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 09b581c1d878..e1fe07477220 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -476,6 +476,18 @@ mapping_min_folio_order(const struct address_space *ma= pping) return (mapping->flags & AS_FOLIO_ORDER_MIN_MASK) >> AS_FOLIO_ORDER_MIN; } =20 +static inline unsigned int +mapping_ra_folio_order(struct address_space *mapping, unsigned int order) +{ + if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) + return 0; + + if (!mapping->a_ops->ra_folio_order) + return order; + + return mapping->a_ops->ra_folio_order(mapping, order); +} + static inline unsigned long mapping_min_folio_nrpages(const struct address_space *mapping) { diff --git a/mm/readahead.c b/mm/readahead.c index 5beaf7803554..8c7d08af6e00 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -592,8 +592,10 @@ void page_cache_sync_ra(struct readahead_control *ract= l, * A start of file, oversized read, or sequential cache miss: * trivial case: (index - prev_index) =3D=3D 1 * unaligned reads: (index - prev_index) =3D=3D 0 + * if filesystem sets high-order allocation */ - if (!index || req_count > max_pages || index - prev_index <=3D 1UL) { + if (!index || req_count > max_pages || index - prev_index <=3D 1UL || + mapping_ra_folio_order(ractl->mapping, 0)) { ra->start =3D index; ra->size =3D get_init_ra_size(req_count, max_pages); ra->async_size =3D ra->size > req_count ? ra->size - req_count : @@ -627,7 +629,7 @@ void page_cache_sync_ra(struct readahead_control *ractl, ra->size =3D min(contig_count + req_count, max_pages); ra->async_size =3D 1; readit: - ra->order =3D 0; + ra->order =3D mapping_ra_folio_order(ractl->mapping, 0); ractl->_index =3D ra->start; page_cache_ra_order(ractl, ra); } --=20 2.52.0.107.ga0afd4fd5b-goog From nobody Mon Dec 1 20:53:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 10F1F262FC7 for ; Mon, 1 Dec 2025 19:19:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764616791; cv=none; b=cRwUOqp0HsU7JLjVpbePhxV+g9bSm/C1o9irX20VFk0wfK2y47p7SOHcHQFCfuf9l4ua6v9S8Ok2Xd3dy6SkuSmwQFdq6C6GM7Ifm27XUHlrisbCFRJfa0rndgvt3TkCet06ZH7Fr622Il0ZBRdbpVHVVFaRGH0M5yUpmNT9b0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764616791; c=relaxed/simple; bh=yQWcD18TLiYKqUnnCMGR7D3L1yi9ktuyT2awpIXDdM8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u2as2wdcGMIMCy+mGIHSzaN2yfodYSizUIiStNxryrpPfOs27PVpr0lOn42JLHqY3N3yR5ri2SFM6gWXyer1/ji4V61eFgMJ1B7aNWJemhwE2QUAp2+M62CSeRll88KvzIc2Nf6ttT55xFv+n9IZ2s947R0ugFG4oZAoX3hqbm0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DHOj6SBm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DHOj6SBm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8053CC4CEF1; Mon, 1 Dec 2025 19:19:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764616789; bh=yQWcD18TLiYKqUnnCMGR7D3L1yi9ktuyT2awpIXDdM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DHOj6SBmUT+6RFQqgxHoqAR2XBLJ78YEgsX+umpqHGeLbTSnnfLCrbP8NGLcc9Hq8 ckbvmfhj7hofWfx1DIBQT3P4tvrgnrD174NoySJBJMEnJdHMMyE2SMwjAWU4VLZ9qM 1DHAhjNJKo+lRfNfiV71ODwLp4vHlPaz4P1oRMzdu8NWtI3belLja0p4SDN9fqJQrS 2FkzFob4ZBLHU9mt9PhFBKgq9IVOM1EjDXRsC4+++RuLDjTo/ijHGpl0GWnb164LLX sArEI795Ss/HFVbD5TopoN6nNQpNppHV5SdpBEMr6le1j2d5wfzFba5z6HojunUzTS Uclic7q9yH6/w== From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim Subject: [PATCH 4/4] f2fs: attach a_ops->ra_folio_order to allocate large folios for readahead Date: Mon, 1 Dec 2025 19:16:16 +0000 Message-ID: <20251201191940.883657-5-jaegeuk@kernel.org> X-Mailer: git-send-email 2.52.0.107.ga0afd4fd5b-goog In-Reply-To: <20251201191940.883657-1-jaegeuk@kernel.org> References: <20251201191940.883657-1-jaegeuk@kernel.org> 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 Content-Type: text/plain; charset="utf-8" This patch adds a sysfs entry to change the folio order. Given ra_folio_ord= er=3D9, we can see page_cache_ra_order getting order=3D9 when we submit readahead()= as below. =3D=3D=3D=3D folio_order=3D0 =3D=3D=3D=3D f2fs_fadvise: dev =3D (252,16), ino =3D 14, i_size =3D 4294967296 offset:0= , len:4294967296, advise:3 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D0 req_count=3D2048 order= =3D0 size=3D0 async_size=3D0 ra_pages=3D2048 mmap_miss=3D0 prev_pos=3D-1 page_cache_ra_order: dev=3D252:16 ino=3De index=3D0 order=3D0 size=3D2048 = async_size=3D1024 ra_pages=3D2048 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D2048 req_count=3D2048 ord= er=3D0 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_pos= =3D-1 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D2048 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D4096 req_count=3D2048 ord= er=3D0 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_pos= =3D-1 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D4096 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D6144 req_count=3D2048 ord= er=3D0 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_pos= =3D-1 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D6144 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D8192 req_count=3D2048 ord= er=3D0 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_pos= =3D-1 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D8192 nr_to_read=3D20= 48 lookahead_size=3D0 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D10240 req_count=3D2048 or= der=3D0 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_po= s=3D-1 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D10240 nr_to_read=3D2= 048 lookahead_size=3D0 ... page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D1042432 nr_to_read= =3D2048 lookahead_size=3D0 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D1044480 req_count=3D2048 = order=3D0 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_= pos=3D-1 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D1044480 nr_to_read= =3D2048 lookahead_size=3D0 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D1046528 req_count=3D2048 = order=3D0 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_= pos=3D-1 page_cache_ra_unbounded: dev=3D252:16 ino=3De index=3D1046528 nr_to_read= =3D2048 lookahead_size=3D0 =3D=3D=3D=3D folio_order=3D9 =3D=3D=3D=3D f2fs_fadvise: dev =3D (252,16), ino =3D 14, i_size =3D 4294967296 offset:0= , len:4294967296, advise:3 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D0 req_count=3D2048 order= =3D0 size=3D0 async_size=3D0 ra_pages=3D2048 mmap_miss=3D0 prev_pos=3D-1 page_cache_ra_order: dev=3D252:16 ino=3De index=3D0 order=3D9 size=3D2048 = async_size=3D1024 ra_pages=3D2048 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D2048 req_count=3D2048 ord= er=3D9 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_pos= =3D-1 page_cache_ra_order: dev=3D252:16 ino=3De index=3D2048 order=3D9 size=3D20= 48 async_size=3D1024 ra_pages=3D2048 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D4096 req_count=3D2048 ord= er=3D9 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_pos= =3D-1 page_cache_ra_order: dev=3D252:16 ino=3De index=3D4096 order=3D9 size=3D20= 48 async_size=3D1024 ra_pages=3D2048 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D6144 req_count=3D2048 ord= er=3D9 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_pos= =3D-1 page_cache_ra_order: dev=3D252:16 ino=3De index=3D6144 order=3D9 size=3D20= 48 async_size=3D1024 ra_pages=3D2048 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D8192 req_count=3D2048 ord= er=3D9 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_pos= =3D-1 page_cache_ra_order: dev=3D252:16 ino=3De index=3D8192 order=3D9 size=3D20= 48 async_size=3D1024 ra_pages=3D2048 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D10240 req_count=3D2048 or= der=3D9 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_po= s=3D-1 page_cache_ra_order: dev=3D252:16 ino=3De index=3D10240 order=3D9 size=3D2= 048 async_size=3D1024 ra_pages=3D2048 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D12288 req_count=3D2048 or= der=3D9 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_po= s=3D-1 ... page_cache_sync_ra: dev=3D252:16 ino=3De index=3D1040384 req_count=3D2048 = order=3D9 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_= pos=3D-1 page_cache_ra_order: dev=3D252:16 ino=3De index=3D1040384 order=3D9 size= =3D2048 async_size=3D1024 ra_pages=3D2048 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D1042432 req_count=3D2048 = order=3D9 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_= pos=3D-1 page_cache_ra_order: dev=3D252:16 ino=3De index=3D1042432 order=3D9 size= =3D2048 async_size=3D1024 ra_pages=3D2048 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D1044480 req_count=3D2048 = order=3D9 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_= pos=3D-1 page_cache_ra_order: dev=3D252:16 ino=3De index=3D1044480 order=3D9 size= =3D2048 async_size=3D1024 ra_pages=3D2048 page_cache_sync_ra: dev=3D252:16 ino=3De index=3D1046528 req_count=3D2048 = order=3D9 size=3D2048 async_size=3D1024 ra_pages=3D2048 mmap_miss=3D0 prev_= pos=3D-1 page_cache_ra_order: dev=3D252:16 ino=3De index=3D1046528 order=3D9 size= =3D2048 async_size=3D1024 ra_pages=3D2048 Signed-off-by: Jaegeuk Kim --- fs/f2fs/data.c | 9 +++++++++ fs/f2fs/f2fs.h | 3 +++ fs/f2fs/super.c | 1 + fs/f2fs/sysfs.c | 9 +++++++++ 4 files changed, 22 insertions(+) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 1746519e403d..2813475070f8 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -4059,6 +4059,14 @@ static bool f2fs_dirty_data_folio(struct address_spa= ce *mapping, return false; } =20 +static unsigned int f2fs_ra_folio_order(struct address_space *mapping, + unsigned int order) +{ + if (!mapping_large_folio_support(mapping)) + return order; + + return max(order, F2FS_M_SB(mapping)->ra_folio_order); +} =20 static sector_t f2fs_bmap_compress(struct inode *inode, sector_t block) { @@ -4377,6 +4385,7 @@ const struct address_space_operations f2fs_dblock_aop= s =3D { .dirty_folio =3D f2fs_dirty_data_folio, .migrate_folio =3D filemap_migrate_folio, .invalidate_folio =3D f2fs_invalidate_folio, + .ra_folio_order =3D f2fs_ra_folio_order, .release_folio =3D f2fs_release_folio, .bmap =3D f2fs_bmap, .swap_activate =3D f2fs_swap_activate, diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 6eeb8772cee3..c5be600fb1a6 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1926,6 +1926,9 @@ struct f2fs_sb_info { /* carve out reserved_blocks from total blocks */ bool carve_out; =20 + /* enable large folio for readahead. */ + unsigned int ra_folio_order; + #ifdef CONFIG_F2FS_FS_COMPRESSION struct kmem_cache *page_array_slab; /* page array entry */ unsigned int page_array_slab_size; /* default page array slab size */ diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index ccb477086444..bae02ca96c1f 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4287,6 +4287,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi) NAT_ENTRY_PER_BLOCK)); sbi->allocate_section_hint =3D le32_to_cpu(raw_super->section_count); sbi->allocate_section_policy =3D ALLOCATE_FORWARD_NOHINT; + sbi->ra_folio_order =3D 0; F2FS_ROOT_INO(sbi) =3D le32_to_cpu(raw_super->root_ino); F2FS_NODE_INO(sbi) =3D le32_to_cpu(raw_super->node_ino); F2FS_META_INO(sbi) =3D le32_to_cpu(raw_super->meta_ino); diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index c42f4f979d13..2537a25986a6 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -906,6 +906,13 @@ static ssize_t __sbi_store(struct f2fs_attr *a, return count; } =20 + if (!strcmp(a->attr.name, "ra_folio_order")) { + if (t < 0 || t > MAX_PAGECACHE_ORDER) + return -EINVAL; + sbi->ra_folio_order =3D t; + return count; + } + *ui =3D (unsigned int)t; =20 return count; @@ -1180,6 +1187,7 @@ F2FS_SBI_GENERAL_RW_ATTR(migration_window_granularity= ); F2FS_SBI_GENERAL_RW_ATTR(dir_level); F2FS_SBI_GENERAL_RW_ATTR(allocate_section_hint); F2FS_SBI_GENERAL_RW_ATTR(allocate_section_policy); +F2FS_SBI_GENERAL_RW_ATTR(ra_folio_order); #ifdef CONFIG_F2FS_IOSTAT F2FS_SBI_GENERAL_RW_ATTR(iostat_enable); F2FS_SBI_GENERAL_RW_ATTR(iostat_period_ms); @@ -1422,6 +1430,7 @@ static struct attribute *f2fs_attrs[] =3D { ATTR_LIST(reserved_pin_section), ATTR_LIST(allocate_section_hint), ATTR_LIST(allocate_section_policy), + ATTR_LIST(ra_folio_order), NULL, }; ATTRIBUTE_GROUPS(f2fs); --=20 2.52.0.107.ga0afd4fd5b-goog