Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6614433rwb; Mon, 5 Dec 2022 15:11:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf6GaSnncvLfj227cR3GHJmNQBUQaTrdQ16SqqVofpGPcdjau7r+hxOqKKCyNkSrGb5Ctbew X-Received: by 2002:a63:d944:0:b0:478:cd7c:9085 with SMTP id e4-20020a63d944000000b00478cd7c9085mr3354431pgj.571.1670281879544; Mon, 05 Dec 2022 15:11:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670281879; cv=none; d=google.com; s=arc-20160816; b=WHXhyAgQ90PuzTxWFRtpHCXbDysvAYNXpi6wOatbOi4d61wraerXeEO6xHEe6JRox5 kIjic2Ocfek7sGBiOrmBgxEBJcu4bqZOgR/1MjarTKM+mH6M1qpOOqo0VtKfTJz6eaeQ Klk01M3k7CVeVS4NnlNIeR7EAUpbggvVSEydpwKXbCWvK10gK6XAVsfjfxrhSGib+Ube B4lD8u+ELE4J8w2LXTicjuxTwqRE77bEJ0IGiN9iZZJxAiJHpT6fwar5+Q8bsLxKBIe0 xB4rI8wgH9OLZhHGapbsTGGYSlku5UyjAc4J6LNVs7Gm1VhsJgptjXjEz2iVj3TzAJpE 3reg== 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=oAWeLdbec29o/pQUTk4KG0iaCmNJO1bxhOKX71KFHjw=; b=FoiIEEHPVa+oYME8q1mGzbRHTFDKex9RksoIhU3wWIMvcADQsSV9Qn+etJI4alhO23 nvvuqbnhcHVAbjwGNbnfw0x1s4O/Lr0e1gvcBxAKlYM4rgpWlrGAd7xMQuu0JXpD3Ymd hEZvdBt2APfk0JQpDQZgvd882JvtFJi1Z+TTpUvq7dHoL+ltAGvP7SlOlqFcA03xYP5c Q29j83FFPlHSQdnTqMILzFrpzPDeoIL9AGt4ZqKVb8+9eeXp7Q0ZZL2wj3WFdjaMVzmj ApSkj+OKGagqoRrukA02+vP17zHn7yJFY+krQM1bUbhbClsxheR8a8pmQO87aMbytbeU jAgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jrOqtFOc; 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 f8-20020a056a001ac800b00565a581ecc0si17348838pfv.11.2022.12.05.15.11.08; Mon, 05 Dec 2022 15:11:19 -0800 (PST) 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=jrOqtFOc; 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 S233820AbiLEXJf (ORCPT + 80 others); Mon, 5 Dec 2022 18:09:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232599AbiLEXIq (ORCPT ); Mon, 5 Dec 2022 18:08:46 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFE751EEF0 for ; Mon, 5 Dec 2022 15:08:41 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7A4A3B81158 for ; Mon, 5 Dec 2022 23:08:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB87EC43150; Mon, 5 Dec 2022 23:08:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670281719; bh=MpYV+KbY79xvzeBIqlzmkGgEI6XBAJRwIre/bGlDx34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jrOqtFOcq71qCPzhO6p9V19nT7ndK/ktf8pemOkO/ds3ceglbgw4pBdBGHJXcYuXK B5QxEtOWIvy6mMrfh6WyoGlKsDuZwEUmhs/XJ2EObhf2BzERcjLkvKKuIukv/+mW92 AQSLy7+iW7woDEQkwyqcr5skQlZR9Rrg2M39/yEBfsqKhd1js1Ene52VNP0IQc9LoL 3PTokR6wVqfGVqaEtMBF79FLVdzhBUd8YMVAMU9BlrfdlRbXmF/y2pRo+j8qlYVIo/ Yp/uOGXc0yGOHUKlzPhO3KcQN7fITY8+fyorFvu2Md/9H0phPBnu0F3wlc0kSQhh4X i/nnOsljXmZ7A== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 05/11] mm/damon/sysfs-schemes: implement filters directory Date: Mon, 5 Dec 2022 23:08:24 +0000 Message-Id: <20221205230830.144349-6-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221205230830.144349-1-sj@kernel.org> References: <20221205230830.144349-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 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 DAMOS filters is currently supported by only DAMON kernel API. To expose the feature to user space, implement a DAMON sysfs directory named 'filters' under each scheme directory. Please note that this is implementing only the directory. Following commits will implement more files and directories, and finally connect the DAMOS filters feature. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 85 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 81fc4d27f4e4..50c8148cb474 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -258,6 +258,63 @@ static struct kobj_type damon_sysfs_stats_ktype = { .default_groups = damon_sysfs_stats_groups, }; +/* + * filters directory + */ + +struct damon_sysfs_scheme_filters { + struct kobject kobj; + int nr; +}; + +static struct damon_sysfs_scheme_filters * +damon_sysfs_scheme_filters_alloc(void) +{ + return kzalloc(sizeof(struct damon_sysfs_scheme_filters), GFP_KERNEL); +} + +static ssize_t nr_filters_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damon_sysfs_scheme_filters *filters = container_of(kobj, + struct damon_sysfs_scheme_filters, kobj); + + return sysfs_emit(buf, "%d\n", filters->nr); +} + +static ssize_t nr_filters_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + int nr, err = kstrtoint(buf, 0, &nr); + + if (err) + return err; + if (nr < 0) + return -EINVAL; + + return count; +} + +static void damon_sysfs_scheme_filters_release(struct kobject *kobj) +{ + kfree(container_of(kobj, struct damon_sysfs_scheme_filters, kobj)); +} + +static struct kobj_attribute damon_sysfs_scheme_filters_nr_attr = + __ATTR_RW_MODE(nr_filters, 0600); + +static struct attribute *damon_sysfs_scheme_filters_attrs[] = { + &damon_sysfs_scheme_filters_nr_attr.attr, + NULL, +}; +ATTRIBUTE_GROUPS(damon_sysfs_scheme_filters); + +static struct kobj_type damon_sysfs_scheme_filters_ktype = { + .release = damon_sysfs_scheme_filters_release, + .sysfs_ops = &kobj_sysfs_ops, + .default_groups = damon_sysfs_scheme_filters_groups, +}; + /* * watermarks directory */ @@ -784,6 +841,7 @@ struct damon_sysfs_scheme { struct damon_sysfs_access_pattern *access_pattern; struct damon_sysfs_quotas *quotas; struct damon_sysfs_watermarks *watermarks; + struct damon_sysfs_scheme_filters *filters; struct damon_sysfs_stats *stats; struct damon_sysfs_scheme_regions *tried_regions; }; @@ -878,6 +936,24 @@ static int damon_sysfs_scheme_set_watermarks(struct damon_sysfs_scheme *scheme) return err; } +static int damon_sysfs_scheme_set_filters(struct damon_sysfs_scheme *scheme) +{ + struct damon_sysfs_scheme_filters *filters = + damon_sysfs_scheme_filters_alloc(); + int err; + + if (!filters) + return -ENOMEM; + err = kobject_init_and_add(&filters->kobj, + &damon_sysfs_scheme_filters_ktype, &scheme->kobj, + "filters"); + if (err) + kobject_put(&filters->kobj); + else + scheme->filters = filters; + return err; +} + static int damon_sysfs_scheme_set_stats(struct damon_sysfs_scheme *scheme) { struct damon_sysfs_stats *stats = damon_sysfs_stats_alloc(); @@ -926,9 +1002,12 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme) err = damon_sysfs_scheme_set_watermarks(scheme); if (err) goto put_quotas_access_pattern_out; - err = damon_sysfs_scheme_set_stats(scheme); + err = damon_sysfs_scheme_set_filters(scheme); if (err) goto put_watermarks_quotas_access_pattern_out; + err = damon_sysfs_scheme_set_stats(scheme); + if (err) + goto put_filters_watermarks_quotas_access_pattern_out; err = damon_sysfs_scheme_set_tried_regions(scheme); if (err) goto put_tried_regions_out; @@ -937,6 +1016,9 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme) put_tried_regions_out: kobject_put(&scheme->tried_regions->kobj); scheme->tried_regions = NULL; +put_filters_watermarks_quotas_access_pattern_out: + kobject_put(&scheme->filters->kobj); + scheme->filters = NULL; put_watermarks_quotas_access_pattern_out: kobject_put(&scheme->watermarks->kobj); scheme->watermarks = NULL; @@ -956,6 +1038,7 @@ static void damon_sysfs_scheme_rm_dirs(struct damon_sysfs_scheme *scheme) damon_sysfs_quotas_rm_dirs(scheme->quotas); kobject_put(&scheme->quotas->kobj); kobject_put(&scheme->watermarks->kobj); + kobject_put(&scheme->filters->kobj); kobject_put(&scheme->stats->kobj); damon_sysfs_scheme_regions_rm_dirs(scheme->tried_regions); kobject_put(&scheme->tried_regions->kobj); -- 2.25.1