linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yu Kuai <yukuai3@huawei.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Kent Overstreet <kent.overstreet@gmail.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: Mon, 13 Jun 2022 09:31:11 +0800	[thread overview]
Message-ID: <7e9889b7-8eeb-5e97-3f4b-cdc914a032f4@huawei.com> (raw)
In-Reply-To: <YqTUEZ+Pa24p09Uc@casper.infradead.org>

在 2022/06/12 1:42, Matthew Wilcox 写道:
> On Sat, Jun 11, 2022 at 04:23:42PM +0800, Yu Kuai wrote:
>>> This is going to mark the folio as accessed multiple times if it's
>>> a multi-page folio.  How about this one?
>>>
>> Hi, Matthew
>>
>> Thanks for the patch, it looks good to me.
> 
> Did you test it?  This is clearly a little subtle ;-)

Yes, I confirmed that with this patch, small sequential read will mark
page accessed. However, multi-page folio is not tested yet.

> 
>> BTW, I still think the fix should be commit 06c0444290ce ("mm/filemap.c:
>> generic_file_buffered_read() now uses find_get_pages_contig").
> 
> Hmm, yes.  That code also has problems, but they're more subtle and
> probably don't amount to much.
> 
> -       iocb->ki_pos += copied;
> -
> -       /*
> -        * When a sequential read accesses a page several times,
> -        * only mark it as accessed the first time.
> -        */
> -       if (iocb->ki_pos >> PAGE_SHIFT != ra->prev_pos >> PAGE_SHIFT)
> -               mark_page_accessed(page);
> -
> -       ra->prev_pos = iocb->ki_pos;
> 
> This will mark the page accessed when we _exit_ a page.  So reading
> 512-bytes at a time from offset 0, we'll mark page 0 as accessed on the
> first read (because the prev_pos is initialised to -1).  Then on the
> eighth read, we'll mark page 0 as accessed again (because ki_pos will
> now be 4096 and prev_pos is 3584).  We'll then read chunks of page 1
> without marking it as accessed, until we're about to step into page 2.

You are right, I didn't think of that situation.
> 
> Marking page 0 accessed twice is bad; it'll set the referenced bit the
> first time, and then the second time, it'll activate it.  So it'll be
> thought to be part of the workingset when it's really just been part of
> a streaming read.
> 
> And the last page we read will never be marked accessed unless it
> happens to finish at the end of a page.
> 
> Before Kent started his refactoring, I think it worked:
> 
> -       pgoff_t prev_index;
> -       unsigned int prev_offset;
> ...
> -       prev_index = ra->prev_pos >> PAGE_SHIFT;
> -       prev_offset = ra->prev_pos & (PAGE_SIZE-1);
> ...
> -               if (prev_index != index || offset != prev_offset)
> -                       mark_page_accessed(page);
> -               prev_index = index;
> -               prev_offset = offset;
> ...
> -       ra->prev_pos = prev_index;
> -       ra->prev_pos <<= PAGE_SHIFT;
> -       ra->prev_pos |= prev_offset;
> 
> At least, I don't detect any bugs in this.

Sure, thanks for your explanation.


  reply	other threads:[~2022-06-13  1:31 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
2022-06-11  8:23             ` Yu Kuai
2022-06-11 17:42               ` Matthew Wilcox
2022-06-13  1:31                 ` Yu Kuai [this message]
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=7e9889b7-8eeb-5e97-3f4b-cdc914a032f4@huawei.com \
    --to=yukuai3@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=kent.overstreet@gmail.com \
    --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 \
    /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