All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gladyshev Ilya" <ilya.gladyshev@linux.dev>
To: "Linus Torvalds" <torvalds@linuxfoundation.org>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
	ivgorbunov@me.com, Liam.Howlett@oracle.com, apopple@nvidia.com,
	artem.kuzin@huawei.com, baolin.wang@linux.alibaba.com,
	david@kernel.org, foxido@foxido.dev, harry.yoo@oracle.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	lorenzo.stoakes@oracle.com, mhocko@suse.com,
	muchun.song@linux.dev, rppt@kernel.org, surenb@google.com,
	vbabka@suse.cz, willy@infradead.org, yuzhao@google.com,
	ziy@nvidia.com, pfalcato@suse.de, kirill@shutemov.name
Subject: Re: [PATCH v4 0/2] mm: improve folio refcount scalability
Date: Sun, 21 Jun 2026 21:34:47 +0000	[thread overview]
Message-ID: <839a2ea2755fdddf5af773e006237b07c9e261df@linux.dev> (raw)
In-Reply-To: <CAHk-=wjwdbrwUpTiQef5eAd9pfC3bKig9YpXxoHQinssubRh=w@mail.gmail.com>

June 21, 2026 at 7:46 AM, Linus Torvalds wrote:
> 
> On Sat, 20 Jun 2026 at 11:19, <ilya.gladyshev@linux.dev> wrote:
> 
> > 
> > T2: optimistic get() [0 -> 1]
> > T2: put page back [1 -> 0]
> > T2: calls dtor for type X, returns into the allocator
> > 
> Which optimistic getter does this?

If I understood you correctly, you are talking about the scenario where
an optimistic getter took a refcount on the stolen page, so the validity
check in the XArray will fail. And this scenario does indeed work normally.

This "ABA" happens if the optimistic getter successfully gets a refcount
on a valid page, so the full T2 execution looks like this:

T2: optimistic get() [0 -> 1]
T2: re-checks page [OK]
T2: *normally works with this page*
T2: frees page [1 -> 0 -> FROZEN]
T2: calls dtor for type X, returns into the allocator

... T3 reuses the page, T1 wakes up and conflicts ...

T1 basically needs to sleep for a veeery long time to miss full T2 & T3
execution. 

> I didn't go back and look at the series, but isn't the rule that the code does:
> 
>  - optimistic get
> 
>  - then check that the folio is still valid (*not* using the page
> count, but by re-looking it up elsewhere, typically the address space
> mapping)
> 
>  - put the page if it wasn't valid
> 
>  - if it goes to zero, there's no destructor inherent in that
> 
>  - everybody who sees it go to zero - optimistic or not - does the
> "zero to frozen" cmpxchg

The problem is -- the zero you've seen and zero you are trying to CAS
can be different zeros if the page gets reused fast enough.
(Or couldn't and I am just confused :) )

>  - only *one* of those will succeed, and *THAT* triggers the destructor
>
>
> IOW, the transition to zero is not special per se and has no
> destructor. All it triggers is the "now we try to mark it frozen"
> phase.
> 
> At least that was my mental picture.
> 
> Was I wrong? Am I just confused? Wouldn't be the first time.
> 
>  Linus
>


  reply	other threads:[~2026-06-21 21:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-08 21:53 [PATCH v4 0/2] mm: improve folio refcount scalability Gladyshev Ilya
2026-06-08 21:54 ` [PATCH v4 1/2] mm: drop page refcount zero state semantics ilya.gladyshev
2026-06-08 21:54 ` [PATCH v4 2/2] mm: implement page refcount locking via dedicated bit Gladyshev Ilya
2026-06-08 22:47 ` [PATCH v4 0/2] mm: improve folio refcount scalability Andrew Morton
2026-06-09 10:28   ` David Hildenbrand (Arm)
2026-06-09 19:02   ` Gladyshev Ilya
2026-06-09 21:02     ` Pedro Falcato
2026-06-20 18:19   ` ilya.gladyshev
2026-06-21  1:40     ` Zi Yan
2026-06-22  7:55       ` David Hildenbrand (Arm)
2026-06-21  4:46     ` Linus Torvalds
2026-06-21 21:34       ` Gladyshev Ilya [this message]
2026-06-21 21:50         ` Matthew Wilcox
2026-06-21 22:53         ` Linus Torvalds
2026-06-22  8:15       ` David Hildenbrand (Arm)

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=839a2ea2755fdddf5af773e006237b07c9e261df@linux.dev \
    --to=ilya.gladyshev@linux.dev \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=artem.kuzin@huawei.com \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=foxido@foxido.dev \
    --cc=harry.yoo@oracle.com \
    --cc=ivgorbunov@me.com \
    --cc=kirill@shutemov.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=pfalcato@suse.de \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=torvalds@linuxfoundation.org \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    --cc=yuzhao@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.