cgroup/test_zswap failed with "zswpout does not increase after test program"
Subsystems (3)
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.
tools/testing/selftests/cgroup/lib/cgroup_util.c +2 -0
@@ -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
Michal Koutný
maintainerHello Zenghui.
Quoted 10 lines · Zenghui Yu
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
Hi Michal,
Quoted 14 lines · Michal Koutný
Hello Zenghui.
Quoted 10 lines · Zenghui Yu
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 [...]
Quoted 2 lines
What version of the tests do you run? Namely, does it have the recent patches from Li [1]?
I use today's mm-new [*]
Quoted 2 lines
[1]
83476cc97bc63("Merge tag 'cgroup-for-7.2' ofgit://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
Quoted 51 lines · Zenghui Yu
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" intest_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.
tools/testing/selftests/cgroup/lib/cgroup_util.c +2
-0@@ -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; }
Quoted 1 line
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.
Quoted 11 lines · Yosry Ahmed
On Tue, Jul 7, 2026 at 2:38 AM Zenghui Yu <[email protected]> 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?
Quoted 9 lines · Nhat Pham
Quoted 7 lines · Yosry Ahmed
On Tue, Jul 7, 2026 at 2:38 AM Zenghui Yu <[email protected]> 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.
Quoted 7 lines
Quoted 4 lines
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_PAGEOUTwork 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?
Quoted 16 lines · Yosry Ahmed
Quoted 14 lines · Nhat Pham
Quoted 11 lines · Yosry Ahmed
On Tue, Jul 7, 2026 at 2:38 AM Zenghui Yu <[email protected]> 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.
Quoted 6 lines
Quoted 2 lines
I don't have a good idea for writeback, but for zswap out, would
MADV_PAGEOUTwork 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 :(
Quoted 25 lines · Nhat Pham
Quoted 16 lines · Yosry Ahmed
Quoted 14 lines · Nhat Pham
Quoted 11 lines · Yosry Ahmed
On Tue, Jul 7, 2026 at 2:38 AM Zenghui Yu <[email protected]> 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.
Quoted 6 lines
Quoted 2 lines
I don't have a good idea for writeback, but for zswap out, would
MADV_PAGEOUTwork 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?
Quoted 5 lines
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?
Michal Koutný
maintainerQuoted 7 lines · Yosry Ahmed
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?
There's already the (recent) page size-based scaling, so the idea with nr_cpus scaling could make the selftest useful on wider range of setups (even page size can be considered as a slight implementation detail leak, thus the justification of nr_cpus dependency).
Also, I still think that internally the threshold should be changed to the "harmonic" formula [1] but the selftest can go with the linear dependency for more pronounced effects.
Thanks,
Michal
[1] https://lore.kernel.org/lkml/n6mhkjsxsami3qmczkdh57eep4lmcgbtyl7ox3ajzveke44yf6@m4bjevvsr47k/
Quoted 10 lines · Michal Koutný
Quoted 7 lines · Yosry Ahmed
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?
Quoted 8 lines
There's already the (recent) page size-based scaling, so the idea with
nr_cpusscaling could make the selftest useful on wider range of setups (even page size can be considered as a slight implementation detail leak, thus the justification ofnr_cpusdependency).Also, I still think that internally the threshold should be changed to the "harmonic" formula [1] but the selftest can go with the linear dependency for more pronounced effects.
Yeah I agree the threshold formula can be improved, but we need to make sure performance doesn't regress.
Quoted 17 lines · Yosry Ahmed
Quoted 15 lines · Michal Koutný
Quoted 7 lines · Yosry Ahmed
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?
There's already the (recent) page size-based scaling, so the idea with
nr_cpusscaling could make the selftest useful on wider range of setups (even page size can be considered as a slight implementation detail leak, thus the justification ofnr_cpusdependency).
Quoted 6 lines
Quoted 3 lines
Also, I still think that internally the threshold should be changed to the "harmonic" formula [1] but the selftest can go with the linear dependency for more pronounced effects.
Yeah I agree the threshold formula can be improved, but we need to make sure performance doesn't regress.
Yeah that's a separate discussion indeed. For now I'm fine with fixing the selftests by using more memory.
Is there a good generic formula for this? I understand there will be hardcode values, but at least making it scalable (by how much memory we have, page size, # of cpus) if possible? :)
Quoted 26 lines · Nhat Pham
Quoted 17 lines · Yosry Ahmed
Quoted 15 lines · Michal Koutný
Quoted 7 lines · Yosry Ahmed
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?
There's already the (recent) page size-based scaling, so the idea with
nr_cpusscaling could make the selftest useful on wider range of setups (even page size can be considered as a slight implementation detail leak, thus the justification ofnr_cpusdependency).Quoted 6 lines
Quoted 3 lines
Also, I still think that internally the threshold should be changed to the "harmonic" formula [1] but the selftest can go with the linear dependency for more pronounced effects.
Yeah I agree the threshold formula can be improved, but we need to make sure performance doesn't regress.
Quoted 6 lines
Yeah that's a separate discussion indeed. For now I'm fine with fixing the selftests by using more memory.
Is there a good generic formula for this? I understand there will be hardcode values, but at least making it scalable (by how much memory we have, page size, # of cpus) if possible? :)
The rstat formula depends on the number of CPUs and a constant factor (see memcg_vmstats_needs_flush()), but this formula is for the number of updates (e.g. number of pages reclaimed), and that value will decrease as the page size increases. So I think we want to scale with both the page size and the number of CPUs. The amount of memory in the system is not a factor for now.