Hi,

as I have learned from the "Debugging memory allocation" thread 
Apache::SizeLimit can be used to kill a child if it's unshared part grows to 
big. To measure this unshared part on linux /proc/PID/statm is used. I was in 
doubt that the simple difference between the total number of pages and the 
shared pages really reflect the unshared part. So, I tried out some things:

First, in httpd.conf I allocate a noticeable amount of memory:

<Perl>
$My::Klaus="x"x10000000;
</Perl>

This memory is shared among all children due to linux' copy on write.

Now /proc/PID/statm for the master and a child say:

master: 5254 4190 2089 71 0 3094 0
child:  5272 4208 2107 71 0 3094 0

When I write to $My::Klaus from within a child I expect the total size to 
remain the same and the shared portion to drop considerably (actually ~2500 
pages which is not possible since it is only 2107).

My first try was to assign simply a new string: $My::Klaus="y"x10000000;
Now /proc/PID/statm shows for this child:

7749 6718 2107 71 0 5571 0

Not what I have expected. The shared portion remains but the total size grows 
by 2477 pages. Well, perl allocates simply a new string. Hence the total 
process size grows.

My second try was to modify the string in place: $My::Klaus=~tr/x/y/;
Now /proc/PID/statm shows:

5307 4276 2107 71 0 3129 0

Nothing has changed much. Particularly the number of shared pages remains 
exactly the same.

To check that $My::Klaus is really copied on write I have checked the total 
used and free space shown in /proc/meminfo. The figures show exactly what is 
to be expected. The used memory grows by the amount needed to hold a second 
copy of $My::Klaus.

Hence, killing an apache child when the unshared part grows beyond a certain 
limit do on linux NOT account the copy on write pages that get unshared.

As I have heard libgtop also only provides the information from /proc. That 
means do also not account the copy on write effect. Is that information 
right?

Is there a way on linux to get the amount of pages shared among processes by 
copy on write?

Torsten

Attachment: pgp3GgME6HBU1.pgp
Description: PGP signature

Reply via email to