mirror_iproute2/misc
Stefano Brivio aa5bd6a252 ss: Render buffer to output every time a number of chunks are allocated
Eric reported that, with 10 million sockets, ss -emoi (about 1000 bytes
output per socket) can easily lead to OOM (buffer would grow to 10GB of
memory).

Limit the maximum size of the buffer to five chunks, 1M each. Render and
flush buffers whenever we reach that.

This might make the resulting blocks slightly unaligned between them, with
occasional loss of readability on lines occurring every 5k to 50k sockets
approximately. Something like (from ss -tu):

[...]
CLOSE-WAIT   32       0           192.168.1.50:35232           10.0.0.1:https
ESTAB        0        0           192.168.1.50:53820           10.0.0.1:https
ESTAB       0        0           192.168.1.50:46924            10.0.0.1:https
CLOSE-WAIT  32       0           192.168.1.50:35228            10.0.0.1:https
[...]

However, I don't actually expect any human user to scroll through that
amount of sockets, so readability should be preserved when it matters.

The bulk of the diffstat comes from moving field_next() around, as we now
call render() from it. Functionally, this is implemented by six lines of
code, most of them in field_next().

Reported-by: Eric Dumazet <eric.dumazet@gmail.com>
Fixes: 691bd854bf ("ss: Buffer raw fields first, then render them as a table")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2019-02-21 14:45:45 -08:00
..
.gitignore Add ignore files to make using git easier 2006-08-08 12:04:38 -07:00
arpd.c libnetlink: Add filter function to rtnl_neighdump_req 2019-01-04 12:17:11 -08:00
ifstat.c Tree wide: Drop sockaddr_nl arg 2018-10-22 09:43:48 -07:00
lnstat_util.c lnstat_util: Make sure buffer is NUL-terminated 2017-09-01 12:10:54 -07:00
lnstat.c Replace malloc && memset by calloc 2016-07-20 12:05:24 -07:00
lnstat.h SPDX license identifiers 2017-11-24 12:21:35 -08:00
Makefile Pass CPPFLAGS to the compiler 2018-11-09 08:07:18 -08:00
nstat.c nstat: fix load_ugly_table() limits 2018-12-31 21:45:53 -08:00
rtacct.c misc: fix style issues 2016-03-21 11:56:36 -07:00
ss.c ss: Render buffer to output every time a number of chunks are allocated 2019-02-21 14:45:45 -08:00
ssfilter.h SPDX license identifiers 2017-11-24 12:21:35 -08:00
ssfilter.y ssfilter: Fix for inverted last expression 2018-12-03 14:33:19 -08:00