* [PATCH] tcp: Add memory pressure flag to sockstat
@ 2023-07-14 6:39 Jamie Bainbridge
2023-07-14 22:45 ` Jay Vosburgh
0 siblings, 1 reply; 3+ messages in thread
From: Jamie Bainbridge @ 2023-07-14 6:39 UTC (permalink / raw)
To: David S. Miller, David Ahern, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: Jamie Bainbridge, netdev, linux-kernel
When tuning a system it can be helpful to know whether the protocol is
in memory pressure state or not. This can be determined by corresponding
the number of pages in "net.ipv4.tcp_mem" with the current allocation,
but a global variable already tracks this as the source of truth.
Expose that variable in sockstat where other protocol memory usage is
already reported.
Add "pressure" which is 0 in normal state and 1 under pressure:
# grep TCP /proc/net/sockstat
TCP: inuse 5 orphan 0 tw 0 alloc 7 mem 1 pressure 0
# grep TCP /proc/net/sockstat
TCP: inuse 5 orphan 0 tw 0 alloc 7 mem 1 pressure 1
Tested by writing a large value to global variable tcp_memory_pressure
(it usually stores jiffies when memory pressure was entered) and not
just by code review or editing example output.
Signed-off-by: Jamie Bainbridge <jamie.bainbridge@gmail.com>
---
net/ipv4/proc.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
index eaf1d3113b62f7dc93fdc7b7c4041140ac63bf69..f4c5ced2de49d5c6d7f5d7ccdaa76c89dcf8c932 100644
--- a/net/ipv4/proc.c
+++ b/net/ipv4/proc.c
@@ -51,16 +51,17 @@
static int sockstat_seq_show(struct seq_file *seq, void *v)
{
struct net *net = seq->private;
- int orphans, sockets;
+ int orphans, sockets, tcp_pressure;
orphans = tcp_orphan_count_sum();
sockets = proto_sockets_allocated_sum_positive(&tcp_prot);
+ tcp_pressure = READ_ONCE(tcp_memory_pressure) ? 1 : 0;
socket_seq_show(seq);
- seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %ld\n",
+ seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %ld pressure %d\n",
sock_prot_inuse_get(net, &tcp_prot), orphans,
refcount_read(&net->ipv4.tcp_death_row.tw_refcount) - 1,
- sockets, proto_memory_allocated(&tcp_prot));
+ sockets, proto_memory_allocated(&tcp_prot), tcp_pressure);
seq_printf(seq, "UDP: inuse %d mem %ld\n",
sock_prot_inuse_get(net, &udp_prot),
proto_memory_allocated(&udp_prot));
--
2.41.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] tcp: Add memory pressure flag to sockstat
2023-07-14 6:39 [PATCH] tcp: Add memory pressure flag to sockstat Jamie Bainbridge
@ 2023-07-14 22:45 ` Jay Vosburgh
2023-07-16 23:23 ` Jamie Bainbridge
0 siblings, 1 reply; 3+ messages in thread
From: Jay Vosburgh @ 2023-07-14 22:45 UTC (permalink / raw)
To: Jamie Bainbridge
Cc: David S. Miller, David Ahern, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-kernel
Jamie Bainbridge <jamie.bainbridge@gmail.com> wrote:
>When tuning a system it can be helpful to know whether the protocol is
>in memory pressure state or not. This can be determined by corresponding
>the number of pages in "net.ipv4.tcp_mem" with the current allocation,
>but a global variable already tracks this as the source of truth.
>
>Expose that variable in sockstat where other protocol memory usage is
>already reported.
>
>Add "pressure" which is 0 in normal state and 1 under pressure:
>
> # grep TCP /proc/net/sockstat
> TCP: inuse 5 orphan 0 tw 0 alloc 7 mem 1 pressure 0
>
> # grep TCP /proc/net/sockstat
> TCP: inuse 5 orphan 0 tw 0 alloc 7 mem 1 pressure 1
Isn't this already available in /proc/net/protocols?
protocol size sockets memory press maxhdr slab module cl co di ac io in de sh ss gs se re sp bi br ha uh gp em
[...]
UDP 1472 7 6 NI 0 yes kernel y y y n y y y n y y y y y n n y y y n
TCP 2512 5 1 no 320 yes kernel y y y y y y y y y y y y y n y y y y y
-J
>Tested by writing a large value to global variable tcp_memory_pressure
>(it usually stores jiffies when memory pressure was entered) and not
>just by code review or editing example output.
>
>Signed-off-by: Jamie Bainbridge <jamie.bainbridge@gmail.com>
>---
> net/ipv4/proc.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
>diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
>index eaf1d3113b62f7dc93fdc7b7c4041140ac63bf69..f4c5ced2de49d5c6d7f5d7ccdaa76c89dcf8c932 100644
>--- a/net/ipv4/proc.c
>+++ b/net/ipv4/proc.c
>@@ -51,16 +51,17 @@
> static int sockstat_seq_show(struct seq_file *seq, void *v)
> {
> struct net *net = seq->private;
>- int orphans, sockets;
>+ int orphans, sockets, tcp_pressure;
>
> orphans = tcp_orphan_count_sum();
> sockets = proto_sockets_allocated_sum_positive(&tcp_prot);
>+ tcp_pressure = READ_ONCE(tcp_memory_pressure) ? 1 : 0;
>
> socket_seq_show(seq);
>- seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %ld\n",
>+ seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %ld pressure %d\n",
> sock_prot_inuse_get(net, &tcp_prot), orphans,
> refcount_read(&net->ipv4.tcp_death_row.tw_refcount) - 1,
>- sockets, proto_memory_allocated(&tcp_prot));
>+ sockets, proto_memory_allocated(&tcp_prot), tcp_pressure);
> seq_printf(seq, "UDP: inuse %d mem %ld\n",
> sock_prot_inuse_get(net, &udp_prot),
> proto_memory_allocated(&udp_prot));
>--
>2.41.0
>
>
---
-Jay Vosburgh, jay.vosburgh@canonical.com
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] tcp: Add memory pressure flag to sockstat
2023-07-14 22:45 ` Jay Vosburgh
@ 2023-07-16 23:23 ` Jamie Bainbridge
0 siblings, 0 replies; 3+ messages in thread
From: Jamie Bainbridge @ 2023-07-16 23:23 UTC (permalink / raw)
To: Jay Vosburgh
Cc: David S. Miller, David Ahern, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-kernel
On Sat, 15 Jul 2023 at 08:45, Jay Vosburgh <jay.vosburgh@canonical.com> wrote:
>
> Jamie Bainbridge <jamie.bainbridge@gmail.com> wrote:
>
> >When tuning a system it can be helpful to know whether the protocol is
> >in memory pressure state or not. This can be determined by corresponding
> >the number of pages in "net.ipv4.tcp_mem" with the current allocation,
> >but a global variable already tracks this as the source of truth.
> >
> >Expose that variable in sockstat where other protocol memory usage is
> >already reported.
> >
> >Add "pressure" which is 0 in normal state and 1 under pressure:
> >
> > # grep TCP /proc/net/sockstat
> > TCP: inuse 5 orphan 0 tw 0 alloc 7 mem 1 pressure 0
> >
> > # grep TCP /proc/net/sockstat
> > TCP: inuse 5 orphan 0 tw 0 alloc 7 mem 1 pressure 1
>
> Isn't this already available in /proc/net/protocols?
>
> protocol size sockets memory press maxhdr slab module cl co di ac io in de sh ss gs se re sp bi br ha uh gp em
> [...]
> UDP 1472 7 6 NI 0 yes kernel y y y n y y y n y y y y y n n y y y n
> TCP 2512 5 1 no 320 yes kernel y y y y y y y y y y y y y n y y y y y
I was not aware of this, I was only looking for symbol usage of TCP
and not the generic.
This is perfect, thank you very much!
Jamie
> >Tested by writing a large value to global variable tcp_memory_pressure
> >(it usually stores jiffies when memory pressure was entered) and not
> >just by code review or editing example output.
> >
> >Signed-off-by: Jamie Bainbridge <jamie.bainbridge@gmail.com>
> >---
> > net/ipv4/proc.c | 7 ++++---
> > 1 file changed, 4 insertions(+), 3 deletions(-)
> >
> >diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
> >index eaf1d3113b62f7dc93fdc7b7c4041140ac63bf69..f4c5ced2de49d5c6d7f5d7ccdaa76c89dcf8c932 100644
> >--- a/net/ipv4/proc.c
> >+++ b/net/ipv4/proc.c
> >@@ -51,16 +51,17 @@
> > static int sockstat_seq_show(struct seq_file *seq, void *v)
> > {
> > struct net *net = seq->private;
> >- int orphans, sockets;
> >+ int orphans, sockets, tcp_pressure;
> >
> > orphans = tcp_orphan_count_sum();
> > sockets = proto_sockets_allocated_sum_positive(&tcp_prot);
> >+ tcp_pressure = READ_ONCE(tcp_memory_pressure) ? 1 : 0;
> >
> > socket_seq_show(seq);
> >- seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %ld\n",
> >+ seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %ld pressure %d\n",
> > sock_prot_inuse_get(net, &tcp_prot), orphans,
> > refcount_read(&net->ipv4.tcp_death_row.tw_refcount) - 1,
> >- sockets, proto_memory_allocated(&tcp_prot));
> >+ sockets, proto_memory_allocated(&tcp_prot), tcp_pressure);
> > seq_printf(seq, "UDP: inuse %d mem %ld\n",
> > sock_prot_inuse_get(net, &udp_prot),
> > proto_memory_allocated(&udp_prot));
> >--
> >2.41.0
> >
> >
>
> ---
> -Jay Vosburgh, jay.vosburgh@canonical.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-16 23:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-14 6:39 [PATCH] tcp: Add memory pressure flag to sockstat Jamie Bainbridge
2023-07-14 22:45 ` Jay Vosburgh
2023-07-16 23:23 ` Jamie Bainbridge
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).