mm/damon/tests/vaddr-kunit.h
Source file repositories/reference/linux-study-clean/mm/damon/tests/vaddr-kunit.h
File Facts
- System
- Linux kernel
- Corpus path
mm/damon/tests/vaddr-kunit.h- Extension
.h- Size
- 10087 bytes
- Lines
- 286
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kunit/test.h
Detected Declarations
function __link_vmasfunction __damon_va_three_regionsfunction damon_for_each_regionfunction damon_do_test_apply_three_regionsfunction regionsfunction regionsfunction areafunction damon_test_apply_three_regions4
Annotated Snippet
#ifdef CONFIG_DAMON_VADDR_KUNIT_TEST
#ifndef _DAMON_VADDR_TEST_H
#define _DAMON_VADDR_TEST_H
#include <kunit/test.h>
static int __link_vmas(struct maple_tree *mt, struct vm_area_struct *vmas,
ssize_t nr_vmas)
{
int i, ret = -ENOMEM;
MA_STATE(mas, mt, 0, 0);
if (!nr_vmas)
return 0;
mas_lock(&mas);
for (i = 0; i < nr_vmas; i++) {
mas_set_range(&mas, vmas[i].vm_start, vmas[i].vm_end - 1);
if (mas_store_gfp(&mas, &vmas[i], GFP_KERNEL))
goto failed;
}
ret = 0;
failed:
mas_unlock(&mas);
return ret;
}
/*
* Test __damon_va_three_regions() function
*
* In case of virtual memory address spaces monitoring, DAMON converts the
* complex and dynamic memory mappings of each target task to three
* discontiguous regions which cover every mapped areas. However, the three
* regions should not include the two biggest unmapped areas in the original
* mapping, because the two biggest areas are normally the areas between 1)
* heap and the mmap()-ed regions, and 2) the mmap()-ed regions and stack.
* Because these two unmapped areas are very huge but obviously never accessed,
* covering the region is just a waste.
*
* '__damon_va_three_regions() receives an address space of a process. It
* first identifies the start of mappings, end of mappings, and the two biggest
* unmapped areas. After that, based on the information, it constructs the
* three regions and returns. For more detail, refer to the comment of
* 'damon_init_regions_of()' function definition in 'mm/damon.c' file.
*
* For example, suppose virtual address ranges of 10-20, 20-25, 200-210,
* 210-220, 300-305, and 307-330 (Other comments represent this mappings in
* more short form: 10-20-25, 200-210-220, 300-305, 307-330) of a process are
* mapped. To cover every mappings, the three regions should start with 10,
* and end with 305. The process also has three unmapped areas, 25-200,
* 220-300, and 305-307. Among those, 25-200 and 220-300 are the biggest two
* unmapped areas, and thus it should be converted to three regions of 10-25,
* 200-220, and 300-330.
*/
static void damon_test_three_regions_in_vmas(struct kunit *test)
{
static struct mm_struct mm;
struct damon_addr_range regions[3] = {0};
/* 10-20-25, 200-210-220, 300-305, 307-330 */
static struct vm_area_struct vmas[] = {
(struct vm_area_struct) {.vm_start = 10, .vm_end = 20},
(struct vm_area_struct) {.vm_start = 20, .vm_end = 25},
(struct vm_area_struct) {.vm_start = 200, .vm_end = 210},
(struct vm_area_struct) {.vm_start = 210, .vm_end = 220},
(struct vm_area_struct) {.vm_start = 300, .vm_end = 305},
(struct vm_area_struct) {.vm_start = 307, .vm_end = 330},
};
mt_init_flags(&mm.mm_mt, MT_FLAGS_ALLOC_RANGE | MT_FLAGS_USE_RCU);
if (__link_vmas(&mm.mm_mt, vmas, ARRAY_SIZE(vmas)))
kunit_skip(test, "Failed to create VMA tree");
__damon_va_three_regions(&mm, regions);
KUNIT_EXPECT_EQ(test, 10ul, regions[0].start);
KUNIT_EXPECT_EQ(test, 25ul, regions[0].end);
KUNIT_EXPECT_EQ(test, 200ul, regions[1].start);
KUNIT_EXPECT_EQ(test, 220ul, regions[1].end);
KUNIT_EXPECT_EQ(test, 300ul, regions[2].start);
KUNIT_EXPECT_EQ(test, 330ul, regions[2].end);
}
static struct damon_region *__nth_region_of(struct damon_target *t, int idx)
{
struct damon_region *r;
unsigned int i = 0;
damon_for_each_region(r, t) {
Annotation
- Immediate include surface: `kunit/test.h`.
- Detected declarations: `function __link_vmas`, `function __damon_va_three_regions`, `function damon_for_each_region`, `function damon_do_test_apply_three_regions`, `function regions`, `function regions`, `function area`, `function damon_test_apply_three_regions4`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.