On Windows systems, swap is called "page-file" or something, but it is the same concept as outlined above. I'm sure there is some way to do this in a win system, but I am not going to get into it here. If you are running Linux, then you can do a a couple very simple things to speed your system up:
Only do this if you can afford to; you should have descent system specs (4 gigs of ram and an intel core2duo is what I'm on right now). If you have less, say 2 gigs of RAM, you probably should take precautions if you attempt to tweak this:
First, let's check your swap level:
$ cat /proc/sys/vm/swappiness
You can instruct your system to use a swap less aggressively, by executing (as root) the following comamand:
# sysctl vm.swappiness=0
For whatever reason Debian systems have the vmswappiness set to 60, which is a pretty swap-happy number (on a scale from 0 to 100), so this will speed your system up considerably. If you want to make the change permanent, open
/etc/sysctl.conf
as root, and insert the following line into the file:
# vm.swappiness = $n
Where $n represents an integer (whole number) from 0 to 100 (I use 0) which controls how swap-happy your system gets. Even with my swapiness set to 0, occaisonally when running a lot of RAM consuming tasks (like virtual machines), my system will start swapping everything anyway, even though I have plenty of RAM. You can check your system monitor to see how much swap is in use, if any is in use, and you do not have a solid state drive, (as in my case), you can issue the following commands (as root) to disable & re-enable the swap, which also loads anything in swap to RAM and gives you a clean slate:# swapon -a && swapoff -a
# swapoff -a && swapon -a(oops)
Or you can simply issue swapoff -a to disable it completely. To make things a little easier, I wrote this simple bash script to clear the swap in these situations. Place this in your $path (generally /usr/local/bin/, unless you exported another path... more on that some other time) :
#!/bin/bashIf all goes well, you won't get the error message, otherwise you will (duh). This script also must be ran as root, as it needs administrative privileges. Here is one example of something that could go wrong:
echo "I will now empty the Swap..."
if swapoff -a && swapon a ; then
:
else
echo "# ! ERROR ! #"
echo 'Damn bro, That did not work. Got root?' >&2
exit 1
fi
root@linuxpc:~# reswapSince I am using an encrypted /home partition, my swap file is also encrypted. As we all know, security often comes at the price of convenience. Once in a blue moon, the system will initially fail to find the swap partition (due to linux hiding/obscuring the partition labels and whatnot), but it usually corrects itself after a little while. However, this will work flawlessly most of the time.
I will now empty the Swap...
swapon: a: stat failed: No such file or directory
# ! ERROR ! #
Damn bro, That did not work. Got root?
In conclusion, solid state drives are badass, and if you don't have one, but have enough RAM, kill the swap already!
No comments:
Post a Comment