On Monday 01 May 2006 21:00, Perrin Harkins wrote:
> No.  The current best bet is Linux::Smaps, which Apache2::SizeLimit now
> uses.

For 2.4 kernel series the figures got from /proc/PID/statm are as valid as the 
figures from Linux::Smaps for kernels 2.6.14 and higher. For 2.6.0 up to 
2.6.13 there is no way to count COW (shared by copy-on-write) pages. Since 
COW is the main way of sharing memory in a mod_perl environment figures that 
don't take these pages into account are useless.

But even with Linux::Smaps a problem remains when swapping/paging is allowed. 
When a page is erased from memory and lives only in swap space there is no 
other way on Linux to determine to how many processes it belongs than to page 
it in. And this is certainly to much overhead only for that.

To overcome this problem either disable all swap space or put these lines into 
your startup.pl:

------------ %< -------------------------------
require 'syscall.ph';
require 'sys/mmap.ph';

0==syscall &SYS_mlockall, &MCL_CURRENT | &MCL_FUTURE
  or die "ERROR: mlockall failed: $!\n";
------------ %< -------------------------------

or a little shorter:

------------ %< -------------------------------
0==syscall 152, 3 or die "ERROR: mlockall failed: $!\n";
------------ %< -------------------------------

This locks the parent apache completely into memory making it unpageable. The 
worker processes remain pageable. Now you waste a few megabytes of main 
memory but since the parent process is completely in core and, hence, all 
shared portions are so as well the private memory for each child is correctly 
determined by counting private pages plus swapped pages. This can be done by 
reading /proc/PID/smaps for >=2.6.14 or by reading /proc/PID/statm for 2.4.x.

Torsten

Attachment: pgpTbPDnf9hEz.pgp
Description: PGP signature

Reply via email to