[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <59fef25c-6559-4fb3-8810-c2a7dd36b95a@redhat.com>
Date: Tue, 26 Aug 2025 15:19:47 +0200
From: David Hildenbrand <david@...hat.com>
To: Donet Tom <donettom@...ux.ibm.com>,
Andrew Morton <akpm@...ux-foundation.org>
Cc: Ritesh Harjani <ritesh.list@...il.com>, Xu Xin <xu.xin16@....com.cn>,
Chengming Zhou <chengming.zhou@...ux.dev>,
Wei Yang <richard.weiyang@...il.com>,
Aboorva Devarajan <aboorvad@...ux.ibm.com>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] mm/ksm: Reset KSM counters in mm_struct during fork
On 26.08.25 14:49, Donet Tom wrote:
> Currently, the KSM-related counters in `mm_struct` such as
> `ksm_merging_pages`, `ksm_rmap_items`, and `ksm_zero_pages` are
> inherited by the child process during fork. This results in
> incorrect accounting, since the child has not performed any
> KSM page merging.
So, the situation is that our child process maps these pages, but it
does not have any stable rmap items corresponding to these pages.
rmap_walk_ksm() spells that case out.
Can you clarify that in the description here, and how both stats
correspond to rmap items?
What is the effective result of this misacounting? I assume only a
higher number than expected.
>
> To fix this, reset these counters to 0 in the newly created
> `mm_struct` during fork. This ensures that KSM statistics
> remain accurate and only reflect the activity of each process.
>
Fixes? CC stable?
> Signed-off-by: Donet Tom <donettom@...ux.ibm.com>
> ---
> include/linux/ksm.h | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/ksm.h b/include/linux/ksm.h
> index 22e67ca7cba3..61b8892c632b 100644
> --- a/include/linux/ksm.h
> +++ b/include/linux/ksm.h
> @@ -56,8 +56,12 @@ static inline long mm_ksm_zero_pages(struct mm_struct *mm)
> static inline void ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
> {
> /* Adding mm to ksm is best effort on fork. */
> - if (mm_flags_test(MMF_VM_MERGEABLE, oldmm))
> + if (mm_flags_test(MMF_VM_MERGEABLE, oldmm)) {
> + mm->ksm_merging_pages = 0;
> + mm->ksm_rmap_items = 0;
> + atomic_long_set(&mm->ksm_zero_pages, 0);
> __ksm_enter(mm);
> + }
> }
>
> static inline int ksm_execve(struct mm_struct *mm)
--
Cheers
David / dhildenb
Powered by blists - more mailing lists