linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Zhaoyang Huang <huangzhaoyang@gmail.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: "黄朝阳 (Zhaoyang Huang)" <zhaoyang.huang@unisoc.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"康纪滨 (Steve Kang)" <Steve.Kang@unisoc.com>
Subject: Re: summarize all information again at bottom//reply: reply: [PATCH] mm: fix a race scenario in folio_isolate_lru
Date: Wed, 27 Mar 2024 09:25:59 +0800	[thread overview]
Message-ID: <CAGWkznGLySzLE17+rCe=UoA26vx=iM375o2zkruKM9ssG05QzA@mail.gmail.com> (raw)
In-Reply-To: <ZgK91II_eSYY6D2F@casper.infradead.org>

On Tue, Mar 26, 2024 at 8:21 PM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Tue, Mar 26, 2024 at 05:06:55PM +0800, Zhaoyang Huang wrote:
> > 1. Thread_readahead remove the folio from page cache and drop 2 refcnt
> > by readahead_folio & filemap_remove_folio(get rid of the folios which
> > failed to launch IO during readahead)
> >     refcnt == 0, PG_lru == true, PG_lock == true
> >     read_pages
> > ...
> >         folio = readahead_folio
> >         <one refcnt dropped here>
> > ********For the folio which can not launch IO, we should NOT drop
> > refcnt here??? replaced by __readahead_folio???**********
> >         folio_get
> >         filemap_remove_folio(folio)
> >         folio_unlock
> >         <one refcnt dropped here>
> >         folio_put
>
> Ignoring any other thread, you're basically saying that there's a
> refcount imbalance here.  Which means we'd hit an assert (that folio
> refcount went below zero) in the normal case where another thread wasn't
> simultaneously trying to do anything.
Theoretically Yes but it is rare in practice as aops->readahead will
launch all pages to IO under most scenarios.

read_pages
    aops->readahead[1]
...
    while (folio = readahead_folio)[2]
        filemap_remove_folio

IMO, according to the comments of readahead_page, the refcnt
represents page cache dropped in [1] makes sense for two reasons, '1.
The folio is going to do IO and is locked until IO done;2. The refcnt
will be added back when found again from the page cache and then serve
for PTE or vfs' while it doesn't make sense in [2] as the refcnt of
page cache will be dropped in filemap_remove_folio

 * Context: The page is locked and has an elevated refcount.  The caller
 * should decreases the refcount once the page has been submitted for I/O
 * and unlock the page once all I/O to that page has completed.
 * Return: A pointer to the next page, or %NULL if we are done.


  reply	other threads:[~2024-03-27  1:26 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-18  9:32 黄朝阳 (Zhaoyang Huang)
2024-03-18 12:32 ` Matthew Wilcox
2024-03-19  0:48   ` Zhaoyang Huang
2024-03-19  3:01     ` Matthew Wilcox
2024-03-21  8:25       ` Zhaoyang Huang
2024-03-21 12:36         ` Matthew Wilcox
2024-03-22  1:52           ` Zhaoyang Huang
2024-03-22  3:20             ` Matthew Wilcox
2024-03-24 11:14               ` Zhaoyang Huang
2024-03-25  3:22                 ` Matthew Wilcox
2024-03-26  9:06                   ` Zhaoyang Huang
2024-03-26 12:21                     ` Matthew Wilcox
2024-03-27  1:25                       ` Zhaoyang Huang [this message]
2024-03-27 12:31                         ` Matthew Wilcox
2024-03-28  1:27                           ` Zhaoyang Huang
2024-03-28  3:18                             ` Matthew Wilcox
2024-03-28  4:03                               ` Zhaoyang Huang
2024-03-28 14:12                                 ` Matthew Wilcox
2024-03-29  5:49                                   ` Zhaoyang Huang
2024-03-29 12:19                                     ` Matthew Wilcox

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='CAGWkznGLySzLE17+rCe=UoA26vx=iM375o2zkruKM9ssG05QzA@mail.gmail.com' \
    --to=huangzhaoyang@gmail.com \
    --cc=Steve.Kang@unisoc.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=willy@infradead.org \
    --cc=zhaoyang.huang@unisoc.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