Sobes.tech
Junior

Where is the swap located and which device does it use?

sobes.tech AI

Answer from AI

Swap is a special area on the disk used by the operating system for temporarily storing data from RAM that is not actively used. This occurs when the amount of used RAM exceeds the available physical memory, allowing the system to continue functioning and avoiding crashes due to memory shortages.

Swap can be used:

  • Swap partition: A dedicated partition on a hard drive or SSD.
    # Example of /etc/fstab file showing an entry for the swap partition
    UUID=abcdef12-3456-7890-abcd-ef1234567890 swap swap sw 0 0
    
  • Swap file: A regular file created within the filesystem on an existing partition.
    # Example commands to create a 2GB swap file
    sudo fallocate -l 2G /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile
    

Usually, swap is located on the same physical storage device (HDD or SSD) where the operating system is installed, or on another connected disk. Using an SSD for swap significantly improves performance compared to HDD due to higher access speeds.