From patchwork Tue Sep 12 17:52:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13381988 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 D984CEE3F0B for ; Tue, 12 Sep 2023 17:52:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E43A6B0134; Tue, 12 Sep 2023 13:52:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 337C86B0132; Tue, 12 Sep 2023 13:52:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 163DE6B0134; Tue, 12 Sep 2023 13:52:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 008B36B0132 for ; Tue, 12 Sep 2023 13:52:55 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B4CC31C9ADB for ; Tue, 12 Sep 2023 17:52:55 +0000 (UTC) X-FDA: 81228691110.23.D83D3E6 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf14.hostedemail.com (Postfix) with ESMTP id 298C5100018 for ; Tue, 12 Sep 2023 17:52:53 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf14.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=1694541174; 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:in-reply-to:references:references; bh=CN2i2K1yeQi3CVF3AoCmDBQsHD9chBIcu/eGaGP4nGc=; b=OdNazek95dbtZHXaKLuwhYW93w2jnJZYbKunPwVZCN7ZfpCrJzVmvKn0AJ9s+pyWdC8GSC /VTsNwbvvVASDgXPgq98URfwJmEY0y42NBhjdpcRhaovhB46gD7YilFhVKhz2hVbmvKONH eW6WZgLJjA8hNb1ryQ18+wfFKezUGoA= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf14.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=1694541174; a=rsa-sha256; cv=none; b=mOFl39TOpM+4gZE1Zuq6lf3Ga/wj0ogyKTx9TDASyO3BoF4fMfxZh8oZfy45ph404jAylH 8xhDzTjiRZ0HwA05mNkg0Jbjh/hco+HVCHmDl2TYkILK/yY8842jDRrbWTp5oAR6SlTD9p 0s+zxDAk+z9FqHK4QjDqq1/x2YCoPzo= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 28DACBCD162C; Tue, 12 Sep 2023 10:52:38 -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 Subject: [PATCH v1 2/4] mm/ksm: add pages_skipped metric Date: Tue, 12 Sep 2023 10:52:26 -0700 Message-Id: <20230912175228.952039-3-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230912175228.952039-1-shr@devkernel.io> References: <20230912175228.952039-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: jao597uja9w3rmw5ns7oa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uf3HbKccXpg5iUUYU4BLrnyXXFbNNv8LJ2f4a7B5eXVTLYDi5QUYuYwOgkmZxonhag/TbLqg1L8+ZlWNAVmkrBTLk4j7hxYnt6vTK0/y8TCdxkedKuZ 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: This change adds the "pages skipped" metric. To be able to evaluate how successful smart page scanning is, the pages skipped metric can be compared to the pages scanned metric. The pages skipped metric is a cumulative counter. The counter is stored under /sys/kernel/mm/ksm/pages_skipped. Signed-off-by: Stefan Roesch Reviewed-by: David Hildenbrand --- mm/ksm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mm/ksm.c b/mm/ksm.c index bfd5087c7d5a..728574a3033e 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -293,6 +293,9 @@ static bool ksm_smart_scan; /* The number of zero pages which is placed by KSM */ unsigned long ksm_zero_pages; +/* The number of pages that have been skipped due to "smart scanning" */ +static unsigned long ksm_pages_skipped; + #ifdef CONFIG_NUMA /* Zeroed when merging across nodes is not allowed */ static unsigned int ksm_merge_across_nodes = 1; @@ -2345,6 +2348,7 @@ static bool skip_rmap_item(struct page *page, struct ksm_rmap_item *rmap_item) return false; } + ksm_pages_skipped++; if (rmap_item->skip_age == 0) { rmap_item->skip_age = age + inc_skip_age(age); remove_rmap_item_from_tree(rmap_item); @@ -3435,6 +3439,13 @@ static ssize_t pages_volatile_show(struct kobject *kobj, } KSM_ATTR_RO(pages_volatile); +static ssize_t pages_skipped_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%lu\n", ksm_pages_skipped); +} +KSM_ATTR_RO(pages_skipped); + static ssize_t ksm_zero_pages_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -3532,6 +3543,7 @@ static struct attribute *ksm_attrs[] = { &pages_sharing_attr.attr, &pages_unshared_attr.attr, &pages_volatile_attr.attr, + &pages_skipped_attr.attr, &ksm_zero_pages_attr.attr, &full_scans_attr.attr, #ifdef CONFIG_NUMA