Home > Uncategorized > Dynamic and static swap file

Dynamic and static swap file

I prefer to have my swap in a file instead of a partition because it’s more flexible, and because 99% of time my swap is not used intensively. If it happen to be used intensively it means that there is something buggy in my applications.

I used the swapspace and dphys-swapfile Debian package for several years. Although it work pretty well most of the time, it happen that when I need a lot of swap in a short time (i.e. allocation of 1GB in 1s), the swap doesn’t extend fast enough and I run out of memory. That’s why on computers where I need to do such things I switched to a static swap file:

dd if=/dev/zero of=/var/lib/swap.img bs=1M count=1024
chmod 0600 /var/lib/swap.img
mkswap /var/lib/swap.img
echo '/var/lib/swap.img none swap sw 0 0' >> /etc/fstab
swapon -a
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: