[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d2bbd95c-ccb2-b4db-7c1c-a3b344b1a125@redhat.com>
Date: Wed, 24 May 2023 09:10:22 +0200
From: David Hildenbrand <david@...hat.com>
To: Yang Yang <yang.yang29@....com.cn>, akpm@...ux-foundation.org
Cc: imbrenda@...ux.ibm.com, jiang.xuexin@....com.cn,
linux-kernel@...r.kernel.org, linux-mm@...ck.org,
ran.xiaokai@....com.cn, xu.xin.sc@...il.com, xu.xin16@....com.cn
Subject: Re: [PATCH v9 1/5] ksm: support unsharing KSM-placed zero pages
On 24.05.23 07:57, Yang Yang wrote:
> From: xu xin <xu.xin16@....com.cn>
>
> When use_zero_pages of ksm is enabled, madvise(addr, len, MADV_UNMERGEABLE)
> and other ways (like write 2 to /sys/kernel/mm/ksm/run) to trigger
> unsharing will *not* actually unshare the shared zeropage as placed by KSM
> (which is against the MADV_UNMERGEABLE documentation). As these KSM-placed
> zero pages are out of the control of KSM, the related counts of ksm pages
> don't expose how many zero pages are placed by KSM (these special zero
> pages are different from those initially mapped zero pages, because the
> zero pages mapped to MADV_UNMERGEABLE areas are expected to be a complete
> and unshared page).
>
> To not blindly unshare all shared zero_pages in applicable VMAs, the patch
> use pte_mkdirty (related with architecture) to mark KSM-placed zero pages.
> Thus, MADV_UNMERGEABLE will only unshare those KSM-placed zero pages.
>
> In addition, we'll reuse this mechanism to reliably identify KSM-placed
> ZeroPages to properly account for them (e.g., calculating the KSM profit
> that includes zeropages) in the latter patches.
>
> The patch will not degrade the performance of use_zero_pages as it doesn't
> change the way of merging empty pages in use_zero_pages's feature.
>
> Signed-off-by: xu xin <xu.xin16@....com.cn>
> Suggested-by: David Hildenbrand <david@...hat.com>
> Cc: Claudio Imbrenda <imbrenda@...ux.ibm.com>
> Cc: Xuexin Jiang <jiang.xuexin@....com.cn>
> Reviewed-by: Xiaokai Ran <ran.xiaokai@....com.cn>
> Reviewed-by: Yang Yang <yang.yang29@....com.cn>
> ---
> include/linux/ksm.h | 8 ++++++++
> mm/ksm.c | 11 ++++++++---
> 2 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/ksm.h b/include/linux/ksm.h
> index 899a314bc487..4fd5f4a50bac 100644
> --- a/include/linux/ksm.h
> +++ b/include/linux/ksm.h
> @@ -26,6 +26,12 @@ int ksm_disable(struct mm_struct *mm);
>
> int __ksm_enter(struct mm_struct *mm);
> void __ksm_exit(struct mm_struct *mm);
> +/*
> + * To identify zeropages that were mapped by KSM, we reuse the dirty bit
> + * in the PTE. If the PTE is dirty, the zeropage was mapped by KSM when
> + * deduplicating memory.
> + */
> +#define is_ksm_zero_pte(pte) (is_zero_pfn(pte_pfn(pte)) && pte_dirty(pte))
>
> static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
> {
> @@ -95,6 +101,8 @@ static inline void ksm_exit(struct mm_struct *mm)
> {
> }
>
> +#define is_ksm_zero_pte(pte) 0
> +
Not required in this patch (and AFAIKS in the others). So you can drop that.
Reviewed-by: David Hildenbrand <david@...hat.com>
--
Thanks,
David / dhildenb
Powered by blists - more mailing lists