From patchwork Wed May 24 05:51:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yang X-Patchwork-Id: 9772 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2631063vqo; Tue, 23 May 2023 23:22:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6/WLvB4M/qf23JEn0NVFsf/t+OaWyUQGUZ3RGNohTJN1EN67bEP+gbyp7XrDmA7Ayr42EL X-Received: by 2002:a05:6a00:218a:b0:64d:1451:8233 with SMTP id h10-20020a056a00218a00b0064d14518233mr1931120pfi.21.1684909329441; Tue, 23 May 2023 23:22:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684909329; cv=none; d=google.com; s=arc-20160816; b=xkyipacEOdHpmug7z3CvR32IxlbbAv3n9Ok7QMcG0XVXbLrIoZ1qSg+9aPruABo/G9 8OCpovVtsx+FVUsSC9IMaf0czehJpBOsbxyGFetD4KAjfkK/adA9xBakP00ybHuKmnuT LJ6Poj/WDm+w0JAjMm/r9S2k1ow/tKup7hyAAUtT+clCn2G+KmWM6WL2Y32dTc8CqWyr FKZMM7tnK26vrnFVoKK8NRjtFVtsN3Besz0QOPcdoNuWQI7M0oMQo58miRbNp8gN5GSC Y5SuP7ERFcyuqHL4GKqZZYR12ooG8MczseGhKOIgYWn/TPG9R+8/wxpt22SSZAi7+68e TRJA== 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=9DpidUW141Xln9uQMmYA+IPozD1aChThrPC1MjiY0qs=; b=SrewOjXXyBnBYsHyXqEhEFd4ptxW0ok5qXVR3qXkzcYAsqzyvCUTJUSqTz+2mQ8z/2 /fcZCZgOJFO+l9QdWBy6rpX5Z+1BdTiMjB4tD68cFfqRdYooHOb4tiXmhXswu4ffiDyD JpM+giB2YSi0CYO1vGsQv5muYuKNIJIx2+xVXlKKkFb5K2IYYqxTp5zZWPaQlh6xYoyu WUCXpKGiEjnBVhcTrebsYNdy9jStAg9nQ4MWt0aW7bybFLAEacvqbMtJc1XKSYzS15aC E+QhBZR249SFBI/+536kZePqbJJ6HLOaoLP9yJL7Plnn4tMLpok2EIwWWKVXbNI5vj8o buBA== 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 z22-20020a63b916000000b00524cf947601si3133349pge.23.2023.05.23.23.21.54; Tue, 23 May 2023 23:22:09 -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 S239303AbjEXFvs (ORCPT + 99 others); Wed, 24 May 2023 01:51:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234559AbjEXFvq (ORCPT ); Wed, 24 May 2023 01:51:46 -0400 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3470C1 for ; Tue, 23 May 2023 22:51:43 -0700 (PDT) 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 4QR0gJ6zZ8z8RTWf; Wed, 24 May 2023 13:51:40 +0800 (CST) Received: from szxlzmapp01.zte.com.cn ([10.5.231.85]) by mse-fl1.zte.com.cn with SMTP id 34O5pY5c047952; Wed, 24 May 2023 13:51:34 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp03[null]) by mapi (Zmail) with MAPI id mid14; Wed, 24 May 2023 13:51:36 +0800 (CST) Date: Wed, 24 May 2023 13:51:36 +0800 (CST) X-Zmail-TransId: 2b05646da5e8ffffffffcd2-a2267 X-Mailer: Zmail v1.0 Message-ID: <202305241351365661923@zte.com.cn> Mime-Version: 1.0 From: To: , Cc: , , , , , , , Subject: =?utf-8?q?=5BPATCH_v9_0/5=5D_ksm=3A_support_tracking_KSM-placed_zer?= =?utf-8?q?o-pages?= X-MAIL: mse-fl1.zte.com.cn 34O5pY5c047952 X-Fangmail-Gw-Spam-Type: 0 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 646DA5EC.001/4QR0gJ6zZ8z8RTWf X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, 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?1766755485304732201?= X-GMAIL-MSGID: =?utf-8?q?1766755485304732201?= 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 ---------- v8->v9: ------ (1) The previous [PATCH v8 4/6] is squashed into the current [PATCH v9 2/5]. (2) Improve the codes as David's suggestions. 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 (5): ksm: support unsharing KSM-placed zero pages ksm: count all zero pages placed by KSM ksm: add ksm zero pages for each process ksm: consider KSM-placed zeropages when calculating KSM profit selftest: add a testcase of ksm zero pages Documentation/admin-guide/mm/ksm.rst | 25 ++++++-- fs/proc/base.c | 1 + include/linux/ksm.h | 22 +++++++ include/linux/mm_types.h | 9 ++- mm/khugepaged.c | 2 + mm/ksm.c | 28 ++++++-- mm/memory.c | 5 +- tools/testing/selftests/mm/ksm_functional_tests.c | 78 ++++++++++++++++++++++- 8 files changed, 154 insertions(+), 16 deletions(-)