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 2BEB9C05027 for ; Fri, 10 Feb 2023 01:19:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AEEA6B00C5; Thu, 9 Feb 2023 20:19:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 65EDD6B00C7; Thu, 9 Feb 2023 20:19:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 527FF6B00C8; Thu, 9 Feb 2023 20:19:06 -0500 (EST) 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 407336B00C5 for ; Thu, 9 Feb 2023 20:19:06 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 121061A10B1 for ; Fri, 10 Feb 2023 01:19:06 +0000 (UTC) X-FDA: 80449623492.14.DCF38A5 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.40]) by imf17.hostedemail.com (Postfix) with ESMTP id 3EA5240007 for ; Fri, 10 Feb 2023 01:19:02 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=zte.com.cn; spf=pass (imf17.hostedemail.com: domain of yang.yang29@zte.com.cn designates 63.216.63.40 as permitted sender) smtp.mailfrom=yang.yang29@zte.com.cn ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675991944; 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:in-reply-to: references; bh=v0XSjLI+rO5Kq2Y1Eem8ZQwbVe/7axGQVmO2VxpMLp4=; b=a3WUFSxU2lNRePBaTSBB8/WAjSDfRLgKrTMQiHtBrNObkQGs0XaZR1gUIGkXusGY27kpoM cD5ULnMiIs93P8onNh0oB5ROdTiMgWwFzdasQuyWf9Eu4NrvfIcumQgpwFOqKdFvVYJZEC q7R8NxRvGAkT7b0mRCjNmRn+3Nym0oM= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=zte.com.cn; spf=pass (imf17.hostedemail.com: domain of yang.yang29@zte.com.cn designates 63.216.63.40 as permitted sender) smtp.mailfrom=yang.yang29@zte.com.cn ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675991944; a=rsa-sha256; cv=none; b=ccPoWus0Xcpd5RsbeEpf5cOzwqXY3T1CNzssruP2qvk/2xoKSCsddpMChoRq353eUQjXGZ WjB4kYOxAGVuSU73LE/oWJ+XQ3tB66O7kAZ+CdXa9dCUfUo0LYk8b5OWvGybo0O4isDGXo FrdvbwhQk8u/KBI8/hFna/ls7FLuv3I= 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 mxhk.zte.com.cn (FangMail) with ESMTPS id 4PCbVD3jTNz8R043; Fri, 10 Feb 2023 09:19:00 +0800 (CST) Received: from szxlzmapp07.zte.com.cn ([10.5.230.251]) by mse-fl1.zte.com.cn with SMTP id 31A1IqXc009217; Fri, 10 Feb 2023 09:18:52 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp01[null]) by mapi (Zmail) with MAPI id mid14; Fri, 10 Feb 2023 09:18:52 +0800 (CST) Date: Fri, 10 Feb 2023 09:18:52 +0800 (CST) X-Zmail-TransId: 2b0363e59b7c1e046e42 X-Mailer: Zmail v1.0 Message-ID: <202302100918524481474@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , , , , , , , Subject: =?UTF-8?B?W1BBVENIIHY2IDMvNl0ga3NtOiBjb3VudCBhbGwgemVybyBwYWdlcyBwbGFjZWQgYnkgS1NN?= Content-Type: text/plain; charset="UTF-8" X-MAIL:mse-fl1.zte.com.cn 31A1IqXc009217 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.137.novalocal with ID 63E59B84.000 by FangMail milter! X-FangMail-Envelope: 1675991940/4PCbVD3jTNz8R043/63E59B84.000/10.5.228.132/[10.5.228.132]/mse-fl1.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 63E59B84.000/4PCbVD3jTNz8R043 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3EA5240007 X-Stat-Signature: aw1qajn4p4h3yegeyq41pds9gmjpjfyx X-Rspam-User: X-HE-Tag: 1675991942-162749 X-HE-Meta: U2FsdGVkX19UN0I8nUmHx5RvyZHlMRboaQuv4vq/7dtkJN+DtPzpe4GQE9X6WiObBEl8zwuHfzAjY0N/dA4UqkYrhmcqYqanEBFs9fDgV3caa41sp6YDBxk2udU0CI9+KY4ETTAEZbbS0udi8OShnOmwp+bC2PzByTbB2Q/3PpkstvKWnKtRx/J5d0i12FGtBQYapZCzUxIPJAEO1bPui1Rxz6P/j6YIcBTRnA5iyT2E03d+1Mne0N4Ynhva24FQPYhFb/FMLXqpe/pNH2P2bfIiYbmgQVU7wrN8ofzA+RYZuJsPAqjSyksA6wCdmQugz/AJXagkKoRZXMOlhoxxb9Cqrl4W0ddZzuk8hBR1QaN7mAYrGLmtqbUPK7AQhTU2mQTGv+wqvqs2hN66pwN3MfT98yowfUZKUA1P7MSv97f6lwoOApoqJjARRtqrBqcBuv7/gr2O96wAHTBcrxMWd5Y+BHkg5Z/j5RYROW6VMv/Y2u2LroEc8lZDDEJ0nzK6hkQATg+L45byvgr5K0K38sUIcDFGB50ACnR9W29LFUoq5p/KGJXpdZD/RtFHZ2KfFqwvPUCMriBy6DMEgR6oLxCnlKZLLPl4urvESJt/1cVw9S3Wyrwh2/Nhvu86l4AQmDTEls0bDKgeH7STT8nsvQk7REZopZH+3VFeT2TqtUvPycZca94khlCI2h8cssWRFGEkHTlcBLh9v4qnbiW5IvTbI1mFY+6E/BHIpto37WIxgP4xc52UGGtIf03b9x+dxc32voLh91llKZ3x5Nw6P1ywIsP+RIkbA60HTOnZldLIusRH9VCHHlSqoSFgOsezIU9hFnnTuNBOfubPetuzWHxN+HPp6FVP6VXi2R19JEht5RNGXnaop/CPCxLrWDJurHjIZAyWKca2HIsT5PQzrFpQVjhWvc7MunO7y3bFE0iUWrFKhO0kZUJZhIL2IME3melSfhJFeNYFU8Ejgtb Bh5HTKpG mKRM94EPWKu2DOZvXcU4Rhm2Kv+BZTE12bEY7K3nwsen2k2GFste+BRt8c1L4QQbbG2YEpyyE18mOSCG5NtZNQflqcuFisUnS6TxL3fMwcuXe6tcltr4CpJjxLM5tVTmOFVmZoUEUf6UHaJsqnAd+XC0x08IhQ2sSfQz39JhyPp9v1RLYyPFwRqQhfPZz57mFGqMPuHZZ7F0WFu8Gh5HclBU/0rD2D4+8UASobEz/2TDSfKrlp9U7BamYQvxX793FKbO1dv9lKCOCvX7dvKqIzvMEhFcyvvegoDGY0oU1w0+LJb76KfKcwluL6zA0kfRhglGol66PchnYSkCDb7oNrtfpRHSN3Lx7Mc1c 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: 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 zero_pages_sharing under /sys/kernel/mm/ksm/ to show the number of all zero pages placed by KSM. Signed-off-by: xu xin Cc: Claudio Imbrenda Cc: David Hildenbrand Cc: Xuexin Jiang Reviewed-by: Xiaokai Ran Reviewed-by: Yang Yang v4->v5: fix warning mm/ksm.c:3238:9: warning: no previous prototype for 'zero_pages_sharing_show' [-Wmissing-prototypes]. --- mm/ksm.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index ab04b44679c8..1fa668e1fe82 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -276,6 +276,9 @@ static unsigned int zero_checksum __read_mostly; /* Whether to merge empty (zeroed) pages with actual zero pages */ static bool ksm_use_zero_pages __read_mostly; +/* The number of zero pages placed by KSM use_zero_pages */ +static unsigned long ksm_zero_pages_sharing; + #ifdef CONFIG_NUMA /* Zeroed when merging across nodes is not allowed */ static unsigned int ksm_merge_across_nodes = 1; @@ -789,8 +792,10 @@ static struct page *get_ksm_page(struct ksm_stable_node *stable_node, */ static inline void clean_rmap_item_zero_flag(struct ksm_rmap_item *rmap_item) { - if (rmap_item->address & ZERO_PAGE_FLAG) + if (rmap_item->address & ZERO_PAGE_FLAG) { + ksm_zero_pages_sharing--; rmap_item->address &= PAGE_MASK; + } } /* Only called when rmap_item is going to be freed */ @@ -2109,8 +2114,10 @@ static int try_to_merge_with_kernel_zero_page(struct ksm_rmap_item *rmap_item, if (vma) { err = try_to_merge_one_page(vma, page, ZERO_PAGE(rmap_item->address)); - if (!err) + if (!err) { rmap_item->address |= ZERO_PAGE_FLAG; + ksm_zero_pages_sharing++; + } } else { /* If the vma is out of date, we do not need to continue. */ err = 0; @@ -3230,6 +3237,13 @@ static ssize_t pages_volatile_show(struct kobject *kobj, } KSM_ATTR_RO(pages_volatile); +static ssize_t zero_pages_sharing_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%ld\n", ksm_zero_pages_sharing); +} +KSM_ATTR_RO(zero_pages_sharing); + static ssize_t stable_node_dups_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -3285,6 +3299,7 @@ static struct attribute *ksm_attrs[] = { &pages_sharing_attr.attr, &pages_unshared_attr.attr, &pages_volatile_attr.attr, + &zero_pages_sharing_attr.attr, &full_scans_attr.attr, #ifdef CONFIG_NUMA &merge_across_nodes_attr.attr, -- 2.15.2