From patchwork Mon May 22 10:42:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yang X-Patchwork-Id: 9667 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1353085vqo; Mon, 22 May 2023 03:52:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6w5mjAB7HqQAXUPpluSBPZ0lOYkqfQ5HAxrxLmT6JvpEDYzHu/wJlgXg6jHho0lyL9VMJL X-Received: by 2002:a17:903:1ca:b0:1ae:55d2:fff5 with SMTP id e10-20020a17090301ca00b001ae55d2fff5mr12274892plh.31.1684752727060; Mon, 22 May 2023 03:52:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684752727; cv=none; d=google.com; s=arc-20160816; b=bTnADOZmHLrGiKHZoh8VJVHQaV8cmj3ZkQ2X36i0tVkrDa2uq6JU4eK/+qdPkiVTGW nOFqB07Q7HYGg/zJDGBlT5j1LtOka6g/zQe1UwUybHN5w+xQwm7Hjc9r5s1H/HL/q3W6 AEo8299zyislQVxlZ0wZEOOTGW2aKadX6VK88AgTjK8+QPeg8GbzoiS8Cog9jknnW10i uFFNKeU2Sbq7zh/PHnqRmPZiKHZtaf1Lcb2nuxGFvUqbfMT01bDYVu1yK6CvWJNslbNm ePcuOKOQT1uoQW4dgfr8eCiwlBEGDW0vBJXn9X09c5A31Ec/jJ0KO22oinp+B2tXrn6F K8dg== 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=RY4OBuWbPSJknOEnZ6Y/K51qo27uJkHgPFHMYzREBSg=; b=fcMfdT3GtQN6v8vgM4DHa78yGLTlkVSycLPkTwB55FmXv6WGV5Hdfi7lkTSWNuw7/A KmoUBWwUcRsz+BrfAIDPEYfgJ5Nk85q+bX4LQau3fwsRS30x2xWgNU+esz/Rr6DlBjWJ 2Ks6DOdZt+zC6EYXchu6GHduDnSPjpXIcfYxkotJmXAYCVBnuXXCL77QKA9Tq6oStWz4 H/NH7VIhxHLMxoDU0op4vXxah5+qV7F9UaphBAPiGydgqEY476o3HHVsxhRtq2jaJ0D6 NbtRxUFjuos5fOuo/gYgTsVq3dKBB65v0ZpM7Qy0et6Vpm3I5m4hyxxQw4XKPsR8dGpM mogQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d13-20020a170903230d00b001a97262fe53si3448016plh.552.2023.05.22.03.51.52; Mon, 22 May 2023 03:52:07 -0700 (PDT) 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 S232479AbjEVKnQ (ORCPT + 99 others); Mon, 22 May 2023 06:43:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230362AbjEVKnO (ORCPT ); Mon, 22 May 2023 06:43:14 -0400 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D754CB3 for ; Mon, 22 May 2023 03:43:12 -0700 (PDT) Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (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 4QPvDZ1f2gz5B150; Mon, 22 May 2023 18:43:10 +0800 (CST) Received: from szxlzmapp05.zte.com.cn ([10.5.230.85]) by mse-fl2.zte.com.cn with SMTP id 34MAgtsP031085; Mon, 22 May 2023 18:42:55 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp03[null]) by mapi (Zmail) with MAPI id mid14; Mon, 22 May 2023 18:42:58 +0800 (CST) Date: Mon, 22 May 2023 18:42:58 +0800 (CST) X-Zmail-TransId: 2b05646b4732682-6bb12 X-Mailer: Zmail v1.0 Message-ID: <202305221842587200002@zte.com.cn> Mime-Version: 1.0 From: To: , Cc: , , , , , , , Subject: =?utf-8?q?=5BPATCH_v8_0/6=5D_ksm=3A_support_tracking_KSM-placed_zer?= =?utf-8?q?o-pages?= X-MAIL: mse-fl2.zte.com.cn 34MAgtsP031085 X-Fangmail-Gw-Spam-Type: 0 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 646B473E.000/4QPvDZ1f2gz5B150 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766591275771420838?= X-GMAIL-MSGID: =?utf-8?q?1766591275771420838?= From: xu xin The core idea of this patch set is to enable users to perceive the number of any pages merged by KSM, regardless of whether use_zero_page switch has been turned on, so that users can know how much free memory increase is really due to their madvise(MERGEABLE) actions. But the problem is, when enabling use_zero_pages, all empty pages will be merged with kernel zero pages instead of with each other as use_zero_pages is disabled, and then these zero-pages are no longer monitored by KSM. The motivations to do this is seen at: https://lore.kernel.org/lkml/202302100915227721315@zte.com.cn/ In one word, we hope to implement the support for KSM-placed zero pages tracking without affecting the feature of use_zero_pages, so that app developer can also benefit from knowing the actual KSM profit by getting KSM-placed zero pages to optimize applications eventually when /sys/kernel/mm/ksm/use_zero_pages is enabled. Change log ---------- v7->v8: (1) Since [1] which fix the bug of pte_mkdirty on sparc64 that makes pte writable, then we can remove the architechture restrictions of our features. (2) Improve the scheme of update ksm_zero_pages: add the handling case when khugepaged replaces a shared zeropage by a THP. [1] https://lore.kernel.org/all/20230411141529.428991-2-david@redhat.com/ v6->v7: This is an all-newed version which is different from v6 which relys on KSM's rmap_item. The patch series don't rely on rmap_item but pte_dirty, so the general handling of tracking KSM-placed zero-pages is simplified a lot. For safety, we restrict this feature only to the tested and known-working architechtures (ARM, ARM64, and X86) fow now. xu xin (6): ksm: support unsharing KSM-placed zero pages ksm: count all zero pages placed by KSM ksm: add ksm zero pages for each process ksm: add documentation for ksm zero pages ksm: update the calculation of KSM profit selftest: add a testcase of ksm zero pages Documentation/admin-guide/mm/ksm.rst | 26 +++++--- fs/proc/base.c | 1 + include/linux/ksm.h | 25 ++++++++ include/linux/mm_types.h | 9 ++- mm/khugepaged.c | 3 + mm/ksm.c | 19 +++++- mm/memory.c | 7 ++- tools/testing/selftests/mm/ksm_functional_tests.c | 75 +++++++++++++++++++++++ 8 files changed, 152 insertions(+), 13 deletions(-)