2023-09-04 08:20:11

by Liu Shixin

[permalink] [raw]
Subject: [PATCH] mm, memcg: expose swapcache stat for memcg v1

Since commit b6038942480e ("mm: memcg: add swapcache stat for memcg v2")
adds swapcache stat for the cgroup v2, it seems there is no reason to
hide it in memcg v1. Conversely, with swapcached it is more accurate to
evaluate the available memory for memcg.

Suggested-by: Yosry Ahmed <[email protected]>
Signed-off-by: Liu Shixin <[email protected]>
---
Documentation/admin-guide/cgroup-v1/memory.rst | 1 +
mm/memcontrol.c | 6 ++++++
2 files changed, 7 insertions(+)

diff --git a/Documentation/admin-guide/cgroup-v1/memory.rst b/Documentation/admin-guide/cgroup-v1/memory.rst
index fabaad3fd9c2..fb4abe0dc228 100644
--- a/Documentation/admin-guide/cgroup-v1/memory.rst
+++ b/Documentation/admin-guide/cgroup-v1/memory.rst
@@ -546,6 +546,7 @@ memory.stat file includes following statistics:
event happens each time a page is unaccounted from the
cgroup.
swap # of bytes of swap usage
+ swapcached # of bytes of swap cached in memory
dirty # of bytes that are waiting to get written back to the disk.
writeback # of bytes of file/anon cache that are queued for syncing to
disk.
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index c465829db92b..619acf479be7 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4068,6 +4068,9 @@ static const unsigned int memcg1_stats[] = {
WORKINGSET_REFAULT_ANON,
WORKINGSET_REFAULT_FILE,
MEMCG_SWAP,
+#ifdef CONFIG_SWAP
+ NR_SWAPCACHE,
+#endif
};

static const char *const memcg1_stat_names[] = {
@@ -4083,6 +4086,9 @@ static const char *const memcg1_stat_names[] = {
"workingset_refault_anon",
"workingset_refault_file",
"swap",
+#ifdef CONFIG_SWAP
+ "swapcached",
+#endif
};

/* Universal VM events cgroup1 shows, original sort order */
--
2.25.1


2023-09-26 08:36:08

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH] mm, memcg: expose swapcache stat for memcg v1

On Sat, Sep 02, 2023 at 06:07:28PM +0800, Liu Shixin wrote:
> Since commit b6038942480e ("mm: memcg: add swapcache stat for memcg v2")
> adds swapcache stat for the cgroup v2, it seems there is no reason to
> hide it in memcg v1. Conversely, with swapcached it is more accurate to
> evaluate the available memory for memcg.

Why are we adding new features to the long deprecated cgroup v1?

2023-09-26 14:04:13

by Yosry Ahmed

[permalink] [raw]
Subject: Re: [PATCH] mm, memcg: expose swapcache stat for memcg v1

On Tue, Sep 26, 2023 at 12:30 AM Christoph Hellwig <[email protected]> wrote:
>
> On Sat, Sep 02, 2023 at 06:07:28PM +0800, Liu Shixin wrote:
> > Since commit b6038942480e ("mm: memcg: add swapcache stat for memcg v2")
> > adds swapcache stat for the cgroup v2, it seems there is no reason to
> > hide it in memcg v1. Conversely, with swapcached it is more accurate to
> > evaluate the available memory for memcg.
>
> Why are we adding new features to the long deprecated cgroup v1?
>

Technically this is not a new feature, we are just exposing a stat
that the kernel is already tracking (for both cgroup v1 and v2).

The reason I suggested to expose this for cgroup v1 is because a
recent series [1] started using this stat in the kernel to make some
reclaim decisions, for both cgroup v1 and v2. Exposing the stat in v1
will make sure no one assumes the stat is only useful for v2 and break
the tracking for v1 (which might cause some reclaim regressions then).

[1]https://lore.kernel.org/lkml/[email protected]/