Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Zhaoyang Huang <huangzhaoyang@gmail.com>
Cc: Zi Yan <ziy@nvidia.com>,
	jaegeuk@kernel.org, Chao Yu <chao@kernel.org>,
	"jyescas@google.com" <jyescas@google.com>,
	"David Hildenbrand (Arm)" <david@kernel.org>,
	"zhaoyang.huang" <zhaoyang.huang@unisoc.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Barry Song <baohua@kernel.org>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Lance Yang <lance.yang@linux.dev>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Nico Pache <npache@redhat.com>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	steve.kang@unisoc.com, xiuhong.wang@unisoc.com,
	hao_hao.wang@unisoc.com
Subject: Re: [RFC PATCH] mm/huge_memory: do not add dropped split tail folios to LRU
Date: Fri, 12 Jun 2026 04:44:47 +0100	[thread overview]
Message-ID: <aiuAr0kYDcc-AoVg@casper.infradead.org> (raw)
In-Reply-To: <CAGWkznHyxMNX3=A8ApCuY20As4NJpF_dCTaY_5+STVSv3RjsBw@mail.gmail.com>

On Thu, Jun 11, 2026 at 03:45:19PM +0800, Zhaoyang Huang wrote:
> > > pin_user_pages*(..., FOLL_LONGTERM)
> > > └─ __gup_longterm_locked() [gup.c:2465]
> > > │ ├─ follow_page_pte() [gup.c:802]
> > > │ │ └─ try_grab_folio() [gup.c:858]
> > >              if (WARN_ON_ONCE(folio_ref_count(folio) <= 0))
> > >                  return -ENOMEM;
> > >
> > >                                // Could __folio_split->folio_put could
> > > race here ?
> > >              if (flags & FOLL_GET)
> > >                  folio_ref_add(folio, refs);
> > > └─ check_and_migrate_movable_pages() [gup.c:2490]
> > > └─ collect_longterm_unpinnable_folios() [gup.c:2391]
> > > └─ └─if (!folio_isolate_lru(folio))
> > >
> > > Could the __folio_split race in the above scenario? It looks like
> > > try_grab_folio set the refcount without using atomic operation.
> >
> > folio_ref_add() used by try_grab_folio() is an atomic op.
> > Which refcount change is not atomic here?
> The atomic I mean is folio_try_get is implemented by
> atomic_add_unless, while try_grab_folio does this by the below
> sequence which leaves a window to have __folio_split race with it.
> right?
> 
> if (WARN_ON_ONCE(folio_ref_count(folio) <= 0))
> ....
> 
> if (flags & FOLL_GET)
>     folio_ref_add(folio, refs);

No.  try_grab_folio() is only called when we already have a reference to
the folio.  It says so right in the comment:

 * It is called when we have a stable reference for the folio, typically in
 * GUP slow path.

You may not be able to see it; in the GUP slow path, we have a lock
preventing unmapping, and the folio is mapped, therefore
there's a reference count on the folio already.  This isn't true for
try_grab_folio_fast(), which is why it uses try_get instead of ref_add.



  reply	other threads:[~2026-06-12  3:45 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-10 12:05 [RFC PATCH] mm/huge_memory: do not add dropped split tail folios to LRU zhaoyang.huang
2026-06-10 12:50 ` David Hildenbrand (Arm)
2026-06-10 14:38   ` Zi Yan
2026-06-10 17:25     ` Zi Yan
2026-06-10 18:44       ` Zi Yan
2026-06-11  1:19         ` Zhaoyang Huang
2026-06-11  1:49           ` Zi Yan
2026-06-11  1:39     ` Zhaoyang Huang
2026-06-11  1:56       ` Zi Yan
2026-06-11  2:39         ` Zhaoyang Huang
2026-06-11  3:06           ` Zi Yan
2026-06-11  7:45             ` Zhaoyang Huang
2026-06-12  3:44               ` Matthew Wilcox [this message]
2026-06-12  3:59                 ` Zhaoyang Huang
2026-06-12  4:54                   ` Matthew Wilcox
2026-06-10 20:30 ` Andrew Morton
2026-06-10 20:36   ` Zi Yan
2026-06-11  7:33 ` [syzbot ci] " syzbot ci
2026-06-11  9:30 ` [RFC PATCH] " Lorenzo Stoakes

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=aiuAr0kYDcc-AoVg@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=chao@kernel.org \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=hao_hao.wang@unisoc.com \
    --cc=huangzhaoyang@gmail.com \
    --cc=jaegeuk@kernel.org \
    --cc=jyescas@google.com \
    --cc=lance.yang@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=npache@redhat.com \
    --cc=ryan.roberts@arm.com \
    --cc=steve.kang@unisoc.com \
    --cc=xiuhong.wang@unisoc.com \
    --cc=zhaoyang.huang@unisoc.com \
    --cc=ziy@nvidia.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