mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com>,
	donettom@linux.ibm.com
Cc: aboorvad@linux.ibm.com, akpm@linux-foundation.org,
	chengming.zhou@linux.dev, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, richard.weiyang@gmail.com,
	ritesh.list@gmail.com, xu.xin16@zte.com.cn
Subject: Re: [PATCH 1/2] mm/ksm: Reset KSM counters in mm_struct during fork
Date: Tue, 26 Aug 2025 16:09:15 +0200	[thread overview]
Message-ID: <53a7bf3d-843d-4e19-b0a3-cc6852fe72c1@redhat.com> (raw)
In-Reply-To: <512764a4-611c-42d4-8b4a-2aaca4e519a4@gmail.com>

On 26.08.25 15:47, Giorgi Tchankvetadze wrote:
> What if we only allocate KSM stats when a process actually uses KSM?
> 
> struct ksm_mm_stats {
> 	atomic_long_t merging_pages;
> 	atomic_long_t rmap_items;
> 	atomic_long_t zero_pages;
> };
> struct ksm_mm_stats *mm->ksm_stats; // NULL until first enter
> 
> static inline struct ksm_mm_stats *mm_get_ksm_stats(struct mm_struct *mm)
> {
> 	if (likely(mm->ksm_stats))
> 		return mm->ksm_stats;
> 	return ksm_alloc_stats_if_needed(mm); // Slow path
> }

The fork'ed child uses KSM. It just doesn't have any stable rmap entries.

We have to copy the zero_pages counter such that 
ksm_might_unmap_zero_page() will do the right thing.

But you're comment made me realize that there is likely another bug:

When copying zero_pages during fork(), we have to increment 
&ksm_zero_pages as well. Otherwise we will get an underflow later.

@Donet, can you look into that as well?

-- 
Cheers

David / dhildenb


  reply	other threads:[~2025-08-26 14:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-26 12:49 Donet Tom
2025-08-26 12:49 ` [PATCH 2/2] selftests/mm: add fork inheritance test for ksm_merging_pages counter Donet Tom
2025-08-26 13:22   ` David Hildenbrand
2025-08-27 18:03     ` Donet Tom
2025-08-26 13:19 ` [PATCH 1/2] mm/ksm: Reset KSM counters in mm_struct during fork David Hildenbrand
2025-08-27 18:03   ` Donet Tom
2025-08-26 13:47 ` Giorgi Tchankvetadze
2025-08-26 14:09   ` David Hildenbrand [this message]
2025-08-27 18:09     ` Donet Tom

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=53a7bf3d-843d-4e19-b0a3-cc6852fe72c1@redhat.com \
    --to=david@redhat.com \
    --cc=aboorvad@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=chengming.zhou@linux.dev \
    --cc=donettom@linux.ibm.com \
    --cc=giorgitchankvetadze1997@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=richard.weiyang@gmail.com \
    --cc=ritesh.list@gmail.com \
    --cc=xu.xin16@zte.com.cn \
    /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®