From nobody Wed Oct 8 10:56:39 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 7C30121B9C0; Sat, 28 Jun 2025 16:51:49 +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=1751129509; cv=none; b=fqWu1OgfU/Qr/moImbYk5orLHfIxeXPxxwq4El8unymrVEFahlqD99kJN8NIrG11pxKkHeFk6YRXVYHsn7txH7HQVKTiAnhaGJP+AlEHkp3rIPYmpHUJdq4QYIiaJ2ev2wrH6PwhCzM9dLzVPB6KTMLVR+Rw13mjJLOZQ2LZA8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751129509; c=relaxed/simple; bh=Loco/3F4VYCbvXX7GgEUHxvF0e1mZosYux21IhMdVz0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JVCB/PR2carbo1izJ3XK/vx6jJZkm/Hbv0dPSA36zCVSP+BTZklcTTlQUmf2Ex26jisdwBzFzKradlBepE9TcZ2g3U+GR0r7a4q14O4hNrTde2NCwxRu0EafsagghH4C6N00KLMSwGOOxluFX71PCANw/9VdaIo5qfbjIWvK8/I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bHjz8Uih; 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="bHjz8Uih" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D48B3C4CEEF; Sat, 28 Jun 2025 16:51:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751129509; bh=Loco/3F4VYCbvXX7GgEUHxvF0e1mZosYux21IhMdVz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bHjz8Uih4qDgGK6aYn4YHtpyrrbbBdXqJyFN8sMQjmuayAtj6VAYGa9pE3DJUKhcA o5zosE9OXkUeRPMcFvXm2LeoZR6x8G4DmzIR+HEL0NlEUNyL2dryZHJ4q/H/edrw6B pk9n1sSHV7g5lEiPa0kP1pvHvr7nEyxBevUnnxYkTzTzvpOO+/XEU3vYCKZRt9pQ8A Olm+K0MhGrjFL4AnhyC8Y4kgJx+O5uaV0G/Fy5S01uMYyYZPTROE4qj3jaGqpXfdrC IzWHt8tcoNnNnnbG2rafMXdhVE+oNd09Eu+quEC6l7RFUlFNcdBzd4TJ3iQfxqfkQz AvmnA62YHrOdw== 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/core: introduce [in]active memory ratio damos quota goal metric Date: Sat, 28 Jun 2025 09:51:34 -0700 Message-Id: <20250628165144.55528-2-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628165144.55528-1-sj@kernel.org> References: <20250628165144.55528-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_LRU_[DE]PRIO are DAMOS actions for making balance of active and inactive memory size. There is no appripriate DAMOS quota auto-tuning target metric for the use case. Add two new DAMOS quota goal metrics for the purpose, namely DAMOS_QUOTA_[IN]ACTIVE_MEM_BP. Those weill represent the ratio of [in]active memory to total (inactive + active) memory. Hence, users will be able to ask DAMON to, for example, "find hot and cold memory, and move pages of those to active and inactive LRU lists, adjusting the hot/cold thresholds aiming 50:50 active:inactive memory ratio." Signed-off-by: SeongJae Park --- include/linux/damon.h | 4 ++++ mm/damon/core.c | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 517f48ffe782..c2fc6c8cbbe4 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -179,6 +179,8 @@ 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_ACTIVE_MEM_BP: Active to [in]active memory ratio. + * @DAMOS_QUOTA_INACTIVE_MEM_BP: Inactive to [in]active memory ratio. * @NR_DAMOS_QUOTA_GOAL_METRICS: Number of DAMOS quota goal metrics. * * Metrics equal to larger than @NR_DAMOS_QUOTA_GOAL_METRICS are unsupport= ed. @@ -188,6 +190,8 @@ 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_ACTIVE_MEM_BP, + DAMOS_QUOTA_INACTIVE_MEM_BP, NR_DAMOS_QUOTA_GOAL_METRICS, }; =20 diff --git a/mm/damon/core.c b/mm/damon/core.c index 02493d71460c..88ffc826a118 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2027,6 +2027,23 @@ static __kernel_ulong_t damos_get_node_mem_bp( } #endif =20 +/* + * Returns LRU-active memory to LRU-inactive memory size ratio. + */ +static unsigned int damos_get_in_active_mem_bp(bool active_ratio) +{ + unsigned long active, inactive, total; + + /* This should align with /proc/meminfo output */ + active =3D global_node_page_state(NR_LRU_BASE + LRU_ACTIVE_ANON) + + global_node_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE); + inactive =3D global_node_page_state(NR_LRU_BASE + LRU_INACTIVE_ANON) + + global_node_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE); + total =3D active + inactive; + if (active_ratio) + return active * 10000 / total; + return inactive * 10000 / total; +} =20 static void damos_set_quota_goal_current_value(struct damos_quota_goal *go= al) { @@ -2046,6 +2063,11 @@ static void damos_set_quota_goal_current_value(struc= t 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_ACTIVE_MEM_BP: + case DAMOS_QUOTA_INACTIVE_MEM_BP: + goal->current_value =3D damos_get_in_active_mem_bp( + goal->metric =3D=3D DAMOS_QUOTA_ACTIVE_MEM_BP); + break; default: break; } --=20 2.39.5 From nobody Wed Oct 8 10:56:39 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 76403256C80; Sat, 28 Jun 2025 16:51:50 +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=1751129510; cv=none; b=tybHMa5eNL/civJB0/ivU/2hLkO/n+G6kZmFL4ZF9GpqZHCNiLEIef2YaX5Fko8zhbU3z6oFpRfg1B7F3ZKVVVJehhzzyOAfpMWaCv1y/2T/EnqS4iDwOxIC0YBSSBSScK5XSwj48x2efwewl9TmPWh1py/KEtnWrBWjTEX99/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751129510; c=relaxed/simple; bh=bpHe961oflZU3B/An+TbdXaXn/ljNslL3rvDuZ9B014=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bj2rWmoeGRgR3/a/9EWQKoe14NZweLML7JnmyWkQiDK65WDk7GH+ediX583XjhxfIuaSDDFsr5xyz3nc0xLZQrVYVJVoJjzmZcyczqnl3hbTmjozDXTnfi67kXY4edoP/RRw35rKNEgWVysZHSETiHVFbZ6Y0g70XOi9MiJv+Uk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ty2jW2a/; 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="Ty2jW2a/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1151C4CEED; Sat, 28 Jun 2025 16:51:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751129510; bh=bpHe961oflZU3B/An+TbdXaXn/ljNslL3rvDuZ9B014=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ty2jW2a/8T3spwMO2kGwPkcyMIhSWLjSgU2IkzZBq5yrUkNd9LeW4E3b74LgfsWyA Y/vTe1QDPipfZtRvnfmTSch61Dl7Uc8zdLbU5vgKn6fh4lys1XhHO6Lj6ol53Qt2uA Ns3hR86OTHIK9FlJDdVXbQ+HSYSLFEezgknPjrjUdcYFDeYnz7a0LB+EcjHschtxYv a+N+4aPc2v8BfT+aUST9figVzZGv/yOOCclnjuKKYaGMRKHEMbPuxTUnbNEPjaiWnD u8QN4rcLbwfzz/VRWpEdFUWdALkpo4auZUwV99YhEcvb+zroFvHqCU8Cmtkz5IjFqN 7S3dcxbrJyqwQ== 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/sysfs-schemes: support DAMOS_QUOTA_[IN]ACTIVE_MEM_BP Date: Sat, 28 Jun 2025 09:51:35 -0700 Message-Id: <20250628165144.55528-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628165144.55528-1-sj@kernel.org> References: <20250628165144.55528-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 support of DAMOS_QUOTA_[IN]ACTIVE_MEM_BP on DAMON sysfs interface. Users can use [in]active_mem_bp keyword input to the target_metric sysfs file to use the new DAMOS quota auto-tune target metrics. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index e026eed16c2e..e8dcad65292b 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1029,6 +1029,14 @@ struct damos_sysfs_qgoal_metric_name damos_sysfs_qgo= al_metric_names[] =3D { .metric =3D DAMOS_QUOTA_NODE_MEM_FREE_BP, .name =3D "node_mem_free_bp", }, + { + .metric =3D DAMOS_QUOTA_ACTIVE_MEM_BP, + .name =3D "active_mem_bp", + }, + { + .metric =3D DAMOS_QUOTA_INACTIVE_MEM_BP, + .name =3D "inactive_mem_bp", + }, }; =20 static ssize_t target_metric_show(struct kobject *kobj, --=20 2.39.5 From nobody Wed Oct 8 10:56:39 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 77D512580E7; Sat, 28 Jun 2025 16:51:51 +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=1751129511; cv=none; b=dEVpgpW55Kk2c1EW5yJmVGvJYlive1HFQ33hIS2EdS6Kuf7UYFtAv7vz+fm7IN5u+HXW/jH1a0kBQGsruwzFNmM9hSwn8VKb7upaubrfl2HTF1P6WzakPk2Phl3YT7qzOXhdzPFpWaGjNXxIzKB3vr8Mtc8i28LBnAQk7+K9/B8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751129511; c=relaxed/simple; bh=/0dCUe11qKby9u3vEyXqRJSVAYTCVRTpv2OM8A5msCk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=g2RzXrY/Wd2yDWQaWxSpasbNUyJ1kfvN7lM5l/YKAY4RPxeJlJdI8gJmzGd6bkWH1Qi5j4nVWCIwamuu8zifREszF/LjNezHpzgUUSqvX/WA3EZo/VlWMQWCRUaYZ18bdPTbGi/dUhDJJRoYk9HSExD31qAY7BwuA0gJUFun/Dk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WVqv/iAQ; 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="WVqv/iAQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD940C4CEED; Sat, 28 Jun 2025 16:51:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751129511; bh=/0dCUe11qKby9u3vEyXqRJSVAYTCVRTpv2OM8A5msCk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WVqv/iAQmQTec0pT+CG3bWPgayEsJbxNNvvNWTv00bptdssc2b3QQZ0PIBIQpEVJ0 H6ThLDoMqHS692LBCUYhCmwTFYsIVy9fx7CmBrFLH9FtRraA9F8zXeGQdEl/VFYwGb A+HQku7tbqCP5plBmEYd29zMc642+5IzsKOLxxlg0qv/2uuBG1zfDEZNO5IfgEDeUu 9+Lcq/PcAxgtj1zwnB7ZhmeKuQ8Y7+2i06UuSJiOKjWPaunRBUEr/zhLTLRSl7PKe+ w0COfErWZ3iGjunEfYJyJxeNySCHLGfyWIh1fJFfCX1wnpZOdirhobUNBfy+7oSN+O ho+fjeh8KGXlw== 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 03/11] Docs/mm/damon/design: document DAMOS_QUOTA_[IN]ACTIVE_MEM_BP Date: Sat, 28 Jun 2025 09:51:36 -0700 Message-Id: <20250628165144.55528-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628165144.55528-1-sj@kernel.org> References: <20250628165144.55528-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" Update design document for newly added DAMOS_QUOTA_[IN]ACTIVE_MEM_BP metrics. Note that API document is automatically updated by kernel-doc comment, and the usage document points to the design document which uses keywords same to that for sysfs inputs. Hence updating only design document is sufficient. Signed-off-by: SeongJae Park --- Documentation/mm/damon/design.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/des= ign.rst index 2290ebefc648..ce8c389f0c68 100644 --- a/Documentation/mm/damon/design.rst +++ b/Documentation/mm/damon/design.rst @@ -570,6 +570,10 @@ 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). +- ``active_mem_bp``: Active to active + inactive (LRU) memory size ratio i= n bp + (1/10,000). +- ``inactive_mem_bp``: Inactive to active + inactive (LRU) memory size rat= io 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. --=20 2.39.5 From nobody Wed Oct 8 10:56:39 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 79E1421B9C0; Sat, 28 Jun 2025 16:51:52 +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=1751129512; cv=none; b=Ay/xW8HokZ0iXP5GumjmGmboZzQPM44sAiKSCTk/vhNqHdNWtXvdnzFDEklXSTfI/gLFNiXTnqZAE6SliJXwUioqnPemsBzFhds49NBsXcQj6orHG8HrrroIHW20C1oUgpm8zwriGDExSnBdHp37m/Z2HvF1rSoioetdgdBE1Fs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751129512; c=relaxed/simple; bh=Cm6pjIFRAJZCOmn0gKgJd7u3o4zVBQh0I1eKxLttZ2I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZtlbNdaSzuxaqTGs0xKgtzCtu92NkDufJBIOmOioVKFIvYOO0PKGE76ftnZnm6O8m0pzFkpbNF1+HpbrpnaLbaZSW7BM51WfUUFGe/F87Zylgmb3GftFFq2JxR3SEO7kFieru6GS+h8l4o9kgZGSBYfIrFi3+tbc3qYWjadKzJ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fHlL1odv; 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="fHlL1odv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC25EC4CEEF; Sat, 28 Jun 2025 16:51:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751129512; bh=Cm6pjIFRAJZCOmn0gKgJd7u3o4zVBQh0I1eKxLttZ2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fHlL1odvhMvpV20OVqcThHPTFW7G1vJcUpwFfR4j9Di3UifY/px4+4ofQcdwEQ8M3 jXFYEFTlNoxkuRq/nE5Vz1Al7wRDwJeT5mijjP9zcwv10k6N0hlvasfCAEuDqvgkPO vcIbxH6L2bldpdCC17hR6/SlYcH+543iKT4uIo7KJKq6HpVHaqMuZwVWiSMM4fj4A7 /d5QFgZGEA222bSfDdn+yFr/HmQF+GZFehs/NqRLy2T5t94gFnyBssznM62W/xWijT EQbHfPR1WUqObAATIMi6fxiiHcEe++BOY1vf8aDIh3ZrEUCBsjZkTI/rHnGCkavyiB gO3d3c1D+3hzw== 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/paddr: activate DAMOS_LRU_PRIO targets instead of marking accessed Date: Sat, 28 Jun 2025 09:51:37 -0700 Message-Id: <20250628165144.55528-5-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628165144.55528-1-sj@kernel.org> References: <20250628165144.55528-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_LRU_DEPRIOD directly deactivate the pages, while DAMOS_LRU_PRIO calls folio_mark_accessed(), which does incremental activation. The incremental activation was assumed to be useful for making sure the pages of the hot memory region are really hot. After the introduction of DAMOS_LRU_PRIO, the young page filter has added. Users can use the young page filter to make sure the page is eligible to be activated. Meanwhile, the asymmetric behavior of DAMOS_LRU_[DE]PRIO can confuse users. Directly activate given pages for DAMOS_LRU_PRIO, to eliminate the unnecessary incremental activation steps, and be symmetric with DAMOS_LRU_DEPRIO for easier usages. Signed-off-by: SeongJae Park --- mm/damon/paddr.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index d4261da48b0a..34d4b3017043 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -474,8 +474,8 @@ static unsigned long damon_pa_pageout(struct damon_regi= on *r, struct damos *s, return applied * PAGE_SIZE; } =20 -static inline unsigned long damon_pa_mark_accessed_or_deactivate( - struct damon_region *r, struct damos *s, bool mark_accessed, +static inline unsigned long damon_pa_de_activate( + struct damon_region *r, struct damos *s, bool activate, unsigned long *sz_filter_passed) { unsigned long addr, applied =3D 0; @@ -494,8 +494,8 @@ static inline unsigned long damon_pa_mark_accessed_or_d= eactivate( else *sz_filter_passed +=3D folio_size(folio); =20 - if (mark_accessed) - folio_mark_accessed(folio); + if (activate) + folio_activate(folio); else folio_deactivate(folio); applied +=3D folio_nr_pages(folio); @@ -507,18 +507,16 @@ static inline unsigned long damon_pa_mark_accessed_or= _deactivate( return applied * PAGE_SIZE; } =20 -static unsigned long damon_pa_mark_accessed(struct damon_region *r, +static unsigned long damon_pa_activate_pages(struct damon_region *r, struct damos *s, unsigned long *sz_filter_passed) { - return damon_pa_mark_accessed_or_deactivate(r, s, true, - sz_filter_passed); + return damon_pa_de_activate(r, s, true, sz_filter_passed); } =20 static unsigned long damon_pa_deactivate_pages(struct damon_region *r, struct damos *s, unsigned long *sz_filter_passed) { - return damon_pa_mark_accessed_or_deactivate(r, s, false, - sz_filter_passed); + return damon_pa_de_activate(r, s, false, sz_filter_passed); } =20 static unsigned int __damon_pa_migrate_folio_list( @@ -803,7 +801,7 @@ static unsigned long damon_pa_apply_scheme(struct damon= _ctx *ctx, case DAMOS_PAGEOUT: return damon_pa_pageout(r, scheme, sz_filter_passed); case DAMOS_LRU_PRIO: - return damon_pa_mark_accessed(r, scheme, sz_filter_passed); + return damon_pa_activate_pages(r, scheme, sz_filter_passed); case DAMOS_LRU_DEPRIO: return damon_pa_deactivate_pages(r, scheme, sz_filter_passed); case DAMOS_MIGRATE_HOT: --=20 2.39.5 From nobody Wed Oct 8 10:56:39 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 2708425A2BC; Sat, 28 Jun 2025 16:51:53 +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=1751129513; cv=none; b=m6+fkizi1xBAqvXkCZtB/frTXoLVbEvBD0clazAY6Ov3KcLVW5TgOsZ1HsOptVi5cWD0ZW7/8jKb+XxoGQZ0H651F04UJcW34XRIcdB1+psSyS5oTqLr/4BZkJNyLj6E/hrwbNXIT4H16Y2wAZPUTjngjD66pPEMS9m1GeH1NQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751129513; c=relaxed/simple; bh=L6arW2jwx/Rbwfx5uwGlsnD8HGyjJeRRb71lu8RP0Uc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jBNU2rNpWrf/bjhoEdzXWSrt+50BgswYVXOkG4R6DhRUGAQi28TOi92zMWAaEKEl7UWmYW7X+3c/xEnA4wCNXUp39JGh9IlGZ6QNunK46l/oIFvRq+CBj0bZ30PF4JzqF22xZbNe3qOtNoSxA4Yj38lEDXfXEtuIfhtRCbt4mnU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CXUs26kP; 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="CXUs26kP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA9D7C4CEED; Sat, 28 Jun 2025 16:51:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751129513; bh=L6arW2jwx/Rbwfx5uwGlsnD8HGyjJeRRb71lu8RP0Uc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CXUs26kP0UoD7duEu7XVlCCG8xhCD0eEHfGltVLEgEZVFgEIDFdFanNFuwJ8iUfDF JpVITsSKaWKJJ08wGCv7/lAxYizGdicuzw+wb3j+3w0Zz75hKR7Rtqc9LJ9rZWK7kw LRDS+BjfpPWsnlMqWpP0nnu6/l0HPpZGLh+Us/cL/mRs0KM+q9NxR+PqkWUYQbB79K tGSmQBy4A7wGu6adn7ZTFpSejfJPTOtZA88qXYojXlx4vpStbijaGu6iYhbwd8K6FA rlUlYAMnWJ4aypn/N4DuS0OIIlD6cfbQnHJAcMi4xTgeoAbnfsKT32hnE3f/dAHq6Z SxhbcF4v+zcuA== 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/lru_sort: consider age for quota prioritization Date: Sat, 28 Jun 2025 09:51:38 -0700 Message-Id: <20250628165144.55528-6-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628165144.55528-1-sj@kernel.org> References: <20250628165144.55528-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" DAMON_LRU_SORT is doing under-quota access pattern based regions prioritization using only access frequency. Age of regions is another useful information for distinguishing hot and cold regions. Use it for the prioritization, too. Signed-off-by: SeongJae Park --- mm/damon/lru_sort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 4af8fd4a390b..7513ebc6aeef 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -71,7 +71,7 @@ static struct damos_quota damon_lru_sort_quota =3D { /* Within the quota, mark hotter regions accessed first. */ .weight_sz =3D 0, .weight_nr_accesses =3D 1, - .weight_age =3D 0, + .weight_age =3D 1, }; DEFINE_DAMON_MODULES_DAMOS_TIME_QUOTA(damon_lru_sort_quota); =20 --=20 2.39.5 From nobody Wed Oct 8 10:56:39 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 3F4B825B2E1; Sat, 28 Jun 2025 16:51:54 +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=1751129514; cv=none; b=ECRVdDCTf0n1GaLMTMNcpgFjiCFDThk7DTA76E233P7HuJIpnxmKA13wSez1zdSUy8Oy0NMxc47OtQIQoYcxLp5IKlz386BZhYRoW6mkgskuRq6kFroNpOVAOy8ZomEJjmxuOTv0x00vg+nQzEsDWDCl4h6nJ7jFkA0eqFX47Vc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751129514; c=relaxed/simple; bh=E987cFasn0aqFLcb3GG3lT/UpsHEEEapIGli+ANI810=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FuWTH0SbY0bl524oMBJO6SbgSsC2Pvf4OMIAiRYS6uf+k+0NTvbYQ1amoTB8rjvmWsfY09gGUJdfSw7P045O51V6c1Wm31nYD/eVzOZUX+MyDUgN5J9jiO95GIokK7BW9HCOWrfIbTFCgirF2NspLq5ev5mHdLNyQwYlpzqi2Ws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j1lVM4NS; 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="j1lVM4NS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E917DC4CEF6; Sat, 28 Jun 2025 16:51:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751129514; bh=E987cFasn0aqFLcb3GG3lT/UpsHEEEapIGli+ANI810=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j1lVM4NSUYz57/XIFzh98DET1M+tq3DGlEpvOq5EyyXUJzIS08ity62fiVFsUyC2B ys0uSWXMHJnZsW42GVjJYJxKTpKgp6wIJ3fDzhtuo6i+b593VRJlUZS/c4vm2uc5Vb cnVqsfY0QKcM2Q5oCXKSn5fLmgkgF3m0arKqYF7ToUdZdGGYg9EFhANn5h+iJkJF8x LU5xzKMX+RYx3H4LNyeNEIZU/uAPIfoJCVsPREoDt+zM1CA139tZ62W4c19LT0/y6E OXIJCp68CdGcLpKKlSxSwhZSbF+lXH/eVij3ARttTY+mx6nhDmyZwTT1ZR5Q7NOTjw LuOI2NlK5XJeQ== 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 06/11] mm/damon/lru_sort: support young page filters Date: Sat, 28 Jun 2025 09:51:39 -0700 Message-Id: <20250628165144.55528-7-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628165144.55528-1-sj@kernel.org> References: <20250628165144.55528-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" DAMON monitors access pattern in the region level, and hence there could be some page level mismatches. A few hot pages could be located in cold region, and vice versa. Young page filter can be useful for doing additional page level access check before applying some DAMOS action. DAMON_LRU_SORT is not using young page filters, though. Add a parameter for using it. Signed-off-by: SeongJae Park --- mm/damon/lru_sort.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 7513ebc6aeef..3ccde23a8566 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -41,6 +41,21 @@ static bool enabled __read_mostly; static bool commit_inputs __read_mostly; module_param(commit_inputs, bool, 0600); =20 +/* + * Filter [none-]young pages accordingly for LRU [de]prioritizations. + * + * If this is set, check page level access (youngness) once again before e= ach + * LRU [de]prioritization operation. LRU prioritization operation is skip= ped + * if the page has not accessed since the last check (not young). LRU + * deprioritization operation is skipped if the page has accessed since the + * last check (young). The feature is enabled or disabled if this paramet= er is + * set as ``Y`` or ``N``, respectively. + * + * Disabled by default. + */ +static bool filter_young_pages __read_mostly; +module_param(filter_young_pages, bool, 0600); + /* * Access frequency threshold for hot memory regions identification in per= mil. * @@ -186,6 +201,28 @@ static struct damos *damon_lru_sort_new_cold_scheme(un= signed int cold_thres) return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_DEPRIO); } =20 +static int damon_lru_sort_add_filters(struct damos *hot_scheme, + struct damos *cold_scheme) +{ + struct damos_filter *filter; + + if (!filter_young_pages) + return 0; + + /* disallow prioritizing not-young pages */ + filter =3D damos_new_filter(DAMOS_FILTER_TYPE_YOUNG, false, false); + if (!filter) + return -ENOMEM; + damos_add_filter(hot_scheme, filter); + + /* disabllow de-prioritizing young pages */ + filter =3D damos_new_filter(DAMOS_FILTER_TYPE_YOUNG, true, false); + if (!filter) + return -ENOMEM; + damos_add_filter(cold_scheme, filter); + return 0; +} + static int damon_lru_sort_apply_parameters(void) { struct damon_ctx *param_ctx; @@ -219,6 +256,10 @@ static int damon_lru_sort_apply_parameters(void) damon_set_schemes(param_ctx, &hot_scheme, 1); damon_add_scheme(param_ctx, cold_scheme); =20 + err =3D damon_lru_sort_add_filters(hot_scheme, cold_scheme); + if (err) + goto out; + err =3D damon_set_region_biggest_system_ram_default(param_target, &monitor_region_start, &monitor_region_end); --=20 2.39.5 From nobody Wed Oct 8 10:56:39 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 9001725BF14; Sat, 28 Jun 2025 16:51:55 +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=1751129515; cv=none; b=ZEv4ZwCeFKqiIwSEQ0p6wF5ztgE0yrG+f+NVQAX05VF3XfBgc5yKftlYgw3O1PDJYyjXVNK+8nIW6eEfIvNF/L6Rpsm/sqSnxGJiNM3D7l+CBURjGlLpK8KBHE6wiNmdKMt0bku9wT5WCt4llh3J/+3aHZpm1biF1u7g4JYQOKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751129515; c=relaxed/simple; bh=7i7qunrK1xhj1u0yXR2LnSzmGQuChUp0Hbjbv8uMugI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=us0rD48n9O7xgK9/Xqre5VZRx8lBpwjkV2Pq4coACeNjPzq2yn5Lvy+T07aIFnF4FKVjAAJa6PvChmM393gZNSeQDFh0rxtI4lKc6S+n8zE2ZgMfysGbc0YBd/aPwZtb78kBOFWhOufmuNinZO/JeCtVTatQ/q3y8K6fvbjVaOw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P7XpEwch; 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="P7XpEwch" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 028CDC4CEF0; Sat, 28 Jun 2025 16:51:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751129515; bh=7i7qunrK1xhj1u0yXR2LnSzmGQuChUp0Hbjbv8uMugI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P7XpEwchMN6ffUybiDQQo9Ptpx34FwBKUK4NhGPfrPgqZgkGjNqcRmTojYe4V7Eh1 M61WuKMVdKSSL/YChU5k8PRBGrekTlwN7CVP/5ftSfYYCoqLnywDS6QDOjZfbF7Ncl uOFVS8WqtF3Qq2zWuc8czfLKvCpHVBzd8G+FRG3k8V2dOWHEP2fB/EcESsJX7Vuwd9 m+LDeZhqpVrbrvg43PZlTuH9PgHWsMFYoc+Oir3yMm/kOpmL/md6UWvrwDTqTMLT0n HFUzREO0hPt+QC6gBxsUoWlci42jIllR/1vzt1/KJOw5QHSfkdyJ1lgACE5sSlysPg VzyAa5rsFk0IA== 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/lru_sort: document filter_young_pages Date: Sat, 28 Jun 2025 09:51:40 -0700 Message-Id: <20250628165144.55528-8-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628165144.55528-1-sj@kernel.org> References: <20250628165144.55528-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" Document the new DAMON_LRU_SORT parameter, filter_young_pages. It can be used to use page level access re-check for the LRU sorting. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/lru_sort.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Documentation/admin-guide/mm/damon/lru_sort.rst b/Documentatio= n/admin-guide/mm/damon/lru_sort.rst index 7b0775d281b4..18fa73a59f62 100644 --- a/Documentation/admin-guide/mm/damon/lru_sort.rst +++ b/Documentation/admin-guide/mm/damon/lru_sort.rst @@ -79,6 +79,20 @@ of parametrs except ``enabled`` again. Once the re-read= ing is done, this parameter is set as ``N``. If invalid parameters are found while the re-reading, DAMON_LRU_SORT will be disabled. =20 +filter_young_pages +------------------ + +Filter [none-]young pages accordingly for LRU [de]prioritizations. + +If this is set, check page level access (youngness) once again before each +LRU [de]prioritization operation. LRU prioritization operation is skipped +if the page has not accessed since the last check (not young). LRU +deprioritization operation is skipped if the page has accessed since the +last check (young). The feature is enabled or disabled if this parameter = is +set as ``Y`` or ``N``, respectively. + +Disabled by default. + hot_thres_access_freq --------------------- =20 --=20 2.39.5 From nobody Wed Oct 8 10:56:39 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 9B93825C80D; Sat, 28 Jun 2025 16:51:56 +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=1751129516; cv=none; b=gGNZ8wEocBNuT2E0G/wCTH8R11scKr0nI+QSTwuDMb+gi6HFLV6sVbF09lv9H6E9RpOgLax3synKNWYx4bVjpe/NQf+a4LwPo0/0TcVnBhoTylEy+C21EdKfOOZJczssaZIa7VJweo8x6yVsf7gmcs9ALjAMPHAMPJTG5l0Wcvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751129516; c=relaxed/simple; bh=AIBeBRbmeSSh7sYS8+FVSI4lH0Rgj/i6prmCLpF8QMQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tc6xVgE3Qq9HtXQ1TbTpbQesZf6IdKk99d2A38H/sxHjkThNOS59UNQjQkwSQrT4yyvCSBHED4qpxN0T6VG++J9apwnFnjluyH1ht2TKU7vFivdZopUemwD1lA9E7FbX//95uTfhZLHChkM8C+VyN4nphzlPGD0YvUG/A15zDsk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cuGpmL1m; 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="cuGpmL1m" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 114F4C4CEED; Sat, 28 Jun 2025 16:51:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751129516; bh=AIBeBRbmeSSh7sYS8+FVSI4lH0Rgj/i6prmCLpF8QMQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cuGpmL1mJynk5SlCW0enE68mHiib8LrLQH5BBuHmCx0QYi3WTprxvLhjDGwRLqLXt 1RohepaKPT9JSRA/KXO8bBQuR8xlTJtW4TXuqzsLWnNm3Z41kRgNVF52vFkdQYg8ii xdRpEpfpmwn7wXPRnRs/5HQO2zf+GTbYWBPuLWLNHxmkNALaAzHBupUaOu4k1ADoBZ 5c2eAuEBU4o5EeGVx01M1k9Jh7YHRhX+dvV8m7IuDl3JIx5mKpV6i+khgGHKQq24qu mh1vFB0DzqrZfDAwZ8TceX6BYzoGDp8lEbbepnlVRnnz2bPGm8YxuobQk4gygLMZVB Ak0rXqC6k6ksQ== 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/lru_sort: support active:inactive memory ratio based auto-tuning Date: Sat, 28 Jun 2025 09:51:41 -0700 Message-Id: <20250628165144.55528-9-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628165144.55528-1-sj@kernel.org> References: <20250628165144.55528-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" Doing DAMOS_LRU_[DE]PRIO with DAMOS_QUOTA_[IN]ACTIVE_MEM_BP based quota auto-tuning can be useful. For example, users can ask DAMON to "find hot/cold pages and activate/deactivate those aiming 50:50 active:inactive memory size." But DAMON_LRU_SORT has no interface to do that. Add a module parameter for setting the target ratio. Signed-off-by: SeongJae Park --- mm/damon/lru_sort.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 3ccde23a8566..99c5a22cf3f2 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -41,6 +41,20 @@ static bool enabled __read_mostly; static bool commit_inputs __read_mostly; module_param(commit_inputs, bool, 0600); =20 +/* + * Desired active to [in]active memory ratio in bp (1/10,000). + * + * While keeping the caps that set by other quotas, DAMON_LRU_SORT + * automatically increases and decreases the effective level of the quota + * aiming the LRU [de]prioritizations of the hot and cold memory resulting= in + * this active to [in]active memory ratio. Value zero means disabling this + * auto-tuning feature. + * + * Disabled by default. + */ +static unsigned long active_mem_bp __read_mostly; +module_param(active_mem_bp, ulong, 0600); + /* * Filter [none-]young pages accordingly for LRU [de]prioritizations. * @@ -201,6 +215,26 @@ static struct damos *damon_lru_sort_new_cold_scheme(un= signed int cold_thres) return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_DEPRIO); } =20 +static int damon_lru_sort_add_quota_goals(struct damos *hot_scheme, + struct damos *cold_scheme) +{ + struct damos_quota_goal *goal; + + if (!active_mem_bp) + return 0; + goal =3D damos_new_quota_goal(DAMOS_QUOTA_ACTIVE_MEM_BP, active_mem_bp); + if (!goal) + return -ENOMEM; + damos_add_quota_goal(&hot_scheme->quota, goal); + /* aim 0.2 % goal conflict, to keep little ping pong */ + goal =3D damos_new_quota_goal(DAMOS_QUOTA_INACTIVE_MEM_BP, + 10000 - active_mem_bp + 2); + if (!goal) + return -ENOMEM; + damos_add_quota_goal(&hot_scheme->quota, goal); + return 0; +} + static int damon_lru_sort_add_filters(struct damos *hot_scheme, struct damos *cold_scheme) { @@ -256,6 +290,9 @@ static int damon_lru_sort_apply_parameters(void) damon_set_schemes(param_ctx, &hot_scheme, 1); damon_add_scheme(param_ctx, cold_scheme); =20 + err =3D damon_lru_sort_add_quota_goals(hot_scheme, cold_scheme); + if (err) + goto out; err =3D damon_lru_sort_add_filters(hot_scheme, cold_scheme); if (err) goto out; --=20 2.39.5 From nobody Wed Oct 8 10:56:39 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 AB54325CC64; Sat, 28 Jun 2025 16:51:57 +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=1751129517; cv=none; b=SrP/4lQzspo7JC3BFhjR7uc6bV7tibryKxH94haIdUdaYqfWBG30fWtTigw7f2hZmtMrWS0VejFQgB4kvSTzUZpXPW4IP20ziNl7NuK0KPr2iNapuTjGaW5pgiU+nTXr1rpr4haTlRwuc963/fc46wbEEnpAO7gJcuztQVTSM/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751129517; c=relaxed/simple; bh=9B9axhBqem3qxGrM1GaInOJd4kKcsPOJN3cOuqPuzOs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QXgOs9Yg7GcDWRjy1dHjZammIwLsaZe2uUJcmnLxRP5OpCftdSEh1RWMfRp3u4lx60RqCBCm5yzseIXBmXp1xyVIROVsxAGyqyZZHOKXsaNhv4WEITYobOADNLStZNWdLW3M8Z7yQt1rqiDUrILX2k2VKqxayGG4VxYTTbXb6zQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oEpZf6YG; 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="oEpZf6YG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AE6FC4CEF3; Sat, 28 Jun 2025 16:51:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751129517; bh=9B9axhBqem3qxGrM1GaInOJd4kKcsPOJN3cOuqPuzOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oEpZf6YGC00awkpS9HBD5IJQLRQP7aS9Hr28VHy5mhMEUfdegKRanwpS9kdyQGPwL lk5gWtPSE2VEJkuIXe+Nd5SLn6Pg2Y1Urol3zP/Xo6CtXp11pFeW9Pg8Ts7FvNcOXO 48o0wPg3dfrK8Ml8IRIweokfBtF/llzafeItOr6sy58iITHdNqJRWWGhvCFlFgFytQ qVsxj4svQGM577RRWUnKh4doCt95QklXiEVRB1hgG8HzmeIMMherYnglnYo2qVDMvi PWXwNsnNJdLUe6CpEYNRbvuIiwX0giHc2YtNeeKss9iqaGB8x1huzQf50s0fNaX1G2 9D9C/LqmUicrw== 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 09/11] Docs/admin-guide/mm/damon/lru_sort: document active_mem_bp parameter Date: Sat, 28 Jun 2025 09:51:42 -0700 Message-Id: <20250628165144.55528-10-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628165144.55528-1-sj@kernel.org> References: <20250628165144.55528-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" Document a newly added DAMON_LRU_SORT parameter for doing auto-tuning aiming an active to inactive memory size ratio. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/lru_sort.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Documentation/admin-guide/mm/damon/lru_sort.rst b/Documentatio= n/admin-guide/mm/damon/lru_sort.rst index 18fa73a59f62..ca4e071b3159 100644 --- a/Documentation/admin-guide/mm/damon/lru_sort.rst +++ b/Documentation/admin-guide/mm/damon/lru_sort.rst @@ -79,6 +79,18 @@ of parametrs except ``enabled`` again. Once the re-read= ing is done, this parameter is set as ``N``. If invalid parameters are found while the re-reading, DAMON_LRU_SORT will be disabled. =20 +active_mem_bp +------------- + +Desired active to [in]active memory ratio in bp (1/10,000). + +While keeping the caps that set by other quotas, DAMON_LRU_SORT automatica= lly +increases and decreases the effective level of the quota aiming the LRU +[de]prioritizations of the hot and cold memory resulting in this active to +[in]active memory ratio. Value zero means disabling this auto-tuning feat= ure. + +Disabled by default. + filter_young_pages ------------------ =20 --=20 2.39.5 From nobody Wed Oct 8 10:56:39 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 89D9625D549; Sat, 28 Jun 2025 16:51:58 +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=1751129518; cv=none; b=k4GwMQ8VLC2nhpbZQqgyoWOKtbJaDVAdRBJ/tEUXWFmBNVPN/wMo2W7lrKBEHZQZcAUnnBiaANT8R2BkpGwTCFSCru1jgTe/DMrN0IbK0lNKicb/wamCh6OyGpBm0XkN8sa6zmJj2i3h1WKY354zbB3yjOJyUCMv49ST3p5BTJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751129518; c=relaxed/simple; bh=tlvqxxIUDAypcpXix4DDUce9Gvf8SrIMBmaTGFZI30U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XQiQyIX1g8f4iwHxJpNwodAYPjel3Xki7EwNLJppsfV18Kcqlls15iXJYX6/Okh2cwFB8tOn94scxm+fSY675uWhJg3JrCX3J5ny4+is1Ip8jb8DNm4Aqifi9xVDnu72XYJMPOYWJbiunCYyWH03EpiuXNLK1dsHULSs3699rMM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lgLtLZ6q; 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="lgLtLZ6q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 405D1C4CEED; Sat, 28 Jun 2025 16:51:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751129518; bh=tlvqxxIUDAypcpXix4DDUce9Gvf8SrIMBmaTGFZI30U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lgLtLZ6q9JHyXcZE7E3djoYPOZN6LsoO2UhZ5uv5R40j+Kt/aTRhT71X+TgkdBMWc epy51+h6/a+DXlMCvZwjFGaoVr7BNrO9FmPkC95JSnXO5SxX1FE3V7vH7IwNHCUTvy CU1DpW+/553Is8RvXDBb82W4sPBn39AuMfLcZjVD/SQtayqs6319uJuCl+erCXEqpz 7l8usr6qm4bB3L0l2/V6L8WiP/t8ZiRRWuNwy8lKA2HB88I0Omf4IEEt06p7CD/tEj tflx4ALke51tN6w42QYzk5kVHblMRp8csfEYwWLcX/rQavPWGKArTWqJ9Q/4g15EDm X+5qNzFqaRMDQ== 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/lru_sort: add monitoring intervals auto-tuning parameter Date: Sat, 28 Jun 2025 09:51:43 -0700 Message-Id: <20250628165144.55528-11-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628165144.55528-1-sj@kernel.org> References: <20250628165144.55528-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" DAMON monitoring intervals tuning was crucial for every DAMON use case. Now there are a tuning guideline and an automated intervals tuning feature. DAMON_LRU_SORT is still using manual control of intervals. Add a module parameter for utilizing the auto-tuning feature with a suggested auto-tuning parameters. Signed-off-by: SeongJae Park --- mm/damon/lru_sort.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 99c5a22cf3f2..1e9e19f15b33 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -55,6 +55,20 @@ module_param(commit_inputs, bool, 0600); static unsigned long active_mem_bp __read_mostly; module_param(active_mem_bp, ulong, 0600); =20 +/* + * Auto-tune monitoring intervals. + * + * If this parameter is set as ``Y``, DAMON_LRU_SORT automatically tune + * DAMON's sampling and aggregation intervals. The auto-tuning aims to ca= pture + * meaningful amount of access events in each DAMON-snapshot, while keepin= g the + * sampling interval 5 milliseconds in minimu, and 10 seconds in maximum. + * Setting this as ``Y`` disables the auto-tuning. + * + * Disabled by default. + */ +static bool autotune_monitoring_intervals __read_mostly; +module_param(autotune_monitoring_intervals, bool, 0600); + /* * Filter [none-]young pages accordingly for LRU [de]prioritizations. * @@ -261,6 +275,7 @@ static int damon_lru_sort_apply_parameters(void) { struct damon_ctx *param_ctx; struct damon_target *param_target; + struct damon_attrs attrs; struct damos *hot_scheme, *cold_scheme; unsigned int hot_thres, cold_thres; int err; @@ -269,18 +284,27 @@ static int damon_lru_sort_apply_parameters(void) if (err) return err; =20 - err =3D damon_set_attrs(ctx, &damon_lru_sort_mon_attrs); + attrs =3D damon_lru_sort_mon_attrs; + if (autotune_monitoring_intervals) { + attrs.sample_interval =3D 5000; + attrs.aggr_interval =3D 100000; + attrs.intervals_goal.access_bp =3D 40; + attrs.intervals_goal.aggrs =3D 3; + attrs.intervals_goal.min_sample_us =3D 5000; + attrs.intervals_goal.max_sample_us =3D 10 * 1000 * 1000; + } + err =3D damon_set_attrs(ctx, &attrs); if (err) goto out; =20 err =3D -ENOMEM; - hot_thres =3D damon_max_nr_accesses(&damon_lru_sort_mon_attrs) * + hot_thres =3D damon_max_nr_accesses(&attrs) * hot_thres_access_freq / 1000; hot_scheme =3D damon_lru_sort_new_hot_scheme(hot_thres); if (!hot_scheme) goto out; =20 - cold_thres =3D cold_min_age / damon_lru_sort_mon_attrs.aggr_interval; + cold_thres =3D cold_min_age / attrs.aggr_interval; cold_scheme =3D damon_lru_sort_new_cold_scheme(cold_thres); if (!cold_scheme) { damon_destroy_scheme(hot_scheme); --=20 2.39.5 From nobody Wed Oct 8 10:56:39 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 D890825DD09; Sat, 28 Jun 2025 16:51:59 +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=1751129519; cv=none; b=AF1RmfnrAbFISkS13prnqdDbPuQj/ccNOKn/kcyVouaM35kxwOmg/eJeOFfABjFUFLWivPBfaw1F1AXGvDzp1ktbQ4PLGxrBnm0PM06TLZmuxydNi7qKpmII/0J/K7V9F7nb6a17wQlhrvgxfspa6gYDBTm8OSbaNOOEMT2sRMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751129519; c=relaxed/simple; bh=fbG+KWln8sAPRrugQfWweISG0dHsqG1V9oMoVBcHL/c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZR+9iUgletjAF5cihr8Ank4RiS/5qK6U09k8Kuhkbv98MQABJxgpGZS3uEFnldAI1R2oteEUgXKLv1UksqCtl1A5xBTwgxCnNXCVBhJeDfEnvhKABw980EIZFEgAdRjzhSp9rmtODNbcrRHF7uuFSefM4BoiPFFgnFzqwH3je3Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DS5QeNIM; 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="DS5QeNIM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46876C4CEEA; Sat, 28 Jun 2025 16:51:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751129519; bh=fbG+KWln8sAPRrugQfWweISG0dHsqG1V9oMoVBcHL/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DS5QeNIM5rDCiErt/eCcWwMgF688xD5WMGg+fgZXgr0iH8Vc2BlIJI2Xo8MJoi/pi SQmYij/3HDK/RMJex+bjiE/yfsXdHLWXMGCq5+BnPqizg1/tu0ZhuuyWrZq50bjQan tvt3PBUq5oXPSXmyB97t17rlKvbiFa2rYhkV0LVoQjBdy4OkMOe88R7SfuyLYLye84 L4gzSp4fdatQmqdN32QeLpODeynJiU4N8Q178q8DfVMO2K4iWh13aMF/DG08xWmcF/ Kj35aPZ1VxuuypVPDslwt12oFLwWHX58mKerXkaA4fgoVePzk6D9hjtYb+WFFjpxlP HPG9Dxbs2UpPg== 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/admin-guide/mm/damon/lru_sort: document intervals autotuning Date: Sat, 28 Jun 2025 09:51:44 -0700 Message-Id: <20250628165144.55528-12-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628165144.55528-1-sj@kernel.org> References: <20250628165144.55528-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" Document a newly added DAMON_LRU_SORT module parameter for using monitoring intervals auto-tuning feature of DAMON. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/lru_sort.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/admin-guide/mm/damon/lru_sort.rst b/Documentatio= n/admin-guide/mm/damon/lru_sort.rst index ca4e071b3159..f9dfa8255dda 100644 --- a/Documentation/admin-guide/mm/damon/lru_sort.rst +++ b/Documentation/admin-guide/mm/damon/lru_sort.rst @@ -91,6 +91,17 @@ increases and decreases the effective level of the quota= aiming the LRU =20 Disabled by default. =20 +Auto-tune monitoring intervals +------------------------------ + +If this parameter is set as ``Y``, DAMON_LRU_SORT automatically tune DAMON= 's +sampling and aggregation intervals. The auto-tuning aims to capture meani= ngful +amount of access events in each DAMON-snapshot, while keeping the sampling +interval 5 milliseconds in minimu, and 10 seconds in maximum. Setting thi= s as +``Y`` disables the auto-tuning. + +Disabled by default. + filter_young_pages ------------------ =20 --=20 2.39.5