Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* cgroup/test_zswap failed with "zswpout does not increase after test program"
@ 2026-07-07  9:38 Zenghui Yu
  2026-07-07 12:01 ` Michal Koutný
  2026-07-07 18:25 ` Yosry Ahmed
  0 siblings, 2 replies; 8+ messages in thread
From: Zenghui Yu @ 2026-07-07  9:38 UTC (permalink / raw)
  To: linux-mm, cgroups, linux-kselftest, linux-kernel
  Cc: hannes, yosry, nphamcs, chengming.zhou, tj, mkoutny, Shuah Khan,
	mhocko, Roman Gushchin, Shakeel Butt, Muchun Song, Andrew Morton

Hi,

Running cgroup/test_zswap on my arm64 box failed immediately with:

  [root@localhost cgroup]# ./test_zswap 
  TAP version 13
  1..8
  # zswpout does not increase after test program
  not ok 1 test_zswap_usage
  [...]

I'm sure that pages are successfully written into zswap by checking the
count_memcg_events(.., idx=ZSWPOUT, ..) trace events. But "zswpout_after"
in test_zswap_usage() is 0 and results in this failure.

I guess the problem is that (in this particular case) the memcg stats has
not been flushed when userspace reads it.

 memcg_stat_format()
   mem_cgroup_flush_stats()
     __mem_cgroup_flush_stats(.., force=false)
       needs_flush = memcg_vmstats_needs_flush();

 static bool memcg_vmstats_needs_flush(struct memcg_vmstats *vmstats)
 {
 	return atomic_long_read(&vmstats->stats_updates) >
 		MEMCG_CHARGE_BATCH * num_online_cpus();
 }

I can image that memcg_vmstats_needs_flush() will return false because I'm
testing a 16k-page-size kernel on a box with 96 cpus..

As we have a periodic flusher flushed all the stats every 2 seconds, I use
the following diff to wait the flusher to expose the accurate stats to
userspace.

diff --git a/tools/testing/selftests/cgroup/lib/cgroup_util.c b/tools/testing/selftests/cgroup/lib/cgroup_util.c
index 3ce134509041..9596f294da0b 100644
--- a/tools/testing/selftests/cgroup/lib/cgroup_util.c
+++ b/tools/testing/selftests/cgroup/lib/cgroup_util.c
@@ -95,6 +95,8 @@ int cg_read(const char *cgroup, const char *control, char *buf, size_t len)
 
 	snprintf(path, sizeof(path), "%s/%s", cgroup, control);
 
+	sleep(2);
+
 	ret = read_text(path, buf, len);
 	return ret >= 0 ? 0 : ret;
 }

I have no idea how to "fix" it properly. Please have a look!

Thanks,
Zenghui


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: cgroup/test_zswap failed with "zswpout does not increase after test program"
  2026-07-07  9:38 cgroup/test_zswap failed with "zswpout does not increase after test program" Zenghui Yu
@ 2026-07-07 12:01 ` Michal Koutný
  2026-07-07 12:14   ` Zenghui Yu
  2026-07-07 18:25 ` Yosry Ahmed
  1 sibling, 1 reply; 8+ messages in thread
From: Michal Koutný @ 2026-07-07 12:01 UTC (permalink / raw)
  To: Zenghui Yu
  Cc: linux-mm, cgroups, linux-kselftest, linux-kernel, hannes, yosry,
	nphamcs, chengming.zhou, tj, Shuah Khan, mhocko, Roman Gushchin,
	Shakeel Butt, Muchun Song, Andrew Morton, Li Wang

[-- Attachment #1: Type: text/plain, Size: 593 bytes --]

Hello Zenghui.

On Tue, Jul 07, 2026 at 05:38:13PM +0800, Zenghui Yu <zenghui.yu@linux.dev> wrote:
> Hi,
> 
> Running cgroup/test_zswap on my arm64 box failed immediately with:
> 
>   [root@localhost cgroup]# ./test_zswap 
>   TAP version 13
>   1..8
>   # zswpout does not increase after test program
>   not ok 1 test_zswap_usage
>   [...]

What version of the tests do you run?
Namely, does it have the recent patches from Li [1]?

Thanks,
Michal

[1] 83476cc97bc63 ("Merge tag 'cgroup-for-7.2' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup") v7.2-rc1~136

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 265 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cgroup/test_zswap failed with "zswpout does not increase after test program"
  2026-07-07 12:01 ` Michal Koutný
