Skip to contentSkip to conversation

mm/damon: export DAMON symbols and add sample loadable modules

RFC PATCH New SeongJae Park 1 participant 3 messages Nov 21, 2023

Subsystems (2)
lore
Share & tools
lore

SeongJae Park

author maintainer
#0 lore raw

cover mm/damon: export DAMON symbols and add sample loadable modules

DAMON cannot be used from loadable modules since it is not exporting its symbols. This makes use of DAMON unnecessarily tedious. For example, we presented basic usge of DAMON at kernel summit 2021[1] by writing simple loadable DAMON application modules in live. Because the time was limited (10 minutes) and the coding was to be done step by step, we had to make a downstream commit that exports DAMON symbols. There were users asking why the source code is now not working. It was mainly due to the absence of the symbols export patch on their tree, but also due to the changed DAMON interfaces. There were also multiple users requesting support of loadable modules for easier deployment.

There's no reason to avoid exporting DAMON symbols. However, it would be better to have concrete use cases of the symbols in the tree together, for better maintenance of the interface and the use cases. The kernels summit 2021's live-coded modules could be used for the purpose.

Expose DAMON API modules for supporting the minimum modules and and add the kernel summit 2021's modules that updated for latest DAMON API under the samples directory. We will keep update of the sample modules. For exporting more symbols, requesters would be required to merge their modules using it in the tree together, or updsate the sample modules to use the newly-exporting symbols in reasonable and still simple ways.

[1] https://linuxplumbersconf.org/event/11/contributions/984/

SeongJae Park (2):
mm/damon/core: export symbols for supporting loadable modules
samples: add DAMON sample kernel modules

 MAINTAINERS                       |  1 +
 mm/damon/core.c                   | 10 ++++
 samples/Kconfig                   |  2 +
 samples/Makefile                  |  2 +
 samples/damon/Kconfig             | 30 ++++++++++
 samples/damon/Makefile            |  3 +
 samples/damon/damon_sample_prcl.c | 98 +++++++++++++++++++++++++++++++
 samples/damon/damon_sample_wsse.c | 80 +++++++++++++++++++++++++
 8 files changed, 226 insertions(+)
 create mode 100644 samples/damon/Kconfig
 create mode 100644 samples/damon/Makefile
 create mode 100644 samples/damon/damon_sample_prcl.c
 create mode 100644 samples/damon/damon_sample_wsse.c

base-commit: 79cc930e5e3dc73c972d9e422b5e2ab3fe56dce5

Signature · 1 line
2.34.1
author maintainer
#1 lore raw

RFC PATCH 1/2 mm/damon/core: export symbols for supporting loadable modules

Expose DAMON core symbols for supporting minimum functionality from loadable modules.

---
 mm/damon/core.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
mm/damon/core.c +10 -0
index c080a16f6bdd..8ab8c902b9e2 100644
@@ -111,6 +111,7 @@ int damon_select_ops(struct damon_ctx *ctx, enum damon_ops_id id)
 	mutex_unlock(&damon_ops_lock);
 	return err;
 }
