In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
How to create swap swap partition files in Linux? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!
Introduction to Swap
Swap (swap partition) in Linux, which is similar to the virtual memory of Windows, is to virtualize part of the hard disk space into memory when there is insufficient memory, so as to solve the problem of insufficient memory capacity.
How to create a Swap file
1. Create a file for swapping
Sudo fallocate-l 1G / swapfile
If faillocate is not installed or you receive an error message, fallocate failed: Operation not supported can create a swap file using the following command:
Sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
two。 Set the correct permissions
Only root users can write and read the swap file, to set the correct permission type:
Sudo chmod 600 / swapfile
3. Set up the Linux exchange area
Use the mkswap utility to set the file to the Linux swap area:
Sudo mkswap / swapfile
4. Enable exchan
Activate the swap file using the following command:
Sudo swapon / swapfile
To make the changes permanently open the / etc/fstab file and append the following lines:
/ swapfile swap swap defaults 0 0
5. Verify switching statu
To verify that the exchange is active, we can use the swapon or free command, as follows:
Sudo swapon-show
Output
NAME TYPE SIZE USED PRIO/swapfile file 1024M 507.4M-1sudo free-h
Output
Total used free shared buff/cache availableMem: 488M 158M 83M 2.3M 246M 217MSwap: 1.0G 506M 517M
How to adjust swappiness
Swappiness is a Linux kernel attribute that defines how often the system uses swap space. Swappiness can have a value between 0 and 100. Lower values will make the kernel avoid swapping as much as possible, while higher values will make the kernel use swap space more actively.
The default swappiness value is 60. 0. You can check the current swappiness value by typing the following command:
Cat / proc/sys/vm/swappiness
Output
sixty
Although the desktop can use a swappiness value of 60, for production servers, you may need to set a lower value.
For example, to set the swappiness value to 10, type:
Sudo sysctl vm.swappiness=10
To leave this parameter unchanged after a reboot, append the following line to the / etc/sysctl.conf file:
Vm.swappiness=10
The best swappiness value depends on your system workload and how memory is used. You should adjust this parameter in small increments to find the best value.
How to delete a swap file
If you want to deactivate and delete the swap file for any reason, follow these steps:
1. First, deactivate swapping using the following command:
Sudo swapoff-v / swapfile
two。 Delete the swap file entry / swapfile swap swap defaults 0 0 from the / etc/fstab file.
3. Finally, delete the actual swapfile file:
Sudo rm / swapfile Thank you for reading! After reading the above, do you have a general idea of how to create a swap exchange partition file in Linux? I hope the content of the article will be helpful to all of you. If you want to know more about the relevant articles, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.