Difference between revisions of "Swap"

From WA2IAC Wiki
Jump to: navigation, search
m (What is swap space, and why use it?)
m (Where should I set this up?)
Line 9: Line 9:
  
 
Swap space is disk space used by Linux (and most other operating systems) to store objects from memory when real physical memory starts becoming crowded or is exhausted. Because disk is generally slower than memory, Linux stores in swap the least recently used objects first, and keeps as much as it can in memory. It's generally recommended to have a swap space equal in size to your memory, if possible. See more details about swap space [https://help.ubuntu.com/community/SwapFaq here].
 
Swap space is disk space used by Linux (and most other operating systems) to store objects from memory when real physical memory starts becoming crowded or is exhausted. Because disk is generally slower than memory, Linux stores in swap the least recently used objects first, and keeps as much as it can in memory. It's generally recommended to have a swap space equal in size to your memory, if possible. See more details about swap space [https://help.ubuntu.com/community/SwapFaq here].
 +
 +
=== Use swapon for simplicity ===
 +
 +
Here's the safe and easy cookbook solution. Create a contiguous file, and mount it as swap using the "swapon" command in Linux and most other *nix variants. To add the swap at boot time, put the "swapon" command in /etc/rc.local. If you don't want to rely on swap, there's no point in NOT doing it this way.
 +
 +
Note that in the example below, you'll be creating 4 Gig of swap. You probably don't need that much. To fully cover your butt, make the swap file equal to the amount of RAM you have. But if you have sized your system correctly, and understand what's going on under the hood, you may well need less.
 +
 +
<pre>
 +
dd if=/dev/zero of=/mnt/swap1 bs=1024 count=4M
 +
mkswap /mnt/swap1
 +
chown root.root /mnt/swap1
 +
chmod 600 /mnt/swap1
 +
swapon /mnt/swap1
 +
</pre>
  
 
=== Where should I set this up? ===
 
=== Where should I set this up? ===
  
The Ubuntu 12.04 LTS AMI, which I also started with, is configured with no swap space initially, as the size and number of your storage devices can vary. But most come with a large free ephemeral storage device automatically. Since S3 storage is limited by cost, the ephemeral drive is a good place for a swap file. Mine has the same device name mentioned in the question, /dev/xvdb, but you can configure this during instance launch.
+
The Ubuntu 12.04 LTS AMI is configured with no swap space initially, as the size and number of your storage devices can vary. But most come with a large free ephemeral storage device automatically. Since S3 storage is limited by cost, the ephemeral drive is a good place for a swap file. Mine has the same device name mentioned in the question, /dev/xvdb, but you can configure this during instance launch.
  
 
=== How can I set up a swap space on my ephemeral storage drive? ===
 
=== How can I set up a swap space on my ephemeral storage drive? ===

Revision as of 20:28, 3 March 2015