From patchwork Tue Sep 26 04:09:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13398637 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 A5A46CE7A8E for ; Tue, 26 Sep 2023 04:10:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E14A6B018C; Tue, 26 Sep 2023 00:10:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BAE16B018E; Tue, 26 Sep 2023 00:10:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 659E96B018F; Tue, 26 Sep 2023 00:10:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 554226B018C for ; Tue, 26 Sep 2023 00:10:02 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2C28580E45 for ; Tue, 26 Sep 2023 04:10:02 +0000 (UTC) X-FDA: 81277420644.28.F45F02F Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf30.hostedemail.com (Postfix) with ESMTP id 9115680011 for ; Tue, 26 Sep 2023 04:10:00 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=neutral (imf30.hostedemail.com: 66.220.144.178 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=1695701400; 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=rEeKjj+nCu8+n8S1jluBJxwJZhUI2GEoXKLMBjiuJJY=; b=hDh4LMn3F+nylDPGMI9qnTiMr93ZIXbqrZ+AQrY1sHaW8cifaRbsxnmdIRw0Yx8ww9ONUk zdlUZFQ9W58+IBNdlNxPzLIIsFM8+rlg4g+xWjB9fHlDH2m94aLoDKyWPdJMCybuEl3P5n XgxxNXMYwY6IkTdOMk99yyvsrKp6FMg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695701400; a=rsa-sha256; cv=none; b=WR9BmQRSY0r27motgY/yDubeONscIZSpebNL97+aqdUG824NWvLOb8eWmi6C2Ypudwr13d tK6Oecdhmdi8khescMtIfw333CvGTdjVfUXe8EhgL1JoJcA1sjluipUL5XMDzY1w/5rzIu DoMSYxeIpy5jZ1/7Xpdld7i7DeMJsIU= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=neutral (imf30.hostedemail.com: 66.220.144.178 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 82FD9C8F2446; Mon, 25 Sep 2023 21:09:44 -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 v3 2/4] mm/ksm: add pages_skipped metric Date: Mon, 25 Sep 2023 21:09:37 -0700 Message-Id: <20230926040939.516161-3-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230926040939.516161-1-shr@devkernel.io> References: <20230926040939.516161-1-shr@devkernel.io> MIME-Version: 1.0 X-Stat-Signature: twkmf8qxjqet6gbfenrb3oinxgyoun4w X-Rspam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JfOQ3XL/df/tTYNZvi+qdE3x+jUkjqR5YYjy3fX/geQooyrI71VFvDZLOgpGo6bSYgbdGnAO/kVhqdsWJczXJJDEqNDg= 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 d65eb48f9a13..3de130d170b7 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; @@ -2376,6 +2379,7 @@ static bool should_skip_rmap_item(struct page *page, } /* Skip this page */ + ksm_pages_skipped++; rmap_item->remaining_skips--; remove_rmap_item_from_tree(rmap_item); return true; @@ -3463,6 +3467,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) { @@ -3560,6 +3571,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