From patchwork Mon Sep 18 18:58:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13390258 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 05906CD37B0 for ; Mon, 18 Sep 2023 18:58:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED7B66B0446; Mon, 18 Sep 2023 14:58:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C471C6B044B; Mon, 18 Sep 2023 14:58:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D4856B0447; Mon, 18 Sep 2023 14:58:38 -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 700246B0443 for ; Mon, 18 Sep 2023 14:58:38 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 51010A046C for ; Mon, 18 Sep 2023 18:58:38 +0000 (UTC) X-FDA: 81250629516.09.C739007 Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by imf05.hostedemail.com (Postfix) with ESMTP id B7685100013 for ; Mon, 18 Sep 2023 18:58:36 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; spf=neutral (imf05.hostedemail.com: 66.220.144.179 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695063516; 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=awJU8GMl6Va3wNMo4dFdW3id0t0DydghBy65nawHNHc=; b=x/ttwDElrzOGydXyWuUiJLj0vywF0u96caOLGvJuqbKlmRwkM4HsW7s13tFl8DbTqVqNuR erbvoOFzS49UyEua0NhGzwDY6s3IXF63UosaG/WowfD76IZbCgSBIxBBkDpq4WvQ4ldb9h FodAUOxyYHBRhOdmKYrbGArRGmoRII4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695063516; a=rsa-sha256; cv=none; b=ZtLQnw7q8yVs3cOrZ5umS5b/8JzLnFu0I1YZLt+d37KMugf3UaEB+GRLxSAOpKqNw3l95b ZDEV4eKkKsEuwuiMSzyixZRcr0dbpO1DEXtTsCT9tK3vANO+L2OY5CAvFOJDAn0qL/GU+P /txjNoBQpz9dLYqByVU19AAW6Y2FDQY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=neutral (imf05.hostedemail.com: 66.220.144.179 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 2B029C25F828; Mon, 18 Sep 2023 11:58:22 -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 v2 2/4] mm/ksm: add pages_skipped metric Date: Mon, 18 Sep 2023 11:58:14 -0700 Message-Id: <20230918185816.1518366-3-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230918185816.1518366-1-shr@devkernel.io> References: <20230918185816.1518366-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: B7685100013 X-Rspam-User: X-Stat-Signature: fo7ei75fshr3s8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KyQhiKegtAhAf1y7ec4W7oYhxydCGYfp06LUYaD7qA6ZCuvH5P7w== 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 7a1aa3872cf4..7fbf22814c8d 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; @@ -2378,6 +2381,7 @@ static bool should_skip_rmap_item(struct page *page, * Skip the page and calculate skip_age on when to re-enable scanning * for this page. */ + ++ksm_pages_skipped; if (rmap_item->skip_age == 0) { rmap_item->skip_age = (age + skip_age(age)) & 0xFF; remove_rmap_item_from_tree(rmap_item); @@ -3468,6 +3472,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) { @@ -3565,6 +3576,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