Skip to main content
ToolsKiemTrieuDo

Decoding SWAP in Linux: How Virtual Memory Works

SWAP is a fundamental yet crucial concept in Linux system administration. It acts as 'backup memory' when your physical RAM is full.

SWAP is an extension of RAM on your hard drive.

Essentially, SWAP is a space on the hard drive (either a separate partition or a file) that the Linux operating system uses as virtual RAM. When physical RAM is nearly full, Linux moves less-used memory pages from RAM to the SWAP space to free up RAM for active applications.

When Do You Need to Use SWAP?

Yes. Hard drives (even SSDs) are always much slower than RAM. When the system has to constantly read/write data from SWAP (known as 'swapping' or 'thrashing'), performance will decrease significantly. Therefore, SWAP should be seen as a backup solution, not a substitute for upgrading RAM.

Checking and Creating a SWAP File

To check if your system already has SWAP, use the command:

If no output is returned, you can easily create a SWAP file (e.g., 2GB) with the following commands:

Understanding and correctly configuring SWAP will help your Linux system run more stably and efficiently.

Also available in Vietnamese

Read Vietnamese version →

← Back to Blog