[LTP] [PATCH] swapon01: swapon01: prevent OOM happening in swap process

Wei Gao wegao@suse.com
Fri Mar 15 08:44:32 CET 2024


On Fri, Mar 15, 2024 at 02:24:48PM +0800, Li Wang wrote:
> Here we take many ways to prevent the OOM happening with
> run the swapon test:
> 
>   * shrink the pollute memory size
>   * increase swapfile size
>   * setting swap max for Cgroup
>   * setting test oom_score_adj to -1000
> 
> Reproted-by: Wei Gao <wegao@suse.com>
> Signed-off-by: Li Wang <liwang@redhat.com>
> ---
> 
> Notes:
>     Hi Wei,
>     
>        Could you please test this patch and post the output messages?
tst_device.c:97: TINFO: Found free device 1 '/dev/loop1'
tst_test.c:1741: TINFO: LTP version: 20240129-94-g8f14b06e0
tst_test.c:1627: TINFO: Timeout per run is 0h 00m 30s
tst_supported_fs_types.c:97: TINFO: Kernel supports ext2
tst_supported_fs_types.c:62: TINFO: mkfs.ext2 does exist
tst_supported_fs_types.c:97: TINFO: Kernel supports ext3
tst_supported_fs_types.c:62: TINFO: mkfs.ext3 does exist
tst_supported_fs_types.c:97: TINFO: Kernel supports ext4
tst_supported_fs_types.c:62: TINFO: mkfs.ext4 does exist
tst_supported_fs_types.c:97: TINFO: Kernel supports xfs
tst_supported_fs_types.c:62: TINFO: mkfs.xfs does exist
tst_supported_fs_types.c:97: TINFO: Kernel supports btrfs
tst_supported_fs_types.c:62: TINFO: mkfs.btrfs does exist
tst_supported_fs_types.c:105: TINFO: Skipping bcachefs because of FUSE blacklist
tst_supported_fs_types.c:97: TINFO: Kernel supports vfat
tst_supported_fs_types.c:62: TINFO: mkfs.vfat does exist
tst_supported_fs_types.c:97: TINFO: Kernel supports exfat
tst_supported_fs_types.c:58: TINFO: mkfs.exfat does not exist
tst_supported_fs_types.c:128: TINFO: Filesystem ntfs is not supported
tst_supported_fs_types.c:97: TINFO: Kernel supports tmpfs
tst_supported_fs_types.c:49: TINFO: mkfs is not needed for tmpfs
tst_test.c:1701: TINFO: === Testing on ext2 ===
tst_test.c:1118: TINFO: Formatting /dev/loop1 with ext2 opts='' extra opts=''
mke2fs 1.47.0 (5-Feb-2023)
tst_test.c:1132: TINFO: Mounting /dev/loop1 to /tmp/LTP_swafHGLPe/mntpoint fstyp=ext2 flags=0
tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
swapon01.c:27: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:30: TINFO: SwapCached: 0 Kb
tst_test.c:1701: TINFO: === Testing on ext3 ===
tst_test.c:1118: TINFO: Formatting /dev/loop1 with ext3 opts='' extra opts=''
mke2fs 1.47.0 (5-Feb-2023)
tst_test.c:1132: TINFO: Mounting /dev/loop1 to /tmp/LTP_swafHGLPe/mntpoint fstyp=ext3 flags=0
tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
swapon01.c:27: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:30: TINFO: SwapCached: 0 Kb
tst_test.c:1701: TINFO: === Testing on ext4 ===
tst_test.c:1118: TINFO: Formatting /dev/loop1 with ext4 opts='' extra opts=''
mke2fs 1.47.0 (5-Feb-2023)
tst_test.c:1132: TINFO: Mounting /dev/loop1 to /tmp/LTP_swafHGLPe/mntpoint fstyp=ext4 flags=0
tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
swapon01.c:27: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:30: TINFO: SwapCached: 0 Kb
tst_test.c:1701: TINFO: === Testing on xfs ===
tst_test.c:1118: TINFO: Formatting /dev/loop1 with xfs opts='' extra opts=''
tst_test.c:1132: TINFO: Mounting /dev/loop1 to /tmp/LTP_swafHGLPe/mntpoint fstyp=xfs flags=0
tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
swapon01.c:27: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:30: TINFO: SwapCached: 0 Kb
tst_test.c:1701: TINFO: === Testing on btrfs ===
tst_test.c:1118: TINFO: Formatting /dev/loop1 with btrfs opts='' extra opts=''
tst_test.c:1132: TINFO: Mounting /dev/loop1 to /tmp/LTP_swafHGLPe/mntpoint fstyp=btrfs flags=0
libswap.c:42: TINFO: FS_NOCOW_FL attribute set on mntpoint/swapfile01
tst_ioctl.c:21: TINFO: FIBMAP ioctl is NOT supported: EINVAL (22)
libswap.c:125: TINFO: File 'mntpoint/swapfile01' is not contiguous
libswap.c:42: TINFO: FS_NOCOW_FL attribute set on mntpoint/swapfile01
swapon01.c:27: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:30: TINFO: SwapCached: 0 Kb
tst_test.c:1701: TINFO: === Testing on vfat ===
tst_test.c:1118: TINFO: Formatting /dev/loop1 with vfat opts='' extra opts=''
tst_test.c:1132: TINFO: Mounting /dev/loop1 to /tmp/LTP_swafHGLPe/mntpoint fstyp=vfat flags=0
tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
swapon01.c:27: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:30: TINFO: SwapCached: 0 Kb
tst_test.c:1701: TINFO: === Testing on tmpfs ===
tst_test.c:1118: TINFO: Skipping mkfs for TMPFS filesystem
tst_test.c:1098: TINFO: Limiting tmpfs size to 32MB
tst_test.c:1132: TINFO: Mounting ltp-tmpfs to /tmp/LTP_swafHGLPe/mntpoint fstyp=tmpfs flags=0
tst_ioctl.c:21: TINFO: FIBMAP ioctl is NOT supported: EINVAL (22)
libswap.c:214: TCONF: Swapfile on tmpfs not implemented

