From patchwork Wed Sep 27 16:22:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13401342 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 506C8E82CB0 for ; Wed, 27 Sep 2023 16:22:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 58BF18D009C; Wed, 27 Sep 2023 12:22:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 53C1A8D0098; Wed, 27 Sep 2023 12:22:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3DCE38D009C; Wed, 27 Sep 2023 12:22:52 -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 295218D0098 for ; Wed, 27 Sep 2023 12:22:52 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E7638A0AB2 for ; Wed, 27 Sep 2023 16:22:51 +0000 (UTC) X-FDA: 81282896142.14.A821D24 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 5B871140029 for ; Wed, 27 Sep 2023 16:22:50 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=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; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695831770; 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=1LdjbrSTW7GDbAqE3wkNtvp3gXo6eKi0BIzKiZfMuRg=; b=8EtTCZwzAtcIgto5EMyz3ORGUJ54r/xQ9zbcT0QjDNELvmi2PdCNtAkUEa8Juk5P11ay7V dF2gQ7AuuW2kvrTZsoivVP17pcmtA03jczDXLQnhRIrb02wErM1sGefQfvVSnXAMNJGEeW 45736q9SqoGCkjs4wwCWcod5MQScmAo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695831770; a=rsa-sha256; cv=none; b=ECr9lwgxu30qufIQfuKkNG7CQNRhlYzaikx0lfMmoFoU07f6m4NbNoz8DC8eHM/EGClgSH NHnLeWkAVdfbxJr6jdgZS7nABq0ATl96KWqj3L56X4bD5VwJbI7eXrYwBrXI9+kuftsz+S NZor9FkqJ4gZdV2VdR6f7FXaba8l6oQ= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=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; dmarc=none Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 47CAECA4DC12; Wed, 27 Sep 2023 09:22:32 -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 v4 2/4] mm/ksm: add pages_skipped metric Date: Wed, 27 Sep 2023 09:22:20 -0700 Message-Id: <20230927162222.3827551-3-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230927162222.3827551-1-shr@devkernel.io> References: <20230927162222.3827551-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5B871140029 X-Rspam-User: X-Rsp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J NfIbMajU YV4NHo9WPI0vecbzcQlxI6W1s8p57M4rJ8Rcqt1zdda0g1XhV+GaboVSPbM8XR09wCyXixPpkPJYJyQO2clpXwQ8gtt0dc6zIsbXt 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 c0a2e7759365..1df25a66f162 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -293,6 +293,9 @@ static bool ksm_smart_scan = 1; /* 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