From: Andrew Morton <akpm@linux-foundation.org>
To: Samarth Narang <samarth.colleges@gmail.com>
Cc: David Hildenbrand <david@kernel.org>, Xu Xin <xu.xin@linux.dev>,
Chengming Zhou <chengming.zhou@linux.dev>,
Peter Xu <peterx@redhat.com>, Kiryl Shutsemau <kas@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Lance Yang <lance.yang@linux.dev>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v3] mm/ksm: keep soft-dirty when merging a page
Date: Fri, 23 Oct 2026 22:33:52 -0700 [thread overview]
Message-ID: <20261023223352.c6de9f2b58fe999814e5bb17@linux-foundation.org> (raw)
In-Reply-To: <20261021182157.1873726-1-samarth.colleges@gmail.com>
On Wed, 21 Oct 2026 11:21:57 -0700 Samarth Narang <samarth.colleges@gmail.com> wrote:
> replace_page() maps the KSM page with a PTE built from scratch, so the
> soft-dirty bit of the PTE it replaces is lost. A page written since
> "clear_refs 4" then no longer shows as soft-dirty once it is merged, and
> a soft-dirty based dumper treats it as unchanged.
>
> Copy the soft-dirty bit from the original PTE to the new PTE.
Thanks. My LLM review thing says:
: There's a separate, pre-existing problem with the KSM zero-page
: path which is worth pointing out.
:
: When use_zero_pages is enabled, replace_page() constructs the
: replacement PTE using:
:
: newpte = pte_mkdirty(pte_mkspecial(pfn_pte(...)));
:
: The dirty bit is deliberately set so that KSM can distinguish its
: own zero-page mappings from ordinary zero-page mappings. However,
: on x86, pte_mkdirty() sets both _PAGE_DIRTY and _PAGE_SOFT_DIRTY.
:
: Consequently, a process can clear its soft-dirty bits through
: /proc/PID/clear_refs, perform no further writes, and subsequently
: have a page marked soft-dirty simply because KSM merged an all-zero
: page. Userspace then sees bit 55 set in /proc/PID/pagemap even though
: the page hasn't been modified since tracking was reset.
:
: Your patch doesn't introduce this problem, but it doesn't fix it
: either. The new pte_soft_dirty(orig_pte) check cannot help in the
: zero-page case because pte_mkdirty() has already set the bit in
: newpte.
:
: I don't think this should hold up v3. Losing soft-dirty when merging
: ordinary pages is a more serious problem, since it can cause
: incremental checkpointing to miss modified pages. The zero-page
: case instead produces false positives, causing unnecessary copying.
:
: It would be worth addressing separately, preserving KSM's internal
: zero-page marker without manufacturing a soft-dirty indication.
prev parent reply other threads:[~2026-10-24 5:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 18:21 Samarth Narang
2026-10-22 0:51 ` Lance Yang
2026-10-24 5:33 ` Andrew Morton [this message]
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=20261023223352.c6de9f2b58fe999814e5bb17@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=david@kernel.org \
--cc=kas@kernel.org \
--cc=lance.yang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterx@redhat.com \
--cc=rppt@kernel.org \
--cc=samarth.colleges@gmail.com \
--cc=stable@vger.kernel.org \
--cc=xu.xin@linux.dev \
/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®