]> git.proxmox.com Git - mirror_iproute2.git/commit
ss: Render buffer to output every time a number of chunks are allocated
authorStefano Brivio <sbrivio@redhat.com>
Thu, 14 Feb 2019 00:58:32 +0000 (01:58 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 21 Feb 2019 22:45:45 +0000 (14:45 -0800)
commitaa5bd6a252ce46ee6757458f08a071aabdae9264
tree0efae3cf050b1f11430c11e21bea8cb6ad740fe1
parent9700927a008a803ac119bdf816bdc1baa69d705c
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: 691bd854bf4a ("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>
misc/ss.c