From patchwork Fri Aug 11 19:36:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13351348 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 98B0EC001B0 for ; Fri, 11 Aug 2023 19:37:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2AE226B0078; Fri, 11 Aug 2023 15:37:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2857C6B007B; Fri, 11 Aug 2023 15:37:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1745A6B007D; Fri, 11 Aug 2023 15:37:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0CDC76B0078 for ; Fri, 11 Aug 2023 15:37:15 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C328A80553 for ; Fri, 11 Aug 2023 19:37:14 +0000 (UTC) X-FDA: 81112832388.06.3C367AF Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf09.hostedemail.com (Postfix) with ESMTP id 42EBC140016 for ; Fri, 11 Aug 2023 19:37:13 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf09.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691782633; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=6hD+8YnfkCoYsZNU6zGn2cHjFN/uGoxyLvJgQXzJwFg=; b=WaW61AtGjozegG2SpAqCgaPw2UBx7vQmLaVT1ZLevmML5jtHhroesk4eRreVxJuqPODnmi SGlENKA9axte6D/f64qZbqveH92pNHCnd6xry3c0SW1k8BthrZQJaygBjm9MRhi2EWdXGH dV6NRl2WgRXKq/8+vrGCak7XVSkdzxU= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf09.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691782633; a=rsa-sha256; cv=none; b=zr7AJtl6bJBzNVJzOhFhfYSvfTfvltyiapULqwh637XcDgwjbGXCx8WAAlRTiazOpeyMxA QwJjwa11fdiQSn/LghFnpjRnqPlcdLzj1kqeWoFxL36CKS3MgT269AclZ6nKEo43qSYhKw v+z/5GA4jMtU+fOxuuvCmesIDsnCres= 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 X-Rspamd-Queue-Id: 42EBC140016 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: utmepuk4os5aighuc7bkeg6ijfpbqjmm X-HE-Tag: 1691782633-360172 X-HE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-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Acked-by: David Hildenbrand --- Documentation/admin-guide/mm/ksm.rst | 2 ++ mm/ksm.c | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) base-commit: f4a280e5bb4a764a75d3215b61bc0f02b4c26417 diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-guide/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/``: 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; +/* 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; @@ -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 = scan_npages; - while (scan_npages-- && likely(!freezing(current))) { + while (npages-- && likely(!freezing(current))) { cond_resched(); rmap_item = 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 += scan_npages - npages; } static int ksmd_should_run(void) @@ -3332,6 +3338,13 @@ static ssize_t max_page_sharing_store(struct kobject *kobj, } KSM_ATTR(max_page_sharing); +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[] = { &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,