All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kaitao Cheng <kaitao.cheng@linux.dev>
To: Johannes Weiner <hannes@cmpxchg.org>, Yosry Ahmed <yosry@kernel.org>
Cc: Dave Chinner <david@fromorbit.com>, Qi Zheng <qi.zheng@linux.dev>,
	Muchun Song <muchun.song@linux.dev>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Nhat Pham <nphamcs@gmail.com>,
	Chengming Zhou <chengming.zhou@linux.dev>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Kaitao Cheng <chengkaitao@kylinos.cn>
Subject: Re: [PATCH] mm/zswap: fix double decrement of the LRU node count on writeback
Date: Thu, 29 Oct 2026 12:23:30 +0800	[thread overview]
Message-ID: <2bd4f0df-80c7-4d32-ab50-1225681ff6be@linux.dev> (raw)
In-Reply-To: <auJkvb-Lq0M5Enkz@cmpxchg.org>



在 2026/10/29 05:10, Johannes Weiner 写道:
> On Wed, Oct 28, 2026 at 12:22:43PM -0700, Yosry Ahmed wrote:
>> On Wed, Oct 28, 2026 at 4:36 AM Kaitao Cheng <kaitao.cheng@linux.dev> wrote:
>>>
>>> From: Kaitao Cheng <chengkaitao@kylinos.cn>
>>>
>>> Successful writeback calls zswap_entry_free(), which removes the entry
>>> from the LRU and decrements both the sublist and node item counts.
>>> shrink_memcg_cb() then returns LRU_REMOVED_RETRY, causing the LRU walker
>>> to decrement the node count again.
>>
>> I wonder if we have a valid use case for adding LRU_REMOVED_COUNTED or
>> LRU_DELETED instead to simply avoid the decrement.
> 
> It bugs me that it's the walker, not the callback, that adjusts the
> count. That composes poorly with the normal list manipulation API.
> 
> How about pushing the accounting into the isolation callback, which
> can then simply use __list_lru_del()?
> 
> The tradeoff is that more things need to be passed into the isolation
> callback, but that seems reasonable. It does make the change noisy,
> however, and we might want something like Kaitao's change as a
> backportable fix first regardless.

I tried three approaches.

The first was "pushing the accounting into the isolation callback", as
Johannes Weiner suggested. However, as Johannes's example below also shows,
this would require extensive changes across multiple subsystems. I doubted
that such a broad change would be accepted, so I dropped this approach.

The second was to add a new flag to enum lru_status, as Yosry Ahmed suggested,
to handle cases like zswap where the callback has already decremented the
count. However, the incorrect lru->node[nid].nr_items value in zswap is only
an accounting issue: I could not find any code that reads this counter for
zswap. Changing a generic interface to fix an accounting error with no
apparent functional impact did not seem worthwhile.

The third approach is the one implemented in this patch. It keeps the changes
within zswap and fixes the accounting issue, so I think it is appropriate.

> Thoughts?
> 
> ---
> 
> diff --git a/drivers/android/binder/page_range.rs b/drivers/android/binder/page_range.rs
> index b0c797523bc2..157256e52dd0 100644
> --- a/drivers/android/binder/page_range.rs
> +++ b/drivers/android/binder/page_range.rs
> @@ -24,7 +24,7 @@
>  use kernel::{
>      bindings,
>      error::Result,
> -    ffi::{c_ulong, c_void},
> +    ffi::{c_int, c_ulong, c_void},
>      mm::{virt, Mm, MmWithUser},
>      new_mutex, new_spinlock,
>      page::{Page, PAGE_SHIFT, PAGE_SIZE},
> @@ -684,8 +684,10 @@ fn drop(self: Pin<&mut Self>) {
>  /// Called by the shrinker.
>  #[no_mangle]
>  unsafe extern "C" fn rust_shrink_free_page(
> +    lru: *mut bindings::list_lru,
> +    l: *mut bindings::list_lru_one,
>      item: *mut bindings::list_head,
> -    lru: *mut bindings::list_lru_one,
> +    nid: c_int,
>      _cb_arg: *mut c_void,
>  ) -> bindings::lru_status {
>      // Fields that should survive after unlocking the lru lock.
> @@ -728,7 +730,7 @@ fn drop(self: Pin<&mut Self>) {
>          };
>  
>          // SAFETY: The item is in this lru list, so it's okay to remove it.
> -        unsafe { bindings::list_lru_isolate(lru, item) };
> +        unsafe { bindings::__list_lru_del(lru, l, item, nid) };
>  
>          // SAFETY: Both pointers are in bounds of the same allocation.
>          page_index = unsafe { info.offset_from(inner.pages) } as usize;
> @@ -746,7 +748,7 @@ fn drop(self: Pin<&mut Self>) {
>      }
>  
>      // SAFETY: The lru lock is locked when this method is called.
>  >  ........
>  ........

-- 
Thanks
Kaitao Cheng



  parent reply	other threads:[~2026-10-29  4:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 11:36 [PATCH] mm/zswap: fix double decrement of the LRU node count on writeback Kaitao Cheng
2026-10-28 18:47 ` Nhat Pham
2026-10-29  4:15   ` Kaitao Cheng
2026-10-29 17:11     ` Nhat Pham
2026-10-28 19:22 ` Yosry Ahmed
2026-10-28 21:10   ` Johannes Weiner
2026-10-28 21:17     ` Yosry Ahmed
2026-10-29  4:23     ` Kaitao Cheng [this message]
2026-10-29 15:10       ` Yosry Ahmed

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=2bd4f0df-80c7-4d32-ab50-1225681ff6be@linux.dev \
    --to=kaitao.cheng@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=chengkaitao@kylinos.cn \
    --cc=chengming.zhou@linux.dev \
    --cc=david@fromorbit.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=nphamcs@gmail.com \
    --cc=qi.zheng@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=yosry@kernel.org \
    /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.