From patchwork Tue Nov 1 22:03:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13027519 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 796A2C43217 for ; Tue, 1 Nov 2022 22:03:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90D8D8E0002; Tue, 1 Nov 2022 18:03:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BCF36B007E; Tue, 1 Nov 2022 18:03:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E8928E0002; Tue, 1 Nov 2022 18:03:37 -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 538386B007D for ; Tue, 1 Nov 2022 18:03:37 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0FB1BAB32F for ; Tue, 1 Nov 2022 22:03:37 +0000 (UTC) X-FDA: 80086250874.24.F445927 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf09.hostedemail.com (Postfix) with ESMTP id 7A91A140007 for ; Tue, 1 Nov 2022 22:03:36 +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 0AF52B8117E; Tue, 1 Nov 2022 22:03:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50CFBC43470; 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=1667340213; bh=RJxfjUA7jNYJ7rWPy3bqy3nlzFdR9jtjrg0QcbRrD0Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RLI4dX1ktExmpS86A8YCkyHR1D8R29/qqVpOFjBUDqtvYEmJugGewa7sIYD5WLI9R pBLkM+jK4FtBoIt2BcpKlGqFFuw6XU3fVbXHrSubLQ5kV8nE+QBaTqpKuwaLxclSeg ktyuyFdw5fDZvOgpmgUi5NsOXzvUosBUH+h1EaupHKSxWOLPZ7ZFjZGccgji22fdsq hMKSS3z8J/fXd3CGtSG7hdLUuc3VXOgFZrqQo/QTg9eGN2pFF13QbeLIuFSsqO95L4 0w7ORnyKfxlVwQN0L0jckgI/e93A8xNYx2UNFvn5BUjBy/pHCh7lS4mzsqex25YBBT 4W4WBOLWK5pNw== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 1/8] mm/damon/core: add a callback for scheme target regions check Date: Tue, 1 Nov 2022 22:03:21 +0000 Message-Id: <20221101220328.95765-2-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=1667340216; a=rsa-sha256; cv=none; b=h5Kdr+QlSxO/9QRM/mG/X2blSB59Pq3RBn1n1pJr0I8W8Tt7YEJXFlTU7fM/RJ/HIXUVGP FiWCxxpKHB+Oh3VlvWSFVv60dw9gfXUNeIS3ENZemSLQC/Ibb8z+AgAy1UvG+ng/6wIxyH 5etFt1CDUOKPg4sODJOBJm51X+tYdQU= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RLI4dX1k; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf09.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 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=1667340216; 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=EXkZ4TwVf7k625+CETvzJOgBQodzs6O4Nx6b81uQxAg=; b=JvY3HCnLFUFwWiakT67T9/aYzQ4eHPqJPABsSDzxUIsBVi+WnkO6PNAPdpvfk6njIIZgoN PzCZfpezz4zVOYjOf/DDgpxiAHgupHIhbgba5V/diuU/Z5e09URDofhwpb4TYXoJsX/ZBV okgBQ+WUxsVzx/S8uUMpwEMoomjdzeo= X-Rspamd-Server: rspam02 X-Rspam-User: Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RLI4dX1k; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf09.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org X-Stat-Signature: ubokz8amf46ggubcnqz1qepdg3n9df5s X-Rspamd-Queue-Id: 7A91A140007 X-HE-Tag: 1667340216-983400 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: Getting DAMON monitoring results of only specific access pattern (e.g., getting address ranges of memory that not accessed at all for two minutes) can be useful for efficient monitoring of the system. The information can also be helpful for deep level investigation of DAMON-based operation schemes. For that, users need to record (in case of the user space users) or iterate (in case of the kernel space users) full monitoring results and filter it out for the specific access pattern. In case of the DAMOS investigation, users will even need to simulate DAMOS' quota and prioritization mechanisms. It's inefficient and complex. Add a new DAMON callback that will be called before each scheme is applied to each region. DAMON kernel API users will be able to do the query-like monitoring results collection, or DAMOS investigation in an efficient and simple way using it. Commits for providing the capability to the user space users will follow. Signed-off-by: SeongJae Park --- include/linux/damon.h | 5 +++++ mm/damon/core.c | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 620ada094c3b..35630634d790 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -357,6 +357,7 @@ struct damon_operations { * @after_wmarks_check: Called after each schemes' watermarks check. * @after_sampling: Called after each sampling. * @after_aggregation: Called after each aggregation. + * @before_damos_apply: Called before applying DAMOS action. * @before_terminate: Called before terminating the monitoring. * @private: User private data. * @@ -385,6 +386,10 @@ struct damon_callback { int (*after_wmarks_check)(struct damon_ctx *context); int (*after_sampling)(struct damon_ctx *context); int (*after_aggregation)(struct damon_ctx *context); + int (*before_damos_apply)(struct damon_ctx *context, + struct damon_target *target, + struct damon_region *region, + struct damos *scheme); void (*before_terminate)(struct damon_ctx *context); }; diff --git a/mm/damon/core.c b/mm/damon/core.c index 80d5937fe337..ceec75b88ef9 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -772,6 +772,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, unsigned long sz = damon_sz_region(r); struct timespec64 begin, end; unsigned long sz_applied = 0; + int err = 0; if (c->ops.apply_scheme) { if (quota->esz && quota->charged_sz + sz > quota->esz) { @@ -782,7 +783,10 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, damon_split_region_at(t, r, sz); } ktime_get_coarse_ts64(&begin); - sz_applied = c->ops.apply_scheme(c, t, r, s); + if (c->callback.before_damos_apply) + err = c->callback.before_damos_apply(c, t, r, s); + if (!err) + sz_applied = c->ops.apply_scheme(c, t, r, s); ktime_get_coarse_ts64(&end); quota->total_charged_ns += timespec64_to_ns(&end) - timespec64_to_ns(&begin); 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, From patchwork Tue Nov 1 22:03:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13027518 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 3087FC4332F for ; Tue, 1 Nov 2022 22:03:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B30AE8E0001; Tue, 1 Nov 2022 18:03:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB9346B007B; Tue, 1 Nov 2022 18:03:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 980068E0001; Tue, 1 Nov 2022 18:03:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 89FBC6B0078 for ; Tue, 1 Nov 2022 18:03:36 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 557ADC0D35 for ; Tue, 1 Nov 2022 22:03:36 +0000 (UTC) X-FDA: 80086250832.09.CA191E0 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf25.hostedemail.com (Postfix) with ESMTP id E15EEA0006 for ; Tue, 1 Nov 2022 22:03:35 +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 dfw.source.kernel.org (Postfix) with ESMTPS id 2CBBE61743; Tue, 1 Nov 2022 22:03:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 928B3C43142; Tue, 1 Nov 2022 22:03:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340215; bh=XxGyls76cTczQSYbHGWLSQPHsDHsExVHyaRCBahnUas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UxJvwbxFB1J9f80vW7kpTG/zCmaSFESpIAdMc8Amk+KLCgH1unPsrgot7xb4h8Lu6 n3Edt8+y5wwQkg7sjdMBu6qFeJp2AdKB7Kv20dM+FXWs5fATQdEbLiyaficPI2HNKX PWGBcW+HSi9MgHefe2d+5wbv2t/VWmGl0M7KwSET0rVu27ZwAWt3NMPrl1XRLpakRF RE3FPATrQYmQ9l9CPKTeL/w3fQ4R6FWb2FfhA3aj8mcUsNtJVJq6mdeqiC/9nv7edv N6hxYRWyfbCgpL/oxudbsvef6y8ewHiQ/5Jv/E0vgB5CWt0Fo1AJVWYEvHpnyzPV74 C2/h2edjDoHgA== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 3/8] mm/damon/sysfs-schemes: implement scheme region directory Date: Tue, 1 Nov 2022 22:03:23 +0000 Message-Id: <20221101220328.95765-4-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=1667340216; a=rsa-sha256; cv=none; b=F6LktUkI3JrmmW6GlzBCjzFJx3eUhj5aBk8eeFStnfMED+vrr6R+55VWrm6hC0Xn4pXZmz gW1xMZ/CQ4XjWcLDx9eW52/gIK6UO2XzuwqG/x5dIztxjOdxe7rw33zLkGvcp6Ln9cj9Wm fi5UTSw/gGhkjqxpeyzwd1B4AqrX5I8= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UxJvwbxF; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf25.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=1667340216; 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=v/dR5inH3s1H8zXhPrusz9pz7H2K1iwxE8H3Ys03MYY=; b=eyJEYt+rkoTmsdLTfnaokEYENn3x7wdcjzPrbvFlJHn95FFWaiaiHGrFKlouQe0hQppSVS B/Oe4Lm3Y2EflE/JSl/q1XuopJGpQ3yu3n7hb1VzOIvZQ9ueCrsorS28J8GkQZGrQqsWHQ iU7NELvbvSZjC87kJR7Fcg7Mbyqv+fY= X-Stat-Signature: n9qup9byqpub7mn1zpx1pqdrsjfpxc6d X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E15EEA0006 X-Rspam-User: Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UxJvwbxF; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf25.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org X-HE-Tag: 1667340215-579555 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: Implement region directories under 'tried_regions' directory of each scheme DAMON sysfs directory. This directory will provide the address range, the monitored access frequency ('nr_accesses'), and the age of each DAMON region that corresponding DAMON-based operation scheme has tried to be applied. Note that this commit doesn't implement the code for filling the data but only the sysfs directory. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 123 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index f9714ac62565..1a8ab6341bf1 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -9,18 +9,138 @@ #include "sysfs-common.h" +/* + * scheme region directory + */ + +struct damon_sysfs_scheme_region { + struct kobject kobj; + struct damon_addr_range ar; + unsigned int nr_accesses; + unsigned int age; + struct list_head list; +}; + +static struct damon_sysfs_scheme_region *damon_sysfs_scheme_region_alloc( + struct damon_region *region) +{ + struct damon_sysfs_scheme_region *sysfs_region = kmalloc( + sizeof(*sysfs_region), GFP_KERNEL); + + if (!sysfs_region) + return NULL; + sysfs_region->kobj = (struct kobject){}; + sysfs_region->ar = region->ar; + sysfs_region->nr_accesses = region->nr_accesses; + sysfs_region->age = region->age; + INIT_LIST_HEAD(&sysfs_region->list); + return sysfs_region; +} + +static ssize_t start_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + struct damon_sysfs_scheme_region *region = container_of(kobj, + struct damon_sysfs_scheme_region, kobj); + + return sysfs_emit(buf, "%lu\n", region->ar.start); +} + +static ssize_t end_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + struct damon_sysfs_scheme_region *region = container_of(kobj, + struct damon_sysfs_scheme_region, kobj); + + return sysfs_emit(buf, "%lu\n", region->ar.end); +} + +static ssize_t nr_accesses_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damon_sysfs_scheme_region *region = container_of(kobj, + struct damon_sysfs_scheme_region, kobj); + + return sysfs_emit(buf, "%u\n", region->nr_accesses); +} + +static ssize_t age_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + struct damon_sysfs_scheme_region *region = container_of(kobj, + struct damon_sysfs_scheme_region, kobj); + + return sysfs_emit(buf, "%u\n", region->age); +} + +static void damon_sysfs_scheme_region_release(struct kobject *kobj) +{ + struct damon_sysfs_scheme_region *region = container_of(kobj, + struct damon_sysfs_scheme_region, kobj); + + list_del(®ion->list); + kfree(region); +} + +static struct kobj_attribute damon_sysfs_scheme_region_start_attr = + __ATTR_RO_MODE(start, 0400); + +static struct kobj_attribute damon_sysfs_scheme_region_end_attr = + __ATTR_RO_MODE(end, 0400); + +static struct kobj_attribute damon_sysfs_scheme_region_nr_accesses_attr = + __ATTR_RO_MODE(nr_accesses, 0400); + +static struct kobj_attribute damon_sysfs_scheme_region_age_attr = + __ATTR_RO_MODE(age, 0400); + +static struct attribute *damon_sysfs_scheme_region_attrs[] = { + &damon_sysfs_scheme_region_start_attr.attr, + &damon_sysfs_scheme_region_end_attr.attr, + &damon_sysfs_scheme_region_nr_accesses_attr.attr, + &damon_sysfs_scheme_region_age_attr.attr, + NULL, +}; +ATTRIBUTE_GROUPS(damon_sysfs_scheme_region); + +static struct kobj_type damon_sysfs_scheme_region_ktype = { + .release = damon_sysfs_scheme_region_release, + .sysfs_ops = &kobj_sysfs_ops, + .default_groups = damon_sysfs_scheme_region_groups, +}; + /* * scheme regions directory */ struct damon_sysfs_scheme_regions { struct kobject kobj; + struct list_head regions_list; + int nr_regions; }; static struct damon_sysfs_scheme_regions * damon_sysfs_scheme_regions_alloc(void) { - return kzalloc(sizeof(struct damon_sysfs_scheme_regions), GFP_KERNEL); + struct damon_sysfs_scheme_regions *regions = kmalloc(sizeof(*regions), + GFP_KERNEL); + + regions->kobj = (struct kobject){}; + INIT_LIST_HEAD(®ions->regions_list); + regions->nr_regions = 0; + return regions; +} + +static void damon_sysfs_scheme_regions_rm_dirs( + struct damon_sysfs_scheme_regions *regions) +{ + struct damon_sysfs_scheme_region *r, *next; + + list_for_each_entry_safe(r, next, ®ions->regions_list, list) { + /* release function deletes it from the list */ + kobject_put(&r->kobj); + regions->nr_regions--; + } } static void damon_sysfs_scheme_regions_release(struct kobject *kobj) @@ -837,6 +957,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); + damon_sysfs_scheme_regions_rm_dirs(scheme->tried_regions); kobject_put(&scheme->tried_regions->kobj); } From patchwork Tue Nov 1 22:03:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13027521 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 5CE63C43217 for ; Tue, 1 Nov 2022 22:03:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A74846B0081; Tue, 1 Nov 2022 18:03:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 933A28E0006; 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 5FE0F6B007E; Tue, 1 Nov 2022 18:03:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 481BC6B007D for ; Tue, 1 Nov 2022 18:03:38 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2034DA0404 for ; Tue, 1 Nov 2022 22:03:38 +0000 (UTC) X-FDA: 80086250916.13.A41459D Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf14.hostedemail.com (Postfix) with ESMTP id 96A0C100004 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 EA7B4B81FA5; Tue, 1 Nov 2022 22:03:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38F21C433C1; Tue, 1 Nov 2022 22:03:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340215; bh=2CYTY0LTOD+j47uyqqEPkxAe2vTbM34BEl7VdIQiTbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NY0KGL9pnY8GRjz9mElbgeCD51TS1y9GeR2s5INOEzxXIMsYm/2meHVH0xEcDnXJm vJsPZSH+M3AOlPfc0krvSGWWkOjqWxnOuhMWcSqEexGLkB0ws0sdhuTwFGQpzxSKvH pZgpmh82gjcDbk1VX9MUb1UPnYRPZbSciNV6cy83JbBCsukHoLTMiuRzumD0Zj2lZF JtrTOtcScrMnHnKUJjq5LdQ/yxaKfA8VEx4CZXcpKoZV74AQY4HyHLzD049lyabwsI R4UACiazfXFyVEc44+Yjb2WuzAI1/x6axaxyqNVkyUHNKhC7b1mbHsLERNowe4NqhP 3kS43a1xs7LVg== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 4/8] mm/damon/sysfs: implement DAMOS tried regions update command Date: Tue, 1 Nov 2022 22:03:24 +0000 Message-Id: <20221101220328.95765-5-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=49apCQpV5EmtETV1P8AKKAnWIRE+0oQnCqyhjHhU9rDElHyYEh3fAUXFPwuo0AV/WT0hY3 K6AlueSjV3eYveCysBJQXHFMNBWJb32gELr/stm9XL2lhCrrTe42LAjYmGBavu6POTihoK NFJN9zNxAZEvzzhBegj97bf0VUC94jg= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NY0KGL9p; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 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=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=kfvO97qN1uZg1TjajpDB78wKYckrQS+z/rzngB3fjqU=; b=0YetRv/zs20eFTkoY/udQLzoYgjBh3fsvWvyJTajfz/0q2InFc8k2/7k08rgdVX/zSyG4Z IPn54wc34djYT4P25BilgTuaa7EkomD6rJiht4ADLn3e1gMyKlk3p1eIrY1XeUhaefYe/H TCnCyFhZ3GNe49sm9xu47OrwpQdbvSs= X-Stat-Signature: wiyc5cdxubwcmdg48io83gpqt8pp867f X-Rspamd-Queue-Id: 96A0C100004 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NY0KGL9p; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1667340217-476738 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: Implement the code for filling the data of 'tried_regions' DAMON sysfs directory. With this commit, DAMON sysfs interface users can write a special keyword, 'update_schemes_tried_regions' to the corresponding 'state' file of the kdamond. Then, DAMON sysfs interface will collect the tried regions information using the 'before_damos_apply()' callback for one aggregation interval and populate scheme region directories with the values. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 6 ++++ mm/damon/sysfs-schemes.c | 75 ++++++++++++++++++++++++++++++++++++++++ mm/damon/sysfs.c | 57 ++++++++++++++++++++++++++++-- 3 files changed, 136 insertions(+), 2 deletions(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index 4626b2784404..634a6e7fca78 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -44,3 +44,9 @@ int damon_sysfs_set_schemes(struct damon_ctx *ctx, void damon_sysfs_schemes_update_stats( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx); + +int damon_sysfs_schemes_update_regions_start( + struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx); + +int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 1a8ab6341bf1..dd4ecd093cd6 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1198,3 +1198,78 @@ void damon_sysfs_schemes_update_stats( sysfs_stats->qt_exceeds = scheme->stat.qt_exceeds; } } + +/* + * damon_sysfs_schemes that need to update its schemes regions dir. Protected + * by damon_sysfs_lock + */ +static struct damon_sysfs_schemes *damon_sysfs_schemes_for_damos_callback; +static int damon_sysfs_schemes_region_idx; + +/* + * DAMON callback that called before damos apply. While this callback is + * registered, damon_sysfs_lock should be held to ensure the regions + * directories exist. + */ +static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, + struct damon_target *t, struct damon_region *r, + struct damos *s) +{ + struct damos *scheme; + struct damon_sysfs_scheme_regions *sysfs_regions; + struct damon_sysfs_scheme_region *region; + struct damon_sysfs_schemes *sysfs_schemes = + damon_sysfs_schemes_for_damos_callback; + int schemes_idx = 0; + + damon_for_each_scheme(scheme, ctx) { + if (scheme == s) + break; + schemes_idx++; + } + sysfs_regions = sysfs_schemes->schemes_arr[schemes_idx]->tried_regions; + region = damon_sysfs_scheme_region_alloc(r); + list_add_tail(®ion->list, &sysfs_regions->regions_list); + sysfs_regions->nr_regions++; + if (kobject_init_and_add(®ion->kobj, + &damon_sysfs_scheme_region_ktype, + &sysfs_regions->kobj, "%d", + damon_sysfs_schemes_region_idx++)) { + kobject_put(®ion->kobj); + } + return 0; +} + +/* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ +int damon_sysfs_schemes_update_regions_start( + struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx) +{ + struct damos *scheme; + int schemes_idx = 0; + + damon_for_each_scheme(scheme, ctx) { + struct damon_sysfs_scheme *sysfs_scheme; + + sysfs_scheme = sysfs_schemes->schemes_arr[schemes_idx++]; + damon_sysfs_scheme_regions_rm_dirs( + sysfs_scheme->tried_regions); + } + + damon_sysfs_schemes_for_damos_callback = sysfs_schemes; + ctx->callback.before_damos_apply = damon_sysfs_before_damos_apply; + return 0; +} + +/* + * Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock. Caller + * should unlock damon_sysfs_lock which held before + * damon_sysfs_schemes_update_regions_start() + */ +int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx) +{ + damon_sysfs_schemes_for_damos_callback = NULL; + ctx->callback.before_damos_apply = NULL; + damon_sysfs_schemes_region_idx = 0; + return 0; +} diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 284daf274b3e..ffb5a84059d7 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -999,6 +999,11 @@ enum damon_sysfs_cmd { * files. */ DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS, + /* + * @DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS: Update schemes tried + * regions + */ + DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS, /* * @NR_DAMON_SYSFS_CMDS: Total number of DAMON sysfs commands. */ @@ -1011,6 +1016,7 @@ static const char * const damon_sysfs_cmd_strs[] = { "off", "commit", "update_schemes_stats", + "update_schemes_tried_regions", }; /* @@ -1193,6 +1199,16 @@ static int damon_sysfs_set_targets(struct damon_ctx *ctx, static void damon_sysfs_before_terminate(struct damon_ctx *ctx) { struct damon_target *t, *next; + struct damon_sysfs_kdamond *kdamond; + + /* damon_sysfs_schemes_update_regions_stop() might not yet called */ + kdamond = damon_sysfs_cmd_request.kdamond; + if (kdamond && damon_sysfs_cmd_request.cmd == + DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS && + ctx == kdamond->damon_ctx) { + damon_sysfs_schemes_update_regions_stop(ctx); + mutex_unlock(&damon_sysfs_lock); + } if (!damon_target_has_pid(ctx)) return; @@ -1225,6 +1241,27 @@ static int damon_sysfs_upd_schemes_stats(struct damon_sysfs_kdamond *kdamond) return 0; } +static int damon_sysfs_upd_schemes_regions_start( + struct damon_sysfs_kdamond *kdamond) +{ + struct damon_ctx *ctx = kdamond->damon_ctx; + + if (!ctx) + return -EINVAL; + return damon_sysfs_schemes_update_regions_start( + kdamond->contexts->contexts_arr[0]->schemes, ctx); +} + +static int damon_sysfs_upd_schemes_regions_stop( + struct damon_sysfs_kdamond *kdamond) +{ + struct damon_ctx *ctx = kdamond->damon_ctx; + + if (!ctx) + return -EINVAL; + return damon_sysfs_schemes_update_regions_stop(ctx); +} + static inline bool damon_sysfs_kdamond_running( struct damon_sysfs_kdamond *kdamond) { @@ -1277,10 +1314,12 @@ static int damon_sysfs_commit_input(struct damon_sysfs_kdamond *kdamond) static int damon_sysfs_cmd_request_callback(struct damon_ctx *c) { struct damon_sysfs_kdamond *kdamond; + static bool damon_sysfs_schemes_regions_updating; int err = 0; /* avoid deadlock due to concurrent state_store('off') */ - if (!mutex_trylock(&damon_sysfs_lock)) + if (!damon_sysfs_schemes_regions_updating && + !mutex_trylock(&damon_sysfs_lock)) return 0; kdamond = damon_sysfs_cmd_request.kdamond; if (!kdamond || kdamond->damon_ctx != c) @@ -1292,13 +1331,27 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c) case DAMON_SYSFS_CMD_COMMIT: err = damon_sysfs_commit_input(kdamond); break; + case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS: + if (!damon_sysfs_schemes_regions_updating) { + err = damon_sysfs_upd_schemes_regions_start(kdamond); + if (!err) { + damon_sysfs_schemes_regions_updating = true; + goto keep_lock_out; + } + } else { + err = damon_sysfs_upd_schemes_regions_stop(kdamond); + damon_sysfs_schemes_regions_updating = false; + } + break; default: break; } /* Mark the request as invalid now. */ damon_sysfs_cmd_request.kdamond = NULL; out: - mutex_unlock(&damon_sysfs_lock); + if (!damon_sysfs_schemes_regions_updating) + mutex_unlock(&damon_sysfs_lock); +keep_lock_out: return err; } From patchwork Tue Nov 1 22:03:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13027522 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 D1544C4332F for ; Tue, 1 Nov 2022 22:03:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D7AD38E0006; Tue, 1 Nov 2022 18:03:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D2BA38E0005; 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 A6F986B0080; Tue, 1 Nov 2022 18:03:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 89FBD8E0005 for ; Tue, 1 Nov 2022 18:03:38 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5FD4A140239 for ; Tue, 1 Nov 2022 22:03:38 +0000 (UTC) X-FDA: 80086250916.08.658128C Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf10.hostedemail.com (Postfix) with ESMTP id D01EFC0002 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 8955CB81136; Tue, 1 Nov 2022 22:03:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3191C4347C; Tue, 1 Nov 2022 22:03:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340216; bh=Lnuz++qjG0JC7do/edydo/RT8MRUCyAyDHoJawRr9C4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L6wTjkBdABD96HBqCndDJYbQguK9IQlUs+VxKiKGMy4zPGLQb9UTBcjMLxADqPLLn 6sy06r4zbGougpPdg5OvORgCvcptReeQ6E+q9e7zAkexbBYsZYrqsZRJseNemMsKCm g6Z2u6rybAbV3UgyaJ5gWo5RA/FBiztQF8/2giC+FpE0wkQvqJwxq+jTs0NDNXSzFk Kf/Gh0u+U3Zn2BUg4iqRWdGwnkAZOq6XGxSjfkFnyo0kj6OZnWwYjEDzO2aMFAbCoG W9r9NkOXZc2kq7qDXswlwTXKGKMjjUYv41tricygG6j9gXQaJ411SOwmRhRv+l77/j ohKUbZ83uBJtw== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 5/8] mm/damon/sysfs-schemes: implement DAMOS-tried regions clear command Date: Tue, 1 Nov 2022 22:03:25 +0000 Message-Id: <20221101220328.95765-6-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-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=L6wTjkBd; spf=pass (imf10.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667340218; a=rsa-sha256; cv=none; b=wRTJ1Eapp5Lozcq8F8QIGcQb0JhkJqHZUP6A03zPet2uGP8kIEx8jblg44Z53aWHEL7UFn 8iMz1Baqe+q73Rw+22CnXWSIXH+2NagB+KSREmeOeRUJt1LOMfDHV3uxLJTQVbtpKXjrV4 /eHOgoDFUs7wWwi0WLf6E4xNbjZBrn8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667340218; 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=NhQMagr+R0nIjlkmsHqwTFmonaoJNXjcluUt4LNy3Wk=; b=amWuM15FQA3yVJs9S8G7ws0S/DrHZKyR/re0j3SmMnEhHFTfE0BYcIAcnkoYPIppnE619D rc9wh/5iJN7MdLoSLyKvhsWVg8FpZEcCcOqkDbZOmlVErtnZPXrlPIc9RfRGrKUCcFeYwB Bz8x5rN5mDVxsrU3rnq2fqZpGW/UnEY= X-Stat-Signature: af5wpb47bkowdp4xw6w9ku5cnyr5iasu X-Rspamd-Queue-Id: D01EFC0002 X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=L6wTjkBd; spf=pass (imf10.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-Rspamd-Server: rspam01 X-HE-Tag: 1667340217-883462 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: When there are huge number of DAMON regions that specific scheme actions are tried to be applied, directories and files under 'tried_regions' scheme directory could waste some memory. Add another special input keyword ('clear_schemes_tried_regions') for 'state' file of each kdamond sysfs directory that can be used for cleanup of the 'tried_regions' sub-directories. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 4 ++++ mm/damon/sysfs-schemes.c | 10 +++++++++- mm/damon/sysfs.c | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index 634a6e7fca78..604a6cbc3ede 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -50,3 +50,7 @@ int damon_sysfs_schemes_update_regions_start( struct damon_ctx *ctx); int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); + +int damon_sysfs_schemes_clear_regions( + struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx); diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index dd4ecd093cd6..f0b616f5ffc1 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1241,7 +1241,7 @@ static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, } /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ -int damon_sysfs_schemes_update_regions_start( +int damon_sysfs_schemes_clear_regions( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx) { @@ -1255,7 +1255,15 @@ int damon_sysfs_schemes_update_regions_start( damon_sysfs_scheme_regions_rm_dirs( sysfs_scheme->tried_regions); } + return 0; +} +/* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ +int damon_sysfs_schemes_update_regions_start( + struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx) +{ + damon_sysfs_schemes_clear_regions(sysfs_schemes, ctx); damon_sysfs_schemes_for_damos_callback = sysfs_schemes; ctx->callback.before_damos_apply = damon_sysfs_before_damos_apply; return 0; diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index ffb5a84059d7..aeb0beb1da91 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1004,6 +1004,11 @@ enum damon_sysfs_cmd { * regions */ DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS, + /* + * @DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: Clear schemes tried + * regions + */ + DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS, /* * @NR_DAMON_SYSFS_CMDS: Total number of DAMON sysfs commands. */ @@ -1017,6 +1022,7 @@ static const char * const damon_sysfs_cmd_strs[] = { "commit", "update_schemes_stats", "update_schemes_tried_regions", + "clear_schemes_tried_regions", }; /* @@ -1262,6 +1268,17 @@ static int damon_sysfs_upd_schemes_regions_stop( return damon_sysfs_schemes_update_regions_stop(ctx); } +static int damon_sysfs_clear_schemes_regions( + struct damon_sysfs_kdamond *kdamond) +{ + struct damon_ctx *ctx = kdamond->damon_ctx; + + if (!ctx) + return -EINVAL; + return damon_sysfs_schemes_clear_regions( + kdamond->contexts->contexts_arr[0]->schemes, ctx); +} + static inline bool damon_sysfs_kdamond_running( struct damon_sysfs_kdamond *kdamond) { @@ -1343,6 +1360,9 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c) damon_sysfs_schemes_regions_updating = false; } break; + case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: + err = damon_sysfs_clear_schemes_regions(kdamond); + break; default: break; } From patchwork Tue Nov 1 22:03:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13027524 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 76FBFC4332F for ; Tue, 1 Nov 2022 22:03:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE3A78E0008; Tue, 1 Nov 2022 18:03:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A27E88E0009; Tue, 1 Nov 2022 18:03:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7ABA68E0008; Tue, 1 Nov 2022 18:03:40 -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 6A4A68E0005 for ; Tue, 1 Nov 2022 18:03:40 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 411701C689A for ; Tue, 1 Nov 2022 22:03:40 +0000 (UTC) X-FDA: 80086251000.14.7AE4709 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf27.hostedemail.com (Postfix) with ESMTP id A8F8040007 for ; Tue, 1 Nov 2022 22:03:39 +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 3980CB8117E; Tue, 1 Nov 2022 22:03:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7192BC433B5; Tue, 1 Nov 2022 22:03:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340216; bh=vHgDcIM2X6HC9Xa44Y3Kmnj3zbAk0A48a3qye0uZNww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BB9iuPFmaCYxUJ2icGWtplwAv9fDjQQP8tssoMnF+QYSch4jkG2Gs9jcRHdDg0eLl UN8aSiWrnsriBYDwmlGxbAstIhanC5uEyC9Jlpqz+62z/zkh9J/rPvtRkVkQri7HTz vkQAMOPJG2EgQrODDLra5lazx51qMuIpWcddNcp2JSkKyg7YxGFaX6ZC+fU5aX61rP h6OeWNswACf+ieCA59Ivg5Jl6tF9P/qMwigIaQUxIlmwgrN5LNFsHwmCU8PibAHpaI lDTn7q6EgOXaDMN+LyyE4By4/ykc4vfJZ1mMCKzxY5Pf/etnSIXTU2t3JeollfAF/d JkLl+MMlB1/Mg== From: SeongJae Park To: Andrew Morton Cc: Shuah Khan , damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 6/8] tools/selftets/damon/sysfs: test tried_regions directory existence Date: Tue, 1 Nov 2022 22:03:26 +0000 Message-Id: <20221101220328.95765-7-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=1667340219; a=rsa-sha256; cv=none; b=kkUY+FewqLgARko7CxVKXTRKOmxt5uijT3xOA7+BvyCGk8FPmsP3ngZf1T8/Y23aXqLonK 6bRNAWnDTtcJTAPa9mP60ReKO3ZwMQ/wYgJTefkSkmYuxpa2b6TRmvObkzRTurqTzdYDRt qS75y/EavHooseHxoza4Z8HaUtSDtCM= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BB9iuPFm; spf=pass (imf27.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=1667340219; 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=0mnNHQHnS5UMONrCQ+JY25XGOE4490loOGbbhlBwmLA=; b=lDse1Vg6HvPhcHZjPsBGW/zbPFYJFIqMeBB29AkG368FSWfP5sW8HBx6dPddQn4Su2Y/Ta DkKCCfg+autvTj4KsfunGYgTxlnw+H5FLlaxE/KZcXecuYZYCg0QPQ6PbbwHI7hGa4NDIZ RW4gLtew0ZxciI0Zb+d+RJ00Pewww/0= X-Stat-Signature: szz7tnttq95sfe9y466wzyhf45h6tjo1 X-Rspamd-Server: rspam09 X-Rspam-User: X-Rspamd-Queue-Id: A8F8040007 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BB9iuPFm; spf=pass (imf27.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: 1667340219-393760 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: Add a simple test case for ensuring tried_regions directory existence. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/sysfs.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/testing/selftests/damon/sysfs.sh b/tools/testing/selftests/damon/sysfs.sh index 89592c64462f..db4942383a50 100644 --- a/tools/testing/selftests/damon/sysfs.sh +++ b/tools/testing/selftests/damon/sysfs.sh @@ -80,6 +80,12 @@ test_range() ensure_file "$range_dir/max" "exist" 600 } +test_tried_regions() +{ + tried_regions_dir=$1 + ensure_dir "$tried_regions_dir" "exist" +} + test_stats() { stats_dir=$1 @@ -138,6 +144,7 @@ test_scheme() test_quotas "$scheme_dir/quotas" test_watermarks "$scheme_dir/watermarks" test_stats "$scheme_dir/stats" + test_tried_regions "$scheme_dir/tried_regions" } test_schemes() From patchwork Tue Nov 1 22:03:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13027523 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 268C2C43217 for ; Tue, 1 Nov 2022 22:03:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D4FA8E0007; Tue, 1 Nov 2022 18:03:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E9B08E0005; Tue, 1 Nov 2022 18:03:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53A7B8E0007; Tue, 1 Nov 2022 18:03:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 45DF58E0005 for ; Tue, 1 Nov 2022 18:03:39 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EE194C10AF for ; Tue, 1 Nov 2022 22:03:38 +0000 (UTC) X-FDA: 80086250916.05.5C7798A Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf03.hostedemail.com (Postfix) with ESMTP id 94C7820004 for ; Tue, 1 Nov 2022 22:03:38 +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 dfw.source.kernel.org (Postfix) with ESMTPS id D228061743; Tue, 1 Nov 2022 22:03:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C393C433C1; Tue, 1 Nov 2022 22:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340217; bh=XY/ulrYaYGf2HDwTIn5UM+YygVjoR1FVPIUX5UmsGLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gAuVFi8XC9immb+OBoh45a69etCiIxST3cQ8zlUrBziijVny5gzKm1g6mJqPwryDE gu2m/my5MjOsEff8QdTwpPM2gvreMqHywFlVaGUGE6HrZCS5jBn8HAUSAu7K0t+t8b 3+ATJxW4lPChNcbiIe/KTaGpulS+IsO62n4Zh6qaDCvakn40ifgWtX2ZMwmtuuMFis W2Dd1zQSIB/iAhpN+GeC9JlZtMW1pwuE/lQU7II4S32fjxG6RY/WSqOEzOeQ1hb4c0 9C9pYgxdYobujW+mCapDZEkkGu5CLw0gQj/h94WcbzWiluppkFQGpJWraXyg90HgV/ mpibBeqhmoKNQ== From: SeongJae Park To: Andrew Morton Cc: Jonathan Corbet , damon@lists.linux.dev, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 7/8] Docs/admin-guide/mm/damon/usage: document schemes//tried_regions sysfs directory Date: Tue, 1 Nov 2022 22:03:27 +0000 Message-Id: <20221101220328.95765-8-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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667340218; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZX1igYP/rs92xwNiIj8Ueo+nL/HoVT5aqpHabIfmrIY=; b=eZ6g9pVcS6YOYKTCsmdZXhW6+ZfvYXlOpTiN/U+KKCS+hfKPlARGgX6o4NYHcFG4erummj kRBpPV3OdbYgvEea15i+yxwtVq2KAUBIakNQdfHKUUXm+WRE24v7TRTgcudKIfF5lI4hcd HGYRGrauEtJQh6vfqvmW+8nR1ikEq9g= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gAuVFi8X; spf=pass (imf03.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667340218; a=rsa-sha256; cv=none; b=PvSqjpv7K+GB1GBPBo+UXa0oWBH2BLtNuNH6vqO21dMctKq3Bo8Uhg1mwQl62g7fx6Wpd6 l0a8L8wctAiJF3w+MLrfRiC063PpKbRUa0twXHZ2TUSFMrzVDmX/fdSdH84OOnirgeEGU2 Eihov8ytaMux5Ue4jp77tzj41u4Gpcc= X-Stat-Signature: rt6ay77naj9wtn1o5bzjyo831ne5x5m5 X-Rspamd-Queue-Id: 94C7820004 X-Rspamd-Server: rspam06 X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gAuVFi8X; spf=pass (imf03.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-HE-Tag: 1667340218-613344 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: Document 'tried_regions' directory in DAMON sysfs interface usage in the administrator guide. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 45 ++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst index c17e02e1e426..1a5b6b71efa1 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -88,6 +88,9 @@ comma (","). :: │ │ │ │ │ │ │ │ weights/sz_permil,nr_accesses_permil,age_permil │ │ │ │ │ │ │ watermarks/metric,interval_us,high,mid,low │ │ │ │ │ │ │ stats/nr_tried,sz_tried,nr_applied,sz_applied,qt_exceeds + │ │ │ │ │ │ │ tried_regions/ + │ │ │ │ │ │ │ │ 0/start,end,nr_accesses,age + │ │ │ │ │ │ │ │ ... │ │ │ │ │ │ ... │ │ │ │ ... │ │ ... @@ -125,7 +128,14 @@ in the state. Writing ``commit`` to the ``state`` file makes kdamond reads the user inputs in the sysfs files except ``state`` file again. Writing ``update_schemes_stats`` to ``state`` file updates the contents of stats files for each DAMON-based operation scheme of the kdamond. For details of the -stats, please refer to :ref:`stats section `. +stats, please refer to :ref:`stats section `. Writing +``update_schemes_tried_regions`` to ``state`` file updates the DAMON-based +operation scheme action tried regions directory for each DAMON-based operation +scheme of the kdamond. Writing ``clear_schemes_tried_regions`` to ``state`` +file clears the DAMON-based operating scheme action tried regions directory for +each DAMON-based operation scheme of the kdamond. For details of the +DAMON-based operation scheme action tried regions directory, please refer to +:ref:tried_regions section `. If the state is ``on``, reading ``pid`` shows the pid of the kdamond thread. @@ -166,6 +176,8 @@ You can set and get what type of monitoring operations DAMON will use for the context by writing one of the keywords listed in ``avail_operations`` file and reading from the ``operations`` file. +.. _sysfs_monitoring_attrs: + contexts//monitoring_attrs/ ------------------------------ @@ -255,8 +267,9 @@ to ``N-1``. Each directory represents each DAMON-based operation scheme. schemes// ------------ -In each scheme directory, four directories (``access_pattern``, ``quotas``, -``watermarks``, and ``stats``) and one file (``action``) exist. +In each scheme directory, five directories (``access_pattern``, ``quotas``, +``watermarks``, ``stats``, and ``tried_regions``) and one file (``action``) +exist. The ``action`` file is for setting and getting what action you want to apply to memory regions having specific access pattern of the interest. The keywords @@ -351,6 +364,32 @@ should ask DAMON sysfs interface to updte the content of the files for the stats by writing a special keyword, ``update_schemes_stats`` to the relevant ``kdamonds//state`` file. +.. _sysfs_schemes_tried_regions: + +schemes//tried_regions/ +-------------------------- + +When a special keyword, ``update_schemes_tried_regions``, is written to the +relevant ``kdamonds//state`` file, DAMON creates directories named integer +starting from ``0`` under this directory. Each directory contains files +exposing detailed information about each of the memory region that the +corresponding scheme's ``action`` has tried to be applied under this directory, +during next :ref:`aggregation interval `. The +information includes address range, ``nr_accesses``, , and ``age`` of the +region. + +The directories will be removed when another special keyword, +``clear_schemes_tried_regions``, is written to the relevant +``kdamonds//state`` file. + +tried_regions// +------------------ + +In each region directory, you will find four files (``start``, ``end``, +``nr_accesses``, and ``age``). Reading the files will show the start and end +addresses, ``nr_accesses``, and ``age`` of the region that corresponding +DAMON-based operation scheme ``action`` has tried to be applied. + Example ~~~~~~~ From patchwork Tue Nov 1 22:03:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13027525 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 B7996C433FE for ; Tue, 1 Nov 2022 22:03:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E8C658E0009; Tue, 1 Nov 2022 18:03:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DC73B8E0005; Tue, 1 Nov 2022 18:03:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE3C78E000A; Tue, 1 Nov 2022 18:03:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9940F8E0005 for ; Tue, 1 Nov 2022 18:03:40 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 69F07A0FF5 for ; Tue, 1 Nov 2022 22:03:40 +0000 (UTC) X-FDA: 80086251000.15.0387FFF Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf09.hostedemail.com (Postfix) with ESMTP id DADE8140003 for ; Tue, 1 Nov 2022 22:03:39 +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 93909B81FA0; Tue, 1 Nov 2022 22:03:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDF57C433D7; Tue, 1 Nov 2022 22:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340218; bh=NEW3Do9blxs64Lr6AHVrrQw2/a54TWTrLKMR+YeGsds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d1CFkxeL+dqHmMQeH8SDS0lCGzwBkhf2aHgFfgMOEqNRvCflCYHQI12Oy5F8avJc3 Agchqu719Zx4qxQ1F9QY9Fmuu9lScWN27OlP+GSN8ENks8z6FLxr7PFcWxFVcFTwgj gA6AGQFnZ8ZCWiBLhAIvR1411jLd8UqsVpR/3edr9frW/3xlDwPnoik0xeNFjhX7nI tGGbpkm6EWWV+g9CuX2snpTvjQH70mGLcHELAUY+wfCG2fW3gocNniE8fHFu0uWy/l y+4kDCJjON198FMyUp6iPw83AtZSxfKqgh9DjTGVQG83gSze8ypd8Xtc/pKTHBXRCf WoKgOp7KKNYKg== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 8/8] Docs/ABI/damon: document 'schemes//tried_regions' sysfs directory Date: Tue, 1 Nov 2022 22:03:28 +0000 Message-Id: <20221101220328.95765-9-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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667340220; 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=1xE6LwUt8JFEW6cHp10wzKw8CtFRQTz0icIitbX2c/A=; b=096SoLrbks6CSrI5vNTQCGAoRJJXphfNPDHzx+n5ruotiyyZE0UrSWaejf7C2TFoFnu7OE dEdzfk1LNeVUtU29vXPGVtcAEqljFxkgJGJCgiW7MaDfsWaujz2q9gIjYGpLXgtaXLVGYi HP2DpJAF1o9DZaDWXvb+kO+k/vowNw8= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=d1CFkxeL; spf=pass (imf09.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667340220; a=rsa-sha256; cv=none; b=xWSyftB8thgH89xcnJsL7BD/w1BULLaZ+l8aoVAkEgCG9TMOy7YKenq1DUMGulcYq3OSea z0OZkF1dMsNoEu5Ip/HI4mK0G2j3LIk/J1GuDZIrNoDbZvwQKxuH+ETViDK0iO2T41C3a2 6mWsKXp+Jr4MKZWaVxukA7+p0hcma6c= X-Stat-Signature: 68owes4gyuaa1p434ei8wixox755f6ff X-Rspamd-Queue-Id: DADE8140003 X-Rspamd-Server: rspam06 X-Rspam-User: Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=d1CFkxeL; spf=pass (imf09.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: 1667340219-422222 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: Update DAMON ABI document for the 'tried_regions' directory of DAMON sysfs interface. Signed-off-by: SeongJae Park --- .../ABI/testing/sysfs-kernel-mm-damon | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentation/ABI/testing/sysfs-kernel-mm-damon index 08b9df323560..13397b853692 100644 --- a/Documentation/ABI/testing/sysfs-kernel-mm-damon +++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon @@ -27,6 +27,10 @@ Description: Writing 'on' or 'off' to this file makes the kdamond starts or makes the kdamond reads the user inputs in the sysfs files except 'state' again. Writing 'update_schemes_stats' to the file updates contents of schemes stats files of the kdamond. + Writing 'update_schemes_tried_regions' to the file updates + contents of 'tried_regions' directory of every scheme directory + of this kdamond. Writing 'clear_schemes_tried_regions' to the + file removes contents of the 'tried_regions' directory. What: /sys/kernel/mm/damon/admin/kdamonds//pid Date: Mar 2022 @@ -283,3 +287,31 @@ Date: Mar 2022 Contact: SeongJae Park Description: Reading this file returns the number of the exceed events of the scheme's quotas. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//tried_regions//start +Date: Oct 2022 +Contact: SeongJae Park +Description: Reading this file returns the start address of a memory region + that corresponding DAMON-based Operation Scheme's action has + tried to be applied. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//tried_regions//end +Date: Oct 2022 +Contact: SeongJae Park +Description: Reading this file returns the end address of a memory region + that corresponding DAMON-based Operation Scheme's action has + tried to be applied. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//tried_regions//nr_accesses +Date: Oct 2022 +Contact: SeongJae Park +Description: Reading this file returns the 'nr_accesses' of a memory region + that corresponding DAMON-based Operation Scheme's action has + tried to be applied. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//tried_regions//age +Date: Oct 2022 +Contact: SeongJae Park +Description: Reading this file returns the 'age' of a memory region that + corresponding DAMON-based Operation Scheme's action has tried + to be applied.