Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6670012rwl; Thu, 29 Dec 2022 17:57:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXsnyOD6reZHf8Tf9F0bWJXwZ8XFGdAJ1PbES0Wty3YIgbeWV2uy0XputWzLtagJz/OhWkg3 X-Received: by 2002:a17:90a:2bcd:b0:225:be4c:2586 with SMTP id n13-20020a17090a2bcd00b00225be4c2586mr26522459pje.45.1672365420355; Thu, 29 Dec 2022 17:57:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672365420; cv=none; d=google.com; s=arc-20160816; b=ob/p60i+i0Xqf2Q2zoPMoLBWU3TELZG73P2pRGlPC1s0mgiPLy191e8NGWBn6bRO03 lAs6LEQJ8rzQKRgkHjmHcKjmDVBWxV6VQSGl2rLuz2sDgyA+N8BOdp+aBP+dJc5hYqfe pVN47WsJoJm/IOKNCpxgCH3VMewT3kSauIRKtiWILuLe0X4LRLYZoumBEIuEt5XKbfFs +tQWHuMWMWKVj8He/16KupfmVCuMHLZJd61YwDV8U5KhEQDEBODaS/B1JzIc/LxWcewH Ttf8hPg2FznUVhAS/c37Hlz/8gnh4mcjsp7pNtw2spCM7cPDmts3vmAaU5bFueLsklon iGpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:mime-version:message-id:date; bh=lcOvOXzlofwtDdJWJO/YaawEgINJw6332MG6HHQ7ykY=; b=ss1SR+/9qWKp5mLdzLQa66fZ+QF3Jr4gEaRmCfb1Y43Gzxwj+HaJEfPYSl1a+2w+Am BQWo/THbWv2U83GOUXDgs9gNmTndk0/Y+LTSVEhXyn2E5payRyh1EiLfkq4mPlIoi0vT fxwwG7NT5qFihTvhT0pyH7ybpAdIjZr7NO9J6lEYfO8eKPcKoO0A0xLozD1g065HoA9Q xURCQDIdWVekma2KGqYTv7rjs7Ggy2mmgv/rrfOb2Rfmt6nuuehBVu5df/dEvGm6xrxa hNuZAP+D3DspO4ZW2kljSnXGIirHdLxPqIb7sGoCFy0GEn+AYDFuMyWJ2UrenKaZhmfb 2D1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mq5-20020a17090b380500b002131bb4043asi7940945pjb.177.2022.12.29.17.56.51; Thu, 29 Dec 2022 17:57:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234216AbiL3BQh (ORCPT + 64 others); Thu, 29 Dec 2022 20:16:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234169AbiL3BQg (ORCPT ); Thu, 29 Dec 2022 20:16:36 -0500 Received: from mxct.zte.com.cn (mxct.zte.com.cn [183.62.165.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD716FB for ; Thu, 29 Dec 2022 17:16:34 -0800 (PST) Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxct.zte.com.cn (FangMail) with ESMTPS id 4NjnQn2W1mz501Qh; Fri, 30 Dec 2022 09:16:33 +0800 (CST) Received: from szxlzmapp06.zte.com.cn ([10.5.230.252]) by mse-fl1.zte.com.cn with SMTP id 2BU1GSAF084154; Fri, 30 Dec 2022 09:16:28 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp01[null]) by mapi (Zmail) with MAPI id mid14; Fri, 30 Dec 2022 09:16:29 +0800 (CST) Date: Fri, 30 Dec 2022 09:16:29 +0800 (CST) X-Zmail-TransId: 2b0363ae3bed7a8bf824 X-Mailer: Zmail v1.0 Message-ID: <202212300916292181912@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , , , , , , , Subject: =?UTF-8?B?W1BBVENIIHY1IDQvNl0ga3NtOiBjb3VudCB6ZXJvIHBhZ2VzIGZvciBlYWNoIHByb2Nlc3M=?= Content-Type: text/plain; charset="UTF-8" X-MAIL: mse-fl1.zte.com.cn 2BU1GSAF084154 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.251.13.novalocal with ID 63AE3BF1.000 by FangMail milter! X-FangMail-Envelope: 1672362993/4NjnQn2W1mz501Qh/63AE3BF1.000/10.5.228.132/[10.5.228.132]/mse-fl1.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 63AE3BF1.000/4NjnQn2W1mz501Qh X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_00,SORTED_RECIPS, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: xu xin As the number of ksm zero pages is not included in ksm_merging_pages per process when enabling use_zero_pages, it's unclear of how many actual pages are merged by KSM. To let users accurately estimate their memory demands when unsharing KSM zero-pages, it's necessary to show KSM zero- pages per process. since unsharing zero pages placed by KSM accurately is achieved, then tracking empty pages merging and unmerging is not a difficult thing any longer. Since we already have /proc//ksm_stat, just add the information of zero_pages_sharing in it. Cc: Claudio Imbrenda Cc: David Hildenbrand Cc: Xuexin Jiang Cc: Xiaokai Ran Cc: Yang Yang Signed-off-by: xu xin --- fs/proc/base.c | 1 + include/linux/mm_types.h | 7 ++++++- mm/ksm.c | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 9e479d7d202b..ac9ebe972be0 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -3207,6 +3207,7 @@ static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns, mm = get_task_mm(task); if (mm) { seq_printf(m, "ksm_rmap_items %lu\n", mm->ksm_rmap_items); + seq_printf(m, "zero_pages_sharing %lu\n", mm->ksm_zero_pages_sharing); mmput(mm); } diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 4e1031626403..5c734ebc1890 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -776,7 +776,7 @@ struct mm_struct { #ifdef CONFIG_KSM /* * Represent how many pages of this process are involved in KSM - * merging. + * merging (not including ksm_zero_pages_sharing). */ unsigned long ksm_merging_pages; /* @@ -784,6 +784,11 @@ struct mm_struct { * including merged and not merged. */ unsigned long ksm_rmap_items; + /* + * Represent how many empty pages are merged with kernel zero + * pages when enabling KSM use_zero_pages. + */ + unsigned long ksm_zero_pages_sharing; #endif #ifdef CONFIG_LRU_GEN struct { diff --git a/mm/ksm.c b/mm/ksm.c index 72c0722be280..083f5d125373 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -794,6 +794,7 @@ static inline void clean_rmap_item_zero_flag(struct ksm_rmap_item *rmap_item) { if (rmap_item->address & ZERO_PAGE_FLAG) { ksm_zero_pages_sharing--; + rmap_item->mm->ksm_zero_pages_sharing--; rmap_item->address &= PAGE_MASK; } } @@ -2117,6 +2118,7 @@ static int try_to_merge_with_kernel_zero_page(struct ksm_rmap_item *rmap_item, if (!err) { rmap_item->address |= ZERO_PAGE_FLAG; ksm_zero_pages_sharing++; + rmap_item->mm->ksm_zero_pages_sharing++; } } else { /* If the vma is out of date, we do not need to continue. */ -- 2.15.2