Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1744166rwb; Fri, 28 Jul 2023 14:22:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlGzP2YmOxWMFGy/5btuLyk45ucZF2tld3JL6BltwVACRtQFomoxfn05BcchMC/PQ1U/5NuH X-Received: by 2002:a17:907:8a28:b0:978:8979:c66c with SMTP id sc40-20020a1709078a2800b009788979c66cmr702024ejc.18.1690579362781; Fri, 28 Jul 2023 14:22:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690579362; cv=none; d=google.com; s=arc-20160816; b=ZOXVI3XZbqR3/3QJ0L5MBd4zXMcRsvbKtxZxczfA8a9XQ1hOcUwf/A8m8D/zsPOGJn vVVpSv8SIOx3d4806sRRyyrTTTwruFgFLEHmnpWmi6gIiRX7zFFDffB0xdK+oRfmlkX1 SFvGgLcdf9+jfjSJYN+DsW/w6APlyqpFskiBXH5qg4K7qI/A5Nf3XW+Uo5wQLmCmdYqM u6u3INR4SE+ZoaG5jsWig3Ahdd+ulDAUHyAVbtAdyKiwCBQT+ST2j52Y03M7HLWUEFr6 OArWdYPf2TpxjjUenZwI8Fx1NyB95gVpvajX/oQ0TL8PulRjOZulTuoq7I5N1jVnSMoW p8wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5nQkTjpE5JkIK0Ug+slCBTeILDePWtarDq+twvurfAs=; fh=8oGWbdHExGIIBBigm5y9/rZRjvqmeY+HpW+qV30w+go=; b=QyySTCIhQmt9nnIiPacKLhVazCb8pRQcnJgsKmX0ULGj6EuDj21TbCfUME0T0MtVH0 LWDw4BpytaTUM8NKrhOGQ15QXAYfWme/5pedjyzs5P19UNKTGigae7Z1g2GdoTIFbt5R S4kvktMacyCerF+2QXpIy3yrzCGn2q/nm1zHBTWNpi/tcHeHA7Q8X2Mn2j2bpANAwK7W HfpQQJMu7/40lKSAl1zNJHxXPJNRDgR5DFGsGiocVoqJjQZfOdxd2Jh9PKy0qMF/UUvH ++f4oP1bGTF78M+cjKHYdWMd70+jypQdY79YjBp4lxCnOphD1zKpGsmvtz+qpGBiwB4n 7kKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LXDARGXp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id by23-20020a170906a2d700b00993325b159csi3382286ejb.659.2023.07.28.14.22.18; Fri, 28 Jul 2023 14:22:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LXDARGXp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232969AbjG1USb (ORCPT + 99 others); Fri, 28 Jul 2023 16:18:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230157AbjG1US2 (ORCPT ); Fri, 28 Jul 2023 16:18:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F033423B for ; Fri, 28 Jul 2023 13:18:27 -0700 (PDT) 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 D05E5621F9 for ; 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.25.1