Virtual Memory Management in CentOS7#
Virtual memory is a technology for memory management in computer systems. It provides applications with a continuous and complete address space, allowing applications to think that they have continuous available memory. However, in reality, this memory may be divided into multiple physical memory fragments, and even temporarily stored on external disk storage.
- Virtual memory is a transitional technology (there is a significant difference in storage capacity between computer hardware memory and external storage).
- Based on the principle of program locality, programs that are temporarily not running are placed in a storage space on the hard disk, which is called virtual memory.
free
: View memory (including physical memory and virtual memory)
Classification of virtual memory in Linux:
- Based on hard disk partitions: For example, adding a 1GB hard disk to be used as virtual memory space.
- Based on files: Allocate a file on an existing hard disk.
Commands related to hard disk partitions:
mkswap
(create swap partition or file)swapon
(load swap partition or file)swapoff
(unmount swap partition or file)
Commands related to files:
dd if=/dev/zero of=/root/swapfile bs=1024 count=1024
# dd is used to allocate a swap file
# if is the input device
# of is the output file
# bs represents the block size, with each block being 1KB
# count indicates how many blocks to allocate
mkswap /root/swapfile # Create swap file
swapon /root/swapfile # Load swap file
free -m # View memory