@ 2026-07-07 12:14   ` Zenghui Yu
  0 siblings, 0 replies; 8+ messages in thread
From: Zenghui Yu @ 2026-07-07 12:14 UTC (permalink / raw)
  To: Michal Koutný
  Cc: linux-mm, cgroups, linux-kselftest, linux-kernel, hannes, yosry,
	nphamcs, chengming.zhou, tj, Shuah Khan, mhocko, Roman Gushchin,
	Shakeel Butt, Muchun Song, Andrew Morton, Li Wang

Hi Michal,

On 7/7/26 8:01 PM, Michal Koutný wrote:
> Hello Zenghui.
> 
> On Tue, Jul 07, 2026 at 05:38:13PM +0800, Zenghui Yu <zenghui.yu@linux.dev> wrote:
> > Hi,
> >
> > Running cgroup/test_zswap on my arm64 box failed immediately with:
> >
> >   [root@localhost cgroup]# ./test_zswap 
> >   TAP version 13
> >   1..8
> >   # zswpout does not increase after test program
> >   not ok 1 test_zswap_usage
> >   [...]
> 
> What version of the tests do you run?
> Namely, does it have the recent patches from Li [1]?

I use today's mm-new [*]

> 
> [1] 83476cc97bc63 ("Merge tag 'cgroup-for-7.2' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup") v7.2-rc1~136

... so it should already be included.

[*] https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/log/?h=mm-new

Thanks,
Zenghui


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cgroup/test_zswap failed with "zswpout does not increase after test program"
  2026-07-07  9:38 cgroup/test_zswap failed with "zswpout does not increase after test program" Zenghui Yu
  2026-07-07 12:01 ` Michal Koutný
@ 2026-07-07 18:25 ` Yosry Ahmed
  2026-07-07 21:35   ` Nhat Pham
  1 sibling, 1 reply; 8+ messages in thread
From: Yosry Ahmed @ 2026-07-07 18:25 UTC (permalink / raw)
  To: Zenghui Yu
  Cc: linux-mm, cgroups, linux-kselftest, linux-kernel, hannes, nphamcs,
	chengming.zhou, tj, mkoutny, Shuah Khan, mhocko, Roman Gushchin,
	Shakeel Butt, Muchun Song, Andrew Morton

On Tue, Jul 7, 2026 at 2:38 AM Zenghui Yu <zenghui.yu@linux.dev> wrote:
>
> Hi,
>
> Running cgroup/test_zswap on my arm64 box failed immediately with:
>
>   [root@localhost cgroup]# ./test_zswap
>   TAP version 13
>   1..8
>   # zswpout does not increase after test program
>   not ok 1 test_zswap_usage
>   [...]
>
> I'm sure that pages are successfully written into zswap by checking the
> count_memcg_events(.., idx=ZSWPOUT, ..) trace events. But "zswpout_after"
> in test_zswap_usage() is 0 and results in this failure.
>
> I guess the problem is that (in this particular case) the memcg stats has
> not been flushed when userspace reads it.
>
>  memcg_stat_format()
>    mem_cgroup_flush_stats()
>      __mem_cgroup_flush_stats(.., force=false)
>        needs_flush = memcg_vmstats_needs_flush();
>
>  static bool memcg_vmstats_needs_flush(struct memcg_vmstats *vmstats)
>  {
>         return atomic_long_read(&vmstats->stats_updates) >
>                 MEMCG_CHARGE_BATCH * num_online_cpus();
>  }
>
> I can image that memcg_vmstats_needs_flush() will return false because I'm
> testing a 16k-page-size kernel on a box with 96 cpus..
>
> As we have a periodic flusher flushed all the stats every 2 seconds, I use
> the following diff to wait the flusher to expose the accurate stats to
> userspace.
>
> diff --git a/tools/testing/selftests/cgroup/lib/cgroup_util.c b/tools/testing/selftests/cgroup/lib/cgroup_util.c
> index 3ce134509041..9596f294da0b 100644
> --- a/tools/testing/selftests/cgroup/lib/cgroup_util.c
> +++ b/tools/testing/selftests/cgroup/lib/cgroup_util.c
> @@ -95,6 +95,8 @@ int cg_read(const char *cgroup, const char *control, char *buf, size_t len)
>
>         snprintf(path, sizeof(path), "%s/%s", cgroup, control);
>
> +       sleep(2);
> +
>         ret = read_text(path, buf, len);
>         return ret >= 0 ? 0 : ret;
>  }
>
> I have no idea how to "fix" it properly. Please have a look!

