[LTP] [PATCH] swapon01: swapon01: prevent OOM happening in swap process
Li Wang
liwang@redhat.com
Mon Mar 18 08:26:00 CET 2024
On Mon, Mar 18, 2024 at 3:02 PM Wei Gao <wegao@suse.com> wrote:
> 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
>
That's because the available swapfile on your SUT is too small,
you can adjust it (then retest it) by yourself to find a proper size.
This is fine as long as the swapfile size is less than 300MB,
otherwise we need to set .dev_min_size like what we did
for swapoff01.c.
And, on the other side, we can't guarantee the system SwapCached
happened every time, it depends on the system's configuration.
--
Regards,
Li Wang
More information about the ltp
mailing list