Quellcode-Bibliothek thp_swap_allocator_test.c
Sprache: C
// SPDX-License-Identifier: GPL-2.0-or-later /* * thp_swap_allocator_test * * The purpose of this test program is helping check if THP swpout * can correctly get swap slots to swap out as a whole instead of * being split. It randomly releases swap entries through madvise * DONTNEED and swapin/out on two memory areas: a memory area for * 64KB THP and the other area for small folios. The second memory * can be enabled by "-s". * Before running the program, we need to setup a zRAM or similar * swap device by: * echo lzo > /sys/block/zram0/comp_algorithm * echo 64M > /sys/block/zram0/disksize * echo never > /sys/kernel/mm/transparent_hugepage/hugepages-2048kB/enabled * echo always > /sys/kernel/mm/transparent_hugepage/hugepages-64kB/enabled * mkswap /dev/zram0 * swapon /dev/zram0 * The expected result should be 0% anon swpout fallback ratio w/ or * w/o "-s". * * Author(s): Barry Song <v-songbaohua@oppo.com>
*/
/* * This emulates the behavior of native libc and Java heap, * as well as process exit and munmap. It helps generate mTHP * and ensures that iterations can proceed with mTHP, as we * currently don't support large folios swap-in.
*/ staticvoid random_madvise_dontneed(void *mem, size_t mem_size,
size_t align_size, size_t total_dontneed_size)
{
size_t num_pages = total_dontneed_size / align_size;
size_t i;
size_t offset; void *addr;
for (i = 0; i < num_pages; ++i) {
offset = (rand() % (mem_size / align_size)) * align_size;
addr = (char *)mem + offset; if (madvise(addr, align_size, MADV_DONTNEED) != 0)
perror("madvise dontneed");
/* * The following setup creates a 1:1 ratio of mTHP to small folios * since large folio swap-in isn't supported yet. Once we support * mTHP swap-in, we'll likely need to reduce MEMSIZE_MTHP and * increase MEMSIZE_SMALLFOLIO to maintain the ratio.
*/
random_swapin(mem1, MEMSIZE_MTHP,
aligned_swapin ? ALIGNMENT_MTHP : ALIGNMENT_SMALLFOLIO,
TOTAL_DONTNEED_MTHP);
random_madvise_dontneed(mem1, MEMSIZE_MTHP, ALIGNMENT_MTHP,
TOTAL_DONTNEED_MTHP);
if (use_small_folio) {
random_swapin(mem2, MEMSIZE_SMALLFOLIO,
ALIGNMENT_SMALLFOLIO,
TOTAL_DONTNEED_SMALLFOLIO);
}
if (madvise(mem1, MEMSIZE_MTHP, MADV_PAGEOUT) != 0) {
perror("madvise pageout for mem1");
free(mem1); if (mem2 != NULL)
free(mem2); return EXIT_FAILURE;
}
if (use_small_folio) { if (madvise(mem2, MEMSIZE_SMALLFOLIO, MADV_PAGEOUT) != 0) {
perror("madvise pageout for mem2");
free(mem1);
free(mem2); return EXIT_FAILURE;
}
}
¤ 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.0.13Bemerkung:
(vorverarbeitet)
¤
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.