Re: [LTP] [PATCH 1/2] madvise09: restore cgroup v1 memory limits with numeric values

Li Wang <[email protected]> Thu, 30 Jul 2026 20:52:37 +0800
Newsgroups it.linux.lists.ltp
Message-ID <[email protected]>
Andrea Cervesato wrote:

> > +	if (TST_CG_VER_IS_V1(tst_cg, "memory")) {
> > +		SAFE_CG_PRINTF(tst_cg, "memory.max", "%lld", ori_mem_limit);
> > +
> > +		if (swap_accounting_enabled)
> > +			SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%lld", ori_swap_limit);
> > +	} else {
> > +		SAFE_CG_PRINT(tst_cg, "memory.max", "max");
> > +
> > +		if (swap_accounting_enabled)
> > +			SAFE_CG_PRINT(tst_cg, "memory.swap.max", "max");
> > +	}

> >  static void setup(void)
> >  {
> > -	if (SAFE_CG_HAS(tst_cg, "memory.swap.max"))
> > +	if (TST_CG_VER_IS_V1(tst_cg, "memory"))
> > +		SAFE_CG_SCANF(tst_cg, "memory.max", "%lld", &ori_mem_limit);
> > +
> > +	if (SAFE_CG_HAS(tst_cg, "memory.swap.max")) {
> >  		swap_accounting_enabled = 1;
> > -	else
> > +
> > +		if (TST_CG_VER_IS_V1(tst_cg, "memory"))
> > +			SAFE_CG_SCANF(tst_cg, "memory.swap.max", "%lld", &ori_swap_limit);
> > +	} else {
> >  		tst_res(TINFO, "Swap accounting is disabled");
> > +	}
> 
> 
> I see a pattern inside text function and setup(), maybe we can create
> a function that reset memory.max and memory.swap.max in one place.

Not exactly, the logic in setup (save) and test (restore) are
not identical, one reads the other writes. 

Or, did I miss anything there?

-- 
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp