Is there a way to find out the total memory used by UDP sockets on a system
By monitoring /proc/net/sockstat or /proc/net/protocols, I am able to find out the to开发者_如何学Ctal amount of memory used by TCP sockets in the system in realtime:
[gpadmin@sdw4 ~]$ cat /proc/net/sockstat
sockets: used 240
TCP: inuse 55 orphan 0 tw 0 alloc 69 mem 2171
UDP: inuse 22 mem 0
RAW: inuse 0
FRAG: inuse 0 memory 0
[gpadmin@sdw4 ~]$ cat /proc/net/sockstat
sockets: used 240
TCP: inuse 55 orphan 0 tw 0 alloc 69 mem 761
UDP: inuse 22 mem 0
RAW: inuse 0
FRAG: inuse 0 memory 0
The above metrics show me the memory used by TCP sockets but the UDP socket metrics are marked as 0. Is there a way to find out this information? Any /proc/net files capture this info?
Thanks in advance.
Could it be that you have a low traffic?
This is on my machine, receiving 400 UDP packets/sec on 3 ports (there is a 4th UDP stream but I don't use that).
# cat /proc/net/sockstat
sockets: used 32
TCP: inuse 6 orphan 0 tw 0 alloc 6 mem 1
UDP: inuse 4 mem 3
The same machine, serving those UDP streams to loads of clients on HTTP:
#cat /proc/net/sockstat
sockets: used 7232
TCP: inuse 7206 orphan 0 tw 0 alloc 7206 mem 405397
UDP: inuse 4 mem 30
The HTTP server is single threaded so I had to set the receive buffer for the UDP sockets quite high to not lose any packets. I've run the test for a while but I've never seen UDP mem go above 50.
Sorry if I'm completely off base here but I think you need to turn on udp accounting via /proc/sys/net/ipv4/udp_mem
first before it will collect memory statistics.
精彩评论