From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 476AE36683D; Sat, 16 May 2026 18:37:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778956654; cv=none; b=FYf9ndmfNe/DjajVODAQFrqRcB5uvd492dCqnyXELfJmwB1tBcjXRVtxFCquAoJC7Xu9q4WE4Q6xfgAv6Xk2pKqoKfTAzq0XspEpW1LoAm9sF/+gsIYPFSrxoOCAtJWhGOIQpNbOw4mjEU3jYGuPi4g3Att0Lmm6VpfMOuJt/JQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778956654; c=relaxed/simple; bh=tDrZwwwBJNmUwPRaRB5h2nj7rIVewmnnPdFzESzb/3c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B5k2dF2MAUADGQcGHMIsLpsIhAuG9KUE0hkh41ySJY2k4nmTUMfACAGjgcHjyZ9AWP3T8g8JIMswWAm2gOz7hQQLqqoCpmZdd3dvkSnfpQr4+4WiJRdXvCjfWkPLVJ7FkCAVspx6QDtzsVf/M08rJyW+xheWF/SB1h3MuzzLbTQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fyMPxbky; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fyMPxbky" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD42AC19425; Sat, 16 May 2026 18:37:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778956654; bh=tDrZwwwBJNmUwPRaRB5h2nj7rIVewmnnPdFzESzb/3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fyMPxbkyE3jwDn8+alcqAvbygDtzlIldCESN+H++74MEQT9AEKEtEcvqMR9AFYugI XxPX3L9MlhlkHhA5si/Ayb9/wd7emxSkNRbpOKOZd3Jx6fcbfWGCxn5NdcSKp2Ci6n oP1NZ4RSpjidYjt4dhtn7Bsp8z9VAsBosThF2cchU/M1Tn3CG8uwfBccv5APmdRuRL 5vY76D7dAe3ClIl24EQnB2Up1/qvX+C63xjFfXL83aTK2nfwwqdnyG+dDT9uLunmM/ S3LulO3rpnW+7amTGKXmyRSnR4sywkTpAsR3Ijqd+lB1+O2CKd1Ucm1Z8pu54Anwmo GgBIAVHzq8kLw== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v3 24/28] mm/damon/sysfs: add filters//path file Date: Sat, 16 May 2026 11:37:05 -0700 Message-ID: <20260516183712.81393-25-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260516183712.81393-1-sj@kernel.org> References: <20260516183712.81393-1-sj@kernel.org> Precedence: bulk X-Mailing-List: damon@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Introduce a new DAMON sysfs file for letting users setup the target memory cgroup of the belonging memory cgroup attribute monitoring. The file is named 'path', located under the probe filter directory. Users can set the target memory cgroup by writing the path to the memory cgroup from the cgroup mount point to the file. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index f1b7d79386866..2df1d670ee77d 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -756,6 +756,7 @@ struct damon_sysfs_filter { enum damon_filter_type type; bool matching; bool allow; + char *path; }; static struct damon_sysfs_filter *damon_sysfs_filter_alloc(void) @@ -774,6 +775,10 @@ damon_sysfs_filter_type_names[] = { .type = DAMON_FILTER_TYPE_ANON, .name = "anon", }, + { + .type = DAMON_FILTER_TYPE_MEMCG, + .name = "memcg", + }, }; static ssize_t type_show(struct kobject *kobj, @@ -862,11 +867,46 @@ static ssize_t allow_store(struct kobject *kobj, return count; } +static ssize_t path_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damon_sysfs_filter *filter = container_of(kobj, + struct damon_sysfs_filter, kobj); + int len; + + if (!mutex_trylock(&damon_sysfs_lock)) + return -EBUSY; + len = sysfs_emit(buf, "%s\n", filter->path ? filter->path : ""); + mutex_unlock(&damon_sysfs_lock); + return len; +} + +static ssize_t path_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damon_sysfs_filter *filter = container_of(kobj, + struct damon_sysfs_filter, kobj); + char *path = kmalloc_objs(*path, size_add(count, 1)); + + if (!path) + return -ENOMEM; + strscpy(path, buf, size_add(count, 1)); + if (!mutex_trylock(&damon_sysfs_lock)) { + kfree(path); + return -EBUSY; + } + kfree(filter->path); + filter->path = path; + mutex_unlock(&damon_sysfs_lock); + return count; +} + static void damon_sysfs_filter_release(struct kobject *kobj) { struct damon_sysfs_filter *filter = container_of(kobj, struct damon_sysfs_filter, kobj); + kfree(filter->path); kfree(filter); } @@ -879,10 +919,14 @@ static struct kobj_attribute damon_sysfs_filter_matching_attr = static struct kobj_attribute damon_sysfs_filter_allow_attr = __ATTR_RW_MODE(allow, 0600); +static struct kobj_attribute damon_sysfs_filter_path_attr = + __ATTR_RW_MODE(path, 0600); + static struct attribute *damon_sysfs_filter_attrs[] = { &damon_sysfs_filter_type_attr.attr, &damon_sysfs_filter_matching_attr.attr, &damon_sysfs_filter_allow_attr.attr, + &damon_sysfs_filter_path_attr.attr, NULL, }; ATTRIBUTE_GROUPS(damon_sysfs_filter); -- 2.47.3