您只需将Swap
值除以共享此虚拟内存区域的进程数即可。
实际上,我没有找到如何获取共享VMA的进程数。然而,有时可以通过除以 来计算RSS
它PSS
。当然,它只有在以下情况下才有效PSS != 0
。
最后,您可以使用此 perl 代码(传递smap
文件作为参数):
#!/usr/bin/perl -w
my ($rss, $pss);
my $total = 0;
while(<>) {
$rss = $1 if /Rss: *([0-9]*) kB/;
$pss = $1 if /Pss: *([0-9]*) kB/;
if (/Swap: *([0-9]*) kB/) {
my $swap = $1;
if ($swap != 0) {
if ($pss == 0) {
print "Cannot get number of process using this VMA\n";
} else {
my $swap = $swap * $rss / $pss;
print "P-swap: $swap\n";
}
$total += $swap;
}
}
}
print "Total P-Swap: $total kB\n"
Run Code Online (Sandbox Code Playgroud)