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

Wei Gao wegao@suse.com
Mon Mar 18 08:02:19 CET 2024


On Mon, Mar 18, 2024 at 02:32:41PM +0800, Li Wang wrote:
> On Mon, Mar 18, 2024 at 11:20 AM Wei Gao <wegao@suse.com> wrote:
> 
> > On Sun, Mar 17, 2024 at 05:52:01PM +0800, Li Wang wrote:
> > > Hi Wei,
> > >
> > > Can you try this one and post the test log here?
> > >
> > > And again, it'd be helpful to know the config of your SUT.
> > > e.g. `free -h`  `lscpu`  `uname -r`  infoformation
> > >
> > >
> > > --- a/testcases/kernel/syscalls/swapon/swapon01.c
> > > +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> > > @@ -37,11 +37,20 @@ 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 (SAFE_CG_HAS(tst_cg, "memory.swap.max"))
> > > +               SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%ld", TESTMEM
> > *
> > > 2);
> > > +}
> > > +
> > > +static void cleanup(void)
> > > +{
> > > +       tst_disable_oom_protection(0);
> > >  }
> > >
> > >  static struct tst_test test = {
> > > @@ -51,5 +60,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
> > >  };
> > >
> > >
> 
> 
> 
> >
> > localhost:~ # free -h <<<< before running case
> >                total        used        free      shared  buff/cache
> >  available
> > Mem:           3.8Gi       478Mi       3.3Gi       9.0Mi       346Mi
> >  3.4Gi
> > Swap:             0B          0B          0B
> >
> 
> I see, it is very likely that your system has no swap space
> so that the TESTMEM(1GB) can not be swapped out, then
> OOM killer has to be called out.
> 
> I can reproduce your problem by disabling all swap files on my system.
> 
> So the possible fix way is to reduce the TESTMEM size and increase
> the tested swapfile.
> 
> I guess this patch can work for you, have a try?

No oom, but SwapCached size is unstable, most of time is still 0

wegao:/home/ltp # ./scp.sh
rm -f -f -r swapon01 swapon02 swapon03  *.o *.pyc .cache.mk *.dwo .*.dwo
make -C "/home/ltp/lib" -f "/home/ltp/lib/Makefile" all
make[1]: Entering directory '/home/ltp/lib'
GEN ltp-version.h
make[2]: Nothing to be done for 'all'.
make[2]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/ltp/lib'
BUILD libltpswap.a
make[1]: Nothing to be done for 'all'.
CC testcases/kernel/syscalls/swapon/swapon01
CC testcases/kernel/syscalls/swapon/swapon02
CC testcases/kernel/syscalls/swapon/swapon03
swapon01                                                                                                    100%  851KB 373.6KB/s   00:02
tst_device.c:97: TINFO: Found free device 1 '/dev/loop1'
tst_test.c:1741: TINFO: LTP version: 20240129-92-g9fa305fe3
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_swaDbjDqs/mntpoint fstyp=ext2 flags=0
tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
swapon01.c:28: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:31: TINFO: SwapCached: 56 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_swaDbjDqs/mntpoint fstyp=ext3 flags=0
tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
swapon01.c:28: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:31: 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_swaDbjDqs/mntpoint fstyp=ext4 flags=0
tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
swapon01.c:28: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:31: 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_swaDbjDqs/mntpoint fstyp=xfs flags=0
tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
swapon01.c:28: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:31: 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_swaDbjDqs/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:28: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:31: 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_swaDbjDqs/mntpoint fstyp=vfat flags=0
tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
swapon01.c:28: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:31: 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_swaDbjDqs/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
wegao:/home/ltp # ./scp.sh
rm -f -f -r swapon01 swapon02 swapon03  *.o *.pyc .cache.mk *.dwo .*.dwo
make -C "/home/ltp/lib" -f "/home/ltp/lib/Makefile" all
make[1]: Entering directory '/home/ltp/lib'
GEN ltp-version.h
make[2]: Nothing to be done for 'all'.
make[2]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/ltp/lib'
BUILD libltpswap.a
make[1]: Nothing to be done for 'all'.
CC testcases/kernel/syscalls/swapon/swapon01
CC testcases/kernel/syscalls/swapon/swapon02
CC testcases/kernel/syscalls/swapon/swapon03
swapon01                                                                                                    100%  851KB  96.5KB/s   00:08
tst_device.c:97: TINFO: Found free device 1 '/dev/loop1'
tst_test.c:1741: TINFO: LTP version: 20240129-92-g9fa305fe3
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_swaJSeWym/mntpoint fstyp=ext2 flags=0
tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
swapon01.c:28: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:31: 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_swaJSeWym/mntpoint fstyp=ext3 flags=0
tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
swapon01.c:28: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:31: 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_swaJSeWym/mntpoint fstyp=ext4 flags=0
tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
swapon01.c:28: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:31: 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_swaJSeWym/mntpoint fstyp=xfs flags=0
tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
swapon01.c:28: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:31: 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_swaJSeWym/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:28: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:31: 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_swaJSeWym/mntpoint fstyp=vfat flags=0
tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
swapon01.c:28: TPASS: tst_syscall(__NR_swapon, SWAP_FILE, 0) passed
swapon01.c:31: 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_swaJSeWym/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


> 
> --- a/testcases/kernel/syscalls/swapon/swapon01.c
> +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> @@ -20,7 +20,7 @@
> 
>  #define MNTPOINT       "mntpoint"
>  #define SWAP_FILE      MNTPOINT"/swapfile01"
> -#define TESTMEM                (1UL<<30)
> +#define TESTMEM                (1UL<<24)  /* 16MB */
> 
>  static void verify_swapon(void)
>  {
> @@ -38,7 +38,7 @@ static void verify_swapon(void)
>  static void setup(void)
>  {
>         is_swap_supported(SWAP_FILE);
> -       make_swapfile(SWAP_FILE, 10, 0);
> +       make_swapfile(SWAP_FILE, 4096, 0);
> 
>         SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
>         SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM);
> 
> 
> -- 
> Regards,
> Li Wang


More information about the ltp mailing list