Skip to content

Commit 3f49584

Browse files
sj-awstorvalds
authored andcommitted
mm/damon: implement primitives for the virtual memory address spaces
This commit introduces a reference implementation of the address space specific low level primitives for the virtual address space, so that users of DAMON can easily monitor the data accesses on virtual address spaces of specific processes by simply configuring the implementation to be used by DAMON. The low level primitives for the fundamental access monitoring are defined in two parts: 1. Identification of the monitoring target address range for the address space. 2. Access check of specific address range in the target space. The reference implementation for the virtual address space does the works as below. PTE Accessed-bit Based Access Check ----------------------------------- The implementation uses PTE Accessed-bit for basic access checks. That is, it clears the bit for the next sampling target page and checks whether it is set again after one sampling period. This could disturb the reclaim logic. DAMON uses ``PG_idle`` and ``PG_young`` page flags to solve the conflict, as Idle page tracking does. VMA-based Target Address Range Construction ------------------------------------------- Only small parts in the super-huge virtual address space of the processes are mapped to physical memory and accessed. Thus, tracking the unmapped address regions is just wasteful. However, because DAMON can deal with some level of noise using the adaptive regions adjustment mechanism, tracking every mapping is not strictly required but could even incur a high overhead in some cases. That said, too huge unmapped areas inside the monitoring target should be removed to not take the time for the adaptive mechanism. For the reason, this implementation converts the complex mappings to three distinct regions that cover every mapped area of the address space. Also, the two gaps between the three regions are the two biggest unmapped areas in the given address space. The two biggest unmapped areas would be the gap between the heap and the uppermost mmap()-ed region, and the gap between the lowermost mmap()-ed region and the stack in most of the cases. Because these gaps are exceptionally huge in usual address spaces, excluding these will be sufficient to make a reasonable trade-off. Below shows this in detail:: <heap> <BIG UNMAPPED REGION 1> <uppermost mmap()-ed region> (small mmap()-ed regions and munmap()-ed regions) <lowermost mmap()-ed region> <BIG UNMAPPED REGION 2> <stack> [[email protected]: mm/damon/vaddr.c needs highmem.h for kunmap_atomic()] [[email protected]: remove unnecessary PAGE_EXTENSION setup] Link: https://lkml.kernel.org/r/[email protected] [[email protected]: safely walk page table] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: SeongJae Park <[email protected]> Reviewed-by: Leonard Foerster <[email protected]> Reviewed-by: Fernand Sieber <[email protected]> Acked-by: Shakeel Butt <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Amit Shah <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Brendan Higgins <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: David Rientjes <[email protected]> Cc: David Woodhouse <[email protected]> Cc: Fan Du <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Greg Thelen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Joe Perches <[email protected]> Cc: Jonathan Cameron <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Marco Elver <[email protected]> Cc: Markus Boehme <[email protected]> Cc: Maximilian Heyne <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Rik van Riel <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Steven Rostedt (VMware) <[email protected]> Cc: Vladimir Davydov <[email protected]> Cc: Vlastimil Babka <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1c676e0 commit 3f49584

File tree

4 files changed

+687
-0
lines changed

4 files changed

+687
-0
lines changed

include/linux/damon.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,17 @@ int damon_stop(struct damon_ctx **ctxs, int nr_ctxs);
249249

250250
#endif /* CONFIG_DAMON */
251251

252+
#ifdef CONFIG_DAMON_VADDR
253+
254+
/* Monitoring primitives for virtual memory address spaces */
255+
void damon_va_init(struct damon_ctx *ctx);
256+
void damon_va_update(struct damon_ctx *ctx);
257+
void damon_va_prepare_access_checks(struct damon_ctx *ctx);
258+
unsigned int damon_va_check_accesses(struct damon_ctx *ctx);
259+
bool damon_va_target_valid(void *t);
260+
void damon_va_cleanup(struct damon_ctx *ctx);
261+
void damon_va_set_primitives(struct damon_ctx *ctx);
262+
263+
#endif /* CONFIG_DAMON_VADDR */
264+
252265
#endif /* _DAMON_H */

mm/damon/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@ config DAMON
1212
See https://damonitor.github.io/doc/html/latest-damon/index.html for
1313
more information.
1414

15+
config DAMON_VADDR
16+
bool "Data access monitoring primitives for virtual address spaces"
17+
depends on DAMON && MMU
18+
select PAGE_IDLE_FLAG
19+
help
20+
This builds the default data access monitoring primitives for DAMON
21+
that works for virtual address spaces.
22+
1523
endmenu

mm/damon/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# SPDX-License-Identifier: GPL-2.0
22

33
obj-$(CONFIG_DAMON) := core.o
4+
obj-$(CONFIG_DAMON_VADDR) += vaddr.o

0 commit comments

Comments
 (0)