Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp1202448rdg; Fri, 11 Aug 2023 13:15:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGbdDJFJhqmYA2VrQKxceF9aiqdNE/7Cuz33ULvmS3NWwh0uX2YIctf1R6RSCZq8NBACOIw X-Received: by 2002:aa7:cf04:0:b0:523:b2e7:fbf0 with SMTP id a4-20020aa7cf04000000b00523b2e7fbf0mr1974201edy.40.1691784913285; Fri, 11 Aug 2023 13:15:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691784913; cv=none; d=google.com; s=arc-20160816; b=z4BeATPe/PdUJAP6gvQXMNBXSn0uQkG0jMm1stQMBn0cikfIPPdJDSvdvr4RQtcyz1 8N+n3BBASdFpOWMgs0vnUYlkX3G0fJ1wiC4Kn7I9an2RiStmxunPlxFNMDvZY5LrWADt k2WLFc/KKI0qihn4a2dWvSAZ3+GrnbZzwzO3zXI6j1Zowo1eL/VsZ+04ZQOga32JIJ+7 dbAq0hPYe2pRspMHvj9u8eDV/QnrTqi/8evkj1QuVR2u7ZwqVeE5Yd/AA64FBedQwC8L 8tj5LzK2uWOiAYyBwFKEk9pGwfTg0z0MabNzGrhe4cDm9A24RwBXkjeSk9ip25EoMxy/ AxUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=6hD+8YnfkCoYsZNU6zGn2cHjFN/uGoxyLvJgQXzJwFg=; fh=Cm6QKNCvyuHpBO+VdTdc5ouY/OGbzA/J1gxC022DB+E=; b=qV7NsCRA2i7T8911gGd5FDxE2oSAVCKED4uNUzDhvqKeCRM7jZBB1uUAmfbq4dg6Q6 Zh/EOV4ZOn4Ti1b3FgYiW8S24v8l0Ys1NsaYZJtzl557w+HG0jvvy+HQ3DvSrKCAvi9B BCRHf/BQ7ZGeiQSw4TLatDcxq4FihcNGvUQ3h5aR5QgbQq+H9ZZ3y4neIU/MoxKN7VwK QJwIwR7T4cg0agiP2Ftr+rAveuIcZyE0SgEtXVG0lqscXU6u+6/evE0BvDSQUD7NOvPW U4Um2TiVlPy1kgX5NhpOvSzU9dlKhdBWXSisRO5BhfLBc32z7cukFmagzf+H00k7yYEi sWXA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s4-20020a056402164400b0052348d74868si3784093edx.238.2023.08.11.13.14.48; Fri, 11 Aug 2023 13:15:13 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236575AbjHKThP (ORCPT + 99 others); Fri, 11 Aug 2023 15:37:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231201AbjHKThO (ORCPT ); Fri, 11 Aug 2023 15:37:14 -0400 Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D1B430E6 for ; Fri, 11 Aug 2023 12:37:13 -0700 (PDT) Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id E859DA091D51; Fri, 11 Aug 2023 12:36:59 -0700 (PDT) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, akpm@linux-foundation.org, david@redhat.com, hannes@cmpxchg.org, riel@surriel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org Subject: [PATCH v1] mm/ksm: add pages scanned metric Date: Fri, 11 Aug 2023 12:36:55 -0700 Message-Id: <20230811193655.2518943-1-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RDNS_DYNAMIC,SPF_HELO_PASS,SPF_NEUTRAL, TVD_RCVD_IP 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 ksm currently maintains several statistics, which let you determine how successful KSM is at sharing pages. However it does not contain a metric to determine how much work it does. This commit adds the pages scanned metric. This allows the administrator to determine how many pages have been scanned over a period of time. Signed-off-by: Stefan Roesch --- Documentation/admin-guide/mm/ksm.rst | 2 ++ mm/ksm.c | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-g= uide/mm/ksm.rst index 5c5be7bd84b8..776f244bdae4 100644 --- a/Documentation/admin-guide/mm/ksm.rst +++ b/Documentation/admin-guide/mm/ksm.rst @@ -159,6 +159,8 @@ The effectiveness of KSM and MADV_MERGEABLE is shown = in ``/sys/kernel/mm/ksm/``: =20 general_profit how effective is KSM. The calculation is explained below. +pages_scanned + how many pages are being scanned for ksm pages_shared how many shared pages are being used pages_sharing diff --git a/mm/ksm.c b/mm/ksm.c index 6b7b8928fb96..8d6aee05421d 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -242,6 +242,9 @@ static struct kmem_cache *rmap_item_cache; static struct kmem_cache *stable_node_cache; static struct kmem_cache *mm_slot_cache; =20 +/* The number of pages scanned */ +static unsigned long ksm_pages_scanned; + /* The number of nodes in the stable tree */ static unsigned long ksm_pages_shared; =20 @@ -2483,8 +2486,9 @@ static void ksm_do_scan(unsigned int scan_npages) { struct ksm_rmap_item *rmap_item; struct page *page; + unsigned int npages =3D scan_npages; =20 - while (scan_npages-- && likely(!freezing(current))) { + while (npages-- && likely(!freezing(current))) { cond_resched(); rmap_item =3D scan_get_next_rmap_item(&page); if (!rmap_item) @@ -2492,6 +2496,8 @@ static void ksm_do_scan(unsigned int scan_npages) cmp_and_merge_page(page, rmap_item); put_page(page); } + + ksm_pages_scanned +=3D scan_npages - npages; } =20 static int ksmd_should_run(void) @@ -3332,6 +3338,13 @@ static ssize_t max_page_sharing_store(struct kobje= ct *kobj, } KSM_ATTR(max_page_sharing); =20 +static ssize_t pages_scanned_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%lu\n", ksm_pages_scanned); +} +KSM_ATTR_RO(pages_scanned); + static ssize_t pages_shared_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -3440,6 +3453,7 @@ static struct attribute *ksm_attrs[] =3D { &sleep_millisecs_attr.attr, &pages_to_scan_attr.attr, &run_attr.attr, + &pages_scanned_attr.attr, &pages_shared_attr.attr, &pages_sharing_attr.attr, &pages_unshared_attr.attr, base-commit: f4a280e5bb4a764a75d3215b61bc0f02b4c26417 --=20 2.39.3