banner
破影岚歌

破影岚歌的博客

bilibili
twitter
github

12. Virtual Memory Management

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 they have contiguous available memory. In reality, this memory may be divided into multiple physical memory fragments or even temporarily stored on external disk storage.

  1. Virtual memory is a transitional technology due to the significant difference in storage capacity between computer hardware memory and external storage.
  2. 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: Check memory (including physical memory and virtual memory)

Classification of virtual memory in Linux:

  1. Based on hard disk partition: For example, adding a 1GB hard disk to be used as virtual memory space.
  2. Based on files: Allocate a file on an existing hard disk.

Commands related to hard disk partition:

  1. mkswap (create swap partition or file)
  2. swapon (load swap partition or file)
  3. swapoff (unmount swap partition or file)

Commands related to files:

dd if=/dev/zero of=/root/swapfile bs=1024 count=1024
# dd indicates applying for a swap file
# if is the input device
# of is the output file
# bs indicates the block size, each block is 1KB
# count indicates how many blocks to apply for
mkswap /root/swapfile # Create swap file
swapon /root/swapfile # Load swap file
free -m # Check memory
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.