From: "Xu Xin (vivo)" <xu.xin@linux.dev>
To: david@kernel.org
Cc: akpm@linux-foundation.org, chengming.zhou@linux.dev,
donettom@linux.ibm.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, stable@vger.kernel.org, xu.xin@linux.dev
Subject: Re: [PATCH] mm/ksm: do not inherit ksm_zero_pages counter or PTE markers on fork
Date: Fri, 20 Nov 2026 10:10:27 +0800 [thread overview]
Message-ID: <20261120021027.398507-1-xu.xin@linux.dev> (raw)
In-Reply-To: <41242382-1cfc-4dd1-8f8f-f9486f80b424@kernel.org>
> >> But ... they were placed by KSM?
> >>
> >> Just like any other KSM folios deduplicated before fork and then shared with the
> >> child?
> >
> > I see your point, but in practice, people evaluating use_zero_pages=1 often
> > look at ksm_zero_pages to gauge how much memory KSM actually saved. Since
> > forked pages already share the same physical frame via COW even without KSM,
> > counting them across many forked children can give a somewhat misleading
> > impression of KSM's actual savings.
> >
> > Also, ksm_merging_pages right next to it is already reset to 0 on fork (even
> > when regular KSM folios are shared with the child), so resetting ksm_zero_pages
> > keeps the two counters consistent.
> >
> >>
> >> So won't there be an inconsistency when MADV_UNMERGEABLE?
> >>
> >
> > As for MADV_UNMERGEABLE, leaving the child's mapping as a normal read-only shared
> > zero page is safe and avoids extra allocations. Plus it naturally avoids the
> > skipped-VMA (MADV_DONTFORK) accounting bug you spotted, and does so
> > without extra per-PTE overhead.
> >
> > What do you think?
>
> We should then definitely document the behavioral change, and how ksm_zero_pages
> interacts with fork.
Agreed, I'll update these changes into documents.
>
> For clearing the dirty bit we should have a dedicated helper, such the handling
> is hidden like in is_ksm_zero_pte().
>
>
> So clean up that code (reducing the code comment drastically) and properly
> document all that for ksm_zero_pages.
Ok, Will do it in v2 together with the fix of building error when CONFIG_KSM is not set.
next prev parent reply other threads:[~2026-11-20 2:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 8:18 [PATCH] mm/ksm: do not inherit ksm_zero_pages counter or PTE markers on fork xu.xin
2026-11-17 9:51 ` David Hildenbrand (Arm)
2026-11-18 3:10 ` Xu Xin (vivo)
2026-11-19 17:18 ` David Hildenbrand (Arm)
2026-11-20 2:10 ` Xu Xin (vivo) [this message]
2026-11-17 12:27 ` kernel test robot
2026-11-17 16:50 ` kernel test robot
2026-11-18 8:18 ` sashiko-bot
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=20261120021027.398507-1-xu.xin@linux.dev \
--to=xu.xin@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=david@kernel.org \
--cc=donettom@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=stable@vger.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.