Mailing List Archive

Fwd: [rt.cpan.org #73752] Wrong unshared memory values when using /proc/self/statm
I received an RT notice today for a patch to Apache::SizeLimit.
Inlining the patch here for comments/review.

--- a/lib/Apache/SizeLimit/Core.pm 2011-12-22 03:46:44.000000000 +0000
+++ b/lib/Apache/SizeLimit/Core.pm 2014-03-11 16:52:11.795119567 +0000
@@ -184,10 +184,10 @@
sub _linux_size_check {
my $class = shift;

- my ($size, $share) = (0, 0);
+ my ($size, $data) = (0, 0);

if (open my $fh, '<', '/proc/self/statm') {
- ($size, $share) = (split /\s/, scalar <$fh>)[0,2];
+ ($size, $data) = (split /\s/, scalar <$fh>)[0,5];
close $fh;
}
else {
@@ -195,7 +195,9 @@
}

# linux on intel x86 has 4KB page size...
- return ($size * 4, $share * 4);
+ $size <<= 2;
+ $data <<= 2;
+ return ($size, $size - $data, $data);
}

sub _solaris_2_6_size_check {



---------- Forwarded message ----------
From: Zefram via RT <bug-Apache-SizeLimit@rt.cpan.org>
Date: Tue, Mar 11, 2014 at 9:57 AM
Subject: Re: [rt.cpan.org #73752] Wrong unshared memory values when
using /proc/self/statm
To:


Queue: Apache-SizeLimit
Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=73752 >

The problem is that the "share" value in /proc/self/statm only counts
*resident* shared pages. The solution is to instead read the "data"
value, which counts all unshared pages (whether resident or not).
That gives the correct unshared count directly, and can be subtracted from
"size" to get the correct shared count. Attached patch fixes.

-zefram

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org