[LTP] [PATCH v1] swapon01.c: Apply a margin to avoid oom

Li Wang liwang@redhat.com
Fri Mar 15 05:09:02 CET 2024


On Fri, Mar 15, 2024 at 11:44 AM Wei Gao <wegao@suse.com> wrote:

> On Fri, Mar 15, 2024 at 11:17:01AM +0800, Li Wang wrote:
> > On Fri, Mar 15, 2024 at 9:30 AM Wei Gao <wegao@suse.com> wrote:
> >
> > > On Thu, Mar 14, 2024 at 02:40:40PM +0800, Li Wang wrote:
> > > > Hi Wei,
> > > >
> > > > On Thu, Mar 14, 2024 at 9:33 AM Wei Gao via ltp <ltp@lists.linux.it>
> > > wrote:
> > > >
> > > > > During our test i find a oom error during test which triggered by
> > > > > tst_pollute_memory.
> > > > >
> > > > > kernel:
> > > > >
> > >
> oom-kill:constraint=CONSTRAINT_MEMCG,nodemask=(null),cpuset=/,mems_allowed=0-1,oom_memcg=/ltp/test-9552,task_memcg=/ltp/test-95520
> > > > > kernel: Memory cgroup out of memory: Killed process 9575 (swapon01)
> > > > > total-vm:1051484kB, anon-rss:1046572kB, file-rss:1280kB,
> shmem-rss:0k0
> > > > >
> > > > > Signed-off-by: Wei Gao <wegao@suse.com>
> > > > > ---
> > > > >  testcases/kernel/syscalls/swapon/swapon01.c | 4 +++-
> > > > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/testcases/kernel/syscalls/swapon/swapon01.c
> > > > > b/testcases/kernel/syscalls/swapon/swapon01.c
> > > > > index d406e4bd9..357992525 100644
> > > > > --- a/testcases/kernel/syscalls/swapon/swapon01.c
> > > > > +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> > > > > @@ -41,7 +41,9 @@ static void setup(void)
> > > > >         make_swapfile(SWAP_FILE, 10, 0);
> > > > >
> > > > >         SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
> > > > > -       SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM);
> > > > > +
> > > > > +       /* Apply a margin to avoid oom during tst_pollute_memory */
> > > > > +       SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM +
> > > TESTMEM/100);
> > > > >
> > > >
> > > > Even with a bit of margin added there is still not guarantee to
> avoid OOM
> > > > completely.
> > > >
> > > > As the Cgroup V1 and V2 track memory and swap in two ways, if the
> margin
> > > is
> > > > too large that might not make the swap happen which is not our
> > > expectation.
> > > >
> > > > So other method I can think of is to disable the OOM in Cgoup,
> > > >     echo 1 > memory.oom_control
> > > This option not exist in cgroupv2, it seems no direct oom control for
> > > cgroupv2
> > >
> >
> > Ok, which version (found the OOM issue) did you test on?
> mount | grep cgroup
> cgroup2 on /sys/fs/cgroup type cgroup2
> (rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot)
> > Maybe here we have to split the control work into two parts (V1 and V2).
>


> How to disable OOM and also let swap action happen at the same time for
> cgroup V2?
>

The Cgroup v2 does not provide a way to disable OOM inside directly.

If we want to avoid OOM happening, just have to manage OOM behavior
in cgroup v2 by setting appropriate values for 'memory.max', 'memory.high',
and using 'memory.oom.group' to determine whether the OOM killer should
target individual processes or the whole Cgroup.

After looking back at this case again, I guess the main reason is that the
swapfile is too small to bear the memory load, one direct method is like
you to enlarge the 'memory.max' value, but that still does not resolve
problems eventually.

One possible solution is crate a bit larger swapfile for the test, and
unlimited
the swap out size. Can you try this patch on your system?

--- a/testcases/kernel/syscalls/swapon/swapon01.c
+++ b/testcases/kernel/syscalls/swapon/swapon01.c
@@ -38,10 +38,14 @@ static void verify_swapon(void)
 static void setup(void)
 {
        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 struct tst_test test = {


-- 
Regards,
Li Wang


More information about the ltp mailing list