+EXPORT_SYMBOL(damon_select_ops);
 
 /*
  * Construct a damon_region struct
@@ -353,6 +354,7 @@ struct damos *damon_new_scheme(struct damos_access_pattern *pattern,
 
 	return scheme;
 }
+EXPORT_SYMBOL(damon_new_scheme);
 
 static void damos_set_next_apply_sis(struct damos *s, struct damon_ctx *ctx)
 {
@@ -390,6 +392,7 @@ void damon_destroy_scheme(struct damos *s)
 	damon_del_scheme(s);
 	damon_free_scheme(s);
 }
+EXPORT_SYMBOL(damon_destroy_scheme);
 
 /*
  * Construct a damon_target struct
@@ -411,11 +414,13 @@ struct damon_target *damon_new_target(void)
 
 	return t;
 }
+EXPORT_SYMBOL(damon_new_target);
 
 void damon_add_target(struct damon_ctx *ctx, struct damon_target *t)
 {
 	list_add_tail(&t->list, &ctx->adaptive_targets);
 }
+EXPORT_SYMBOL(damon_add_target);
 
 bool damon_targets_empty(struct damon_ctx *ctx)
 {
@@ -493,6 +498,7 @@ struct damon_ctx *damon_new_ctx(void)
 
 	return ctx;
 }
+EXPORT_SYMBOL(damon_new_ctx);
 
 static void damon_destroy_targets(struct damon_ctx *ctx)
 {
@@ -518,6 +524,7 @@ void damon_destroy_ctx(struct damon_ctx *ctx)
 
 	kfree(ctx);
 }
+EXPORT_SYMBOL(damon_destroy_ctx);
 
 static unsigned int damon_age_for_new_attrs(unsigned int age,
 		struct damon_attrs *old_attrs, struct damon_attrs *new_attrs)
@@ -645,6 +652,7 @@ void damon_set_schemes(struct damon_ctx *ctx, struct damos **schemes,
 	for (i = 0; i < nr_schemes; i++)
 		damon_add_scheme(ctx, schemes[i]);
 }
+EXPORT_SYMBOL(damon_set_schemes);
 
 /**
  * damon_nr_running_ctxs() - Return number of currently running contexts.
@@ -748,6 +756,7 @@ int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive)
 
 	return err;
 }
+EXPORT_SYMBOL(damon_start);
 
 /*
  * __damon_stop() - Stops monitoring of a given context.
@@ -791,6 +800,7 @@ int damon_stop(struct damon_ctx **ctxs, int nr_ctxs)
 	}
 	return err;
 }
+EXPORT_SYMBOL(damon_stop);
 
 /*
  * Reset the aggregated monitoring results ('nr_accesses' of each region).
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

RFC PATCH 2/2 samples: add DAMON sample kernel modules

In reply to SeongJae Park

Add sample DAMON application kernel modules that same to the example kernel modules that presented at kernel summit 2021 with 10 minutes live coding[1] but updated for the latest DAMON interface.

Specifically, add two sample modules, namely damon_sample_wsse and damon_sample_prcl. 'damon_sample_wsse' receives a pid of a process to monitor the access, monitors the access to the virtual address space of the process, calculate estimated working set size, and repeatedly print it on the kernel log. 'damon_sample_prcl' is similar to 'damon_sample_wsse', but find regions that not accessed and proactively reclaim those using DAMOS.

[1] https://linuxplumbersconf.org/event/11/contributions/984/

---
 MAINTAINERS                       |  1 +
 samples/Kconfig                   |  2 +
 samples/Makefile                  |  2 +
 samples/damon/Kconfig             | 30 ++++++++++
 samples/damon/Makefile            |  3 +
 samples/damon/damon_sample_prcl.c | 98 +++++++++++++++++++++++++++++++
 samples/damon/damon_sample_wsse.c | 80 +++++++++++++++++++++++++
 7 files changed, 216 insertions(+)
 create mode 100644 samples/damon/Kconfig
 create mode 100644 samples/damon/Makefile
 create mode 100644 samples/damon/damon_sample_prcl.c
 create mode 100644 samples/damon/damon_sample_wsse.c
MAINTAINERS +1 -0
index 6eedc85a013b..3ee99307229a 100644
@@ -5781,6 +5781,7 @@ F:	Documentation/mm/damon/
 F:	include/linux/damon.h
 F:	include/trace/events/damon.h
 F:	mm/damon/
+F:	samples/damon/
 F:	tools/testing/selftests/damon/
 
 DAVICOM FAST ETHERNET (DMFE) NETWORK DRIVER
samples/Kconfig +2 -0
index b0ddf5f36738..1e3f1b33b3d8 100644
@@ -287,6 +287,8 @@ config SAMPLE_KMEMLEAK
 
 source "samples/rust/Kconfig"
 
+source "samples/damon/Kconfig"
+
 endif # SAMPLES
 
 config HAVE_SAMPLE_FTRACE_DIRECT
samples/Makefile +2 -0
index 0a551c2b33f4..ae863e7c5250 100644
@@ -38,3 +38,5 @@ obj-$(CONFIG_SAMPLE_KMEMLEAK)		+= kmemleak/
 obj-$(CONFIG_SAMPLE_CORESIGHT_SYSCFG)	+= coresight/
 obj-$(CONFIG_SAMPLE_FPROBE)		+= fprobe/
 obj-$(CONFIG_SAMPLES_RUST)		+= rust/
+obj-$(CONFIG_SAMPLE_DAMON_WSSE)		+= damon/
+obj-$(CONFIG_SAMPLE_DAMON_PRCL)		+= damon/
samples/damon/Kconfig new file +30 -0
new file mode 100644
index 000000000000..459042ce5958
@@ -0,0 +1,30 @@
+# SPDX-License-Identifier: GPL-2.0
+
+menu "DAMON Samples"
+
+config SAMPLE_DAMON_WSSE
+	tristate "DAMON sameple module for working set size estimation"
+	depends on DAMON && DAMON_VADDR
+	help
+	  This builds DAMON sample module for working set size estimation.
+
+	  The module receives pid of a process, monitor access to the virtual
+	  address space of the process, calculate the estimated working set
+	  size of the process, and repeatedly print the size on the kernel log.
+
+	  If unsure, say N.
+
+config SAMPLE_DAMON_PRCL
+	tristate "DAMON sameple module for access-aware proactive reclamation"
+	depends on DAMON && DAMON_VADDR
+	help
+	  This builds DAMON sample module for access-aware proactive
+	  reclamation.
+
+	  The module receives pid of a process, monitor access to the virtual
+	  address space of the process, find memory regions that not accessed,
+	  and proactively reclaim the regions.
+
+	  If unsure, say N.
+
+endmenu
samples/damon/Makefile new file +3 -0
new file mode 100644
index 000000000000..df102e8c2b7b
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_SAMPLE_DAMON_WSSE) += damon_sample_wsse.o
+obj-$(CONFIG_SAMPLE_DAMON_PRCL) += damon_sample_prcl.o
samples/damon/damon_sample_prcl.c new file +98 -0

98 lines not on this page · raw message

samples/damon/damon_sample_wsse.c new file +80 -0

80 lines not on this page · raw message

Signature · 1 line
2.34.1