« Fame | Home | Nintendo Wii Launch Titles »
Managing Virtual Memory within Linux
By DivineOmega | August 9, 2006
Swap files (or virtual memory) are areas of disc space an operating system uses as a temporary alternative to RAM (physical memory).
It is the commonly believed that 1.5 times your existing physical memory is usually a sufficient sized to be used as swap space. For this reason, most Linux distribution automatically create a swap space (usually a linux-swap partition) of an equal size. However, this is not always enough dependant upon your needs.
This tutorial will cover how to add additional virtual memory to Linux, i.e. create an additional swap file. We will assume that you already have an existing swap file and/or Linux-swap parition, and simply with to add to it.
Firstly, you must open a terminal. By default in GNOME, a terminal window can be opened via Applications -> Accessories -> Terminal. Next, you want to create your new swap file.
dd if=/dev/zero of=/home/.swapfile bs=1024 count=1M
This command will create a 1 Gigabyte file (filled with zeros, the output of /dev/zero) called .swapfile in /home/. The parameters can be easily adjusted to change the size of the outputted file to meet your needs and indeed, its destination.
Next, you need to tell your distribution that you want to use this swap file every time you start. This procedure is not very involved, and simple involves modifying your start-up mount list, stored in the /etc/fstab file. You will need root priveledges to edit this file.
If using a GNOME enviroment (with the default gedit application installed), such as in the Ubuntu distribution enter the follow command:
gksudo gedit /etc/fstab
Alternatively, if you wish to use a command line editor such as pico, use the following command:
sudo pico /etc/fstab
Regardless of the editor used, you must now append the following line to the file, assuring that you correctly substitute in the location of the swap file you previously created.
/home/.swapfile none swap pri=100,defaults 0 0
The /etc/fstab file is read on the start of your system to ensure that all filesystems including swap space is succesfully mounted and made ready for use.
That’s it! You can now reboot your system to make immediate use of the additional swap space. If you don’t want to / can’t reboot your system, the command below will dynamically add the swap file to the currently running system.
swapon /home/.swapfile
Please feel free to make comments about this tutorial or add any additional details you think might be useful.
Tags: Linux, Linux Tutorials |