* [PATCH] Port hierarchical_mem{ory,sw}_limit cgroup1->cgroup2
@ 2024-02-09 14:48 Jan Kratochvil (Azul)
2024-02-09 15:51 ` Waiman Long
0 siblings, 1 reply; 4+ messages in thread
From: Jan Kratochvil (Azul) @ 2024-02-09 14:48 UTC (permalink / raw)
To: cgroups
Hello,
cgroup1 (by function memcg1_stat_format) already contains two lines
hierarchical_memory_limit %llu
hierarchical_memsw_limit %llu
which are useful for userland to easily and performance-wise find out the
effective cgroup limits being applied. Otherwise userland has to
open+read+close the file "memory.max" and/or "memory.swap.max" in multiple
parent directories of a nested cgroup.
For cgroup1 it was implemented by:
memcg: show real limit under hierarchy mode
https://github.com/torvalds/linux/commit/fee7b548e6f2bd4bfd03a1a45d3afd593de7d5e9
Date: Wed Jan 7 18:08:26 2009 -0800
But for cgroup2 it has been missing so far, this is just a copy-paste of the
cgroup1 code. I have added it to the end of "memory.stat" to prevent possible
compatibility problems with existing code parsing that file.
Jan Kratochvil
Signed-off-by: Jan Kratochvil (Azul) <jkratochvil@azul.com>
mm/memcontrol.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 46d8d0211..39f2a4a06 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1636,6 +1636,8 @@ static inline unsigned long memcg_page_state_local_output(
static void memcg_stat_format(struct mem_cgroup *memcg, struct seq_buf *s)
{
int i;
+ unsigned long memory, memsw;
+ struct mem_cgroup *mi;
/*
* Provide statistics on the state of the memory subsystem as
@@ -1682,6 +1684,17 @@ static void memcg_stat_format(struct mem_cgroup *memcg, struct seq_buf *s)
memcg_events(memcg, memcg_vm_event_stat[i]));
}
+ /* Hierarchical information */
+ memory = memsw = PAGE_COUNTER_MAX;
+ for (mi = memcg; mi; mi = parent_mem_cgroup(mi)) {
+ memory = min(memory, READ_ONCE(mi->memory.max));
+ memsw = min(memsw, READ_ONCE(mi->memsw.max));
+ }
+ seq_buf_printf(s, "hierarchical_memory_limit %llu\n",
+ (u64)memory * PAGE_SIZE);
+ seq_buf_printf(s, "hierarchical_memsw_limit %llu\n",
+ (u64)memsw * PAGE_SIZE);
+
/* The above should easily fit into one page */
WARN_ON_ONCE(seq_buf_has_overflowed(s));
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Port hierarchical_mem{ory,sw}_limit cgroup1->cgroup2
2024-02-09 14:48 [PATCH] Port hierarchical_mem{ory,sw}_limit cgroup1->cgroup2 Jan Kratochvil (Azul)
@ 2024-02-09 15:51 ` Waiman Long
2024-02-11 12:49 ` [PATCH v2] Port hierarchical_{memory,swap}_limit cgroup1->cgroup2 Jan Kratochvil (Azul)
0 siblings, 1 reply; 4+ messages in thread
From: Waiman Long @ 2024-02-09 15:51 UTC (permalink / raw)
To: Jan Kratochvil (Azul), cgroups
On 2/9/24 09:48, Jan Kratochvil (Azul) wrote:
> Hello,
>
> cgroup1 (by function memcg1_stat_format) already contains two lines
> hierarchical_memory_limit %llu
> hierarchical_memsw_limit %llu
>
> which are useful for userland to easily and performance-wise find out the
> effective cgroup limits being applied. Otherwise userland has to
> open+read+close the file "memory.max" and/or "memory.swap.max" in multiple
> parent directories of a nested cgroup.
>
> For cgroup1 it was implemented by:
> memcg: show real limit under hierarchy mode
> https://github.com/torvalds/linux/commit/fee7b548e6f2bd4bfd03a1a45d3afd593de7d5e9
> Date: Wed Jan 7 18:08:26 2009 -0800
>
> But for cgroup2 it has been missing so far, this is just a copy-paste of the
> cgroup1 code. I have added it to the end of "memory.stat" to prevent possible
> compatibility problems with existing code parsing that file.
>
>
> Jan Kratochvil
>
>
> Signed-off-by: Jan Kratochvil (Azul) <jkratochvil@azul.com>
>
> mm/memcontrol.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 46d8d0211..39f2a4a06 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -1636,6 +1636,8 @@ static inline unsigned long memcg_page_state_local_output(
> static void memcg_stat_format(struct mem_cgroup *memcg, struct seq_buf *s)
> {
> int i;
> + unsigned long memory, memsw;
> + struct mem_cgroup *mi;
>
> /*
> * Provide statistics on the state of the memory subsystem as
> @@ -1682,6 +1684,17 @@ static void memcg_stat_format(struct mem_cgroup *memcg, struct seq_buf *s)
> memcg_events(memcg, memcg_vm_event_stat[i]));
> }
>
> + /* Hierarchical information */
> + memory = memsw = PAGE_COUNTER_MAX;
> + for (mi = memcg; mi; mi = parent_mem_cgroup(mi)) {
> + memory = min(memory, READ_ONCE(mi->memory.max));
> + memsw = min(memsw, READ_ONCE(mi->memsw.max));
> + }
> + seq_buf_printf(s, "hierarchical_memory_limit %llu\n",
> + (u64)memory * PAGE_SIZE);
> + seq_buf_printf(s, "hierarchical_memsw_limit %llu\n",
> + (u64)memsw * PAGE_SIZE);
> +
> /* The above should easily fit into one page */
> WARN_ON_ONCE(seq_buf_has_overflowed(s));
> }
I don't think we use mi->memsw in cgroup v2, only memory and swap should
be used.
Cheers,
Longman
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] Port hierarchical_{memory,swap}_limit cgroup1->cgroup2
2024-02-09 15:51 ` Waiman Long
@ 2024-02-11 12:49 ` Jan Kratochvil (Azul)
2024-02-11 18:01 ` Waiman Long
0 siblings, 1 reply; 4+ messages in thread
From: Jan Kratochvil (Azul) @ 2024-02-11 12:49 UTC (permalink / raw)
To: Waiman Long; +Cc: cgroups
Hello Waiman,
On Fri, 09 Feb 2024 23:51:54 +0800, Waiman Long wrote:
> I don't think we use mi->memsw in cgroup v2, only memory and swap should
> be used.
you are right, thanks:
struct mem_cgroup {
...
union {
struct page_counter swap; /* v2 only */
struct page_counter memsw; /* v1 only */
};
Jan Kratochvil
Signed-off-by: Jan Kratochvil (Azul) <jkratochvil@azul.com>
mm/memcontrol.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 46d8d0211..2631dd810 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1636,6 +1636,8 @@ static inline unsigned long memcg_page_state_local_output(
static void memcg_stat_format(struct mem_cgroup *memcg, struct seq_buf *s)
{
int i;
+ unsigned long memory, swap;
+ struct mem_cgroup *mi;
/*
* Provide statistics on the state of the memory subsystem as
@@ -1682,6 +1684,17 @@ static void memcg_stat_format(struct mem_cgroup *memcg, struct seq_buf *s)
memcg_events(memcg, memcg_vm_event_stat[i]));
}
+ /* Hierarchical information */
+ memory = swap = PAGE_COUNTER_MAX;
+ for (mi = memcg; mi; mi = parent_mem_cgroup(mi)) {
+ memory = min(memory, READ_ONCE(mi->memory.max));
+ swap = min(swap, READ_ONCE(mi->swap.max));
+ }
+ seq_buf_printf(s, "hierarchical_memory_limit %llu\n",
+ (u64)memory * PAGE_SIZE);
+ seq_buf_printf(s, "hierarchical_swap_limit %llu\n",
+ (u64)swap * PAGE_SIZE);
+
/* The above should easily fit into one page */
WARN_ON_ONCE(seq_buf_has_overflowed(s));
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] Port hierarchical_{memory,swap}_limit cgroup1->cgroup2
2024-02-11 12:49 ` [PATCH v2] Port hierarchical_{memory,swap}_limit cgroup1->cgroup2 Jan Kratochvil (Azul)
@ 2024-02-11 18:01 ` Waiman Long
0 siblings, 0 replies; 4+ messages in thread
From: Waiman Long @ 2024-02-11 18:01 UTC (permalink / raw)
To: Jan Kratochvil (Azul); +Cc: cgroups
On 2/11/24 07:49, Jan Kratochvil (Azul) wrote:
> Hello Waiman,
>
> On Fri, 09 Feb 2024 23:51:54 +0800, Waiman Long wrote:
>> I don't think we use mi->memsw in cgroup v2, only memory and swap should
>> be used.
> you are right, thanks:
>
> struct mem_cgroup {
> ...
> union {
> struct page_counter swap; /* v2 only */
> struct page_counter memsw; /* v1 only */
> };
>
>
> Jan Kratochvil
>
>
> Signed-off-by: Jan Kratochvil (Azul) <jkratochvil@azul.com>
Please send a proper v2 patch to the full list for review.
Cheers,
Longman
>
> mm/memcontrol.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 46d8d0211..2631dd810 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -1636,6 +1636,8 @@ static inline unsigned long memcg_page_state_local_output(
> static void memcg_stat_format(struct mem_cgroup *memcg, struct seq_buf *s)
> {
> int i;
> + unsigned long memory, swap;
> + struct mem_cgroup *mi;
>
> /*
> * Provide statistics on the state of the memory subsystem as
> @@ -1682,6 +1684,17 @@ static void memcg_stat_format(struct mem_cgroup *memcg, struct seq_buf *s)
> memcg_events(memcg, memcg_vm_event_stat[i]));
> }
>
> + /* Hierarchical information */
> + memory = swap = PAGE_COUNTER_MAX;
> + for (mi = memcg; mi; mi = parent_mem_cgroup(mi)) {
> + memory = min(memory, READ_ONCE(mi->memory.max));
> + swap = min(swap, READ_ONCE(mi->swap.max));
> + }
> + seq_buf_printf(s, "hierarchical_memory_limit %llu\n",
> + (u64)memory * PAGE_SIZE);
> + seq_buf_printf(s, "hierarchical_swap_limit %llu\n",
> + (u64)swap * PAGE_SIZE);
> +
> /* The above should easily fit into one page */
> WARN_ON_ONCE(seq_buf_has_overflowed(s));
> }
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-02-11 18:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-09 14:48 [PATCH] Port hierarchical_mem{ory,sw}_limit cgroup1->cgroup2 Jan Kratochvil (Azul)
2024-02-09 15:51 ` Waiman Long
2024-02-11 12:49 ` [PATCH v2] Port hierarchical_{memory,swap}_limit cgroup1->cgroup2 Jan Kratochvil (Azul)
2024-02-11 18:01 ` Waiman Long
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox