[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <53a7bf3d-843d-4e19-b0a3-cc6852fe72c1@redhat.com>
Date: Tue, 26 Aug 2025 16:09:15 +0200
From: David Hildenbrand <david@...hat.com>
To: Giorgi Tchankvetadze <giorgitchankvetadze1997@...il.com>,
donettom@...ux.ibm.com
Cc: aboorvad@...ux.ibm.com, akpm@...ux-foundation.org,
chengming.zhou@...ux.dev, linux-kernel@...r.kernel.org, linux-mm@...ck.org,
richard.weiyang@...il.com, ritesh.list@...il.com, xu.xin16@....com.cn
Subject: Re: [PATCH 1/2] mm/ksm: Reset KSM counters in mm_struct during fork
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
Powered by blists - more mailing lists