[LTP] [PATCH] swapon01: swapon01: prevent OOM happening in swap process
Li Wang
liwang@redhat.com
Mon Mar 18 07:32:41 CET 2024
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?
--- 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