From: "Xu Xin (vivo)" <xu.xin@linux.dev>
To: David Hildenbrand <david@kernel.org>, Xu Xin <xu.xin@linux.dev>,
Chengming Zhou <chengming.zhou@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
Lorenzo Stoakes <ljs@kernel.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Jonathan Corbet <corbet@lwn.net>,
Jinjiang Tu <tujinjiang@huawei.com>,
Qiliang Yuan <odys.yuan@gmail.com>
Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
Huan Yang <link@vivo.com>, Wang Xiao <xiao.wang@vivo.com>
Subject: [PATCH v2 0/4] KSM: introduce only_merge_zero_pages
Date: Tue, 10 Nov 2026 15:43:12 +0800 [thread overview]
Message-ID: <20261110074312.219847-1-xu.xin@linux.dev> (raw)
Hi all,
This series adds a new KSM sysfs attribute, only_merge_zero_pages, which
makes ksmd merge only empty (zeroed) anonymous pages with the kernel
zero page and skip the stable/unstable trees for pages that carry data.
Patch 1 adds the attribute and the early return in cmp_and_merge_page().
Patch 2 (co-developed with Jinjiang Tu) goes one step further and skips
non-zero pages already in the scan path, before an rmap_item is
allocated for them, which is what makes the mode practical on
large-memory workloads with mostly non-mergeable anonymous memory.
Patch 3 consolidates the ksm_stat readers in vm_util.c into a single
ksm_get_self_stat() helper (pure refactor). Patch 4 adds a functional
selftest.
Changelog
=========
v1 -> v2
- Patch 1: Take ksm_thread_mutex around the check-and-set in both
use_zero_pages_store() and only_merge_zero_pages_store(), so
that a concurrent write to the two attributes cannot leave
use_zero_pages=0 and only_merge_zero_pages=1, a state in which
ksmd would scan and checksum pages but never merge any.
- New patch 2, 3 and 4 are added.
Motivation
==========
On an Android device, I measured the KSM savings potential on 15.7 GiB
RAM, ~1100 processes, a typical usage session with several video apps
running) using a userspace survey tool that walks /proc/<pid>/maps +
/proc/<pid>/pagemap, deduplicates anonymous pages by their physical
frame number (PFN), and hashes page contents to find identical pages.
Key results (two samples taken 10 minutes apart):
Category Resident Savings (upper bound)
------------------- --------- ---------------------
anon, non-zero pages 2.9G 67-74 MiB (2.3-2.4%)
anon, zero pages - 281-424 MiB (9.5-13.9%)
In other scenario with a MySQL instance from huawei, there are around
15 GB consumed by hashtables, which contain many zero-filled pages that
are eligible for merging to reduce memory footprint [1].
[1] https://lore.kernel.org/all/2a642af6-b97a-4f24-9889-1844812de4cc@huawei.com/
Xu Xin (vivo) (4):
ksm: add only_merge_zero_pages to merge only empty anonymous pages
ksm: skip rmap_item allocation for non-zero pages under
only_merge_zero_pages
selftests/ksm: consolidate ksm_stat readers into ksm_get_self_stat()
selftests/ksm: add test for only_merge_zero_pages
Documentation/admin-guide/mm/ksm.rst | 40 ++++-
mm/ksm.c | 149 ++++++++++++++++++
.../selftests/mm/ksm_functional_tests.c | 135 ++++++++++++++--
tools/testing/selftests/mm/vm_util.c | 40 ++---
tools/testing/selftests/mm/vm_util.h | 3 +-
5 files changed, 327 insertions(+), 40 deletions(-)
--
2.34.1
next reply other threads:[~2026-11-10 7:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 7:43 Xu Xin (vivo) [this message]
2026-11-10 7:44 ` [PATCH 1/4] ksm: add only_merge_zero_pages to merge only empty anonymous pages Xu Xin (vivo)
2026-11-10 7:44 ` [PATCH 2/4] ksm: skip rmap_item allocation for non-zero pages under only_merge_zero_pages Xu Xin (vivo)
2026-11-10 7:44 ` [PATCH 3/4] selftests/ksm: consolidate ksm_stat readers into ksm_get_self_stat() Xu Xin (vivo)
2026-11-10 7:44 ` [PATCH 4/4] selftests/ksm: add test for only_merge_zero_pages Xu Xin (vivo)
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=20261110074312.219847-1-xu.xin@linux.dev \
--to=xu.xin@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=link@vivo.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=odys.yuan@gmail.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=tujinjiang@huawei.com \
--cc=vbabka@kernel.org \
--cc=xiao.wang@vivo.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®