From patchwork Fri Jul 28 20:18:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13332635 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 D7641C41513 for ; Fri, 28 Jul 2023 20:18:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C3B946B0074; Fri, 28 Jul 2023 16:18:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0B878D0001; Fri, 28 Jul 2023 16:18:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79F068D0002; Fri, 28 Jul 2023 16:18:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 519C06B0074 for ; Fri, 28 Jul 2023 16:18:30 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 216B2A07F8 for ; Fri, 28 Jul 2023 20:18:30 +0000 (UTC) X-FDA: 81062133180.05.CFA29F5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id 539C020006 for ; Fri, 28 Jul 2023 20:18:28 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LXDARGXp; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690575508; 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:dkim-signature; bh=5nQkTjpE5JkIK0Ug+slCBTeILDePWtarDq+twvurfAs=; b=IR1QweGKUbtuxnS1cmk6f+tc7ws4LvZnC+BzO+618cqzkhv3ApJxoSFLqZvVB5kHamJf+V lxTsZ9mecUr8x3Xgx7Yr9BPXV9oYjQSckXMO7ubEKqSRnfSohiQbE1O5qg1ZKCJGPqC7az SJ6mPXTHI66iwfPkM9haKSXa41I/cmA= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LXDARGXp; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690575508; a=rsa-sha256; cv=none; b=3Qs0+hp1nJgemiN1iq8wzo7MSjTcf/Fxd1vrc8pDeVPfuwEUVZq7sgG2o3SlWZb7tPYy8h uk6KZ60TvZW6oxrtz73vbK7MhC0KaGpedkFiM2xei/qdBIJLrHdOxavU2M2P1zCoSrGpNL mmwc8djCc09WWAkqJH4uTNPPAPepNuw= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D410C621FA; Fri, 28 Jul 2023 20:18:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1EF3C433C9; Fri, 28 Jul 2023 20:18:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690575506; bh=f9khGIJiHzKXZGP9/5olstezaDHUu4yK0qoxQ3r57d0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LXDARGXp/FQxUmz94YzoxW4KJmVhaTi8JMBOSvWlDj/b+y6OEkY2wrOSS7c5yn1i0 Ci+nBCovt0ADVQQKNC0GDEWUMEuRklyBLHOS6s9X8KU0sKUxqrHnYRyxZgqA5xGIQ6 4Q+mpKNFvUoPm4uIlWa9pz0/8RiO/K43iPvbe8fM+poFQuOj0WMnoe7smZKgJWEkim G0bWwohWE+kl+R+Azlx0tgbK2DDgcccqX3oyiyPbnbyz0G74JY7JUkBX8dWeux+Iu3 d0HEGCyrbhDETvHyadG0aX7JRJ0J3k1p30E9qQFkVAowidxX/3+npipplm8elUwNUj RixUsfUXlC/gA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/5] mm/damon/sysfs-schemes: implement DAMOS tried total bytes file Date: Fri, 28 Jul 2023 20:18:13 +0000 Message-Id: <20230728201817.70602-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230728201817.70602-1-sj@kernel.org> References: <20230728201817.70602-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 539C020006 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: jks3axc1wdkz3hyk58x33j5irqz3pgoi X-HE-Tag: 1690575508-257620 X-HE-Meta: U2FsdGVkX1/KpmPySMmboQ1ZXz1iQFdy8gVYKm+duV31jQ26wYtsXmhagaJEpYcuvqhSIF1n2tsN1al8Yh66dEeFPoEw0nE8j8ORchBmjzMXvsizGXJklMHFrzX/S124NubqtZtFTxtVhrXIUVL6QIoD19HUVEpHg/viMu5tzydmDe9KXzCnWmRmdJ7SBWtqpku1kCJocJFlp5zxuc3bS8YekgO7flojniP5cYAa+vv+epqvtXa5xbkNU7E4bOl9bDCFKw5DC/vjmz7BVzCR6HvqxSLnKEvpkcPVS5SyCI9t+b4m9MDfa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ence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The tried_regions directory can be used for retrieving the monitoring results snapshot for regions of specific access pattern, by setting the scheme's action as 'stat' and the access pattern as required. While the interface provides every detail of the monitoring results, some use cases including working set size monitoring requires only the total size of the regions. For such cases, users should read all the information and calculate the total size of the regions. However, it could incur high overhead if the number of regions is high. Add a file for retrieving only the information, namely 'total_bytes' file. It allows users to get the total size by reading only the file. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 50cf89dcd898..6d3462eb31f2 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -117,6 +117,7 @@ struct damon_sysfs_scheme_regions { struct kobject kobj; struct list_head regions_list; int nr_regions; + unsigned long total_bytes; }; static struct damon_sysfs_scheme_regions * @@ -128,9 +129,19 @@ damon_sysfs_scheme_regions_alloc(void) regions->kobj = (struct kobject){}; INIT_LIST_HEAD(®ions->regions_list); regions->nr_regions = 0; + regions->total_bytes = 0; return regions; } +static ssize_t total_bytes_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damon_sysfs_scheme_regions *regions = container_of(kobj, + struct damon_sysfs_scheme_regions, kobj); + + return sysfs_emit(buf, "%lu\n", regions->total_bytes); +} + static void damon_sysfs_scheme_regions_rm_dirs( struct damon_sysfs_scheme_regions *regions) { @@ -148,7 +159,11 @@ static void damon_sysfs_scheme_regions_release(struct kobject *kobj) kfree(container_of(kobj, struct damon_sysfs_scheme_regions, kobj)); } +static struct kobj_attribute damon_sysfs_scheme_regions_total_bytes_attr = + __ATTR_RO_MODE(total_bytes, 0400); + static struct attribute *damon_sysfs_scheme_regions_attrs[] = { + &damon_sysfs_scheme_regions_total_bytes_attr.attr, NULL, }; ATTRIBUTE_GROUPS(damon_sysfs_scheme_regions); @@ -1648,6 +1663,7 @@ static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, return 0; sysfs_regions = sysfs_schemes->schemes_arr[schemes_idx]->tried_regions; + sysfs_regions->total_bytes += r->ar.end - r->ar.start; region = damon_sysfs_scheme_region_alloc(r); list_add_tail(®ion->list, &sysfs_regions->regions_list); sysfs_regions->nr_regions++; @@ -1678,6 +1694,7 @@ int damon_sysfs_schemes_clear_regions( sysfs_scheme = sysfs_schemes->schemes_arr[schemes_idx++]; damon_sysfs_scheme_regions_rm_dirs( sysfs_scheme->tried_regions); + sysfs_scheme->tried_regions->total_bytes = 0; } return 0; }