Linux Tutorials - Herong's Tutorial Examples - v5.45, by Herong Yang
What Is Swap Space
This section describes swap space, reserved area on the hard disk that extends RAM to form a larger physical memory.
What Is Swap Space? - Swap Space is a reserved area on the hard disk that extends RAM to form a larger physical memory. Swap space provides 3 benefits to the Linux system:
1. Allows applications to use more memory larger than RAM - For example, if you have a system with 8 GB of RAM with an 8 GB of swap space, then 16 GB of physical memory is available to run applications.
2. Allows larger Cache memory to improve performance - For example, if you have a system with 8 GB of RAM, and your applications only need 8 GB to run, then you don't have to add any swap space. However, if you do add an 8 GB of swap space, system will move inactive applications and their data from RAM to the swap space. Then the free space in RAM can be used as buffer and cache memory to speed remaining active applications.
3. Allows the system to go into sleep (hibernation) mode - If you enable the sleep mode, system will copy all running processes and their data from RAM to swap space. When you power on the system again, all running processes can be resumed.
"free" - Display Swap Space - "free" command displays usage of the physical memory, including swap space. The default output shows the swap space usage in the "Swap:" line. All numbers have a unit of KiB.
herong$ free total used free shared buff/cache available Mem: 7745404 2390776 537928 302640 4816700 4740408 Swap: 8085500 957800 7127700
"/proc/swaps" - Swap Space Information - /proc/swaps is a pseudo file that contains swap space usage information. You can use the "cat" command to display information from /proc/swaps:
herong$ cat /proc/swaps Filename Type Size Used Priority /dev/dm-1 partition 8085500 1000296 -2
Note that the "swapon -s" command also prints out the same information.
Other related commands are:
swapon -a # To enable all swap spaces swapoff -a # To disable all swap spaces mkswap # To create a new swap space
Table of Contents
Cockpit - Web Portal for Administrator
Layers of Memory and Access Speed
List CPU Caches and Their Sizes
Virtual Memory vs. Physical Memory
Buffer Memory and Cache Memory
Verify Cache Memory with "cp" Command
Virtual Memory Mapping and Page Table
"ps -o rss,drs,trs,vsz,sz" - Process Status Options
smem - Process Memory Usage Report
/proc/{id}/maps - Process Memory Map
/proc/{id}/smaps - Process Memory Map Details
SELinux - Security-Enhanced Linux
SSH Protocol and ssh/scp Commands
Software Package Manager on CentOS - DNF and YUM
vsftpd - Very Secure FTP Daemon