From patchwork Tue Nov 1 22:03:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13027520 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 14B12C433FE for ; Tue, 1 Nov 2022 22:03:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6054B8E0003; Tue, 1 Nov 2022 18:03:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 520A26B0080; Tue, 1 Nov 2022 18:03:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38CD48E0003; Tue, 1 Nov 2022 18:03:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2B9796B007D for ; Tue, 1 Nov 2022 18:03:38 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E8CB5AB32F for ; Tue, 1 Nov 2022 22:03:37 +0000 (UTC) X-FDA: 80086250874.15.D82E959 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf25.hostedemail.com (Postfix) with ESMTP id 5A596A0003 for ; Tue, 1 Nov 2022 22:03:37 +0000 (UTC) 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 D8E4EB81FA0; Tue, 1 Nov 2022 22:03:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBCDEC433D7; Tue, 1 Nov 2022 22:03:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340214; bh=/1k1bBlsjxjo9k4yKNnny083mrtwv5FWU+9lM1PdzeQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VRXQmr3mV2mTLz+4+nYdZKAv6AO3TB8XVGLyNXGM0nSSgG5AbZTa1in/nOl8zUDsK BM92vEa7Ze75qXBbB4lvkORJhA+DhNlHnCwC2KBcRkSKqJNwEkmf5SJYpS+6QTK9Pf ypIr8YDbRCzZ77CmCjkUo8YvVKObinMT6rMhnU3ouu9wyFV6+3ALHP7cJpJZ6lXzaC pNkzIbhS9x51U7S/LPtmIwYfozv51FCau3jFvePiUbjPwIfofxT4tj3ggUwqD8qUNM 5w4BL/hXvdy5wFxZXHz/0Ile5zLQtAzu6woU5LPH2UNUyhdf2iEP35Ae/2Qm1EgU77 HhfKu3/Ino90w== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 2/8] mm/damon/sysfs-schemes: implement schemes/tried_regions directory Date: Tue, 1 Nov 2022 22:03:22 +0000 Message-Id: <20221101220328.95765-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101220328.95765-1-sj@kernel.org> References: <20221101220328.95765-1-sj@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667340217; a=rsa-sha256; cv=none; b=SxHE5TDQpiUyhK+AO91zZugmQUwiCIzXqzbYZoVKNJWJOgvN1UnpNm1TfxaoaQkX7UlhMI rkl+GyUJgdej3a6BmXvymoDEI9dkQcnjw3bRODTPwL7sFxEY9xdELVrouOKFXwl4gz/v8h L3zAOklfQOD5bAfG2LeH5hTaBBiDn7E= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=VRXQmr3m; spf=pass (imf25.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667340217; 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=O6KK2U5/3ncofYbeOs/tMg6vCGEKqqa6+Q4m/z1r/AY=; b=BjbwjnO9lQo629pu9kjaosVWSFqX4Ig/EK6eis05XH8iJgu+XxZ3VKLgi5s5WsgKPyieZK XzWbMHU2uY12ApGM1H23rJwce82zcH/tcOPy10qsXux+KTgEZzeaxvBpvtyvNYXBGN9cTF IeddRZtbywiC/uW78g6XS+nFhdd2k4E= X-Stat-Signature: kgjbsje99nf34m5chjwygp5g976z6tr9 X-Rspamd-Server: rspam09 X-Rspam-User: X-Rspamd-Queue-Id: 5A596A0003 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=VRXQmr3m; spf=pass (imf25.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-HE-Tag: 1667340217-216190 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: For efficient and simple query-like DAMON monitoring results readings and deep level investigations of DAMOS, DAMON kernel API (include/linux/damon.h) users can use 'before_damos_apply' DAMON callback. However, DAMON sysfs interface users don't have such option. Add a directory, namely 'tried_regions', under each scheme directory to use it as the interface for the purpose. Note that this commit is implementing only the directory but the data filling. After the data filling change is made, users will be able to signal DAMON to fill the directory with the regions that corresponding scheme has tried to be applied. By setting the access pattern of the scheme, users could do the efficient query-like monitoring. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 7ea4bcce90cb..f9714ac62565 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -9,6 +9,36 @@ #include "sysfs-common.h" +/* + * scheme regions directory + */ + +struct damon_sysfs_scheme_regions { + struct kobject kobj; +}; + +static struct damon_sysfs_scheme_regions * +damon_sysfs_scheme_regions_alloc(void) +{ + return kzalloc(sizeof(struct damon_sysfs_scheme_regions), GFP_KERNEL); +} + +static void damon_sysfs_scheme_regions_release(struct kobject *kobj) +{ + kfree(container_of(kobj, struct damon_sysfs_scheme_regions, kobj)); +} + +static struct attribute *damon_sysfs_scheme_regions_attrs[] = { + NULL, +}; +ATTRIBUTE_GROUPS(damon_sysfs_scheme_regions); + +static struct kobj_type damon_sysfs_scheme_regions_ktype = { + .release = damon_sysfs_scheme_regions_release, + .sysfs_ops = &kobj_sysfs_ops, + .default_groups = damon_sysfs_scheme_regions_groups, +}; + /* * schemes/stats directory */ @@ -635,6 +665,7 @@ struct damon_sysfs_scheme { struct damon_sysfs_quotas *quotas; struct damon_sysfs_watermarks *watermarks; struct damon_sysfs_stats *stats; + struct damon_sysfs_scheme_regions *tried_regions; }; /* This should match with enum damos_action */ @@ -743,6 +774,25 @@ static int damon_sysfs_scheme_set_stats(struct damon_sysfs_scheme *scheme) return err; } +static int damon_sysfs_scheme_set_tried_regions( + struct damon_sysfs_scheme *scheme) +{ + struct damon_sysfs_scheme_regions *tried_regions = + damon_sysfs_scheme_regions_alloc(); + int err; + + if (!tried_regions) + return -ENOMEM; + err = kobject_init_and_add(&tried_regions->kobj, + &damon_sysfs_scheme_regions_ktype, &scheme->kobj, + "tried_regions"); + if (err) + kobject_put(&tried_regions->kobj); + else + scheme->tried_regions = tried_regions; + return err; +} + static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme) { int err; @@ -759,8 +809,14 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme) err = damon_sysfs_scheme_set_stats(scheme); if (err) goto put_watermarks_quotas_access_pattern_out; + err = damon_sysfs_scheme_set_tried_regions(scheme); + if (err) + goto put_tried_regions_out; return 0; +put_tried_regions_out: + kobject_put(&scheme->tried_regions->kobj); + scheme->tried_regions = NULL; put_watermarks_quotas_access_pattern_out: kobject_put(&scheme->watermarks->kobj); scheme->watermarks = NULL; @@ -781,6 +837,7 @@ static void damon_sysfs_scheme_rm_dirs(struct damon_sysfs_scheme *scheme) kobject_put(&scheme->quotas->kobj); kobject_put(&scheme->watermarks->kobj); kobject_put(&scheme->stats->kobj); + kobject_put(&scheme->tried_regions->kobj); } static ssize_t action_show(struct kobject *kobj, struct kobj_attribute *attr,