perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Torsten Foertsch <>
Subject [PATCH] Apache2::SizeLimit on Linux
Date Sun, 07 Aug 2005 18:37:34 GMT

the attached patch allows Apache2::SizeLimit to use the new /proc/PID/smaps 
instead of /proc/PID/statm. This takes into account copy-on-write pages when 
counting shared memory.

The patch looks if /proc/PID/smaps exists and if Linux::Smaps is installed. If 
not it uses the old /proc/PID/statm. Hence, it is compatible with old 

/proc/PID/smaps exists by now in the mm-series of the linux kernel. I hope the 
patch will take its way into the vanilla kernel in the not so distant future.

The following handler shows the effect:

require Apache2::SizeLimit;
package X;
use strict;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Const -compile=>qw(OK);

my $x="a"x(1024*1024);

sub handler {
  my $r=shift;
  my $args=$r->args;
  my ($size, $shared)=$Apache2::SizeLimit::HOW_BIG_IS_IT->();
  $x=~tr/a/b/ if( $args );
  my ($size2, $shared2)=$Apache2::SizeLimit::HOW_BIG_IS_IT->();
  $r->print("1: size=$size shared=$shared\n");
  $r->print("2: size=$size2 shared=$shared2\n");
  return Apache2::Const::OK;

<Location /X>
SetHandler modperl
PerlResponseHandler X

The parent apache allocates a megabyte for the string in $x. The tr-command 
then overwrites all "a" with "b" if the handler is called with an argument.
This write is done in place, thus, the process size doesn't change. Only $x is 
not shared anymore by means of COW between the parent and the child.

When Smaps are available curl shows:

  r2@s93:~/work/mp2> curl http://localhost:8181/X?1
  1: size=13452 shared=7456
  2: size=13452 shared=6432

The shared memory has lost 1024 kB.

Without Smaps it says:

  r2@s93:~/work/mp2> curl http://localhost:8181/X?1
  1: size=13052 shared=3628
  2: size=13052 shared=3636

One can see the kernel lies about the shared memory. It simply doesn't count 
COW pages as shared.

Both experiments are done with a Suse9.3, apache 2.0.54, mod_perl 2.0.1 and 
Linux::Smaps 0.01.

The first one uses linux 2.6.13-rc4-mm1 (with a little patch that will go into 
the next mm-version, see, the 
second with Suses default kernel (


View raw message