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

Li Wang liwang@redhat.com
Fri Mar 15 04:17:01 CET 2024


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?
Maybe here we have to split the control work into two parts (V1 and V2).



> > or, set `overcommit_memory` to 2 to prevent the OOM from occurring.
> >     echo 2 > /proc/sys/vm/overcommit_memory
> I have tried this option, oom still happen.
>

Well, it looks like overcommit controlled by overcommit_memory is
allowed for the entire system, not just the Cgroup.


-- 
Regards,
Li Wang


More information about the ltp mailing list