/* SPDX-License-Identifier: GPL-2.0 */ /* * Data Access Monitor Unit Tests * * Copyright 2019 Amazon.com, Inc. or its affiliates. All rights reserved. * * Author: SeongJae Park <[email protected]> */ #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) { … } /* * 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 damon_region *__nth_region_of(struct damon_target *t, int idx) { … } /* * Test 'damon_set_regions()' * * test kunit object * regions an array containing start/end addresses of current * monitoring target regions * nr_regions the number of the addresses in 'regions' * three_regions The three regions that need to be applied now * expected start/end addresses of monitoring target regions that * 'three_regions' are applied * nr_expected the number of addresses in 'expected' * * The memory mapping of the target processes changes dynamically. To follow * the change, DAMON periodically reads the mappings, simplifies it to the * three regions, and updates the monitoring target regions to fit in the three * regions. The update of current target regions is the role of * 'damon_set_regions()'. * * This test passes the given target regions and the new three regions that * need to be applied to the function and check whether it updates the regions * as expected. */ static void damon_do_test_apply_three_regions(struct kunit *test, unsigned long *regions, int nr_regions, struct damon_addr_range *three_regions, unsigned long *expected, int nr_expected) { … } /* * This function test most common case where the three big regions are only * slightly changed. Target regions should adjust their boundary (10-20-30, * 50-55, 70-80, 90-100) to fit with the new big regions or remove target * regions (57-79) that now out of the three regions. */ static void damon_test_apply_three_regions1(struct kunit *test) { … } /* * Test slightly bigger change. Similar to above, but the second big region * now require two target regions (50-55, 57-59) to be removed. */ static void damon_test_apply_three_regions2(struct kunit *test) { … } /* * Test a big change. The second big region has totally freed and mapped to * different area (50-59 -> 61-63). The target regions which were in the old * second big region (50-55-57-59) should be removed and new target region * covering the second big region (61-63) should be created. */ static void damon_test_apply_three_regions3(struct kunit *test) { … } /* * Test another big change. Both of the second and third big regions (50-59 * and 70-100) has totally freed and mapped to different area (30-32 and * 65-68). The target regions which were in the old second and third big * regions should now be removed and new target regions covering the new second * and third big regions should be created. */ static void damon_test_apply_three_regions4(struct kunit *test) { … } static void damon_test_split_evenly_fail(struct kunit *test, unsigned long start, unsigned long end, unsigned int nr_pieces) { … } static void damon_test_split_evenly_succ(struct kunit *test, unsigned long start, unsigned long end, unsigned int nr_pieces) { … } static void damon_test_split_evenly(struct kunit *test) { … } static struct kunit_case damon_test_cases[] = …; static struct kunit_suite damon_test_suite = …; kunit_test_suite(…) …; #endif /* _DAMON_VADDR_TEST_H */ #endif /* CONFIG_DAMON_VADDR_KUNIT_TEST */