I believe I have the answer... The problem is that the parent httpd swaps, and any new children it creates load the portion of memory that was swaped from swap, which does not make it copy-on-write. The really annoying thing - when memory gets tight, the parent is the most likely httpd process to swap, because its memory is 99% idle. This issue aflicts Linux, Solaris, and a bunch of other OSes.
The solution is mlockall(2), available under Linux, Solaris, and other POSIX.1b compliant OSes. I've not experimented with calling it from perl, and I've not looked at Apache enough to consider patching it there, but this system call, if your process is run as root, will prevent any and all swapping of your process's memory. If your process is not run as root, it returns an error. The reason turning off swap works is because it forces the memory from the parent process that was swapped out to be swapped back in. It will not fix those processes that have been sired after the shared memory loss, as of Linux 2.2.15 and Solaris 2.6. (I have not checked since then for behavior in this regard, nor have I checked on other OSes.) Ed On Thu, 14 Mar 2002, Bill Marrs wrote: > >It's copy-on-write. The swap is a write-to-disk. > >There's no such thing as sharing memory between one process on disk(/swap) > >and another in memory. > > agreed. What's interesting is that if I turn swap off and back on again, > the sharing is restored! So, now I'm tempted to run a crontab every 30 > minutes that turns the swap off and on again, just to keep the httpds > shared. No Apache restart required! > > Seems like a crazy thing to do, though. > > >You'll also want to look into tuning your paging algorithm. > > Yeah... I'll look into it. If I had a way to tell the kernel to never swap > out any httpd process, that would be a great solution. The kernel is > making a bad choice here. By swapping, it triggers more memory usage > because sharing removed on the httpd process group (thus multiplied)... > > I've got MaxClients down to 8 now and it's still happening. I think my > best course of action may be a crontab swap flusher. > > -bill