[OT]RE: loss of shared memory in parent httpd
Call me an idiot. How is it even remotely possible that turning off swap restores memory shared between processes? Is the Linux kernel going from process to process comparing pages of memory as they re-enter RAM? "Oh, those two look identical, they'll get shared?" -Incredulous -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Thursday, March 14, 2002 8:24 AM To: Bill Marrs Cc: [EMAIL PROTECTED] Subject: Re: loss of shared memory in parent httpd > On Thu, 14 Mar 2002 07:25:27 -0500, Bill Marrs <[EMAIL PROTECTED]> said: >> 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! Funny, I'm doing this for ages and I never really knew why, you just found the reason, Thank You! My concerns were similar to yours but on a smaller scale, so I did not worry that much, but I'm running a swapflusher regularly. Make sure you have a recent kernel, because all old kernels up to 2.4.12 or so were extremely unresponsive during swapoff. With current kernels, this is much, much faster and nothing to worry about. Let me show you the script I use for the job. No rocket science, but it's easy to do it wrong. Be careful to maintain equality of priority among disks: use strict; $|=1; print "Running swapon -a, just in case...\n"; system "swapon -a"; print "Running swapon -s\n"; open S, "swapon -s |"; my(%prio); PARTITION: while () { print; next if /^Filename/; chop; my($f,$t,$s,$used,$p) = split; my $disk = $f; $disk =~ s/\d+$//; $prio{$disk} ||= 5; $prio{$disk}--; if ($used == 0) { print "Unused, skipping\n"; next PARTITION; } print "Turning off\n"; system "swapoff $f"; print "Turning on with priority $prio{$disk}\n"; system "swapon -p $prio{$disk} $f"; } system "swapon -s"; Let me know if you see room for improvements, Regards, -- andreas -- This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice.
Re: [OT]RE: loss of shared memory in parent httpd
>How is it even remotely possible that turning off swap restores memory >shared between processes? Is the Linux kernel going from process to process >comparing pages of memory as they re-enter RAM? "Oh, those two look >identical, they'll get shared?" This is a good point. I really have no clue how the kernel deals with swapping/sharing, so I can only speculate. I could imagine that it's possible for it to do this, if the pages are marked properly, they could be restored. But, I'll admit, it seems unlikely. ...and, I had this thought before. Maybe this apparent loss of shared memory is an illusion. It appears to make the amount of memory that the httpds use grow very high, but perhaps it is a kind of shared-swap, and thus the calculation I'm using to determine overall memory usage would need to also factor out swap. ...in which case, there's no problem at all. But, I do see an albeit qualitative performance increase and CPU load lowering when I get the httpds to stay shared (and unswapped). So, I think it does matter. Though, if you think about it, it sort of makes sense. Some portion of the shared part of the httpd is also not being used much, so it gets swapped out to disk. But, if those pages really aren't being used, then there shouldn't be a performance hit. If they are being used, then they'd get swapped back in. ...which sort of disproves my qualitative reasoning that swap/unshared is bad. my head hurts, maybe I should join a kernel mailing list and see is someone there can help me (and if I can understand them). -bill
Re: [OT]RE: loss of shared memory in parent httpd
Narins, Josh wrote: > Call me an idiot. > > How is it even remotely possible that turning off swap restores memory > shared between processes? Is the Linux kernel going from process to process > comparing pages of memory as they re-enter RAM? "Oh, those two look > identical, they'll get shared?" You actually can do this. See the mergemem project: http://www.complang.tuwien.ac.at/ulrich/mergemem/ I've never tried it myself, so if anybody did please share your experience. > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] > Sent: Thursday, March 14, 2002 8:24 AM > To: Bill Marrs > Cc: [EMAIL PROTECTED] > Subject: Re: loss of shared memory in parent httpd > > > >>On Thu, 14 Mar 2002 07:25:27 -0500, Bill Marrs <[EMAIL PROTECTED]> >> > said: > > >> 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! > > Funny, I'm doing this for ages and I never really knew why, you just > found the reason, Thank You! My concerns were similar to yours but on > a smaller scale, so I did not worry that much, but I'm running a > swapflusher regularly. > > Make sure you have a recent kernel, because all old kernels up to > 2.4.12 or so were extremely unresponsive during swapoff. With current > kernels, this is much, much faster and nothing to worry about. > > Let me show you the script I use for the job. No rocket science, but > it's easy to do it wrong. Be careful to maintain equality of priority > among disks: > > use strict; > > $|=1; > print "Running swapon -a, just in case...\n"; > system "swapon -a"; > print "Running swapon -s\n"; > open S, "swapon -s |"; > my(%prio); > PARTITION: while () { > print; > next if /^Filename/; > chop; > my($f,$t,$s,$used,$p) = split; > my $disk = $f; > $disk =~ s/\d+$//; > $prio{$disk} ||= 5; > $prio{$disk}--; > if ($used == 0) { > print "Unused, skipping\n"; > next PARTITION; > } > print "Turning off\n"; > system "swapoff $f"; > print "Turning on with priority $prio{$disk}\n"; > system "swapon -p $prio{$disk} $f"; > } > system "swapon -s"; > > > Let me know if you see room for improvements, > > Regards, > -- _ Stas Bekman JAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide http://perl.apache.org/guide mailto:[EMAIL PROTECTED] http://ticketmaster.com http://apacheweek.com http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
Re: [OT]RE: loss of shared memory in parent httpd
>You actually can do this. See the mergemem project: >http://www.complang.tuwien.ac.at/ulrich/mergemem/ I'm interested in this, but it involves a kernel hack and the latest version is from 29-Jan-1999, so I got cold feet. -bill
Re: [OT]RE: loss of shared memory in parent httpd
Bill Marrs wrote: > >> You actually can do this. See the mergemem project: >> http://www.complang.tuwien.ac.at/ulrich/mergemem/ > > > I'm interested in this, but it involves a kernel hack and the latest > version is from 29-Jan-1999, so I got cold feet. It was a student project. And unless someone tells me differently wasn't picked up by community. In any case I've mentioned this as a proof of concept. Of course I'd love to see a working tool too. _ Stas Bekman JAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide http://perl.apache.org/guide mailto:[EMAIL PROTECTED] http://ticketmaster.com http://apacheweek.com http://singlesheaven.com http://perl.apache.org http://perlmonth.com/