Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

samples: add a skeleton of a sample DAMON module for working set size estimation

Patch series "mm/damon: add sample modules".

Implement a proactive cold memory regions reclaiming logic of prcl sample
module using DAMOS. The logic treats memory regions that not accessed at
all for five or more seconds as cold, and reclaim those as soon as found.


This patch (of 5):

Add a skeleton for a sample DAMON static module that can be used for
estimating working set size of a given process. Note that it is a static
module since DAMON is not exporting symbols to loadable modules for now.
It exposes two module parameters, namely 'pid' and 'enable'. 'pid' will
specify the process that the module will estimate the working set size of.
'enable' will receive whether to start or stop the estimation. Because
this is just a skeleton, the parameters do nothing, though. The
functionalities will be implemented by following commits.

Link: https://lkml.kernel.org/r/20241210215030.85675-1-sj@kernel.org
Link: https://lkml.kernel.org/r/20241210215030.85675-2-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
19d7c3ad 08cc4c39

+89
+1
MAINTAINERS
··· 6330 6330 F: include/linux/damon.h 6331 6331 F: include/trace/events/damon.h 6332 6332 F: mm/damon/ 6333 + F: samples/damon/ 6333 6334 F: tools/testing/selftests/damon/ 6334 6335 6335 6336 DAVICOM FAST ETHERNET (DMFE) NETWORK DRIVER
+2
samples/Kconfig
··· 293 293 294 294 source "samples/rust/Kconfig" 295 295 296 + source "samples/damon/Kconfig" 297 + 296 298 endif # SAMPLES 297 299 298 300 config HAVE_SAMPLE_FTRACE_DIRECT
+1
samples/Makefile
··· 39 39 obj-$(CONFIG_SAMPLE_CORESIGHT_SYSCFG) += coresight/ 40 40 obj-$(CONFIG_SAMPLE_FPROBE) += fprobe/ 41 41 obj-$(CONFIG_SAMPLES_RUST) += rust/ 42 + obj-$(CONFIG_SAMPLE_DAMON_WSSE) += damon/
+17
samples/damon/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + 3 + menu "DAMON Samples" 4 + 5 + config SAMPLE_DAMON_WSSE 6 + bool "DAMON sameple module for working set size estimation" 7 + depends on DAMON && DAMON_VADDR 8 + help 9 + This builds DAMON sample module for working set size estimation. 10 + 11 + The module receives a pid, monitor access to the virtual address 12 + space of the process, estimate working set size of the process, and 13 + repeatedly prints the size on the kernel log. 14 + 15 + If unsure, say N. 16 + 17 + endmenu
+3
samples/damon/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + 3 + obj-$(CONFIG_SAMPLE_DAMON_WSSE) += wsse.o
+65
samples/damon/wsse.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * working set size estimation: monitor access pattern of given process and 4 + * print estimated working set size (total size of regions that showing some 5 + * access). 6 + */ 7 + 8 + #define pr_fmt(fmt) "damon_sample_wsse: " fmt 9 + 10 + #include <linux/damon.h> 11 + #include <linux/init.h> 12 + #include <linux/kernel.h> 13 + #include <linux/module.h> 14 + 15 + static int target_pid __read_mostly; 16 + module_param(target_pid, int, 0600); 17 + 18 + static int damon_sample_wsse_enable_store( 19 + const char *val, const struct kernel_param *kp); 20 + 21 + static const struct kernel_param_ops enable_param_ops = { 22 + .set = damon_sample_wsse_enable_store, 23 + .get = param_get_bool, 24 + }; 25 + 26 + static bool enable __read_mostly; 27 + module_param_cb(enable, &enable_param_ops, &enable, 0600); 28 + MODULE_PARM_DESC(enable, "Enable or disable DAMON_SAMPLE_WSSE"); 29 + 30 + static int damon_sample_wsse_start(void) 31 + { 32 + pr_info("start\n"); 33 + return 0; 34 + } 35 + 36 + static void damon_sample_wsse_stop(void) 37 + { 38 + pr_info("stop\n"); 39 + } 40 + 41 + static int damon_sample_wsse_enable_store( 42 + const char *val, const struct kernel_param *kp) 43 + { 44 + bool enabled = enable; 45 + int err; 46 + 47 + err = kstrtobool(val, &enable); 48 + if (err) 49 + return err; 50 + 51 + if (enable == enabled) 52 + return 0; 53 + 54 + if (enable) 55 + return damon_sample_wsse_start(); 56 + damon_sample_wsse_stop(); 57 + return 0; 58 + } 59 + 60 + static int __init damon_sample_wsse_init(void) 61 + { 62 + return 0; 63 + } 64 + 65 + module_init(damon_sample_wsse_init);