Summary:
passed   6
failed   0
broken   0
skipped  1
warnings 0


>        Thanks!!
> 
>  testcases/kernel/syscalls/swapon/swapon01.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
> index d406e4bd9..b4fc02d6e 100644
> --- a/testcases/kernel/syscalls/swapon/swapon01.c
> +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> @@ -26,7 +26,7 @@ static void verify_swapon(void)
>  {
>  	TST_EXP_PASS(tst_syscall(__NR_swapon, SWAP_FILE, 0));
>  
> -	tst_pollute_memory(TESTMEM, 0x41);
> +	tst_pollute_memory(TESTMEM * 9/10, 0x41);
>  	tst_res(TINFO, "SwapCached: %ld Kb", SAFE_READ_MEMINFO("SwapCached:"));
>  
>  	if (TST_PASS && tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
> @@ -37,11 +37,21 @@ static void verify_swapon(void)
>  
>  static void setup(void)
>  {
> +	tst_enable_oom_protection(0);
>  	is_swap_supported(SWAP_FILE);
> -	make_swapfile(SWAP_FILE, 10, 0);
> +	make_swapfile(SWAP_FILE, 1024, 0);
>  
>  	SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
>  	SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM);
> +	if (TST_CG_VER_IS_V1(tst_cg, "memory"))
> +		SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%lu", ~0UL);
> +	else
> +		SAFE_CG_PRINT(tst_cg, "memory.swap.max", "max");
> +}
> +
> +static void cleanup(void)
> +{
> +	tst_disable_oom_protection(0);
>  }
>  
>  static struct tst_test test = {
> @@ -51,5 +61,6 @@ static struct tst_test test = {
>  	.all_filesystems = 1,
>  	.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
>  	.test_all = verify_swapon,
> -	.setup = setup
> +	.setup = setup,
> +	.cleanup = cleanup
>  };
> -- 
> 2.40.1
> 


More information about the ltp mailing list