#45: Super-fast temporary files

Remember the old days of RAM disks? Well, Linux has them too! If you've never 
tried them, a RAM disk is a virtual filesystem that runs entirely from your 
PC's main memory, which means it's lightning fast to read and write anything 
you want.

How much space you choose to allocate to your RAM disk is down to how much RAM 
you have and how much you plan to use it - if you have 1GB of RAM, you can 
easily spare 64MB for a ramdisk; if you have 2GB you can probably spare 256MB, 
and if you're lucky enough to have 4GB then you can easily stretch your RAM 
disk legs with 1GB.

Here's how to set up a 64MB disk - just change the 65536 for the size you want:

mkfs -t ext3 -q /dev/ram1 65536
mkdir -p /ramdisk
mount /dev/ram1 /ramdisk -o defaults,rw

Alternatively, a reader suggested you could also try using tmpfs, like this:

mkdir /ramdisk
mount none -t tmpfs -o size=256M /ramdisk

That will allocate 256MB of space to your RAM disk. If you skip the "-o 
size=256M" part, half your RAM will be used by default.
#46: Avoid the disk

There's very little that's more annoying in Linux than its ability to use the 
swap file completely regardless of how much RAM you have installed on your 
machine. Yes, this is helpful in some scenarios - notably when your system is 
under heavy load and is really getting maxed out - but generally, if you have 
2GB or more RAM, you'll have lots free waiting to be used.

The way to force Linux to use swap space less is to edit the /etc/sysctl.conf 
file and to look for (or create) the vm.swappiness line. If you have lots of 
RAM and want to minimise the amount of swapping Linux does, set the line to be 
this:

vm.swappiness=10

#47: No more disk thrashing

We've said this time and time again, but people really never seem to take it 
seriously: if you want your disks to run at their full potential, make sure and 
enable the relatime option in /etc/fstab.

You see, every time your disk does a read (eg reading a file), it also does a 
write, to store the information pertaining to when the file was last read. This 
process is incredibly slow, and you can get a sizeable speed boost - usually 
around 10 per cent - with just one simple tweak.

Switch to root, then open up /etc/fstab in your favourite text editor. Look for 
where you root filesystem is, and make sure that it uses 
defaults,relatime,data=writeback for its settings, then save, reboot and let 
your poor overworked PC perform to its full potential... At last!

Reply via email to