mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Zi Yan" <ziy@nvidia.com>
To: "Linus Torvalds" <torvalds@linuxfoundation.org>,
	"David Hildenbrand (Arm)" <david@kernel.org>
Cc: "Ilya Gladyshev" <ilya.gladyshev@linux.dev>,
	<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: Thu, 24 Sep 2026 22:44:44 -0400	[thread overview]
Message-ID: <DLO1WIACYFWF.3N01DXYFJLMD0@nvidia.com> (raw)
In-Reply-To: <CAHk-=wh3LLDV2AMZn1PZcU1o3Na-BNcQtP=LPXouLKPZWaiRdQ@mail.gmail.com>

On Thu Sep 24, 2026 at 4:06 PM EDT, Linus Torvalds wrote:
> On Thu, 24 Sept 2026 at 11:52, David Hildenbrand (Arm) <david@kernel.org> wrote:
>>
>> There needs to be a common page freeing function that dipatches stuff.
>
> 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.

-- 
Best Regards,
Yan, Zi


  reply	other threads:[~2026-09-25  2:44 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 [this message]
2026-09-25  7:03             ` Ilya Gladyshev
2026-09-25  7:06               ` David Hildenbrand (Arm)
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=DLO1WIACYFWF.3N01DXYFJLMD0@nvidia.com \
    --to=ziy@nvidia.com \
    --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=david@kernel.org \
    --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 \
    /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®