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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6F2FC25B50 for ; Mon, 23 Jan 2023 17:58:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232984AbjAWR6n (ORCPT ); Mon, 23 Jan 2023 12:58:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232223AbjAWR6m (ORCPT ); Mon, 23 Jan 2023 12:58:42 -0500 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C088223D88 for ; Mon, 23 Jan 2023 09:58:41 -0800 (PST) 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); =20 +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 =3D ksm_max_page_sharing + ksm_pages_shared + + ksm_pages_unshared + pages_volatile(); + general_profit =3D 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[] =3D { &stable_node_dups_attr.attr, &stable_node_chains_prune_millisecs_attr.attr, &use_zero_pages_attr.attr, + &general_profit_attr.attr, NULL, }; =20 --=20 2.30.2