Thursday, March 3, 2011

Howto: Swap memory increase with swap file

-----------------------------------------------------------------------------------
swap partition vs swap file
* Linux Optimization
I have been trying to find the performance differences between a swap partition and a swap file in Linux.

I have found several affirmations that swap partitions are better, but lots also say they are the same (at least for kernels 2.6).

I can find some differences that can help you make the good choice, or when to use swap on file or partition.

Swap partitions can be used by two or more Linux installations on the same PC (dual boot or triple boot).

Swap partition are better in case of full disk where the swap file could be created fragmented.

On the other hand swap files are good if you need to change the size of the swap memory regularly as it is easier to resize the swap file that the whole partition, you may say you can have two swap partitions and enable or disable as you need, but you will be wasting the space of the disabled swap partition.

The swap files will work as good as the swap partitions if they are created on non-full disks to avoid fragmentation.

I may also think that one is a good complement of the other whenever you may need more swap memory, and your system is already installed, in that case you can add swap memory with swap files.

If you have any experiences on this topic please post your comments, and also read this article
------------------------------------------------------------------------------------
How to create a swap file?
sudo dd if=/dev/zero of=/swapfile bs=1024 count=100000
------------------------------------------------------------------------------------
This will create file (swapfile) of size 100 MB (round)
sudo mkswap /swapfile
------------------------------------------------------------------------------------
add this file to your swap pool
sudo swapon /swapfile
------------------------------------------------------------------------------------
This will do the job, now you have 100 more Mbytes of swap memory.
------------------------------------------------------------------------------------

No comments:

Post a Comment