generic: test swapping process pages in and out of a swapfile
Subsystems (3)
PATCH 1/1 generic: test swapping process pages in and out of a swapfile
From: Darrick J. Wong <[email protected]>
This test is intended to perform minimal spot-checking that we can swap pages to a swapfile and recall them into memory without burning peoples' machines to the ground.
--- .gitignore | 1 common/cgroup2 | 5 ++ common/config | 1 common/rc | 4 - src/Makefile | 2 - src/usemem_and_swapoff.c | 117 ++++++++++++++++++++++++++++++++++++++ tests/generic/728 | 141 ++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/728.out | 9 +++ 8 files changed, 276 insertions(+), 4 deletions(-) create mode 100644 src/usemem_and_swapoff.c create mode 100755 tests/generic/728 create mode 100644 tests/generic/728.out
.gitignore +1 -0
@@ -166,6 +166,7 @@ tags /src/unwritten_mmap /src/unwritten_sync /src/usemem +/src/usemem_and_swapoff /src/writemod /src/writev_on_pagefault /src/xfsctl
common/cgroup2 +5 -0
@@ -17,4 +17,9 @@ _require_cgroup2() fi } +_require_memcg() +{ + test -e "$CGROUP2_PATH/memory.stat" || _notrun "memcg required for test" +} + /bin/true
common/config +1 -0
@@ -272,6 +272,7 @@ export MKFS_REISER4_PROG=$(type -P mkfs.reiser4) export E2FSCK_PROG=$(type -P e2fsck) export TUNE2FS_PROG=$(type -P tune2fs) export FSCK_OVERLAY_PROG=$(type -P fsck.overlay) +export SYSTEMD_RUN_PROG="$(type -P systemd-run)" # SELinux adds extra xattrs which can mess up our expected output. # So, mount with a context, and they won't be created.
common/rc +1 -3
@@ -2593,10 +2593,8 @@ _format_swapfile() { } _swapon_file() { - local fname="$1" - # Ignore permission complaints on filesystems that don't support perms - swapon "$fname" 2> >(grep -v "insecure permissions" >&2) + swapon "$@" 2> >(grep -v "insecure permissions" >&2) } # Check that the filesystem supports swapfiles
src/Makefile +1 -1
@@ -31,7 +31,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ dio-invalidate-cache stat_test t_encrypted_d_revalidate \ attr_replace_test swapon mkswap t_attr_corruption t_open_tmpfiles \ fscrypt-crypt-util bulkstat_null_ocount splice-test chprojid_fail \ - detached_mounts_propagation + detached_mounts_propagation usemem_and_swapoff EXTRA_EXECS = dmerror fill2attr fill2fs fill2fs_check scaleread.sh \ btrfs_crc32c_forged_name.py
src/usemem_and_swapoff.c new file +117 -0
117 lines not on this page · raw message
tests/generic/728 new file +141 -0
141 lines not on this page · raw message
tests/generic/728.out new file +9 -0
@@ -0,0 +1,9 @@ +QA output created by 728 +Allocating 52428800 memory. +Dirtying memory. +Now mlocking memory. +Allocating 52428800 memory. +Dirtying memory. +Now activating swapfile2. +Now deactivating swapfile1. +Silence is golden
src/usemem_and_swapoff.c line 61
Quoted 6 lines · Darrick J. Wong
src/usemem_and_swapoff.c new file +6
-0+printf ("Dirtying memory.\n" ); +fflush (stdout); + +/* Dirty the memory to force this program to be swapped out. */ +for (p = pstart; p < pend; p += pagesize) + *p ='X' ;
What I liked about dhowells' program was that it checked whether the pages brought back in from swap were the same ones that had been written to swap. As a block filesystem person, you only know the misery of having swap go behind your back to the block device. As a network filesystem person, David is acutely aware of the misery of having to remember to use page_file_index() instead of page->index in order to avoid reading a page from the wrong offset in the swap partition.
Yes, our swap code is nasty in many different ways, why do you ask?
Quoted 16 lines · Matthew Wilcox
src/usemem_and_swapoff.c line 61
Quoted 6 lines · Darrick J. Wong
src/usemem_and_swapoff.c new file +6
-0+printf ("Dirtying memory.\n" ); +fflush (stdout); + +/* Dirty the memory to force this program to be swapped out. */ +for (p = pstart; p < pend; p += pagesize) + *p ='X' ;What I liked about dhowells' program was that it checked whether the pages brought back in from swap were the same ones that had been written to swap. As a block filesystem person, you only know the misery of having swap go behind your back to the block device. As a network filesystem person, David is acutely aware of the misery of having to remember to use
page_file_index()instead ofpage->indexin order to avoid reading a page from the wrong offset in the swap partition.
Quoted 1 line
Yes, our swap code is nasty in many different ways, why do you ask?
Wheeee, I'll go change it to store per-page data in each page and check it on the way back.
--D