您只需要将交换值除以共享此虚拟内存区域的进程数。
其实我没有找到如何获得数量的进程共享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"