linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kent Overstreet <kent.overstreet@gmail.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Yu Kuai <yukuai3@huawei.com>,
	akpm@linux-foundation.org, axboe@kernel.dk,
	linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, yi.zhang@huawei.com
Subject: Re: [PATCH -next] mm/filemap: fix that first page is not mark accessed in filemap_read()
Date: Fri, 10 Jun 2022 14:48:54 -0400	[thread overview]
Message-ID: <115fe76f-f5f2-338b-c4a6-d900ec151abe@gmail.com> (raw)
In-Reply-To: <YqOOsHecZUWlHEn/@casper.infradead.org>

On 6/10/22 14:34, Matthew Wilcox wrote:
> On Fri, Jun 10, 2022 at 01:47:02PM -0400, Kent Overstreet wrote:
>> I think this is the fix we want - I think Yu basically had the right idea
>> and had the off by one fix, this should be clearer though:
>>
>> Yu, can you confirm the fix?
>>
>> -- >8 --
>> Subject: [PATCH] filemap: Fix off by one error when marking folios accessed
>>
>> In filemap_read() we mark pages accessed as we read them - but we don't
>> want to do so redundantly, if the previous read already did so.
>>
>> But there was an off by one error: we want to check if the current page
>> was the same as the last page we read from, but the last page we read
>> from was (ra->prev_pos - 1) >> PAGE_SHIFT.
>>
>> Reported-by: Yu Kuai <yukuai3@huawei.com>
>> Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
>>
>> diff --git a/mm/filemap.c b/mm/filemap.c
>> index 9daeaab360..8d5c8043cb 100644
>> --- a/mm/filemap.c
>> +++ b/mm/filemap.c
>> @@ -2704,7 +2704,7 @@ ssize_t filemap_read(struct kiocb *iocb, struct
>> iov_iter *iter,
>>                   * mark it as accessed the first time.
>>                   */
>>                  if (iocb->ki_pos >> PAGE_SHIFT !=
>> -                   ra->prev_pos >> PAGE_SHIFT)
>> +                   (ra->prev_pos - 1) >> PAGE_SHIFT)
>>                          folio_mark_accessed(fbatch.folios[0]);
>>
>>                  for (i = 0; i < folio_batch_count(&fbatch); i++) {
>>
> 
> This is going to mark the folio as accessed multiple times if it's
> a multi-page folio.  How about this one?

I like that one - you can add my Reviewed-by

> 
> 
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 5f227b5420d7..a30587f2e598 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2599,6 +2599,13 @@ static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter,
>   	return err;
>   }
>   
> +static inline bool pos_same_folio(loff_t pos1, loff_t pos2, struct folio *folio)
> +{
> +	unsigned int shift = folio_shift(folio);
> +
> +	return (pos1 >> shift == pos2 >> shift);
> +}
> +
>   /**
>    * filemap_read - Read data from the page cache.
>    * @iocb: The iocb to read.
> @@ -2670,11 +2677,11 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,
>   		writably_mapped = mapping_writably_mapped(mapping);
>   
>   		/*
> -		 * When a sequential read accesses a page several times, only
> +		 * When a read accesses the same folio several times, only
>   		 * mark it as accessed the first time.
>   		 */
> -		if (iocb->ki_pos >> PAGE_SHIFT !=
> -		    ra->prev_pos >> PAGE_SHIFT)
> +		if (!pos_same_folio(iocb->ki_pos, ra->prev_pos - 1,
> +							fbatch.folios[0]))
>   			folio_mark_accessed(fbatch.folios[0]);
>   
>   		for (i = 0; i < folio_batch_count(&fbatch); i++) {



  reply	other threads:[~2022-06-10 18:48 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-02  8:21 Yu Kuai
2022-06-02 18:22 ` Andrew Morton
2022-06-06  1:11   ` Yu Kuai
2022-06-02 18:30 ` Matthew Wilcox
2022-06-02 22:25   ` yukuai (C)
2022-06-06  1:10   ` Yu Kuai
2022-06-10 14:34     ` Matthew Wilcox
2022-06-10 14:36       ` Matthew Wilcox
2022-06-10 17:23         ` Kent Overstreet
2022-06-10 17:47         ` Kent Overstreet
2022-06-10 18:34           ` Matthew Wilcox
2022-06-10 18:48             ` Kent Overstreet [this message]
2022-06-11  8:23             ` Yu Kuai
2022-06-11 17:42               ` Matthew Wilcox
2022-06-13  1:31                 ` Yu Kuai
2022-06-09  0:59 ` Yu Kuai
2022-06-15  8:36 ` [mm/filemap] 8b157c14b5: phoronix-test-suite.fio.SequentialRead.LinuxAIO.Yes.Yes.4KB.DefaultTestDirectory.mb_s -8.1% regression kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=115fe76f-f5f2-338b-c4a6-d900ec151abe@gmail.com \
    --to=kent.overstreet@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=willy@infradead.org \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox