staticvoid test_simple(int pagemap_fd, int pagesize)
{ int i; char *map;
map = aligned_alloc(pagesize, pagesize); if (!map)
ksft_exit_fail_msg("mmap failed\n");
clear_softdirty();
for (i = 0 ; i < TEST_ITERATIONS; i++) { if (pagemap_is_softdirty(pagemap_fd, map) == 1) {
ksft_print_msg("dirty bit was 1, but should be 0 (i=%d)\n", i); break;
}
clear_softdirty(); // Write something to the page to get the dirty bit enabled on the page
map[0]++;
if (pagemap_is_softdirty(pagemap_fd, map) == 0) {
ksft_print_msg("dirty bit was 0, but should be 1 (i=%d)\n", i); break;
}
// The kernel always marks new regions as soft dirty
ksft_test_result(pagemap_is_softdirty(pagemap_fd, map) == 1, "Test %s dirty bit of allocated page\n", __func__);
// Dirty bit is set for new regions even if they are reused if (map == map2)
ksft_test_result(pagemap_is_softdirty(pagemap_fd, map2) == 1, "Test %s dirty bit of reused address page\n", __func__); else
ksft_test_result_skip("Test %s dirty bit of reused address page\n", __func__);
munmap(map2, pagesize);
}
staticvoid test_hugepage(int pagemap_fd, int pagesize)
{ char *map; int i, ret;
if (!thp_is_enabled()) {
ksft_test_result_skip("Transparent Hugepages not available\n"); return;
}
size_t hpage_len = read_pmd_pagesize(); if (!hpage_len)
ksft_exit_fail_msg("Reading PMD pagesize failed");
map = memalign(hpage_len, hpage_len); if (!map)
ksft_exit_fail_msg("memalign failed\n");
ret = madvise(map, hpage_len, MADV_HUGEPAGE); if (ret)
ksft_exit_fail_msg("madvise failed %d\n", ret);
clear_softdirty(); for (i = 0 ; i < TEST_ITERATIONS ; i++) { if (pagemap_is_softdirty(pagemap_fd, map) == 1) {
ksft_print_msg("dirty bit was 1, but should be 0 (i=%d)\n", i); break;
}
clear_softdirty(); // Write something to the page to get the dirty bit enabled on the page
map[0]++;
if (pagemap_is_softdirty(pagemap_fd, map) == 0) {
ksft_print_msg("dirty bit was 0, but should be 1 (i=%d)\n", i); break;
}
clear_softdirty();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.