Linux systems implement virtual memory in two ways: swap (swap partition) and exchange files

 

Linux systems implement virtual memory in two ways: swap (swap partition) and exchange files

Interchange File

  1. View Memory: free -m, -m is displayed in units of MB, -g unit GB
  2. Create a file:touch /root/swapfile
  3. Use ddthe command to create a file size of the swapfile 2G:
    dd if=/dev/zero of=/root/swapfile bs=1M count=2048// End command waiting period
    if the input file indicates input_file
    of output file represents output_file
    bs block_size represents the block size
    count represents a count.
    Here, I used a block size of 1M, the number of data blocks 2048, space is allocated in this way the size of 2G.
  4. Interchange File Format:mkswap /root/swapfile
  5. Enable swap file:swapon /root/swapfile
  6. Boot automatically load virtual memory, add the following command in the / etc / fstab file:
    /root/swapfile swap swap defaults 0 0
  7. After the restart to take effectreboot

If you want to delete the swap partition and the swap file, against the above order of operations:

  1. Delete the swap file / etc / fstab file, add the line
  2. Disable swap fileswapoff /root/swapfile
  3. Delete the swap filerm -fr /root/swapfile

Swap partition

The use of swap approach is actually to create a new partition, and then mount the partition as swap space, with the traditional method steps as the new partition. Just format the partition and mount partitions were used mkswap and swapon command. Before creating a partition, we often used fdisk -l and df -Th command to view disk information and mount information to determine the size of the partition.


 
 
  1. Hdb1 create partitions in a shell as root fdisk /dev/hdb1and then save and exit w
  2. Set swap partition, as the case may set up their own size.mkswap /dev/hdb1
  3. Enabling swapswapon /dev/hdb1
  4. Boot automatically load virtual memory, add the following command in the / etc / fstab file:
    /dev/hdb1 swap swap defaults 0 0
 
 
 

Guess you like

Origin www.cnblogs.com/timssd/p/11954958.html
Recommended