From: Johannes Weiner <hannes@cmpxchg.org>
To: Barry Song <21cnbao@gmail.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Barry Song <v-songbaohua@oppo.com>,
Nhat Pham <nphamcs@gmail.com>,
Usama Arif <usamaarif642@gmail.com>,
Chengming Zhou <chengming.zhou@linux.dev>,
Yosry Ahmed <yosryahmed@google.com>,
Hailong Liu <hailong.liu@oppo.com>,
David Hildenbrand <david@redhat.com>,
Hugh Dickins <hughd@google.com>,
Matthew Wilcox <willy@infradead.org>,
Shakeel Butt <shakeel.butt@linux.dev>,
Andi Kleen <ak@linux.intel.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Chris Li <chrisl@kernel.org>,
"Huang, Ying" <ying.huang@intel.com>,
Kairui Song <kasong@tencent.com>,
Ryan Roberts <ryan.roberts@arm.com>
Subject: Re: [PATCH v3] mm: count zeromap read and set for swapout and swapin
Date: Wed, 6 Nov 2024 10:06:31 -0500 [thread overview]
Message-ID: <20241106150631.GA1172372@cmpxchg.org> (raw)
In-Reply-To: <20241105211934.5083-1-21cnbao@gmail.com>
On Wed, Nov 06, 2024 at 10:19:34AM +1300, Barry Song wrote:
> From: Barry Song <v-songbaohua@oppo.com>
>
> When the proportion of folios from the zeromap is small, missing their
> accounting may not significantly impact profiling. However, it’s easy
> to construct a scenario where this becomes an issue—for example,
> allocating 1 GB of memory, writing zeros from userspace, followed by
> MADV_PAGEOUT, and then swapping it back in. In this case, the swap-out
> and swap-in counts seem to vanish into a black hole, potentially
> causing semantic ambiguity.
>
> On the other hand, Usama reported that zero-filled pages can exceed 10% in
> workloads utilizing zswap, while Hailong noted that some app in Android
> have more than 6% zero-filled pages. Before commit 0ca0c24e3211 ("mm: store
> zero pages to be swapped out in a bitmap"), both zswap and zRAM implemented
> similar optimizations, leading to these optimized-out pages being counted
> in either zswap or zRAM counters (with pswpin/pswpout also increasing for
> zRAM). With zeromap functioning prior to both zswap and zRAM, userspace
> will no longer detect these swap-out and swap-in actions.
>
> We have three ways to address this:
>
> 1. Introduce a dedicated counter specifically for the zeromap.
> 2. Use pswpin/pswpout accounting, treating the zero map as a standard
> backend. This approach aligns with zRAM's current handling of
> same-page fills at the device level. However, it would mean losing
> the optimized-out page counters previously available in zRAM and
> would not align with systems using zswap. Additionally, as noted by
> Nhat Pham, pswpin/pswpout counters apply only to I/O done directly
> to the backend device.
> 3. Count zeromap pages under zswap, aligning with system behavior when
> zswap is enabled. However, this would not be consistent with zRAM,
> nor would it align with systems lacking both zswap and zRAM.
>
> Given the complications with options 2 and 3, this patch selects
> option 1.
>
> We can find these counters from /proc/vmstat (counters for the whole
> system) and memcg's memory.stat (counters for the interested memcg).
>
> For example:
>
> $ grep -E 'swpin_zero|swpout_zero' /proc/vmstat
> swpin_zero 1648
> swpout_zero 33536
>
> $ grep -E 'swpin_zero|swpout_zero' /sys/fs/cgroup/system.slice/memory.stat
> swpin_zero 3905
> swpout_zero 3985
>
> This patch does not address any specific zeromap bug, but the missing
> swpout and swpin counts for zero-filled pages can be highly confusing
> and may mislead user-space agents that rely on changes in these counters
> as indicators. Therefore, we add a Fixes tag to encourage the inclusion
> of this counter in any kernel versions with zeromap.
>
> Fixes: 0ca0c24e3211 ("mm: store zero pages to be swapped out in a bitmap")
> Reviewed-by: Nhat Pham <nphamcs@gmail.com>
> Cc: Usama Arif <usamaarif642@gmail.com>
> Cc: Chengming Zhou <chengming.zhou@linux.dev>
> Cc: Yosry Ahmed <yosryahmed@google.com>
> Cc: Hailong Liu <hailong.liu@oppo.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
> Cc: Shakeel Butt <shakeel.butt@linux.dev>
> Cc: Andi Kleen <ak@linux.intel.com>
> Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
> Cc: Chris Li <chrisl@kernel.org>
> Cc: "Huang, Ying" <ying.huang@intel.com>
> Cc: Kairui Song <kasong@tencent.com>
> Cc: Ryan Roberts <ryan.roberts@arm.com>
> Signed-off-by: Barry Song <v-songbaohua@oppo.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
next prev parent reply other threads:[~2024-11-06 15:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-05 21:19 Barry Song
2024-11-06 2:52 ` Chengming Zhou
2024-11-06 15:06 ` Johannes Weiner [this message]
2024-11-06 20:01 ` Barry Song
2024-11-06 20:42 ` Andrew Morton
2024-11-06 21:00 ` Barry Song
2024-11-06 21:44 ` Andrew Morton
2024-11-06 21:53 ` Barry Song
2024-11-06 22:02 ` Andrew Morton
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=20241106150631.GA1172372@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=21cnbao@gmail.com \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=chengming.zhou@linux.dev \
--cc=chrisl@kernel.org \
--cc=david@redhat.com \
--cc=hailong.liu@oppo.com \
--cc=hughd@google.com \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=ryan.roberts@arm.com \
--cc=shakeel.butt@linux.dev \
--cc=usamaarif642@gmail.com \
--cc=v-songbaohua@oppo.com \
--cc=willy@infradead.org \
--cc=ying.huang@intel.com \
--cc=yosryahmed@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