From nobody Thu Oct 9 04:43:58 2025 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 5DFFA28CF6B; Thu, 19 Jun 2025 22:00:30 +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=1750370430; cv=none; b=DWWdd/tDwvYNBP144TXz3wRzG5lLJfIoK8WKBBnMwBqbDWWTRI8gNy1dyHYFixkvf7EYq7JFZOW9InkfMwjYCyEvzWY5VEF+nunz/sdez8iBNkqpxjW8wo9oJiFTxkJlrjsGqPGV09k0nJilHWBdkKn2dPlIETG4zO2u3qb0tZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750370430; c=relaxed/simple; bh=FL+q0PIy56zCfoaOYFZdf7xArsaTKGHGS5paNyqWubA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YnIxab6hUKbzs36xLlCN4TnMtpvKZqHFFOfOfpOn0wxxHFLLnoX63YTu+OVe2f3M+RnRNSDln0W3r2TUjDGAc4+Xq7l39ExZZQvWA1IkqlXRd7rPYb590978JQMECamByj/kpEmEWKH1AXFT+BdtuqKNtv9pUDOofGAccJMF9qQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P/Q3Veqo; 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="P/Q3Veqo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B789DC4CEEA; Thu, 19 Jun 2025 22:00:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750370429; bh=FL+q0PIy56zCfoaOYFZdf7xArsaTKGHGS5paNyqWubA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P/Q3Veqo05zrRL2NWOdDsxRdXpHEILquWBMELgpQQ+DHnYfM28d0FT3gKYgf+yWTK JD5nvU2IHlyLGPDsCVWVQOUWvlsHypgC0wMYEJFPXtMm1fIVOGjk2LAYUFUQR5RdbB kGPZy/sLuh1bTkF2xaN8EVEt/eVbXlQbDM7mQetqMVgCbCGi82o9E3+Z3/R4K0900J RBPGyTZLWk1EToSRSeo8Q5ohng37MlsDK8w4nR6/7Z8Uy/t0gr5ADcoLPMTLsfG26b jFG4k+9qjUBBTfcjlThWs0SZ7SXWZHYg/GJf/+NW9HW/cqtY9HN6JnjlDAAkWJDAvi CDWK2sXkAxy/w== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 01/11] mm/damon: document damos_quota_goal->nid use case Date: Thu, 19 Jun 2025 15:00:13 -0700 Message-Id: <20250619220023.24023-2-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250619220023.24023-1-sj@kernel.org> References: <20250619220023.24023-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" damos_quota_goal kerneldoc comment is not explaining @metric use case. Add it. Signed-off-by: SeongJae Park --- include/linux/damon.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 492be8319a25..39b835dd3c4d 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -206,6 +206,9 @@ enum damos_quota_goal_metric { * If @metric is DAMOS_QUOTA_USER_INPUT, @current_value should be manually * entered by the user, probably inside the kdamond callbacks. Otherwise, * DAMON sets @current_value with self-measured value of @metric. + * + * If @metric is DAMOS_QUOTA_NODE_MEM_{USED,FREE}_BP, @nid represents the = node + * id of the target node to account the used/free memory. */ struct damos_quota_goal { enum damos_quota_goal_metric metric; --=20 2.39.5 From nobody Thu Oct 9 04:43:58 2025 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 7A858261591; Thu, 19 Jun 2025 22:00:31 +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=1750370431; cv=none; b=pFR+aQe+91tbUCnYMoL7NfR4ByYmKaMKOosYipzEPKtqwRFsJyrYJ7MBHJcbSXEXhy8BhLwZPhUtnQgXixcW4JCovQuuG7KcbJbZEuMuLXAIYN+N+EjDFKfuO1kGpC4SXzwOyY6Odift5hR6+tO3OhnNisdstNEFa2V7y3mc9T0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750370431; c=relaxed/simple; bh=Sd7W7p0Z+HVtPzictunii3Ma4j0vmmcBWE6o+ftHaDg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jz8F6W6AfbRx0vA/bfMtBdbojpmJCW1iTJC8vDKxzsfm/iWgiLYxHNdWNuFAmdpt7Gahb+fSNViJpS6+p/OXShX3GE6a6Sqg0ujz4PBPyNoEzKfqqrmjrcBm6FmwtSPP++Y1ZMiOvwg+Otcpofhu1EQlRJkIG9wXiiSzJL8M4Y0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M3Wlabva; 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="M3Wlabva" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D34ADC4CEEE; Thu, 19 Jun 2025 22:00:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750370431; bh=Sd7W7p0Z+HVtPzictunii3Ma4j0vmmcBWE6o+ftHaDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M3Wlabva7fAPBjEGLuMNQ/vz15Fk+3x9EUkjlHBmWHgr2zK4gj09L5hNDPPFyQHvk J7g1SmiAaB4nMCr/cCXJBvsj8KiROywzeioOQzLjW0KaYApGD+IoJo07eVzbkaVp91 k1SzEEb9o22+akiOCGUNxXs8/SHQOk8PpD04btxTp1p1x8Og7QlhlVwK7FQOSZvaCD w+z+nVv5ggR2InyUb4GF6xf3VjLHdwWvPxNkegzogPLn3Pgyvh+u3/wEwIPDf6P8F2 qqS/yfzmNguoOOSuwBWr89lkgu5lsvI8PGy0CN04sHp8B9XD8Tx0Z81gpG1q/IjWD8 ApmV4xtHuCBqg== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 02/11] mm/damon: add a new DAMOS quota goal metric for cgroup on node memory usage Date: Thu, 19 Jun 2025 15:00:14 -0700 Message-Id: <20250619220023.24023-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250619220023.24023-1-sj@kernel.org> References: <20250619220023.24023-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Define a new DAMOS quota auto-tuning target metrics for per-cgroup per-node memory usage. Also extend damos_quota_goal struct to have a field for specifying the cgroup of the interest. Note that this commit is only for DAMON kernel API extension. Real behavior of the new metric will be implemented by a following commit. Signed-off-by: SeongJae Park --- include/linux/damon.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 39b835dd3c4d..43aef959d357 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -175,6 +175,7 @@ enum damos_action { * @DAMOS_QUOTA_SOME_MEM_PSI_US: System level some memory PSI in us. * @DAMOS_QUOTA_NODE_MEM_USED_BP: MemUsed ratio of a node. * @DAMOS_QUOTA_NODE_MEM_FREE_BP: MemFree ratio of a node. + * @DAMOS_QUOTA_NODE_MEMCG_USED_BP: MemUsed ratio of a node for a cgroup. * @DAMOS_QUOTA_ACTIVE_MEM_BP: Active to inactive memory ratio. * @NR_DAMOS_QUOTA_GOAL_METRICS: Number of DAMOS quota goal metrics. * @@ -185,6 +186,7 @@ enum damos_quota_goal_metric { DAMOS_QUOTA_SOME_MEM_PSI_US, DAMOS_QUOTA_NODE_MEM_USED_BP, DAMOS_QUOTA_NODE_MEM_FREE_BP, + DAMOS_QUOTA_NODE_MEMCG_USED_BP, DAMOS_QUOTA_ACTIVE_MEM_BP, NR_DAMOS_QUOTA_GOAL_METRICS, }; @@ -196,6 +198,7 @@ enum damos_quota_goal_metric { * @current_value: Current value of @metric. * @last_psi_total: Last measured total PSI * @nid: Node id. + * @memcg: Memcg id. * @list: List head for siblings. * * Data structure for getting the current score of the quota tuning goal. = The @@ -209,6 +212,9 @@ enum damos_quota_goal_metric { * * If @metric is DAMOS_QUOTA_NODE_MEM_{USED,FREE}_BP, @nid represents the = node * id of the target node to account the used/free memory. + * + * If @metric is DAMOS_QUOTA_NODE_MEMCG_USED_BP, @nid and @memcg_id repres= ents + * the node id and the cgroup to account the used memory for. */ struct damos_quota_goal { enum damos_quota_goal_metric metric; @@ -217,7 +223,10 @@ struct damos_quota_goal { /* metric-dependent fields */ union { u64 last_psi_total; - int nid; + struct { + int nid; + unsigned short memcg_id; + }; }; struct list_head list; }; --=20 2.39.5 From nobody Thu Oct 9 04:43:58 2025 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 A86BE28DF3F; Thu, 19 Jun 2025 22:00:32 +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=1750370432; cv=none; b=UlzrAtxZRMPN0TTDiOJcz0t/wSio3MpsTO7ougLQ3TfuveV6KCPx/O5R+ONh9CoQAOK/LHAYR/1PK2ef+An0Xv+Hq+AinyBIR6gxljbPqw74BU5rOgAAnhTKPhBHcvfcSue4jJSymin3l1J61r/HGjdEPfE4tDbMOoUZsvE7ucY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750370432; c=relaxed/simple; bh=ruhTjHTMSB8Frh5X86EoKCSKXfbBH40pNj+dni3HQq4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KROiDWR/2pwO91/pyCP4bYxP1UqjH68Gvs4bkGDzcsvy+aUP7LEypXgUyZxJO1fUSgUSKI+PeNBWTixyP9qmY1YaU+IzdDZ4ofUzCvazEB5c8NYFgiubxNxL7WZ+LXGfmWYAtpXqIZurFbTpJ/bIo8y4wniSdbRs4hSeB3obR80= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YfG/klgG; 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="YfG/klgG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0497AC4CEEE; Thu, 19 Jun 2025 22:00:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750370432; bh=ruhTjHTMSB8Frh5X86EoKCSKXfbBH40pNj+dni3HQq4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YfG/klgGxqXrLNWew9LBj2e/nPIoTPalafzZNhcp5HHVKp3iKRRBIKkCWni+DGv0N 0Qi4/5YUWVavIluMjGGfBilOoxFMa/oxaniOd/mFbpKwZL+xPcyDyr3S4JIwT8QUtG CWVpyijK7Kf71gE10l5V9dHg5zh8cD6WW5gY7bwsUA0WtxLspMBnFc7Oi7zxMyfldk 4ZsdXXNAxy5US69ahqQEwBf2dK47GeLKlOOkkaRHawCaUysqJaMfMtO34yVs/8jKML fSh8drtWw48On8wB2lHgXhOt74KwLRi3xEqtChhkszltN5kV1fRVJ/IAz3Sd5hkw1t ScbDALkDkkNSQ== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 03/11] mm/damon/core: implement DAMOS_QUOTA_NODE_MEMCG_USED_BP Date: Thu, 19 Jun 2025 15:00:15 -0700 Message-Id: <20250619220023.24023-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250619220023.24023-1-sj@kernel.org> References: <20250619220023.24023-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement the behavior of DAMOS_QUOTA_NODE_MEMCG_USED_BP. It uses sum of active/inactive anon/file pages of a given cgroup on a given NUMA node as the value of the metric. Signed-off-by: SeongJae Park --- mm/damon/core.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index d675dd932a23..1481b43f2710 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -2021,12 +2022,40 @@ static __kernel_ulong_t damos_get_node_mem_bp( numerator =3D i.freeram; return numerator * 10000 / i.totalram; } + +static unsigned long damos_get_node_memcg_used_bp( + struct damos_quota_goal *goal) +{ + struct mem_cgroup *memcg; + struct lruvec *lruvec; + unsigned long used_pages; + struct sysinfo i; + + rcu_read_lock(); + memcg =3D mem_cgroup_from_id(goal->memcg_id); + mem_cgroup_flush_stats(memcg); + lruvec =3D mem_cgroup_lruvec(memcg, NODE_DATA(goal->nid)); + used_pages =3D lruvec_page_state(lruvec, NR_ACTIVE_ANON); + used_pages +=3D lruvec_page_state(lruvec, NR_INACTIVE_ANON); + used_pages +=3D lruvec_page_state(lruvec, NR_ACTIVE_FILE); + used_pages +=3D lruvec_page_state(lruvec, NR_INACTIVE_FILE); + rcu_read_unlock(); + + si_meminfo_node(&i, goal->nid); + return used_pages * PAGE_SIZE * 10000 / i.totalram; +} #else static __kernel_ulong_t damos_get_node_mem_bp( struct damos_quota_goal *goal) { return 0; } + +static unsigned long damos_get_node_memcg_used_bp( + struct damos_quota_goal *goal) +{ + return 0; +} #endif =20 /* @@ -2062,6 +2091,9 @@ static void damos_set_quota_goal_current_value(struct= damos_quota_goal *goal) case DAMOS_QUOTA_NODE_MEM_FREE_BP: goal->current_value =3D damos_get_node_mem_bp(goal); break; + case DAMOS_QUOTA_NODE_MEMCG_USED_BP: + goal->current_value =3D damos_get_node_memcg_used_bp(goal); + break; case DAMOS_QUOTA_ACTIVE_MEM_BP: goal->current_value =3D damos_get_active_inactive_mem_bp(); break; --=20 2.39.5 From nobody Thu Oct 9 04:43:58 2025 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 7697228EA5A; Thu, 19 Jun 2025 22:00:33 +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=1750370433; cv=none; b=kY7aGxchp+hdhxdU1O2jGYiqpIvH15tBUwc0OTs7UTwWM0ga3TKqVkR0QNUalZnaU+n14rambdYLMkbY65D7CIMNB8vWg8orzF+eKx9ghVA06zeWKGAtsvIo0nsf1yhQw1aEYIV+2er82lOz+7bWbmmvCEk9AEqtP543NS/S0dI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750370433; c=relaxed/simple; bh=Dun+8Vi/DMwdzvUNXFdqjk12wLALbq7Ec1njVivI7r4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HMtU/++21x/qrMnI2QlEY297+XsR6/TcLQX3TyuJOvfy6B04rlLccr7RQB4MdrjUISy++tlqfpaJSFL4AkLnxfxKhCWb5wX/Z1pe/b4eF3QXVHnw9uhpltiHmiSlKwcIUdvBs/rPB2nIGkCFim415Il7d+7kF5qqNIcYiwSAYxs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HIoivf4C; 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="HIoivf4C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 324B1C4CEEA; Thu, 19 Jun 2025 22:00:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750370433; bh=Dun+8Vi/DMwdzvUNXFdqjk12wLALbq7Ec1njVivI7r4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HIoivf4CwD93oxJWrX+WLG0p+JKxKkSR3kRkADy1Vt2JJFx/ckAkAVhXpV3Ck7etV RNni5Ecb6a8u4kHzhNk3jCAAXdejXbJsBOgahClUzoydn0YhcqISFfDmL6EvUTap59 iQ0VCK8/Hbb8bOvvrSOb3pvwiTESRpBWTPYFon1ZM9o6kBTM/hiX9SEswXA3rNm5L7 n46tFb1fZcf8zposGXhAkZ3BALNJ3EhaqiACOdTduPB76TSPz2ndPjMJ/xpiYc0YT8 hNPw9wRoiQpOvigJ2LKdzPwafUKjCCjQvr/wuFOPiK6SM56Pw2ozcV/eELuyQ5fM3y LEahb4wirpCYg== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 04/11] mm/damon/sysfs-schemes: implement path file under quota goal directory Date: Thu, 19 Jun 2025 15:00:16 -0700 Message-Id: <20250619220023.24023-5-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250619220023.24023-1-sj@kernel.org> References: <20250619220023.24023-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a DAMOS sysfs file for specifying the cgroup of the interest for DAMOS_QUOTA_NODE_MEMCG_USED_BP. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 4805761d9127..4a340baa72a4 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -999,6 +999,7 @@ struct damos_sysfs_quota_goal { unsigned long target_value; unsigned long current_value; int nid; + char *path; }; =20 static struct damos_sysfs_quota_goal *damos_sysfs_quota_goal_alloc(void) @@ -1132,10 +1133,39 @@ static ssize_t nid_store(struct kobject *kobj, return err ? err : count; } =20 +static ssize_t path_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damos_sysfs_quota_goal *goal =3D container_of(kobj, + struct damos_sysfs_quota_goal, kobj); + + return sysfs_emit(buf, "%s\n", goal->path ? goal->path : ""); +} + +static ssize_t path_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damos_sysfs_quota_goal *goal =3D container_of(kobj, + struct damos_sysfs_quota_goal, kobj); + char *path =3D kmalloc_array(size_add(count, 1), sizeof(*path), + GFP_KERNEL); + + if (!path) + return -ENOMEM; + + strscpy(path, buf, count + 1); + kfree(goal->path); + goal->path =3D path; + return count; +} + static void damos_sysfs_quota_goal_release(struct kobject *kobj) { - /* or, notify this release to the feed callback */ - kfree(container_of(kobj, struct damos_sysfs_quota_goal, kobj)); + struct damos_sysfs_quota_goal *goal =3D container_of(kobj, + struct damos_sysfs_quota_goal, kobj); + + kfree(goal->path); + kfree(goal); } =20 static struct kobj_attribute damos_sysfs_quota_goal_target_metric_attr =3D @@ -1150,11 +1180,15 @@ static struct kobj_attribute damos_sysfs_quota_goal= _current_value_attr =3D static struct kobj_attribute damos_sysfs_quota_goal_nid_attr =3D __ATTR_RW_MODE(nid, 0600); =20 +static struct kobj_attribute damos_sysfs_quota_goal_path_attr =3D + __ATTR_RW_MODE(path, 0600); + static struct attribute *damos_sysfs_quota_goal_attrs[] =3D { &damos_sysfs_quota_goal_target_metric_attr.attr, &damos_sysfs_quota_goal_target_value_attr.attr, &damos_sysfs_quota_goal_current_value_attr.attr, &damos_sysfs_quota_goal_nid_attr.attr, + &damos_sysfs_quota_goal_path_attr.attr, NULL, }; ATTRIBUTE_GROUPS(damos_sysfs_quota_goal); --=20 2.39.5 From nobody Thu Oct 9 04:43:58 2025 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 B806A29187E; Thu, 19 Jun 2025 22:00: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=1750370434; cv=none; b=e6XeTKAcQqPdEj5jqT6w5+9H+4x3wUaluOWzZWWKUKqVUjlI4v3VNHOlFi/Dte3Wr/FkwuqH80cEdzQVYTkuQPZgSHNt2E+3ZSCQk46VNsIqCQR2ZAcUOOurofjlSaKmbAP2FH0NU0Wb3KQXJspuUspyXJp1ZWEA9kW6S+T4cSo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750370434; c=relaxed/simple; bh=gncPAmp9X4uOKinuCsBckPc5W+YYA5SmjzqnymRxrxQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MkYwgnPqWRw7itqL9jXkleJdkqjTq3AbIT90xnuvSBUkQ6/GvqfrxYwYpCl2A4oMzKUk1x5RSWJU0vZOXMWOxWdxm8oZU3eFhqcx6xNTlXJ40e4yEoxaP+UD6KjgM9JjLMT/okj4xwkukSFgVM69FJvIi/319Hh5NgmUCCeoUqk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f3mhJg1l; 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="f3mhJg1l" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36519C4CEEE; Thu, 19 Jun 2025 22:00:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750370434; bh=gncPAmp9X4uOKinuCsBckPc5W+YYA5SmjzqnymRxrxQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f3mhJg1lE5Mw/oWXgvzSeZUyYE4TOy1VQx/Qh2VJluCl5Vn7MmUdEwFLc4e/FSZsL pdbuWKIjCnHOXnFHvruTofGhSAKi+z9MXdfD19ZCf/tBF1s3EyUtNvQ876O5jN/zEc GMLl+KPbb4MVGmvv481CEM6K3/f9OsJQYiHpj2MOOLehjRds7RPQuP3sXjA7k4e1sb FMZOBa28PwSb5FM2zWmSNvVDCKNX+hv7AAVWsgj916SuTYqc1vWgUjgAfNoJvYPOIj b/phKgDIFcE3AViSrm0uzefdJTlk5sS3XDxoK8paY5dIC9Rufz307eUgF/5Klw0Ch1 5FAJEZFDk5CfA== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 05/11] mm/damon/sysfs-schemes: connect quota goal path file to DAMON core Date: Thu, 19 Jun 2025 15:00:17 -0700 Message-Id: <20250619220023.24023-6-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250619220023.24023-1-sj@kernel.org> References: <20250619220023.24023-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Read and commit the user-specified cgroup information for DAMOS_QUOTA_NODE_MEMCG_USED_BP to DAMON core. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 4a340baa72a4..89e5e40bdf63 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1030,6 +1030,10 @@ static struct damos_sysfs_qgoal_metric_name damos_sy= sfs_qgoal_metric_names[] =3D .metric =3D DAMOS_QUOTA_NODE_MEM_FREE_BP, .name =3D "node_mem_free_bp", }, + { + .metric =3D DAMOS_QUOTA_NODE_MEMCG_USED_BP, + .name =3D "node_memcg_used_bp", + }, { .metric =3D DAMOS_QUOTA_ACTIVE_MEM_BP, .name =3D "active_mem_bp", @@ -2317,7 +2321,7 @@ static int damos_sysfs_add_quota_score( struct damos_quota *quota) { struct damos_quota_goal *goal; - int i; + int i, err; =20 for (i =3D 0; i < sysfs_goals->nr; i++) { struct damos_sysfs_quota_goal *sysfs_goal =3D @@ -2338,6 +2342,15 @@ static int damos_sysfs_add_quota_score( case DAMOS_QUOTA_NODE_MEM_FREE_BP: goal->nid =3D sysfs_goal->nid; break; + case DAMOS_QUOTA_NODE_MEMCG_USED_BP: + err =3D damon_sysfs_memcg_path_to_id( + sysfs_goal->path, &goal->memcg_id); + if (err) { + damos_destroy_quota_goal(goal); + return err; + } + goal->nid =3D sysfs_goal->nid; + break; default: break; } --=20 2.39.5 From nobody Thu Oct 9 04:43:58 2025 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 131C52951BA; Thu, 19 Jun 2025 22:00:35 +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=1750370437; cv=none; b=f/a0EVDanJQIJjvyK5CMMn51MshpL9lgCEHZ8FkjRg/RL2j1iK8hq+15aLDIWcBd1xTgoORSVTVoszjN0669lLcfIA7SxitysggGCSumegcTVmc/4gq0yWvXKLce/K2K9s0Kyn+v17uEAVUgW1tB2zi4GHk3ZeerVmS8cOjVE3w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750370437; c=relaxed/simple; bh=mKWAyXf0fhqfpjFolQB3dWnDHH2ABS2xQxltFWbhL9Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NjFuy8cJwZp9LojGGkaOebxCBDBFbrhBEVNLANFzaU7M5+/xfIXNUZRToWhgs6Luuftn2sk5gkNHGtXca18x616jZQ/Fr+ZMM4NhsnfDe80EkEG4AM28UT+p4us7oAey3BBZ4/SXWmYE1BpQdDhHK5ViTnNYJQoVCq6qDukVCzI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cakvDxr1; 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="cakvDxr1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A362C4CEF1; Thu, 19 Jun 2025 22:00:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750370435; bh=mKWAyXf0fhqfpjFolQB3dWnDHH2ABS2xQxltFWbhL9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cakvDxr1OyYgAtKoMJIZscdHNiK6lfpkPs8Cg2Z+zf54e+TuOPWXYQW4b/s8kmFJ6 CY5lhuiXnvghjEbIDaDHBSHTSnmj5q6I2nutSdl2LrOrfklBMDf+z0HeusEQE9g+Bj P9QWTUz7K+WbpDIkbfNkxAIaXJbsL47EroH1MdUvqpd4+j6wAbp/+0NTnw5egaaYn9 Fy1NsdPrt2RumgOeNINGGO8ywv22HTyQ1/J+iZ0TvksQDCou1LAhToJ5gP3VFWG+oj th2BSMgshRLEkZateM7dsNZcrN5fgQ6IzbxUI1Z9tQ5eon287c+ATPLdnfEoH7acuX Kd0nk8cATvkCw== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , Jonathan Corbet , damon@lists.linux.dev, kernel-team@meta.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 06/11] Docs/mm/damon/design: document DAMOS_QUOTA_NODE_MEMCG_USED_BP Date: Thu, 19 Jun 2025 15:00:18 -0700 Message-Id: <20250619220023.24023-7-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250619220023.24023-1-sj@kernel.org> References: <20250619220023.24023-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: SeongJae Park --- Documentation/mm/damon/design.rst | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/des= ign.rst index 2290ebefc648..eb6d3b7d0643 100644 --- a/Documentation/mm/damon/design.rst +++ b/Documentation/mm/damon/design.rst @@ -553,9 +553,9 @@ aggressiveness (the quota) of the corresponding scheme.= For example, if DAMOS is under achieving the goal, DAMOS automatically increases the quota. If = DAMOS is over achieving the goal, it decreases the quota. =20 -The goal can be specified with four parameters, namely ``target_metric``, -``target_value``, ``current_value`` and ``nid``. The auto-tuning mechanism -tries to make ``current_value`` of ``target_metric`` be same to +The goal can be specified with five parameters, namely ``target_metric``, +``target_value``, ``current_value``, ``nid`` and ``path``. The auto-tuning +mechanism tries to make ``current_value`` of ``target_metric`` be same to ``target_value``. =20 - ``user_input``: User-provided value. Users could use any metric that th= ey @@ -570,9 +570,16 @@ tries to make ``current_value`` of ``target_metric`` b= e same to set by users at the initial time. In other words, DAMOS does self-feedb= ack. - ``node_mem_used_bp``: Specific NUMA node's used memory ratio in bp (1/10= ,000). - ``node_mem_free_bp``: Specific NUMA node's free memory ratio in bp (1/10= ,000). +- ``node_memcg_used_bp``: Specific cgroup's node used memory ratio for a + specific NUMA node, in bp (1/10,000). =20 -``nid`` is optionally required for only ``node_mem_used_bp`` and -``node_mem_free_bp`` to point the specific NUMA node. +``nid`` is optionally required for only ``node_mem_used_bp``, +``node_mem_free_bp`` and ``node_memcg_used_bp`` to point the specific NUMA +node. + +``path`` is optionally required for only ``node_memcg_used_bp`` to point t= he +path to the cgroup. The value should be the path of the memory cgroup fro= m the +cgroups mount point. =20 To know how user-space can set the tuning goal metric, the target value, a= nd/or the current value via :ref:`DAMON sysfs interface `, refe= r to --=20 2.39.5 From nobody Thu Oct 9 04:43:58 2025 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 1311A28EA5A; Thu, 19 Jun 2025 22:00:36 +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=1750370437; cv=none; b=r0s1Fw7yj2s2j3qYvQhEZZBYK52s/Bm8o1kIqNOfPzgUMO+OAH1UA/f4K5uIKhS31Os85Q0M54nEQktDli6xCqEuC1dja5zyKH1lGlt56VH0Abk1e0joEV+5KokFjNy2Gc0+fPwbL0oDJ76kk8uU+JlQpxsYoctxJL09mBD9ADQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750370437; c=relaxed/simple; bh=wqH48E+LGip6Lq2rL7wSlJRXxht7rFrTFl8NcghwPtI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ap/WHoj5wI5h1wXziYr/V+G3JXaq4pOTMoAKD5ZTer+P58ruf/8RQ2pp9v8GtzAJZGpXD9PgyD9skID8924MG4/4t2FSBrQEQHG8pZsvIjMRK+cFs6sXqw/kOdLkXiXaEPzZqQcTKz57fQSrLAyKpyuG0hLOih3UDo/5dj5A2uY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LBBRVztj; 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="LBBRVztj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71A4EC4CEEE; Thu, 19 Jun 2025 22:00:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750370436; bh=wqH48E+LGip6Lq2rL7wSlJRXxht7rFrTFl8NcghwPtI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LBBRVztjNgZs3K22XZVoEGcLZ2UzS917Lt8kDKWDbhb3qm5W9h2U7YcckfF5stkoV 3SqNvdfqWGIStxzvMslk5141R/d6pPDMplZxHVHcwkmw0eUJi9jCaJAYeTssMSbOxI lM06ohGtS2ojM9ANfmoftpSI/REBWavjEH0dSH2mznX8XKMyWx1NRPu8PAzD1TWBKn 5b4MwFIfnS1mPZpnTiji+2xkQNYamkx4Uubw9sHvXtJ6r8q25zGuW1qxQroYc6FKy+ qsuXp6OaopSqpgEyBdWapHRkrnf1hkVRJV3D9FpZ9lqI1Nh1REau9K3UikMO4akpQY b2OVMP+TIBL8g== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , Jonathan Corbet , damon@lists.linux.dev, kernel-team@meta.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 07/11] Docs/admin-guide/mm/damon/usage: document DAMOS quota goal path file Date: Thu, 19 Jun 2025 15:00:19 -0700 Message-Id: <20250619220023.24023-8-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250619220023.24023-1-sj@kernel.org> References: <20250619220023.24023-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/a= dmin-guide/mm/damon/usage.rst index d960aba72b82..2f603977fa88 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -81,7 +81,7 @@ comma (","). =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`quotas `/ms,bytes,reset_interval_ms,effective_bytes =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 weights/sz_permil,nr_accesses_permil,age_permil =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 :ref:`goals `/nr_goals - =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 =E2=94=82 0/target_metric,target_value,current_value,nid + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 =E2=94=82 0/target_metric,target_value,current_value,nid,path =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`watermarks `/metric,interval_us,high,mid,low =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`{core_,ops_,}filters `/nr_filters =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 0/type,matching,allow,memcg_path,addr_start,addr_end,target_idx,m= in,max @@ -390,9 +390,9 @@ number (``N``) to the file creates the number of child = directories named ``0`` to ``N-1``. Each directory represents each goal and current achievement. Among the multiple feedback, the best one is used. =20 -Each goal directory contains four files, namely ``target_metric``, -``target_value``, ``current_value`` and ``nid``. Users can set and get the -four parameters for the quota auto-tuning goals that specified on the +Each goal directory contains five files, namely ``target_metric``, +``target_value``, ``current_value`` ``nid`` and ``path``. Users can set a= nd +get the five parameters for the quota auto-tuning goals that specified on = the :ref:`design doc ` by writing to and reading from each of the files. Note that users should further write ``commit_schemes_quota_goals`` to the ``state`` file of the :ref:`kdamond --=20 2.39.5 From nobody Thu Oct 9 04:43:58 2025 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 19FBF2980DF; Thu, 19 Jun 2025 22:00:37 +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=1750370439; cv=none; b=XKNpv7oXu09ZKv9D5fpgmECv+ugG8tHueEp+eqzkcNW07dCfPiDOMal7tFGkrqrOAF+oqG1wos7qtn96WJvMKedzyA3bxFMIem7BxT3uw76wn/up9vxN4Q7vWzwH2qI/Fm7ToJwawMpt40WsXAzX798KvdCj5EBaULcpWSGjGf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750370439; c=relaxed/simple; bh=SD/oeFdnj1gBxwoLiXjI4d1QKLNcRhVN2gjFTeKD8k0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SQnKVZ46p643ZTzCfAnkAMkd5fK0GQcIukKZREPj4xQ4ruCc4uoj6PUoZWRB3WMJsBEujuAB5eRTLkRt9QLe+lv1yiJRIuXiX0EXakVBAsqDQmKkUGCzVfGjykgAT1Mom/Y3nrLVmYe9MgBH+vMuGfQEAWaXmUicsgi6AVDznM8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NtyZUZKt; 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="NtyZUZKt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77AC4C4CEEA; Thu, 19 Jun 2025 22:00:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750370437; bh=SD/oeFdnj1gBxwoLiXjI4d1QKLNcRhVN2gjFTeKD8k0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NtyZUZKtBQqNFhYY/V1AEtjRwk1uHPZShVWg9p8KpXOUV444YhNyTSMs4gcbAp3WJ 7eW1AWkETUtr0Z8RG0WO7DM7bML78Qa74KWMEnhS0dDvFeCO5t8g7hfv+/lbi9UCZz Fo/S+eq8YAwWOsNeWyMyq/27DLQ2kWjQdPA/gC3HABWz1Cy0MyelNo7zOa+Ek2cGkh e7ZPR7fUZYLyRTCxmJKWkfE86ijwsP+uouKuc0xCi/QcqEFlEX+3axLDBqqPMAdVmJ 5BhZhwnYItUrYlVd40hZKlOnnw1N0mYp9tNoWrW4wyc51pxRA+jXDl7bvISJtVW+sL 6UaQYqIIG/YOQ== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 08/11] mm/damon: add DAMOS_QUOTA_NODE_MEMCG_FREE_BP quota tuning goal metric Date: Thu, 19 Jun 2025 15:00:20 -0700 Message-Id: <20250619220023.24023-9-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250619220023.24023-1-sj@kernel.org> References: <20250619220023.24023-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a variant of DAMOS_QUOTA_NODE_MEMCG_USED_BP, for free memory portion. Note that this commit only extends the DAMON API. The real behavior will be implemented by a following commit. Signed-off-by: SeongJae Park --- include/linux/damon.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 43aef959d357..ba02c95e7d85 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -176,6 +176,7 @@ enum damos_action { * @DAMOS_QUOTA_NODE_MEM_USED_BP: MemUsed ratio of a node. * @DAMOS_QUOTA_NODE_MEM_FREE_BP: MemFree ratio of a node. * @DAMOS_QUOTA_NODE_MEMCG_USED_BP: MemUsed ratio of a node for a cgroup. + * @DAMOS_QUOTA_NODE_MEMCG_FREE_BP: MemFree ratio of a node for a cgroup. * @DAMOS_QUOTA_ACTIVE_MEM_BP: Active to inactive memory ratio. * @NR_DAMOS_QUOTA_GOAL_METRICS: Number of DAMOS quota goal metrics. * @@ -187,6 +188,7 @@ enum damos_quota_goal_metric { DAMOS_QUOTA_NODE_MEM_USED_BP, DAMOS_QUOTA_NODE_MEM_FREE_BP, DAMOS_QUOTA_NODE_MEMCG_USED_BP, + DAMOS_QUOTA_NODE_MEMCG_FREE_BP, DAMOS_QUOTA_ACTIVE_MEM_BP, NR_DAMOS_QUOTA_GOAL_METRICS, }; @@ -213,8 +215,8 @@ enum damos_quota_goal_metric { * If @metric is DAMOS_QUOTA_NODE_MEM_{USED,FREE}_BP, @nid represents the = node * id of the target node to account the used/free memory. * - * If @metric is DAMOS_QUOTA_NODE_MEMCG_USED_BP, @nid and @memcg_id repres= ents - * the node id and the cgroup to account the used memory for. + * If @metric is DAMOS_QUOTA_NODE_MEMCG_{USED,FREE}_BP, @nid and @memcg_id + * represents the node id and the cgroup to account the used memory for. */ struct damos_quota_goal { enum damos_quota_goal_metric metric; --=20 2.39.5 From nobody Thu Oct 9 04:43:58 2025 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 1C226298241; Thu, 19 Jun 2025 22:00:38 +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=1750370439; cv=none; b=mKM26DhjzyEiE/IxzG9jhyVKwDMQ1zUilI2YStirBqeYuFZYir9oxENi+EJq8pPJ6GKW6bSEjqOoxumISiJhDecJ6Fgy1OjoEg8q+BHDeM8FLnpFVW5yHvl4+WPm/qLPWXPBJEiKiqTaKxP/Z8sP7hzf1uU67MIsMXt4YZ+l3GY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750370439; c=relaxed/simple; bh=lRIYfv6d9ZUagG+D/Ljb9Zv5CaI6stHZpkxzrSwoTP0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EkBCPcnKi2NLedoMYSl1txk8AqBkUU6GNwCB0ah8iEFjj8KGCfXq8ktfVlW763+6al6HenFH7F10/9EYTFytmp/sy+5FDRyBRJ+6fJ/QVr1oSQXBjMKs0bP9dW/BnegwycZJPoguSMwTDHQt0Umslc0nQxLuAOUHDV08FZP7Ioc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D7i+0ApA; 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="D7i+0ApA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79DECC4CEEE; Thu, 19 Jun 2025 22:00:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750370438; bh=lRIYfv6d9ZUagG+D/Ljb9Zv5CaI6stHZpkxzrSwoTP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D7i+0ApAUZMon9H3bfHfx/w0HiENvgxYh8bpDLqXcE3QzNvILJeAaklXWmcveR6cj w733RFwBA1ZaxKtWGGsFacjR78XdEE0C81GHpaj7GZA8IEKusclmYq0LoLMpJtVmdu MF3LkeWkwFlTTvNlmMz45bpdPYIYXtugtMdqCEKnMPC0Cbb4aIoLcRdvSwQU+MrecU zlvKNCzaz5QqVPRhsWSR063BfKUqg/HOLOMSRRhJCq5Kv6TN97aj15r9ohNshsz3FU 31Ti5Of6gyHHwZZfzIzTQ2uL4S48VxfN+dmkaNx2mZqniGlONQUg90LD1wTXOdJh0j j+JsiFqqCpAWg== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 09/11] mm/damon/core: implement DAMOS_QUOTA_NODE_MEMCG_FREE_BP Date: Thu, 19 Jun 2025 15:00:21 -0700 Message-Id: <20250619220023.24023-10-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250619220023.24023-1-sj@kernel.org> References: <20250619220023.24023-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement the core part of DAMOS_QUOTA_NODE_MEMCG_FREE_BP to get the real value. The value is implemented as the entire memory of the given NUMA node, except the given cgroup's portion. So strictly speaking, it is not free memory but memory that not used by the cgroup. Signed-off-by: SeongJae Park --- mm/damon/core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 1481b43f2710..ee3d6d4b3c9b 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2028,7 +2028,7 @@ static unsigned long damos_get_node_memcg_used_bp( { struct mem_cgroup *memcg; struct lruvec *lruvec; - unsigned long used_pages; + unsigned long used_pages, numerator; struct sysinfo i; =20 rcu_read_lock(); @@ -2042,7 +2042,11 @@ static unsigned long damos_get_node_memcg_used_bp( rcu_read_unlock(); =20 si_meminfo_node(&i, goal->nid); - return used_pages * PAGE_SIZE * 10000 / i.totalram; + if (goal->metric =3D=3D DAMOS_QUOTA_NODE_MEMCG_USED_BP) + numerator =3D used_pages * PAGE_SIZE; + else /* DAMOS_QUOTA_NODE_MEMCG_FREE_BP */ + numerator =3D i.totalram - used_pages * PAGE_SIZE; + return numerator * 10000 / i.totalram; } #else static __kernel_ulong_t damos_get_node_mem_bp( @@ -2092,6 +2096,7 @@ static void damos_set_quota_goal_current_value(struct= damos_quota_goal *goal) goal->current_value =3D damos_get_node_mem_bp(goal); break; case DAMOS_QUOTA_NODE_MEMCG_USED_BP: + case DAMOS_QUOTA_NODE_MEMCG_FREE_BP: goal->current_value =3D damos_get_node_memcg_used_bp(goal); break; case DAMOS_QUOTA_ACTIVE_MEM_BP: --=20 2.39.5 From nobody Thu Oct 9 04:43:58 2025 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 195BB29994A; Thu, 19 Jun 2025 22:00:39 +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=1750370440; cv=none; b=uZD27yXz4HNfJflRjbhcOIxfTGX260kgc3dHvRXjrEQDo0DWPZYr02DrO8sldT5k80xEUSLEsliqnf8FpaFJgfnAcDvPHJ5/LwEUSfkDsUasNcPRoC5ZUxZWf4TJuT7qD1aepVRTGeJixEtpRRdPjPzkBCk+xmL2FQ/IuJHIp9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750370440; c=relaxed/simple; bh=ZNI7/tZOYHb60wq0Az69HW/eVRwT+4RSn0T5f4Wa/tQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dkCnulACUdf/aO0QmI0GCQwv0jRj3pAYG5mikiPMusR59fDl5WyMPNKzwnOI5RVaUDvKW3ua5lv0yVm35wku60Qc0fiAA03FPJ50twP58jhcdfA/Z3ZNcVLVM1cBoD7UXSsp36GbivPUzCRmoQBzYXJ9XGw/pxN2SxUFdLkaBNg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GLBic7nS; 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="GLBic7nS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FE05C4CEEA; Thu, 19 Jun 2025 22:00:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750370439; bh=ZNI7/tZOYHb60wq0Az69HW/eVRwT+4RSn0T5f4Wa/tQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GLBic7nS3Vb/FBT/LScHk/fPd9ih11k7VR0Sb6OVs/+cehe7HzGMa6PszQizdy/hr UeHIusRhNeGgwvi59EUcLOEIW4qhFSWIpzximKneWAlticH0Bb3hkVzBll8l41HHw6 CltcsJhdD/LPYtME6wXTZTFJlFHVOzeq44JZlqS+UplOiAgUlS8e734DgB2BeW9Dwr FCIoeZ2RPbyKzeDuEG7M/VcpuSsBAsWrACb7CKHxoVNC1CREbkeHNj4FVlKUWXTCZb LTCZkJa4JcnJ4pfAkqsb6umct8Wwfh8CBBxXlwJvy4obi84AwX82IvvZcLjNohTKNb Izg4WYaxNj9qg== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 10/11] mm/damon/sysfs-schemes: support DAMOS_QUOTA_NODE_MEMCG_FREE_BP Date: Thu, 19 Jun 2025 15:00:22 -0700 Message-Id: <20250619220023.24023-11-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250619220023.24023-1-sj@kernel.org> References: <20250619220023.24023-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Let DAMON sysfs to support DAMOS_QUOTA_NODE_MEMCG_FREE_BP. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 89e5e40bdf63..819e16151752 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1034,6 +1034,10 @@ static struct damos_sysfs_qgoal_metric_name damos_sy= sfs_qgoal_metric_names[] =3D .metric =3D DAMOS_QUOTA_NODE_MEMCG_USED_BP, .name =3D "node_memcg_used_bp", }, + { + .metric =3D DAMOS_QUOTA_NODE_MEMCG_FREE_BP, + .name =3D "node_memcg_free_bp", + }, { .metric =3D DAMOS_QUOTA_ACTIVE_MEM_BP, .name =3D "active_mem_bp", @@ -2343,6 +2347,7 @@ static int damos_sysfs_add_quota_score( goal->nid =3D sysfs_goal->nid; break; case DAMOS_QUOTA_NODE_MEMCG_USED_BP: + case DAMOS_QUOTA_NODE_MEMCG_FREE_BP: err =3D damon_sysfs_memcg_path_to_id( sysfs_goal->path, &goal->memcg_id); if (err) { --=20 2.39.5 From nobody Thu Oct 9 04:43:58 2025 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 DDC2929A326; Thu, 19 Jun 2025 22:00:40 +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=1750370441; cv=none; b=ctYRe+w3gC8pZ5nhmD/FRv8B3X3Odxkxqe4kownjhHrjsPYkTSFf8oIuQ3Qq3ciq3zfVBoreCHsfZnIeVbg3NaLT6fQEqNVLyHIAa+oy8I4S4C/NLm3JdekJj26XvT1aZOg68LztJg6Igmewd+LskNQ710sA0g0Jnkcu3l7Q/kU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750370441; c=relaxed/simple; bh=t+FYzdxss4O8PIT6azsMosL7ZC/90ZpCpkaRaenf1iQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QESoRdkM9HE1BFqd7YyIDGPeQwxj4AeJ5aJdYaE34WNS4U5hA33rsX43jdBkdve2J7PmwbgVKuVUYxaFjOz3ftoHqedgWCVlOS/qK50qHXrknzT0EgNfe7/b919ogJokSSKUpIAT6smj7WiZi6n9lRQu+wRiro4wTSH6G6QvKS0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mmJIg977; 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="mmJIg977" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93623C4CEEA; Thu, 19 Jun 2025 22:00:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750370440; bh=t+FYzdxss4O8PIT6azsMosL7ZC/90ZpCpkaRaenf1iQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mmJIg977cWmX1e009jjzG7TfAtvLm92a6f3IH03B27nsJjTQzym3L95Wa+J8Dtzcg ukOa8Nw8tPivP/YCknfL5bK3kkcAbvRm/B+qLYtM0FRMBsp1bp2bzwOvShPcl9g9Lz xhgfVcWfTpTLgeQyhAnSK7lmTw/gygK5vqWBewyKRfQoGho0atHo+o0NgiNOKiqPi/ M3eQCCmxlgfDmVb8kXMKezKg0kFCeSPM8pb6UWFbp7m5Sk/adZ7PDpkguFZsaDyd2h 02jtx00LHCJYdJqljYakY46PZHOrfM/YPJ4hNp/k7Prq4VF3ZxSRHzur1SLXAub1jG jPe3OJFnFNz+g== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , Jonathan Corbet , damon@lists.linux.dev, kernel-team@meta.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 11/11] Docs/mm/damon/design: document DAMOS_QUOTA_NODE_MEMCG_FREE_BP Date: Thu, 19 Jun 2025 15:00:23 -0700 Message-Id: <20250619220023.24023-12-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250619220023.24023-1-sj@kernel.org> References: <20250619220023.24023-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: SeongJae Park --- Documentation/mm/damon/design.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/des= ign.rst index eb6d3b7d0643..6e1f772006d9 100644 --- a/Documentation/mm/damon/design.rst +++ b/Documentation/mm/damon/design.rst @@ -571,15 +571,16 @@ mechanism tries to make ``current_value`` of ``target= _metric`` be same to - ``node_mem_used_bp``: Specific NUMA node's used memory ratio in bp (1/10= ,000). - ``node_mem_free_bp``: Specific NUMA node's free memory ratio in bp (1/10= ,000). - ``node_memcg_used_bp``: Specific cgroup's node used memory ratio for a +- ``node_memcg_free_bp``: Specific cgroup's node unused memory ratio for a specific NUMA node, in bp (1/10,000). =20 ``nid`` is optionally required for only ``node_mem_used_bp``, -``node_mem_free_bp`` and ``node_memcg_used_bp`` to point the specific NUMA -node. +``node_mem_free_bp``, ``node_memcg_used_bp`` and ``node_memcg_free_bp`` to +point the specific NUMA node. =20 -``path`` is optionally required for only ``node_memcg_used_bp`` to point t= he -path to the cgroup. The value should be the path of the memory cgroup fro= m the -cgroups mount point. +``path`` is optionally required for only ``node_memcg_used_bp`` and +``node_memcg_free_bp`` to point the path to the cgroup. The value should = be +the path of the memory cgroup from the cgroups mount point. =20 To know how user-space can set the tuning goal metric, the target value, a= nd/or the current value via :ref:`DAMON sysfs interface `, refe= r to --=20 2.39.5