selftests/vm: add test to measure MADV_UNMERGEABLE performance
Let's add a test to measure performance of KSM breaking not triggered via COW, but triggered by disabling KSM on an area filled with KSM pages via MADV_UNMERGEABLE. Link: https://lkml.kernel.org/r/20221021101141.84170-2-david@redhat.com Signed-off-by: David Hildenbrand <david@redhat.com> Acked-by: Peter Xu <peterx@redhat.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Hugh Dickins <hughd@google.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Shuah Khan <shuah@kernel.org> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
c31783eeae
commit
5036880efd
@ -40,6 +40,7 @@ enum ksm_test_name {
|
|||||||
CHECK_KSM_NUMA_MERGE,
|
CHECK_KSM_NUMA_MERGE,
|
||||||
KSM_MERGE_TIME,
|
KSM_MERGE_TIME,
|
||||||
KSM_MERGE_TIME_HUGE_PAGES,
|
KSM_MERGE_TIME_HUGE_PAGES,
|
||||||
|
KSM_UNMERGE_TIME,
|
||||||
KSM_COW_TIME
|
KSM_COW_TIME
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -108,7 +109,10 @@ static void print_help(void)
|
|||||||
" -P evaluate merging time and speed.\n"
|
" -P evaluate merging time and speed.\n"
|
||||||
" For this test, the size of duplicated memory area (in MiB)\n"
|
" For this test, the size of duplicated memory area (in MiB)\n"
|
||||||
" must be provided using -s option\n"
|
" must be provided using -s option\n"
|
||||||
" -H evaluate merging time and speed of area allocated mostly with huge pages\n"
|
" -H evaluate merging time and speed of area allocated mostly with huge pages\n"
|
||||||
|
" For this test, the size of duplicated memory area (in MiB)\n"
|
||||||
|
" must be provided using -s option\n"
|
||||||
|
" -D evaluate unmerging time and speed when disabling KSM.\n"
|
||||||
" For this test, the size of duplicated memory area (in MiB)\n"
|
" For this test, the size of duplicated memory area (in MiB)\n"
|
||||||
" must be provided using -s option\n"
|
" must be provided using -s option\n"
|
||||||
" -C evaluate the time required to break COW of merged pages.\n\n");
|
" -C evaluate the time required to break COW of merged pages.\n\n");
|
||||||
@ -188,6 +192,16 @@ static int ksm_merge_pages(void *addr, size_t size, struct timespec start_time,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ksm_unmerge_pages(void *addr, size_t size,
|
||||||
|
struct timespec start_time, int timeout)
|
||||||
|
{
|
||||||
|
if (madvise(addr, size, MADV_UNMERGEABLE)) {
|
||||||
|
perror("madvise");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static bool assert_ksm_pages_count(long dupl_page_count)
|
static bool assert_ksm_pages_count(long dupl_page_count)
|
||||||
{
|
{
|
||||||
unsigned long max_page_sharing, pages_sharing, pages_shared;
|
unsigned long max_page_sharing, pages_sharing, pages_shared;
|
||||||
@ -560,6 +574,53 @@ err_out:
|
|||||||
return KSFT_FAIL;
|
return KSFT_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ksm_unmerge_time(int mapping, int prot, int timeout, size_t map_size)
|
||||||
|
{
|
||||||
|
void *map_ptr;
|
||||||
|
struct timespec start_time, end_time;
|
||||||
|
unsigned long scan_time_ns;
|
||||||
|
|
||||||
|
map_size *= MB;
|
||||||
|
|
||||||
|
map_ptr = allocate_memory(NULL, prot, mapping, '*', map_size);
|
||||||
|
if (!map_ptr)
|
||||||
|
return KSFT_FAIL;
|
||||||
|
if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) {
|
||||||
|
perror("clock_gettime");
|
||||||
|
goto err_out;
|
||||||
|
}
|
||||||
|
if (ksm_merge_pages(map_ptr, map_size, start_time, timeout))
|
||||||
|
goto err_out;
|
||||||
|
|
||||||
|
if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) {
|
||||||
|
perror("clock_gettime");
|
||||||
|
goto err_out;
|
||||||
|
}
|
||||||
|
if (ksm_unmerge_pages(map_ptr, map_size, start_time, timeout))
|
||||||
|
goto err_out;
|
||||||
|
if (clock_gettime(CLOCK_MONOTONIC_RAW, &end_time)) {
|
||||||
|
perror("clock_gettime");
|
||||||
|
goto err_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
scan_time_ns = (end_time.tv_sec - start_time.tv_sec) * NSEC_PER_SEC +
|
||||||
|
(end_time.tv_nsec - start_time.tv_nsec);
|
||||||
|
|
||||||
|
printf("Total size: %lu MiB\n", map_size / MB);
|
||||||
|
printf("Total time: %ld.%09ld s\n", scan_time_ns / NSEC_PER_SEC,
|
||||||
|
scan_time_ns % NSEC_PER_SEC);
|
||||||
|
printf("Average speed: %.3f MiB/s\n", (map_size / MB) /
|
||||||
|
((double)scan_time_ns / NSEC_PER_SEC));
|
||||||
|
|
||||||
|
munmap(map_ptr, map_size);
|
||||||
|
return KSFT_PASS;
|
||||||
|
|
||||||
|
err_out:
|
||||||
|
printf("Not OK\n");
|
||||||
|
munmap(map_ptr, map_size);
|
||||||
|
return KSFT_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
static int ksm_cow_time(int mapping, int prot, int timeout, size_t page_size)
|
static int ksm_cow_time(int mapping, int prot, int timeout, size_t page_size)
|
||||||
{
|
{
|
||||||
void *map_ptr;
|
void *map_ptr;
|
||||||
@ -644,7 +705,7 @@ int main(int argc, char *argv[])
|
|||||||
bool merge_across_nodes = KSM_MERGE_ACROSS_NODES_DEFAULT;
|
bool merge_across_nodes = KSM_MERGE_ACROSS_NODES_DEFAULT;
|
||||||
long size_MB = 0;
|
long size_MB = 0;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "ha:p:l:z:m:s:MUZNPCH")) != -1) {
|
while ((opt = getopt(argc, argv, "ha:p:l:z:m:s:MUZNPCHD")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'a':
|
case 'a':
|
||||||
prot = str_to_prot(optarg);
|
prot = str_to_prot(optarg);
|
||||||
@ -701,6 +762,9 @@ int main(int argc, char *argv[])
|
|||||||
case 'H':
|
case 'H':
|
||||||
test_name = KSM_MERGE_TIME_HUGE_PAGES;
|
test_name = KSM_MERGE_TIME_HUGE_PAGES;
|
||||||
break;
|
break;
|
||||||
|
case 'D':
|
||||||
|
test_name = KSM_UNMERGE_TIME;
|
||||||
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
test_name = KSM_COW_TIME;
|
test_name = KSM_COW_TIME;
|
||||||
break;
|
break;
|
||||||
@ -762,6 +826,14 @@ int main(int argc, char *argv[])
|
|||||||
ret = ksm_merge_hugepages_time(MAP_PRIVATE | MAP_ANONYMOUS, prot,
|
ret = ksm_merge_hugepages_time(MAP_PRIVATE | MAP_ANONYMOUS, prot,
|
||||||
ksm_scan_limit_sec, size_MB);
|
ksm_scan_limit_sec, size_MB);
|
||||||
break;
|
break;
|
||||||
|
case KSM_UNMERGE_TIME:
|
||||||
|
if (size_MB == 0) {
|
||||||
|
printf("Option '-s' is required.\n");
|
||||||
|
return KSFT_FAIL;
|
||||||
|
}
|
||||||
|
ret = ksm_unmerge_time(MAP_PRIVATE | MAP_ANONYMOUS, prot,
|
||||||
|
ksm_scan_limit_sec, size_MB);
|
||||||
|
break;
|
||||||
case KSM_COW_TIME:
|
case KSM_COW_TIME:
|
||||||
ret = ksm_cow_time(MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec,
|
ret = ksm_cow_time(MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec,
|
||||||
page_size);
|
page_size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user