From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Ilya Gladyshev <ilya.gladyshev@linux.dev>,
Zi Yan <ziy@nvidia.com>,
Linus Torvalds <torvalds@linuxfoundation.org>
Cc: akpm@linux-foundation.org, andrew+netdev@lunn.ch,
apopple@nvidia.com, artem.kuzin@huawei.com,
baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com,
edumazet@google.com, harry.yoo@oracle.com,
hramamurthy@google.com, ivgorbunov@me.com, joshwash@google.com,
kirill@shutemov.name, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, lorenzo.stoakes@oracle.com, mhocko@suse.com,
muchun.song@linux.dev, pfalcato@suse.de, rppt@kernel.org,
surenb@google.com, vbabka@suse.cz, willy@infradead.org,
yuzhao@google.com
Subject: Re: [PATCH v6 3/3] mm: implement page refcount locking via dedicated bit
Date: Fri, 25 Sep 2026 09:06:22 +0200 [thread overview]
Message-ID: <30f58666-a798-4028-a2c3-9eb63612c4cc@kernel.org> (raw)
In-Reply-To: <a1d5881926dbf4b16dc796fb1da939f32dd42f18@linux.dev>
On 9/25/26 09:03, Ilya Gladyshev wrote:
> September 25, 2026 at 5:44 AM, Zi Yan wrote:
>>
>> On Thu Sep 24, 2026 at 4:06 PM EDT, Linus Torvalds wrote:
>>
>>>
>>>
>>> I think this all needs to be entirely generic to all pages. Agreed.
>>> Everybody needs to do it right.
>>>
>> It assumes all callers of page_ref_dec_and_test() are free page
>> functions, but there are two exceptions:
>>
>> 1. compaction_free() uses folio_put_testzero(), which calls
>> page_ref_dec_and_test() to put not used migration dst page back to
>> isolated freelist instead of freeing them.
>>
>> 2. virtio_mem_fake_offline_going_offline() drops the last reference of
>> fake-offline pages, so that they can be offline.
>>
>> They will need to be converted to not use page_ref_dec_and_test() in
>> addition to a common page freeing function. And any such future use
>> needs to be banned.
>>
>>>
>>> But I think that in the scenario that Ilya mentioned:
>>>
>>> Refcount operations as follows (FR = FROZEN):
>>>
>>> A: DEC 1 -> 0 [ page_ref_dec_and_test() ]
>>> B: INC 0 -> 1 [ folio_try_get() ] => success
>>> B: DEC 1 -> 0 [ page_ref_dec_and_test() ]
>>> B: CAS 0 -> FR [ page_ref_dec_and_test() ]
>>> B: * deallocates via __folio_put() *
>>>
>>> C: * re-allocates page *
>>> C: DEC 1 -> 0 [ page_ref_dec_and_test() ]
>>> A: CAS 0 -> FR [ page_ref_dec_and_test() ] => success
>>> A: * deallocates directly via free_frozen_pages() * => BUG
>>>
>>> the big here is that the de-allocation was done not from the state of
>>> the *page*, but from the state of who finished it off.
>>>
>>> So that
>>>
>>> A: CAS 0 -> FR [ page_ref_dec_and_test() ] => success
>>>
>>> is not a problem per se. It's a fine case of "we had one single unique
>>> final free".
>>>
>>> The failure is that A then goes on to do that
>>>
>>> "deallocates directly via free_frozen_pages"
>>>
>>> because A mis-judged the page as having the old stale state that it
>>> had when *A* was using it.
>>>
>>> IOW, I think the soluition is either:
>>>
>>> (a) every user of put_page_testzero(page) agrees tro do exactly the
>>> same thing and there is no difference between how that final
>>> "0->FROZEN" is dealt with, so it doesn't matter that A is freeing a
>>> page that C allocated for something else
>>>
>>> or
>>>
>>> (b) the CAS 0 -> FR state sequence always looks at the *page* to
>>> decide what to do, never at the caller state (ie A will look at
>>> whatever C wrote when it allocated the page to know how to do that
>>> final free).
>>>
>>> Hmm?
>>>
>> Just wonder if we could make 1 -> FROZEN atomic to get rid of the gap.
>
> Hmmm, I’m afraid that since you need CAS for a safe 1->FR transition,
> it will result in a CAS loop for the decrement itself (like in
> atomic_sub_unless).
I was playing with exact this idea when I was reviewing one of the earlier
versions; didn't manage to make it fly in a nice way :)
--
Cheers,
David
next prev parent reply other threads:[~2026-09-25 7:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-12 19:50 [PATCH v6 0/3] mm: improve folio refcount scalability Ilya Gladyshev
2026-09-12 19:50 ` [PATCH v6 1/3] gve: reduce pagecnt_bias to USHRT_MAX Ilya Gladyshev
2026-09-12 19:50 ` [PATCH v6 2/3] mm: drop page refcount zero state semantics Ilya Gladyshev
2026-09-14 9:13 ` Kiryl Shutsemau
2026-09-12 19:50 ` [PATCH v6 3/3] mm: implement page refcount locking via dedicated bit Ilya Gladyshev
2026-09-14 10:39 ` Kiryl Shutsemau
2026-09-15 2:42 ` Zi Yan
2026-09-23 17:34 ` Ilya Gladyshev
2026-09-24 18:51 ` David Hildenbrand (Arm)
2026-09-24 20:06 ` Linus Torvalds
2026-09-25 2:44 ` Zi Yan
2026-09-25 7:03 ` Ilya Gladyshev
2026-09-25 7:06 ` David Hildenbrand (Arm) [this message]
2026-09-25 7:15 ` David Hildenbrand (Arm)
2026-09-14 0:06 ` [PATCH v6 0/3] mm: improve folio refcount scalability Andrew Morton
2026-09-14 8:10 ` Ilya Gladyshev
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=30f58666-a798-4028-a2c3-9eb63612c4cc@kernel.org \
--to=david@kernel.org \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=andrew+netdev@lunn.ch \
--cc=apopple@nvidia.com \
--cc=artem.kuzin@huawei.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=edumazet@google.com \
--cc=harry.yoo@oracle.com \
--cc=hramamurthy@google.com \
--cc=ilya.gladyshev@linux.dev \
--cc=ivgorbunov@me.com \
--cc=joshwash@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®