From patchwork Mon Jan 23 17:37: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: 13112642 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 4616FC25B50 for ; Mon, 23 Jan 2023 17:38:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3C0E6B0087; Mon, 23 Jan 2023 12:38:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AECCA6B0088; Mon, 23 Jan 2023 12:38:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80E786B0089; Mon, 23 Jan 2023 12:38:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 61E616B0087 for ; Mon, 23 Jan 2023 12:38:22 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2EC9A1C6B8B for ; Mon, 23 Jan 2023 17:38:22 +0000 (UTC) X-FDA: 80386772844.18.EB1C4FD Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf11.hostedemail.com (Postfix) with ESMTP id 4EA3540020 for ; Mon, 23 Jan 2023 17:38:20 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=neutral (imf11.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674495500; a=rsa-sha256; cv=none; b=CzI70CpTWtkHLc0KeiJozmkDejo8RuHhukr1j1M0v8+ovhCL3bX2KL73vBjGOLoDgGaIgR Cu5NgYVBw486zTHL8mrlyHxHOHIphS9beGeFGCn6zOceHNUp4QHdsVWCc3h5rUH/tEmjVC 7rx0/FrLl3koRwalrMrGZ3KoqXAEjGs= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=neutral (imf11.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=1674495500; 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=BL99fR2JiovciqZqm6mH4hPxhKKNFtoaiqSvJzgiEIg=; b=Al3VnFUx9LPaQ0b7P5lwkuskcXafAUdsUeMlk1Arr0VdRQhOJ7qXxB4y4XeYMv4GI29Aqq PNAuoPUI6YjJF9qGxP9c3LlA5tTOtYbcTOM42cN1hh726duGrbQ2nklDd7uHLLmLeq54ir bznHNNDpL7jjXxJxElGFiHCC+RjOs/U= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 636A05616BE3; Mon, 23 Jan 2023 09:37:56 -0800 (PST) From: Stefan Roesch To: linux-mm@kvack.org Cc: shr@devkernel.io, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [RESEND RFC PATCH v1 09/20] mm: expose general_profit metric Date: Mon, 23 Jan 2023 09:37:37 -0800 Message-Id: <20230123173748.1734238-10-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230123173748.1734238-1-shr@devkernel.io> References: <20230123173748.1734238-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-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d5Ee1xMSeKz T1IpeveF XaLa/WgkmqHDmrJznvOue0t6PnBKrl/vVvw8E0HC9T4q8U2gmKABbj0u3stAa+axNcLU1B0QQXO/VBNyIwH4SYbAMy38s2cKXTQwJ 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 19f434f97dc1..d29454a802a0 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -3205,6 +3205,21 @@ static ssize_t pages_volatile_show(struct kobject *kobj, } KSM_ATTR_RO(pages_volatile); +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) { @@ -3269,6 +3284,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, };