Date: Thu, 14 Feb 2019 12:30:30 +0100 From: Stefan Esser <se@freebsd.org> To: Andriy Gapon <avg@FreeBSD.org>, freebsd-stable@freebsd.org Cc: Eugene Grosbein <eugen@grosbein.net>, Garrett Wollman <wollman@bimajority.org> Subject: Re: 11.2-STABLE kernel wired memory leak Message-ID: <cf20a272-4ff0-b9cb-3a49-c2442282c1e5@freebsd.org> In-Reply-To: <0710bc0a-7691-b29f-3331-da94412ab737@FreeBSD.org> References: <d8c7abc0-3ba1-40e4-22b1-1b30d28ced14@grosbein.net> <201902121757.x1CHve0h056876@hergotha.csail.mit.edu> <7125e053-5adf-929a-bde6-a64fceae2aaa@grosbein.net> <8a9361fd-4701-4e33-33f0-e4800af7637c@grosbein.net> <0710bc0a-7691-b29f-3331-da94412ab737@FreeBSD.org>
index | next in thread | previous in thread | raw e-mail
Am 13.02.19 um 10:59 schrieb Andriy Gapon:
> On 12/02/2019 20:17, Eugene Grosbein wrote:
>> 13.02.2019 1:14, Eugene Grosbein wrote:
>>
>>> Use following command to see how much memory is wasted in your case:
>>>
>>> vmstat -z | awk -F, '{printf "%10s %s\n", $2*$5/1024/1024, $1}' | sort -k1,1 -rn | head
>>
>> Oops, small correction:
>>
>> vmstat -z | sed 's/:/,/' | awk -F, '{printf "%10s %s\n", $2*$5/1024/1024, $1}' | sort -k1,1 -rn | head
>
> I have a much uglier but somewhat more informative "one-liner" for
> post-processing vmstat -z output:
>
> vmstat -z | tail +3 | awk -F '[:,] *' 'BEGIN { total=0; cache=0; used=0 } {u =
> $2 * $4; c = $2 * $5; t = u + c; cache += c; used += u; total += t; name=$1;
> gsub(" ", "_", name); print t, name, u, c} END { print total, "TOTAL", used,
> cache } ' | sort -n | perl -a -p -e 'while (($j, $_) = each(@F)) { 1 while
> s/^(-?\d+)(\d{3})/$1,$2/; print $_, " "} print "\n"' | column -t
>
> This would be much nicer as a small python script.
Or, since you are already using perl:
----------------------------------------------------------------
#!/usr/local/bin/perl5
open STDIN, "vmstat -z |" or die "Failed to run vmstat program";
open STDOUT, "| sort -n @ARGV -k 2" or die "Failed to pipe through sort";
$fmt="%-30s %8.3f %8.3f %8.3f %6.1f%%\n";
while (<STDIN>) {
($n, $s, undef, $u, $c) = split /[:,] */;
next unless $s > 0;
$n =~ s/ /_/g;
$s /= 1024 * 1024;
$u *= $s;
$c *= $s;
$t = $u + $c;
next unless $t > 0;
printf $fmt, $n, $t, $u, $c, 100 * $c / $t;
$cache += $c;
$used += $u;
$total += $t;
}
printf $fmt, TOTAL, $total, $used, $cache, 100 * $cached / $total;
close STDOUT;
----------------------------------------------------------------
This script takes additional parameters, e.g. "-r" to reverse the
sort or "-r -k5" to print those entries with the highest percentage
of unused memory at the top.
(I chose to suppress lines with a current "total" of 0 - you may
want to remove the "next" command above the printf in the loop to
see them, but they did not seem useful to me.)
> Or, even, we could add a sort option for vmstat -z / -m.
Yes, and the hardest part might be to select option characters
for the various useful report formats. ;-)
Regards, STefan
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?cf20a272-4ff0-b9cb-3a49-c2442282c1e5>
