From nobody Sun Jun 14 06:55:33 2026 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 A35F8FBE1 for ; Thu, 11 Jun 2026 15:03:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781190230; cv=none; b=RFWpktTqa6mx7XrYZ/wObbE8IEs5qSPdAd34UFuf1aD6YTMhVsxC4oxTG/4SkeQXWfCc7fzOltdBVHFvKgjUH/tccZMNc01MQPSchhWmUhDVinQFeOsazDjmyRxoXV7RJfbQs3wQSWssR+aiHvjdTSOq4cgNtjyXHyu6iu3IK7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781190230; c=relaxed/simple; bh=vn8+ADTQdUF+GAQSrJkdK6xONgPIrplNLy6Gejx2jUs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pzXF2x9ebjS2YfCWpj3uFu6QzSsfU+tYjDoVFYb1eMltztW7xlzdHavsZzmbrlmuCVyCut/PzuFkJWMfVL61S39GMYppcFBwhv0lNdeaYF3uQQl3HcfChhWFToMw/GfElSWfZha5+P9F6znG/8B+XxKxJD4eOpUnqdz+7wMkWzM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei-partners.com; spf=pass smtp.mailfrom=huawei-partners.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei-partners.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei-partners.com Received: from mail.maildlp.com (unknown [172.18.224.83]) by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4gbm9v5G6nzHnGkJ; Thu, 11 Jun 2026 23:03:31 +0800 (CST) Received: from mscpeml500003.china.huawei.com (unknown [7.188.49.51]) by mail.maildlp.com (Postfix) with ESMTPS id 53EED40575; Thu, 11 Jun 2026 23:03:38 +0800 (CST) Received: from mscphis01197.huawei.com (10.123.65.218) by mscpeml500003.china.huawei.com (7.188.49.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 11 Jun 2026 18:03:37 +0300 From: To: , , , , , , , , , , Subject: [RFC PATCH v4 1/4] mm/damon: Introduce DAMOS_QUOTA_HUGEPAGE auto tuning Date: Thu, 11 Jun 2026 15:02:41 +0000 Message-ID: <20260611150244.3454699-2-gutierrez.asier@huawei-partners.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260611150244.3454699-1-gutierrez.asier@huawei-partners.com> References: <20260611150244.3454699-1-gutierrez.asier@huawei-partners.com> 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 X-ClientProxiedBy: mscpeml500003.china.huawei.com (7.188.49.51) To mscpeml500003.china.huawei.com (7.188.49.51) Content-Type: text/plain; charset="utf-8" From: Asier Gutierrez Introduce DAMOS_QUOTA_HUGEPAGE auto tuning Add a new DAMOS quota goal metric to measure the amount of huge page consumption to total memory consumption ratio. Signed-off-by: Asier Gutierrez --- include/linux/damon.h | 2 ++ mm/damon/core.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 6f7edb3590ef..23a9cec05033 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -162,6 +162,7 @@ enum damos_action { * @DAMOS_QUOTA_INACTIVE_MEM_BP: Inactive to total LRU memory ratio. * @DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP: Scheme-eligible memory ratio of a * node in basis points (0-10000). + * @DAMOS_QUOTA_HUGEPAGE_MEM_BP: Huge page to total used 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. @@ -176,6 +177,7 @@ enum damos_quota_goal_metric { DAMOS_QUOTA_ACTIVE_MEM_BP, DAMOS_QUOTA_INACTIVE_MEM_BP, DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP, + DAMOS_QUOTA_HUGEPAGE_MEM_BP, NR_DAMOS_QUOTA_GOAL_METRICS, }; =20 diff --git a/mm/damon/core.c b/mm/damon/core.c index 7e4b9affc5b0..b001f80681b1 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2795,6 +2795,17 @@ static unsigned int damos_get_in_active_mem_bp(bool = active_ratio) return mult_frac(inactive, 10000, total); } =20 +static unsigned int damos_hugepage_mem_bp(void) +{ + unsigned long thp, total; + + thp =3D global_node_page_state(NR_ANON_THPS) + + global_node_page_state(NR_SHMEM_THPS) + + global_node_page_state(NR_FILE_THPS); + total =3D totalram_pages() - global_zone_page_state(NR_FREE_PAGES); + return mult_frac(thp, 10000, total); +} + static void damos_set_quota_goal_current_value(struct damon_ctx *c, struct damos *s, struct damos_quota_goal *goal) { @@ -2826,6 +2837,9 @@ static void damos_set_quota_goal_current_value(struct= damon_ctx *c, goal->current_value =3D damos_get_node_eligible_mem_bp(c, s, goal->nid); break; + case DAMOS_QUOTA_HUGEPAGE_MEM_BP: + goal->current_value =3D damos_hugepage_mem_bp(); + break; default: break; } --=20 2.43.0 From nobody Sun Jun 14 06:55:33 2026 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 292E13FBA7 for ; Thu, 11 Jun 2026 15:03:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781190227; cv=none; b=fm2mXXfPxIjQ2MvUzHDRtKh0BSWeiG7UCpZ4BiNGyOmhAQX6f5U5uPsFze8U4ndbBONC5s3eMLYUN1C1xxBQaF6zJiGJhBGiKtkQeK3DIFApON9pYZ0clfBuAV2u28hBUeaYoi3vjHRESI7YS8uP7eQrO/YQGTv06fpPbecF2a8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781190227; c=relaxed/simple; bh=420DwsVj+FtVuaT9ZkIgpRDdSTphcHGl6Sc2L7ewJG0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Imaglr/Qei0eU8z/ZzMoiPVn1KrnJS77gm4N1+XX8D0feAQP2gqOBQac2JRkWvQBNPMLXBV3mDBmzirlZ/c6nYKI2RqjAIJ4MIaVAEkWJ6nE/KZc+9oC5PteFzO9w+HxcFV8f2DT/udlu0lLCdaeUWaORefLXpdFub3knQwExzo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei-partners.com; spf=pass smtp.mailfrom=huawei-partners.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei-partners.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei-partners.com Received: from mail.maildlp.com (unknown [172.18.224.83]) by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4gbm9l13dczJ46BB; Thu, 11 Jun 2026 23:03:23 +0800 (CST) Received: from mscpeml500003.china.huawei.com (unknown [7.188.49.51]) by mail.maildlp.com (Postfix) with ESMTPS id 6656540569; Thu, 11 Jun 2026 23:03:38 +0800 (CST) Received: from mscphis01197.huawei.com (10.123.65.218) by mscpeml500003.china.huawei.com (7.188.49.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 11 Jun 2026 18:03:38 +0300 From: To: , , , , , , , , , , Subject: [RFC PATCH v4 2/4] mm/damon: introduce DAMON_HUGEPAGE for hot region hugepage collapsing Date: Thu, 11 Jun 2026 15:02:42 +0000 Message-ID: <20260611150244.3454699-3-gutierrez.asier@huawei-partners.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260611150244.3454699-1-gutierrez.asier@huawei-partners.com> References: <20260611150244.3454699-1-gutierrez.asier@huawei-partners.com> 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 X-ClientProxiedBy: mscpeml500003.china.huawei.com (7.188.49.51) To mscpeml500003.china.huawei.com (7.188.49.51) Content-Type: text/plain; charset="utf-8" From: Asier Gutierrez This patch introduces a new DAMON module (SAMPLE_DAMON_HUGEPAGE) which collapses hot regions into huge pages. SAMPLE_DAMON_HUGEPAGE operates in the virtual memory space, for a specific task. The user is expected to supply the PID of the task that is going to be monitored through the monitored_pid module variable. SAMPLE_DAMON_HUGEPAGE uses the hugepage auto-tune mechanism to increase or decrease the aggressiveness of page collapsing. User autotuning is also available for additional tuning aggressiveness control. The module also includes changes to the DAMON compilation, so that the module can be enabled or disabled. Signed-off-by: Asier Gutierrez --- samples/damon/Kconfig | 12 ++ samples/damon/Makefile | 1 + samples/damon/hugepage.c (new) | 207 +++++++++++++++++++++++++++++++++ 3 files changed, 220 insertions(+) diff --git a/samples/damon/Kconfig b/samples/damon/Kconfig index cbf96fd8a8bf..512f150aaabb 100644 --- a/samples/damon/Kconfig +++ b/samples/damon/Kconfig @@ -40,4 +40,16 @@ config SAMPLE_DAMON_MTIER =20 If unsure, say N. =20 +config SAMPLE_DAMON_HUGEPAGE + bool "Build DAMON-based collapse of hot regions (SAMPLE_DAMON_HUGEPAGE)" + depends on DAMON && DAMON_VADDR + help + This module monitors a certain PID provided by the user through + monitored_pid attribute. Hot regions are determined by DAMON-based + sampling. Collapsing occurs according to the quota goal using total + memory usage to huge page usage ratio. The ratio is set by the user + through a module attribute. + + If unsure, say N. + endmenu diff --git a/samples/damon/Makefile b/samples/damon/Makefile index 72f68cbf422a..96bde2c44846 100644 --- a/samples/damon/Makefile +++ b/samples/damon/Makefile @@ -3,3 +3,4 @@ obj-$(CONFIG_SAMPLE_DAMON_WSSE) +=3D wsse.o obj-$(CONFIG_SAMPLE_DAMON_PRCL) +=3D prcl.o obj-$(CONFIG_SAMPLE_DAMON_MTIER) +=3D mtier.o +obj-$(CONFIG_SAMPLE_DAMON_HUGEPAGE) +=3D hugepage.o diff --git a/samples/damon/hugepage.c b/samples/damon/hugepage.c new file mode 100644 index 000000000000..2c7fd213a8db --- /dev/null +++ b/samples/damon/hugepage.c @@ -0,0 +1,207 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2026 HUAWEI, Inc. + * https://www.huawei.com + * + * Author: Asier Gutierrez + */ + +#define pr_fmt(fmt) "damon_sample_hugepage: " fmt + +#include +#include +#include + +#ifdef MODULE_PARAM_PREFIX +#undef MODULE_PARAM_PREFIX +#endif +#define MODULE_PARAM_PREFIX "damon_sample_hugepage." + +static bool enabled __read_mostly; + +static unsigned long target_pid; +module_param(target_pid, ulong, 0600); + +/* By default, total huge pages to system memory usage ratio set to 10% */ +static unsigned long quota_percentage_hugepage __read_mostly =3D 1000; +module_param(quota_percentage_hugepage, ulong, 0600); + +static unsigned long quota_autotune_feedback __read_mostly; +module_param(quota_autotune_feedback, ulong, 0600); + +static struct damon_ctx *ctx; +static struct pid *target_pidp; + +static int damon_sample_hugepage_damon_call_fn(void *data) +{ + struct damon_ctx *c =3D data; + struct damon_target *t; + + damon_for_each_target(t, c) { + struct damon_region *r; + unsigned long hugepages =3D 0; + + damon_for_each_region(r, t) { + if (r->nr_accesses > 0) + hugepages +=3D r->ar.end - r->ar.start; + } + hugepages =3D hugepages / HPAGE_PMD_SIZE; + pr_info("hugepage: %lu\n", hugepages); + } + return 0; +} + +static struct damon_call_control call_control =3D { + .fn =3D damon_sample_hugepage_damon_call_fn, + .repeat =3D true, +}; + +static int damon_sample_hugepage_start(void) +{ + int err; + struct damon_target *target; + struct damos *scheme; + struct damos_quota_goal *goal; + + pr_info("start\n"); + + + ctx =3D damon_new_ctx(); + if (!ctx) + return -ENOMEM; + if (damon_select_ops(ctx, DAMON_OPS_VADDR)) { + damon_destroy_ctx(ctx); + return -EINVAL; + } + + target =3D damon_new_target(); + if (!target) { + damon_destroy_ctx(ctx); + return -ENOMEM; + } + damon_add_target(ctx, target); + target_pidp =3D find_get_pid(target_pid); + if (!target_pidp) { + damon_destroy_ctx(ctx); + return -EINVAL; + } + target->pid =3D target_pidp; + + scheme =3D damon_new_scheme(&(struct damos_access_pattern) { + .min_sz_region =3D HPAGE_PMD_SIZE, + .max_sz_region =3D ULONG_MAX, + .min_nr_accesses =3D 0, + .max_nr_accesses =3D UINT_MAX, + .min_age_region =3D 50, + .max_age_region =3D UINT_MAX}, + DAMOS_COLLAPSE, 0, + &(struct damos_quota) { + .ms =3D 10, + .sz =3D 128 * 1024 * 1024, + .reset_interval =3D 1000, + .weight_sz =3D 0, + .weight_nr_accesses =3D 1, + .weight_age =3D 1, + .goal_tuner =3D DAMOS_QUOTA_GOAL_TUNER_TEMPORAL}, + &(struct damos_watermarks){}, NUMA_NO_NODE); + if (!scheme) { + damon_destroy_ctx(ctx); + return -ENOMEM; + } + damon_set_schemes(ctx, &scheme, 1); + goal =3D damos_new_quota_goal(DAMOS_QUOTA_HUGEPAGE_MEM_BP, + quota_percentage_hugepage); + if (!goal) { + damon_destroy_ctx(ctx); + return -ENOMEM; + } + damos_add_quota_goal(&scheme->quota, goal); + + if (quota_autotune_feedback) { + goal =3D damos_new_quota_goal(DAMOS_QUOTA_USER_INPUT, 10000); + if (!goal) { + damon_destroy_ctx(ctx); + return -ENOMEM; + } + goal->current_value =3D quota_autotune_feedback; + damos_add_quota_goal(&scheme->quota, goal); + } + + err =3D damon_start(&ctx, 1, true); + if (err) { + damon_destroy_ctx(ctx); + return err; + } + + call_control.data =3D ctx; + err =3D damon_call(ctx, &call_control); + if (err) { + damon_stop(&ctx, 1); + damon_destroy_ctx(ctx); + } + return err; +} + +static void damon_sample_hugepage_stop(void) +{ + pr_info("stop\n"); + if (ctx) { + damon_stop(&ctx, 1); + damon_destroy_ctx(ctx); + } +} +static int damon_sample_hugepage_enabled_store(const char *val, + const struct kernel_param *kp) +{ + bool is_enabled =3D enabled; + int err; + + err =3D kstrtobool(val, &enabled); + if (err) + return err; + + if (enabled =3D=3D is_enabled) + return 0; + + if (!damon_initialized()) + return 0; + + if (enabled) { + err =3D damon_sample_hugepage_start(); + if (err) + enabled =3D false; + return err; + } + damon_sample_hugepage_stop(); + return 0; +} + +static const struct kernel_param_ops enabled_param_ops =3D { + .set =3D damon_sample_hugepage_enabled_store, + .get =3D param_get_bool, +}; + +module_param_cb(enabled, &enabled_param_ops, &enabled, 0600); +MODULE_PARM_DESC(enabled, + "Enable or disable DAMON_HUGEPAGE (default: disabled)"); + +static int __init damon_sample_hugepage_init(void) +{ + int err =3D 0; + + if (!damon_initialized()) { + if (enabled) + enabled =3D false; + pr_warn("Module not initialized\n"); + return -ENOMEM; + } + + if (enabled) { + err =3D damon_sample_hugepage_start(); + if (err) + enabled =3D false; + } + return err; +} + +module_init(damon_sample_hugepage_init); --=20 2.43.0 From nobody Sun Jun 14 06:55:33 2026 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 A37B8313546 for ; Thu, 11 Jun 2026 15:03:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781190227; cv=none; b=Tf7iD6tcANSf/PX+qLoU4IFCPK7hLYCTi9oOalflQK5KqEVaNvgWQpBknodove2fSo3JTlLLWr+GQ1FTRQZtRaeTWozKKkCQsQaWe6RY2ta+xIxLvgh31x0BrF56qkIyjHX3AVcTJxNSWODX3ruth6XZVCB6E3EPFz4ySe3bB2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781190227; c=relaxed/simple; bh=ZeFVoIo4QbIKLih1KzBIXzKoQ0K7MNj8fltcKI7gRUo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=i2MKW7eV0V+sZYFbR1QAnd9x8P5w6jmx7TltAyaonEk1D3LfTFML4KE7N3UB+17u4ve7zesOanrFrV8zLsTM0v+lHAoxMFUL+fBRuOYoo2Bv4OjBDpTcJsCtDjfcNNdSPTqDLIluOhuowl5ThA27jdpFQjtiElKA5rYdTcvwe2E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei-partners.com; spf=pass smtp.mailfrom=huawei-partners.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei-partners.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei-partners.com Received: from mail.maildlp.com (unknown [172.18.224.83]) by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4gbm9v6MQXzHnGkb; Thu, 11 Jun 2026 23:03:31 +0800 (CST) Received: from mscpeml500003.china.huawei.com (unknown [7.188.49.51]) by mail.maildlp.com (Postfix) with ESMTPS id 79AA240575; Thu, 11 Jun 2026 23:03:38 +0800 (CST) Received: from mscphis01197.huawei.com (10.123.65.218) by mscpeml500003.china.huawei.com (7.188.49.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 11 Jun 2026 18:03:38 +0300 From: To: , , , , , , , , , , Subject: [RFC PATCH v4 3/4] mm/damon/sysfs: support hugepage_mem_bp quota goal metric Date: Thu, 11 Jun 2026 15:02:43 +0000 Message-ID: <20260611150244.3454699-4-gutierrez.asier@huawei-partners.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260611150244.3454699-1-gutierrez.asier@huawei-partners.com> References: <20260611150244.3454699-1-gutierrez.asier@huawei-partners.com> 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 X-ClientProxiedBy: mscpeml500003.china.huawei.com (7.188.49.51) To mscpeml500003.china.huawei.com (7.188.49.51) Content-Type: text/plain; charset="utf-8" From: Asier Gutierrez Add the "hugepage_mem_bp" to the sysfs-schemes interface. Also handle DAMOS_QUOTA_HUGEPAGE_MEM_BP when constructing quota goals. Signed-off-by: Asier Gutierrez --- mm/damon/sysfs-schemes.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 329cfd0bbe9f..dc46ec128083 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1267,6 +1267,10 @@ struct damos_sysfs_qgoal_metric_name damos_sysfs_qgo= al_metric_names[] =3D { .metric =3D DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP, .name =3D "node_eligible_mem_bp", }, + { + .metric =3D DAMOS_QUOTA_HUGEPAGE_MEM_BP, + .name =3D "hugepage_mem_bp", + }, }; =20 static ssize_t target_metric_show(struct kobject *kobj, @@ -2877,6 +2881,9 @@ static int damos_sysfs_add_quota_score( case DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP: goal->nid =3D sysfs_goal->nid; break; + case DAMOS_QUOTA_HUGEPAGE_MEM_BP: + goal->current_value =3D sysfs_goal->current_value; + break; default: break; } --=20 2.43.0 From nobody Sun Jun 14 06:55:33 2026 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 293F235504D for ; Thu, 11 Jun 2026 15:03:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781190228; cv=none; b=OtYsbqV5U3s5D6rfOET6auEtKjAoytXza8UjkFXxU8MhFoPlC83t2LYTLQKr7s3TAt5k1212XEXXk3OSKEJB8mX8lLxAzgj6YQtq44oTnVGhNcFc6nNwqUMfjVB9RPNa6hQtumBMhuFbORgf+J/OOKfwkPe6v3AsoJUiUsIoHUQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781190228; c=relaxed/simple; bh=8fdc65f3lRWLitWCfZLmOgnvFgadAS0MFLX+J3U6iYs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CXUQhIpEhrLp/rgnZb/XSy3k7lQgNO2uz2z1R+YeVGSi9c6B5DWRvSieOcEcfZX1bVqh7I/N6Qq2RpMS9B7aYiVASL4LCVSFelF3iwPXs6CJ0RCIIYMii+EfhZVwNcd2pnQQL5miTrM3IQKzV1joxWe8ZPMz1U86eW0ngFGzaok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei-partners.com; spf=pass smtp.mailfrom=huawei-partners.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei-partners.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei-partners.com Received: from mail.maildlp.com (unknown [172.18.224.150]) by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4gbm9l4D8SzJ46bR; Thu, 11 Jun 2026 23:03:23 +0800 (CST) Received: from mscpeml500003.china.huawei.com (unknown [7.188.49.51]) by mail.maildlp.com (Postfix) with ESMTPS id D175F40571; Thu, 11 Jun 2026 23:03:38 +0800 (CST) Received: from mscphis01197.huawei.com (10.123.65.218) by mscpeml500003.china.huawei.com (7.188.49.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 11 Jun 2026 18:03:38 +0300 From: To: , , , , , , , , , , Subject: [RFC PATCH v4 4/4] Documentation/admin-guide/mm/damon: add DAMON-based Hugepage Management Date: Thu, 11 Jun 2026 15:02:44 +0000 Message-ID: <20260611150244.3454699-5-gutierrez.asier@huawei-partners.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260611150244.3454699-1-gutierrez.asier@huawei-partners.com> References: <20260611150244.3454699-1-gutierrez.asier@huawei-partners.com> 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 X-ClientProxiedBy: mscpeml500003.china.huawei.com (7.188.49.51) To mscpeml500003.china.huawei.com (7.188.49.51) Content-Type: text/plain; charset="utf-8" From: Asier Gutierrez Add documentation for the DAMON-based Hugepage Management (SAMPLE_DAMON_HUGEPAGE) feature, which automatically manages huge pages by identifying hot memory regions and collapsing them back to regular pages. The documentation covers the module's features, operation, and all available module parameters. Signed-off-by: Asier Gutierrez --- .../admin-guide/mm/damon/hugepage.rst (new) | 113 ++++++++++++++++++ Documentation/admin-guide/mm/damon/index.rst | 1 + 2 files changed, 114 insertions(+) diff --git a/Documentation/admin-guide/mm/damon/hugepage.rst b/Documentatio= n/admin-guide/mm/damon/hugepage.rst new file mode 100644 index 000000000000..470ae2bc8cc3 --- /dev/null +++ b/Documentation/admin-guide/mm/damon/hugepage.rst @@ -0,0 +1,113 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D +DAMON-based huge page collapsing +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D + +DAMON-based huge page collapsing (SAMPLE_DAMON_HUGEPAGE) is a static kernel +module that aims to collapse hot regions into huge pages. + +Where Proactive huge page collapsing is Required? +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The amount of available memory grows faster than the amount of TLB entries. +This leads to higher amount of TLB misses and excessive cycle wastes. Huge +pages are meant to solve this problem. However, huge pages usually lead to +memory fragmentation and memory waste. + +Collapsing selectively hot regions in a specific process can avoid big +memory fragmentation, while increasing TLB performance. + +SAMPLE_DAMON_HUGEPAGE solves this by: + +- Identifying hot regions that have been accessed for a configured time +- Automatically collapsing the regions into huge pages back +- Auto tune the huge page usage ratio to meet desired targets +- Controlling the collapse rate with configurable quotas to avoid performa= nce + degradation + + +How It Works? +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +SAMPLE_DAMON_HUGEPAGE uses kdamond to identify anonymous memory regions th= at +are: + +1. Large enough to be backed by huge pages (``HPAGE_PMD_SIZE`` or larger) +2. Have been accessed for a configured time period + +Once identified, SAMPLE_DAMON_HUGEPAGE triggers synchronous partial collap= se +of those regions. The collapse operation is controlled by quotas to limit = the +impact on system performance. + +The module also supports automatic tuning of the collapse rate to achieve a +desired huge page usage ratio. Administrators can configure a target perce= ntage +of huge page usage vs total anonymous memory usage. + +Additionally, the module accepts manual feedback from system administrator= s to +adjust the effective quota level based on observed system behavior. + +Interface: Module Parameters +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D + +To use this feature, you should first ensure your system is running on a k= ernel +that is built with ``CONFIG_DAMON_HUGEPAGE=3Dy``. + +To let sysadmins enable or disable it and tune for the given system, +SAMPLE_DAMON_HUGEPAGE utilizes module parameters. That is, you can put +``damon_sample_hugepage.=3D`` on the kernel boot command= line or +write proper values to ``/sys/module/damon_sample_hugepage/parameters/`` +files. + +Below are the description of each parameter. + +enabled +------- + +Enable or disable SAMPLE_DAMON_HUGEPAGE. + +You can enable SAMPLE_DAMON_HUGEPAGE by setting the value of this paramete= r as ``Y``. +Setting it as ``N`` disables SAMPLE_DAMON_HUGEPAGE. Note that SAMPLE_DAMO= N_HUGEPAGE +could do no real monitoring and collapse due to the activation condition. + +quota_autotune_feedback +----------------------- + +User-specifiable feedback for auto-tuning of the effective quota. + +While keeping the caps that set by other quotas, SAMPLE_DAMON_HUGEPAGE +automatically increases and decreases the effective level of the quota +aiming receiving this feedback of value ``10,000`` from the user. +SAMPLE_DAMON_HUGEPAGE assumes the feedback value and the quota are positiv= ely +proportional. Value zero means disabling this auto-tuning feature. + +Disabled by default. + +quota_percentage_hugepage +------------------------- + +Huge page consumption to total memory anonymous memory consumption ratio g= oal +in bp ``(10,000)``. SAMPLE_DAMON_HUGEPAGE automatically increases and +decreases page collapse aggressiveness in order to achieve the given value. + +target_pid +---------- + +PID of the task that is going to be monitored for hot regions. + + +Example +=3D=3D=3D=3D=3D=3D=3D + +Below runtime example commands make SAMPLE_DAMON_HUGEPAGE to find memory +regions of the task with PID 1234 that have been accessed in the last 100 +milliseconds or more and collpases those pages into huge pages. The page +collapsing is limited to be done only up to 1 GiB per second to avoid +SAMPLE_DAMON_HUGEPAGE consuming too much CPU time for the collapse operati= on. :: + + # cd /sys/module/damon_sample_hugepage/parameters + # echo 1234 > target_pid + # echo Y > enabled + +Note that this module (SAMPLE_DAMON_HUGEPAGE) cannot run simultaneously +with other DAMON-based special-purpose modules. Refer to +:ref:`DAMON design special purpose modules exclusivity +` for more details. \ No newline at end of file diff --git a/Documentation/admin-guide/mm/damon/index.rst b/Documentation/a= dmin-guide/mm/damon/index.rst index 3ce3164480c7..6f2cad21a2da 100644 --- a/Documentation/admin-guide/mm/damon/index.rst +++ b/Documentation/admin-guide/mm/damon/index.rst @@ -15,3 +15,4 @@ access monitoring and access-aware system operations. reclaim lru_sort stat + hugepage --=20 2.43.0