From: Kuniyuki Iwashima <kuniyu@google.com>
To: Daniel Sedlak <daniel.sedlak@cdn77.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Jonathan Corbet <corbet@lwn.net>,
Neal Cardwell <ncardwell@google.com>,
David Ahern <dsahern@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Shakeel Butt <shakeel.butt@linux.dev>,
Yosry Ahmed <yosry.ahmed@linux.dev>,
linux-mm@kvack.org, netdev@vger.kernel.org,
Matyas Hurtik <matyas.hurtik@cdn77.com>,
Daniel Sedlak <danie.sedlak@cdn77.com>
Subject: Re: [PATCH v2 net-next 2/2] mm/vmpressure: add tracepoint for socket pressure detection
Date: Tue, 15 Jul 2025 10:17:11 -0700 [thread overview]
Message-ID: <CAAVpQUDj23KHKpMFA4J7gV=H_BnvG4z0aVxf6-B04KsYtBL=1w@mail.gmail.com> (raw)
In-Reply-To: <8a7cea99-0ab5-4dba-bc89-62d4819531eb@cdn77.com>
On Tue, Jul 15, 2025 at 12:01 AM Daniel Sedlak <daniel.sedlak@cdn77.com> wrote:
>
> Hi Kuniyuki,
>
> On 7/14/25 8:02 PM, Kuniyuki Iwashima wrote:
> >> +TRACE_EVENT(memcg_socket_under_pressure,
> >> +
> >> + TP_PROTO(const struct mem_cgroup *memcg, unsigned long scanned,
> >> + unsigned long reclaimed),
> >> +
> >> + TP_ARGS(memcg, scanned, reclaimed),
> >> +
> >> + TP_STRUCT__entry(
> >> + __field(u64, id)
> >> + __field(unsigned long, scanned)
> >> + __field(unsigned long, reclaimed)
> >> + ),
> >> +
> >> + TP_fast_assign(
> >> + __entry->id = cgroup_id(memcg->css.cgroup);
> >> + __entry->scanned = scanned;
> >> + __entry->reclaimed = reclaimed;
> >> + ),
> >> +
> >> + TP_printk("memcg_id=%llu scanned=%lu reclaimed=%lu",
> >> + __entry->id,
> >
> > Maybe a noob question: How can we translate the memcg ID
> > to the /sys/fs/cgroup/... path ?
>
> IMO this should be really named `cgroup_id` instead of `memcg_id`, but
> we kept the latter to keep consistency with the rest of the file.
>
> To find cgroup path you can use:
> - find /sys/fs/cgroup/ -inum `memcg_id`, and it will print "path" to the
> affected cgroup.
> - or you can use bpftrace tracepoint hooks and there is a helper
> function [1].
Thanks, this is good to know and worth in the commit message.
>
> Or we can put the cgroup_path to the tracepoint instead of that ID, but
> I feel it can be too much overhead, the paths can be pretty long.
Agree, the ID is good enough given we can find the cgroup by oneliner.
>
> Link: https://bpftrace.org/docs/latest#functions-cgroup_path [1]
> > It would be nice to place this patch first and the description of
> > patch 2 has how to use the new stat with this tracepoint.
>
> Sure, can do that. However, I am unsure how a good idea is to
> cross-reference commits, since each may go through a different tree
> because each commit is for a different subsystem. They would have to go
> through one tree, right?
Right. Probably you can just assume both patches will be merged
and post the tracepoint patch to mm ML first and then add its
lore.kernel.org link and howto in the stat patch and post it to netdev ML.
>
>
> >> + __entry->scanned,
> >> + __entry->reclaimed)
> >> +);
> >> +
> >> #endif /* _TRACE_MEMCG_H */
> >>
> >> /* This part must be outside protection */
> >> diff --git a/mm/vmpressure.c b/mm/vmpressure.c
> >> index bd5183dfd879..aa9583066731 100644
> >> --- a/mm/vmpressure.c
> >> +++ b/mm/vmpressure.c
> >> @@ -21,6 +21,8 @@
> >> #include <linux/printk.h>
> >> #include <linux/vmpressure.h>
> >>
> >> +#include <trace/events/memcg.h>
> >> +
> >> /*
> >> * The window size (vmpressure_win) is the number of scanned pages before
> >> * we try to analyze scanned/reclaimed ratio. So the window is used as a
> >> @@ -317,6 +319,7 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree,
> >> * pressure events can occur.
> >> */
> >> WRITE_ONCE(memcg->socket_pressure, jiffies + HZ);
> >> + trace_memcg_socket_under_pressure(memcg, scanned, reclaimed);
> >
> > This is triggered only when we enter the memory pressure state
> > and not when we leave the state, right ? Is it possible to issue
> > such an event ?
>
> AFAIK, the currently used API in the vmpressure function does not have
> anything like enter or leave the socket memory pressure state. It only
> periodically re-arms the socket pressure for a specific duration. So the
> current tracepoint is called when the socket pressure is re-armed.
>
> I am not sure how feasible it is to rewrite it so we have enter and
> leave logic. I am not that familiar with those code paths.
Unlike tcp mem pressure, the memcg pressure only persists for one
second, so it won't make sense to add the "leave" event, and I guess
the assumption would be that socket_pressure will keep updated under
memory pressure.
next prev parent reply other threads:[~2025-07-15 17:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-14 14:36 [PATCH v2 net-next 0/2] account for TCP memory pressure signaled by cgroup Daniel Sedlak
2025-07-14 14:36 ` [PATCH v2 net-next 1/2] tcp: account for " Daniel Sedlak
2025-07-16 16:49 ` Shakeel Butt
2025-07-16 18:07 ` Kuniyuki Iwashima
2025-07-16 18:37 ` Shakeel Butt
2025-07-17 15:31 ` Daniel Sedlak
2025-07-17 17:26 ` Kuniyuki Iwashima
2025-07-14 14:36 ` [PATCH v2 net-next 2/2] mm/vmpressure: add tracepoint for socket pressure detection Daniel Sedlak
2025-07-14 18:02 ` Kuniyuki Iwashima
2025-07-15 7:01 ` Daniel Sedlak
2025-07-15 17:17 ` Kuniyuki Iwashima [this message]
2025-07-15 17:46 ` Kuniyuki Iwashima
2025-07-16 8:47 ` Daniel Sedlak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAAVpQUDj23KHKpMFA4J7gV=H_BnvG4z0aVxf6-B04KsYtBL=1w@mail.gmail.com' \
--to=kuniyu@google.com \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=danie.sedlak@cdn77.com \
--cc=daniel.sedlak@cdn77.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-mm@kvack.org \
--cc=matyas.hurtik@cdn77.com \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shakeel.butt@linux.dev \
--cc=yosry.ahmed@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).