From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 205FDC77B7A for ; Wed, 24 May 2023 07:23:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC16E900003; Wed, 24 May 2023 03:23:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A727C900002; Wed, 24 May 2023 03:23:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93B91900003; Wed, 24 May 2023 03:23:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 80A1A900002 for ; Wed, 24 May 2023 03:23:20 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 46E7C140887 for ; Wed, 24 May 2023 07:23:20 +0000 (UTC) X-FDA: 80824307760.17.DDE0BB0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 0C32910000A for ; Wed, 24 May 2023 07:23:17 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=L8dJk1sk; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684912998; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QGVulM+7Dkm8yCOBQhzNwQ4gCPj3HR7YyVPPxi6Fqc8=; b=zPIoHIcSylE3l9ZrkMkTma0yfgQVz7396hHnP6AtaQjzVBrYN79EzyyheTnVUN5S6RHQdM /H2AM9fl9biIEXUtE+WWSpF4erGeWFN2IPZQAS0z6a6tG+lDgGBgoS0Qc1vQkNYjo8pV5y 2NMrpTgwqs8HS04ex92v7AIQqDa0fso= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=L8dJk1sk; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684912998; a=rsa-sha256; cv=none; b=XBewU69SfFT0y3PL8KDX3hltDWha9foU06nfvtWyWrGXvt1S0otfIJIGKBpf0lvORQZFwC RltG+NEoV+nmEH5KB3aleyzxOVUu4FjTwV0lPTvKquZ4cSfyYgllON8XDuVxuTe7eY+f7o CgCqcWLTJuqpGJII/vq6JoTIndCmptQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684912997; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QGVulM+7Dkm8yCOBQhzNwQ4gCPj3HR7YyVPPxi6Fqc8=; b=L8dJk1skSK92/slC1P0kuyjk9T1QBxu0JqZ66hfmSelH7hWXktFuDOP2upsHzwNJ78LZfz CkLQS6N2JRUhbve+g8kR1nQQEZX9CBDc0kUs5ip9RncSIXZ/UVkyd57Xovk4AwElHwFGQr z3ErcnOz+JD+jd+HDZk3iffy7+X+YdM= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-382-LM0WrgeFNPWkF6E1ETgrSw-1; Wed, 24 May 2023 03:23:15 -0400 X-MC-Unique: LM0WrgeFNPWkF6E1ETgrSw-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3093e600770so280141f8f.2 for ; Wed, 24 May 2023 00:23:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684912994; x=1687504994; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QGVulM+7Dkm8yCOBQhzNwQ4gCPj3HR7YyVPPxi6Fqc8=; b=M5ndi/HEr4Tkyeb05OWoKf+8TS26X7L7OtAlI1jbAcMsuuqplkMwGj0ZKbgrydS50z bt16k3nUwsfAQvf5ayjdM/R37Sn6N8sAFWLUOSK/AZaDvz8Ar4Fk9z8tq89p9TsZowrC qee5/qTUHxXvZDrYq4qA/ssDF9NvmnzwSItVRLHiiGErP5KdKeraNwoOnMpZ2BdRoy9w ZvhOc4Uieq4ikGnNm5BZuF3QP7QOtZbQV7/oLgV4BUU3MITWYNRYQfAF+cILcHK+TAb6 jtd9OYtNRQcDoWxCOO9Kxz0v8Gf9rNVhoUVgSb25SVQ8/eXR5Ed2ki7vDPLLZw07J0e0 t2MQ== X-Gm-Message-State: AC+VfDyHca4BlS08BrKLaKUu/0Me2oj2vIj4q+mhWjWoWcFOJjVSL/RK BjLk203YhPZu+YX/IVqpQF6vzE6b+CbZkq4jY1Oq2SSlA0L7pPEBreGYlSQgEBJCTb4yvr4RU/D KhJThM0QIbU8= X-Received: by 2002:a5d:50d2:0:b0:2fa:36db:8060 with SMTP id f18-20020a5d50d2000000b002fa36db8060mr12095819wrt.60.1684912994598; Wed, 24 May 2023 00:23:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5JYlmtU36DomBA8uQD+JjqciUgm1OjppgMR3Vlzdb/MXvAvbZ4BAghFtZrgiMeC4eojaCbng== X-Received: by 2002:a5d:50d2:0:b0:2fa:36db:8060 with SMTP id f18-20020a5d50d2000000b002fa36db8060mr12095797wrt.60.1684912994206; Wed, 24 May 2023 00:23:14 -0700 (PDT) Received: from ?IPV6:2003:cb:c70d:f700:24cd:855:1c60:1ff4? (p200300cbc70df70024cd08551c601ff4.dip0.t-ipconnect.de. [2003:cb:c70d:f700:24cd:855:1c60:1ff4]) by smtp.gmail.com with ESMTPSA id k6-20020adfe8c6000000b003095a329e90sm13251545wrn.97.2023.05.24.00.23.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 May 2023 00:23:13 -0700 (PDT) Message-ID: <52bfd744-3086-a22a-e2e7-8b64d5fccfcc@redhat.com> Date: Wed, 24 May 2023 09:23:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 To: Yang Yang , akpm@linux-foundation.org Cc: imbrenda@linux.ibm.com, jiang.xuexin@zte.com.cn, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ran.xiaokai@zte.com.cn, xu.xin.sc@gmail.com, xu.xin16@zte.com.cn References: <202305241351365661923@zte.com.cn> <20230524055752.20449-1-yang.yang29@zte.com.cn> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v9 2/5] ksm: count all zero pages placed by KSM In-Reply-To: <20230524055752.20449-1-yang.yang29@zte.com.cn> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Stat-Signature: i6j58mxdmkc3fcrxj64fr8h7mbui1fzo X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0C32910000A X-HE-Tag: 1684912997-782413 X-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vOqr15sPhntnkyhyCTxQMtwJZcHbq1XeXyrssiEzichZX75yFPaq0ggQZy+lV94klFmQaH/jk8wBJJSV37szV+aopotCNJ8Tkf6TjlYkOo50Nlx1blZE5rZuEKpAX/olPSub0EGOOmDMNaRFXWRiU4bE1EhECzsLNUpd6fyKmSoR/NBY0Po+8wI99xDyAKhZ6JtKVcwaCbyDlcY91Y3JrRutghF24UYtmAu1bwpy5XIt31YjXR2LRjxNo+WION2A4Ezhz82rZpwz64XZGxUBZtRmpQvsF92ZTFHAoYGkGt5ay3ZHymbMsSHgwk3YHcbQyecJ6Dqp3NFa14Xz9/d2Uh/2MrX2QIosHsOgz9p0asYyGOVxj2ELG3SdBeOZeTcHqx4m8zQCZlML5I/AhVBdsM+QfN/gAVD+VQ0fHJZNXEOn06WdMBAho1O4HBhKX3pAXWuD74jOl5ED/NvI0ZubMqYezpiSA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 24.05.23 07:57, Yang Yang wrote: > From: xu xin > > As pages_sharing and pages_shared don't include the number of zero pages > merged by KSM, we cannot know how many pages are zero pages placed by KSM > when enabling use_zero_pages, which leads to KSM not being transparent with > all actual merged pages by KSM. In the early days of use_zero_pages, > zero-pages was unable to get unshared by the ways like MADV_UNMERGEABLE so > it's hard to count how many times one of those zeropages was then unmerged. > > But now, unsharing KSM-placed zero page accurately has been achieved, so we > can easily count both how many times a page full of zeroes was merged with > zero-page and how many times one of those pages was then unmerged. and so, > it helps to estimate memory demands when each and every shared page could > get unshared. > > So we add ksm_zero_pages under /sys/kernel/mm/ksm/ to show the number > of all zero pages placed by KSM. Meanwhile, we update the Documentation. > > Signed-off-by: xu xin > Suggested-by: David Hildenbrand > Cc: Claudio Imbrenda > Cc: Xuexin Jiang > Reviewed-by: Xiaokai Ran > Reviewed-by: Yang Yang > --- > Documentation/admin-guide/mm/ksm.rst | 7 +++++++ > include/linux/ksm.h | 12 ++++++++++++ > mm/khugepaged.c | 2 ++ > mm/ksm.c | 12 ++++++++++++ > mm/memory.c | 5 ++++- > 5 files changed, 37 insertions(+), 1 deletion(-) > > diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-guide/mm/ksm.rst > index 7626392fe82c..6cc919dbfd55 100644 > --- a/Documentation/admin-guide/mm/ksm.rst > +++ b/Documentation/admin-guide/mm/ksm.rst > @@ -173,6 +173,13 @@ stable_node_chains > the number of KSM pages that hit the ``max_page_sharing`` limit > stable_node_dups > number of duplicated KSM pages > +ksm_zero_pages > + how many zero pages that are still mapped into processes were mapped by > + KSM when deduplicating. > + > +When ``use_zero_pages`` is/was enabled, the sum of ``pages_sharing`` + > +``ksm_zero_pages`` represents the actual number of pages saved by KSM. > +if ``use_zero_pages`` has never been enabled, ``ksm_zero_pages`` is 0. > > A high ratio of ``pages_sharing`` to ``pages_shared`` indicates good > sharing, but a high ratio of ``pages_unshared`` to ``pages_sharing`` > diff --git a/include/linux/ksm.h b/include/linux/ksm.h > index 4fd5f4a50bac..f2d98c53cfec 100644 > --- a/include/linux/ksm.h > +++ b/include/linux/ksm.h > @@ -33,6 +33,14 @@ void __ksm_exit(struct mm_struct *mm); > */ > #define is_ksm_zero_pte(pte) (is_zero_pfn(pte_pfn(pte)) && pte_dirty(pte)) > > +extern unsigned long ksm_zero_pages; > + > +static inline void ksm_notify_unmap_zero_page(pte_t pte) > +{ > + if (is_ksm_zero_pte(pte)) > + ksm_zero_pages--; > +} > + > static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) > { > int ret; > @@ -103,6 +111,10 @@ static inline void ksm_exit(struct mm_struct *mm) > > #define is_ksm_zero_pte(pte) 0 > > +static inline void ksm_notify_unmap_zero_page(pte_t pte) > +{ > +} > + Having proposed that name ... I realize that we call this function whenever there might be a zeropage mapped (when we have !page after vm_normal_page()) -- but it could also not be the zeropage. Not really able to come up with a better name :) ksm_notify_maybe_unmap_zero_page ? ksm_maybe_unmap_zero_page ? Maybe someone else reading along has a better idea. In any case, the logic itself LGTM Reviewed-by: David Hildenbrand -- Thanks, David / dhildenb