linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] readahead: fix return value of page_cache_next_miss() when no hole is found
@ 2025-06-05  5:49 Chi Zhiling
  2025-06-05  8:22 ` Jan Kara
  0 siblings, 1 reply; 5+ messages in thread
From: Chi Zhiling @ 2025-06-05  5:49 UTC (permalink / raw)
  To: willy, akpm, josef, jack
  Cc: linux-fsdevel, linux-mm, linux-kernel, Chi Zhiling

From: Chi Zhiling <chizhiling@kylinos.cn>

max_scan in page_cache_next_miss always decreases to zero when no hole
is found, causing the return value to be index + 0.

Fix this by preserving the max_scan value throughout the loop.

Fixes: 901a269ff3d5 ("filemap: fix page_cache_next_miss() when no hole found")
Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
---
 mm/filemap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index b5e784f34d98..148be65be1cd 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1767,8 +1767,9 @@ pgoff_t page_cache_next_miss(struct address_space *mapping,
 			     pgoff_t index, unsigned long max_scan)
 {
 	XA_STATE(xas, &mapping->i_pages, index);
+	unsigned long nr = max_scan;
 
-	while (max_scan--) {
+	while (nr--) {
 		void *entry = xas_next(&xas);
 		if (!entry || xa_is_value(entry))
 			return xas.xa_index;
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] readahead: fix return value of page_cache_next_miss() when no hole is found
  2025-06-05  5:49 [PATCH] readahead: fix return value of page_cache_next_miss() when no hole is found Chi Zhiling
@ 2025-06-05  8:22 ` Jan Kara
  2025-06-05 21:51   ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Kara @ 2025-06-05  8:22 UTC (permalink / raw)
  To: Chi Zhiling
  Cc: willy, akpm, josef, jack, linux-fsdevel, linux-mm, linux-kernel,
	Chi Zhiling

On Thu 05-06-25 13:49:35, Chi Zhiling wrote:
> From: Chi Zhiling <chizhiling@kylinos.cn>
> 
> max_scan in page_cache_next_miss always decreases to zero when no hole
> is found, causing the return value to be index + 0.
> 
> Fix this by preserving the max_scan value throughout the loop.
> 
> Fixes: 901a269ff3d5 ("filemap: fix page_cache_next_miss() when no hole found")
> Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>

