linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Donet Tom <donettom@linux.ibm.com>
To: David Hildenbrand <david@redhat.com>,
	Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.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: Wed, 27 Aug 2025 23:39:13 +0530	[thread overview]
Message-ID: <b451b318-133b-45f6-87b3-3dc3fa1f75a8@linux.ibm.com> (raw)
In-Reply-To: <53a7bf3d-843d-4e19-b0a3-cc6852fe72c1@redhat.com>


On 8/26/25 7:39 PM, David Hildenbrand wrote:
> 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.


Yes, David, you are right. I added a test to check this scenario, and I 
am seeing ksm_zero_pages go negative.

# cat /sys/kernel/mm/ksm/ksm_zero_pages
-128
#


>
> @Donet, can you look into that as well?


Sure, I will add a fix for this issue in the next version.




      reply	other threads:[~2025-08-27 18: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
2025-08-27 18:09     ` Donet Tom [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=b451b318-133b-45f6-87b3-3dc3fa1f75a8@linux.ibm.com \
    --to=donettom@linux.ibm.com \
    --cc=aboorvad@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=chengming.zhou@linux.dev \
    --cc=david@redhat.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