How to Increase Swap Space

When an operating system runs out of memory in which to place running applications, the OS moves some of the contents in memory out to the computer’s hard disk in a swap file or virtual memory file. This process allows the OS to actually have more applications running than physical memory can contain. Adding more memory to the computer helps; but when memory is added, the swap file needs to be increased to accommodate it.

replacing a failed hard drive
A swap file or virtual memory file makes a computer's memory appear larger than it is.
credit: miklyxa13/iStock/Getty Images

Linux Swap Space

Create a swap file in the root directory filled with zeroes, set the permissions so the OS can use it, and turn the new swap file on with the following commands. Root privileges are required, so "sudo" is used to gain rights to issue the commands.

sudo dd if=/dev/zero of=swapfile count=1M bs=1k (This creates a 1GB swap file) sudo mkswap swapfile (This makes it a swap file) sudo chmod 0600 swapfile (This sets permissions) sudo swapon swapfile (This turns swapfile on)

The first command may take up to a minute, depending on the file size you choose. The second command will respond with information on success or failure, while the third command will return no response. The last command will activate swapping using the new swapfile.

Windows Virtual Memory File

To create a swap, or virtual memory file, in Windows, click "Start," right-click "Computer," click "Properties," "Advanced System Settings," "Performance" and "Settings." In the Settings dialog, click "Advanced," "Virtual Memory" and "Change." Clear the Automatically Manage Paging File Size for All Drives check box. Then click the drive where the paging file lives, which will typically be the C: drive. Click "Custom Size" and enter your new virtual memory file size in megabytes in either the Initial or Maximum size box. Click "Set," and "OK". This should activate the new virtual memory paging file size for Windows.