Indeed. Thanks for catching this. Don't know how I missed that. Feel free
to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  mm/filemap.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/filemap.c b/mm/filemap.c
> index b5e784f34d98..148be65be1cd 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -1767,8 +1767,9 @@ pgoff_t page_cache_next_miss(struct address_space *mapping,
>  			     pgoff_t index, unsigned long max_scan)
>  {
>  	XA_STATE(xas, &mapping->i_pages, index);
> +	unsigned long nr = max_scan;
>  
> -	while (max_scan--) {
> +	while (nr--) {
>  		void *entry = xas_next(&xas);
>  		if (!entry || xa_is_value(entry))
>  			return xas.xa_index;
> -- 
> 2.43.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] readahead: fix return value of page_cache_next_miss() when no hole is found
  2025-06-05  8:22 ` Jan Kara
@ 2025-06-05 21:51   ` Andrew Morton
  2025-06-06 10:54     ` Jan Kara
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2025-06-05 21:51 UTC (permalink / raw)
  To: Jan Kara
  Cc: Chi Zhiling, willy, josef, linux-fsdevel, linux-mm, linux-kernel,
	Chi Zhiling

On Thu, 5 Jun 2025 10:22:23 +0200 Jan Kara <jack@suse.cz> wrote:

> On Thu 05-06-25 13:49:35, Chi Zhiling wrote:
> > From: Chi Zhiling <chizhiling@kylinos.cn>
> > 
> > max_scan in page_cache_next_miss always decreases to zero when no hole
> > is found, causing the return value to be index + 0.
> > 
> > Fix this by preserving the max_scan value throughout the loop.
> > 
> > Fixes: 901a269ff3d5 ("filemap: fix page_cache_next_miss() when no hole found")
> > Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
> 
> Indeed. Thanks for catching this. Don't know how I missed that. Feel free
> to add:
> 
> Reviewed-by: Jan Kara <jack@suse.cz>
> 

Thanks.  It's a simple patch - do we expect it to have significant
runtime effects?



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] readahead: fix return value of page_cache_next_miss() when no hole is found
  2025-06-05 21:51   ` Andrew Morton
@ 2025-06-06 10:54     ` Jan Kara
  2025-06-08  3:00       ` Chi Zhiling
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Kara @ 2025-06-06 10:54 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Jan Kara, Chi Zhiling, willy, josef, linux-fsdevel, linux-mm,
	linux-kernel, Chi Zhiling

On Thu 05-06-25 14:51:52, Andrew Morton wrote:
> On Thu, 5 Jun 2025 10:22:23 +0200 Jan Kara <jack@suse.cz> wrote:
> 
> > On Thu 05-06-25 13:49:35, Chi Zhiling wrote:
> > > From: Chi Zhiling <chizhiling@kylinos.cn>
> > > 
> > > max_scan in page_cache_next_miss always decreases to zero when no hole
> > > is found, causing the return value to be index + 0.
> > > 
> > > Fix this by preserving the max_scan value throughout the loop.
> > > 
> > > Fixes: 901a269ff3d5 ("filemap: fix page_cache_next_miss() when no hole found")
> > > Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
> > 
> > Indeed. Thanks for catching this. Don't know how I missed that. Feel free
> > to add:
> > 
> > Reviewed-by: Jan Kara <jack@suse.cz>
> > 
> 
> Thanks.  It's a simple patch - do we expect it to have significant
> runtime effects?

I'm not sure if Chi Zhiling observed some practical effects. From what I
know and have seen in the past, wrong responses from page_cache_next_miss()
can lead to readahead window reduction and thus reduced read speeds.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] readahead: fix return value of page_cache_next_miss() when no hole is found
  2025-06-06 10:54     ` Jan Kara
@ 2025-06-08  3:00       ` Chi Zhiling
  0 siblings, 0 replies; 5+ messages in thread
From: Chi Zhiling @ 2025-06-08  3:00 UTC (permalink / raw)
  To: Jan Kara, Andrew Morton
  Cc: willy, josef, linux-fsdevel, linux-mm, linux-kernel, Chi Zhiling

On 2025/6/6 18:54, Jan Kara wrote:
> On Thu 05-06-25 14:51:52, Andrew Morton wrote:
>> On Thu, 5 Jun 2025 10:22:23 +0200 Jan Kara <jack@suse.cz> wrote:
>>
>>> On Thu 05-06-25 13:49:35, Chi Zhiling wrote:
>>>> From: Chi Zhiling <chizhiling@kylinos.cn>
>>>>
>>>> max_scan in page_cache_next_miss always decreases to zero when no hole
>>>> is found, causing the return value to be index + 0.
>>>>
>>>> Fix this by preserving the max_scan value throughout the loop.
>>>>
>>>> Fixes: 901a269ff3d5 ("filemap: fix page_cache_next_miss() when no hole found")
>>>> Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
>>>
>>> Indeed. Thanks for catching this. Don't know how I missed that. Feel free
>>> to add:
>>>
>>> Reviewed-by: Jan Kara <jack@suse.cz>

Thanks

>>>
>>
>> Thanks.  It's a simple patch - do we expect it to have significant
>> runtime effects?
> 
> I'm not sure if Chi Zhiling observed some practical effects. From what I
> know and have seen in the past, wrong responses from page_cache_next_miss()
> can lead to readahead window reduction and thus reduced read speeds.
> 
> 								Honza

TBH, in my simple sequential reading test, I did not see any significant 
speed improvement.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-06-08  3:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-05  5:49 [PATCH] readahead: fix return value of page_cache_next_miss() when no hole is found Chi Zhiling
2025-06-05  8:22 ` Jan Kara
2025-06-05 21:51   ` Andrew Morton
2025-06-06 10:54     ` Jan Kara
2025-06-08  3:00       ` Chi Zhiling

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).