We were discussing a way for userspace to explicitly trigger a flush
before, which would come in handy for testing. However, we decided not
to expose flushing as a concept to userspace.

Unfortunately I think the only way to "fix" the test is to allocate
more memory, enough to trigger a flush on most interesting setups.
Perhaps we should scale the amount of memory with the number of CPUs
so that we don't have to keep playing whack-a-mole.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cgroup/test_zswap failed with "zswpout does not increase after test program"
  2026-07-07 18:25 ` Yosry Ahmed
@ 2026-07-07 21:35   ` Nhat Pham
  2026-07-07 21:36     ` Yosry Ahmed
  0 siblings, 1 reply; 8+ messages in thread
From: Nhat Pham @ 2026-07-07 21:35 UTC (permalink / raw)
  To: Yosry Ahmed
  Cc: Zenghui Yu, linux-mm, cgroups, linux-kselftest, linux-kernel,
	hannes, chengming.zhou, tj, mkoutny, Shuah Khan, mhocko,
	Roman Gushchin, Shakeel Butt, Muchun Song, Andrew Morton

On Tue, Jul 7, 2026 at 11:25 AM Yosry Ahmed <yosry@kernel.org> wrote:
>
> On Tue, Jul 7, 2026 at 2:38 AM Zenghui Yu <zenghui.yu@linux.dev> wrote:
>
> We were discussing a way for userspace to explicitly trigger a flush
> before, which would come in handy for testing. However, we decided not
> to expose flushing as a concept to userspace.
>
> Unfortunately I think the only way to "fix" the test is to allocate
> more memory, enough to trigger a flush on most interesting setups.
> Perhaps we should scale the amount of memory with the number of CPUs
> so that we don't have to keep playing whack-a-mole.

I don't have a good idea for writeback, but for zswap out, would
MADV_PAGEOUT work here?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cgroup/test_zswap failed with "zswpout does not increase after test program"
  2026-07-07 21:35   ` Nhat Pham
@ 2026-07-07 21:36     ` Yosry Ahmed
  2026-07-07 21:46       ` Nhat Pham
  0 siblings, 1 reply; 8+ messages in thread
From: Yosry Ahmed @ 2026-07-07 21:36 UTC (permalink / raw)
  To: Nhat Pham
  Cc: Zenghui Yu, linux-mm, cgroups, linux-kselftest, linux-kernel,
	hannes, chengming.zhou, tj, mkoutny, Shuah Khan, mhocko,
	Roman Gushchin, Shakeel Butt, Muchun Song, Andrew Morton

On Tue, Jul 7, 2026 at 2:35 PM Nhat Pham <nphamcs@gmail.com> wrote:
>
> On Tue, Jul 7, 2026 at 11:25 AM Yosry Ahmed <yosry@kernel.org> wrote:
> >
> > On Tue, Jul 7, 2026 at 2:38 AM Zenghui Yu <zenghui.yu@linux.dev> wrote:
> >
> > We were discussing a way for userspace to explicitly trigger a flush
> > before, which would come in handy for testing. However, we decided not
> > to expose flushing as a concept to userspace.
> >
> > Unfortunately I think the only way to "fix" the test is to allocate
> > more memory, enough to trigger a flush on most interesting setups.
> > Perhaps we should scale the amount of memory with the number of CPUs
> > so that we don't have to keep playing whack-a-mole.
>
> I don't have a good idea for writeback, but for zswap out, would
> MADV_PAGEOUT work here?

