Dan Zwell
8/7/2007 3:22:00 AM
Ari Brown wrote:
>
> On Aug 6, 2007, at 8:35 PM, Alex Gutteridge wrote:
>> Other people have explained why this really isn't such a great idea,
>> but in the spirit of experimentation...
>>
>
> I can understand why it's not suggested that I forcefully clear the RAM,
> but will it have a negative effect on my programs? And is there a
> suggested way to clear the RAM using Ruby?
>
> Ari
It's good when your computer uses most of its ram. Seriously, you didn't
pay for it to look pretty. That being said, memory is used primarily for
two things: file caching and storing CPU instructions (running
programs). Now, if you clear the memory that was holding file caches,
you don't lose much (unless you need to re-read a file that had been in
the cache), but you don't gain anything, either. Like I said, unused
memory serves no purpose. If you clear ram that was holding CPU
instructions, those instructions will be pushed into swap. Because swap
is on your hard disk, it thousands of times slower than main memory.
When a program you are running tries to load data that is not in main
memory, the data needs to be dragged out of swap before the program can
continue running. This slows down your system terribly.
There is one thing you can do to speed up your system if you are on
Linux. You can tell it to use more ram. That's right, the opposite of
freeing ram. The OS has a setting called "swappiness". A higher
swappiness means to use more swap (and have more free ram, which is used
for file caching). A lower swappiness means you will have less file
cache, but applications are less likely to get swapped out. That means
that, for example, when you restore an application that has been
minimized to your system tray for three days, it is instantaneous--no
delay as the application data gets read into memory from swap, because
it isn't swapped out. You need enough ram for this to be of any benefit.
Use the command "free -m" to see how much memory you are using total,
and for file caching. If you have little free ram (but are using a
significant portion of it for file caching), or your computer just isn't
using as much of your ram as you would like, try the following:
The default "swappiness" is 60 (out of 100). Try changing it to 15.
# echo 15 > /proc/sys/vm/swappiness
If you don't like it, change it back.
# echo 60 > /proc/sys/vm/swappiness
If you want to make this change permanent, you will have to consult your
distro's documentation.
I hope someone finds this useful. If there is a similar trick that can
be used in Windows, I would love to hear about it.
Dan