From patchwork Fri Feb 10 21:50:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136501 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 74E39C636D4 for ; Fri, 10 Feb 2023 21:53:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 112C428001C; Fri, 10 Feb 2023 16:53:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C350280003; Fri, 10 Feb 2023 16:53:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF49A28001C; Fri, 10 Feb 2023 16:53:54 -0500 (EST) 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 E51EF280003 for ; Fri, 10 Feb 2023 16:53:54 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BF83BC056B for ; Fri, 10 Feb 2023 21:53:54 +0000 (UTC) X-FDA: 80452735188.26.31728F5 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf03.hostedemail.com (Postfix) with ESMTP id 167C920005 for ; Fri, 10 Feb 2023 21:53:52 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf03.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=1676066033; 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=Dp79YSgRwaUp2aprA+6ueDKaYGfQaoLR/Om6v/6itTU=; b=7u/EBLS0RiUoorEucdJk/YczYCietkGSRA2OPlB0T4Qqy0hZw4v7KNy6lENAng3Rp6RK96 c8pH8khGULdpG/pM+7x/lz5SXNNnhPYvl8eV9h9WDl32gVoCDOkCPZyMspHuEF9J1KyGd0 shc65CPCXijeYs1DvvQaipphRYflG/I= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf03.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=1676066033; a=rsa-sha256; cv=none; b=v8l+GY5kIFUp1C5WQYoDUcbC7yVNysLwIjxbEGWkl8MFGa+FXsey4SlpozoLwl8lOiCEcl JKPXHsZsf5aMFf3meS6BSpdYesmwo/Se92s3uKfAf08tliTityt3ix0bx6IOcQ9wQ32O0t 1Ibwhp7nx5M3ZAmfvaVrFpJMQZlP8pY= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 849216BFC2D5; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 08/19] mm: expose general_profit metric Date: Fri, 10 Feb 2023 13:50:12 -0800 Message-Id: <20230210215023.2740545-9-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: 167C920005 X-Stat-Signature: wmttxd4cnskffch874r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7Hml5FsFZRV2fNBoqL1WLtORLI+7GlgAwr45e0bJdgonrnI9YWf96zudn9qheAEq2BxwmmxDik4XxZbd0X 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: The documentation mentions a general profit metric, however this metric is not calculated. In addition the formula depends on the size of internal structures, which makes it more difficult for an administrator to make the calculation. Adding the metric for a better user experience. Signed-off-by: Stefan Roesch --- mm/ksm.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mm/ksm.c b/mm/ksm.c index 7f3b28b7536e..a0b4611112c0 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -3301,6 +3301,21 @@ static ssize_t zero_pages_sharing_show(struct kobject *kobj, } KSM_ATTR_RO(zero_pages_sharing); +static ssize_t general_profit_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + long general_profit; + long all_rmap_items; + + all_rmap_items = ksm_max_page_sharing + ksm_pages_shared + + ksm_pages_unshared + pages_volatile(); + general_profit = ksm_pages_sharing * PAGE_SIZE - + all_rmap_items * sizeof(struct ksm_rmap_item); + + return sysfs_emit(buf, "%ld\n", general_profit); +} +KSM_ATTR_RO(general_profit); + static ssize_t stable_node_dups_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -3366,6 +3381,7 @@ static struct attribute *ksm_attrs[] = { &stable_node_dups_attr.attr, &stable_node_chains_prune_millisecs_attr.attr, &use_zero_pages_attr.attr, + &general_profit_attr.attr, NULL, };