I don't think the reclaim mechanism is the problem, but the fact that
we don't have enough pending updates to flush the stats. Am I missing
something?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cgroup/test_zswap failed with "zswpout does not increase after test program"
  2026-07-07 21:36     ` Yosry Ahmed
@ 2026-07-07 21:46       ` Nhat Pham
  2026-07-07 21:49         ` Yosry Ahmed
  0 siblings, 1 reply; 8+ messages in thread
From: Nhat Pham @ 2026-07-07 21:46 UTC (permalink / raw)
  To: Yosry Ahmed
  Cc: Zenghui Yu, linux-mm, cgroups, linux-kselftest, linux-kernel,
	hannes, chengming.zhou, tj, mkoutny, Shuah Khan, mhocko,
	Roman Gushchin, Shakeel Butt, Muchun Song, Andrew Morton

On Tue, Jul 7, 2026 at 2:36 PM Yosry Ahmed <yosry@kernel.org> wrote:
>
> On Tue, Jul 7, 2026 at 2:35 PM Nhat Pham <nphamcs@gmail.com> wrote:
> >
> > On Tue, Jul 7, 2026 at 11:25 AM Yosry Ahmed <yosry@kernel.org> wrote:
> > >
> > > On Tue, Jul 7, 2026 at 2:38 AM Zenghui Yu <zenghui.yu@linux.dev> wrote:
> > >
> > > We were discussing a way for userspace to explicitly trigger a flush
> > > before, which would come in handy for testing. However, we decided not
> > > to expose flushing as a concept to userspace.
> > >
> > > Unfortunately I think the only way to "fix" the test is to allocate
> > > more memory, enough to trigger a flush on most interesting setups.
> > > Perhaps we should scale the amount of memory with the number of CPUs
> > > so that we don't have to keep playing whack-a-mole.
> >
> > I don't have a good idea for writeback, but for zswap out, would
> > MADV_PAGEOUT work here?
>
> I don't think the reclaim mechanism is the problem, but the fact that
> we don't have enough pending updates to flush the stats. Am I missing
> something?

Ah yeah, you're right. Hmmm.

Yeah it sucks, but maybe sleeping (more than the flush period) before
read is the only way. Which
is terribly implementation-dependent :(


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cgroup/test_zswap failed with "zswpout does not increase after test program"
  2026-07-07 21:46       ` Nhat Pham
@ 2026-07-07 21:49         ` Yosry Ahmed
  0 siblings, 0 replies; 8+ messages in thread
From: Yosry Ahmed @ 2026-07-07 21:49 UTC (permalink / raw)
  To: Nhat Pham
  Cc: Zenghui Yu, linux-mm, cgroups, linux-kselftest, linux-kernel,
	hannes, chengming.zhou, tj, mkoutny, Shuah Khan, mhocko,
	Roman Gushchin, Shakeel Butt, Muchun Song, Andrew Morton

On Tue, Jul 7, 2026 at 2:47 PM Nhat Pham <nphamcs@gmail.com> wrote:
>
> On Tue, Jul 7, 2026 at 2:36 PM Yosry Ahmed <yosry@kernel.org> wrote:
> >
> > On Tue, Jul 7, 2026 at 2:35 PM Nhat Pham <nphamcs@gmail.com> wrote:
> > >
> > > On Tue, Jul 7, 2026 at 11:25 AM Yosry Ahmed <yosry@kernel.org> wrote:
> > > >
> > > > On Tue, Jul 7, 2026 at 2:38 AM Zenghui Yu <zenghui.yu@linux.dev> wrote:
> > > >
> > > > We were discussing a way for userspace to explicitly trigger a flush
> > > > before, which would come in handy for testing. However, we decided not
> > > > to expose flushing as a concept to userspace.
> > > >
> > > > Unfortunately I think the only way to "fix" the test is to allocate
> > > > more memory, enough to trigger a flush on most interesting setups.
> > > > Perhaps we should scale the amount of memory with the number of CPUs
> > > > so that we don't have to keep playing whack-a-mole.
> > >
> > > I don't have a good idea for writeback, but for zswap out, would
> > > MADV_PAGEOUT work here?
> >
> > I don't think the reclaim mechanism is the problem, but the fact that
> > we don't have enough pending updates to flush the stats. Am I missing
> > something?
>
> Ah yeah, you're right. Hmmm.
>
> Yeah it sucks, but maybe sleeping (more than the flush period) before
> read is the only way. Which
> is terribly implementation-dependent :(

I would honestly rather use more memory. I think there might be cases
where the flusher is delayed. The flush being slightly delayed is not
technically a bug that we want to see a failure for, but if a large
stats change is not visible that's a user-noticeable behavior that we
want a failure for.

WDYT?


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-07-07 21:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-07  9:38 cgroup/test_zswap failed with "zswpout does not increase after test program" Zenghui Yu
2026-07-07 12:01 ` Michal Koutný
2026-07-07 12:14   ` Zenghui Yu
2026-07-07 18:25 ` Yosry Ahmed
2026-07-07 21:35   ` Nhat Pham
2026-07-07 21:36     ` Yosry Ahmed
2026-07-07 21:46       ` Nhat Pham
2026-07-07 21:49         ` Yosry Ahmed

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox