In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This paper mainly studies the relevant content of swap partition under linux, which is introduced in detail as follows.
Swap Partition introduction
Embedded Linux Chinese station message, the Swap partition of Linux system, namely exchange area, the function of Swap space can be simply described as: when the physical memory of the system is insufficient, a part of the physical memory needs to be released for use by the currently running program. The freed space may come from programs that have been inactive for a long time, and the freed space is temporarily saved in Swap space, and when those programs are about to run, the saved data is recovered from Swap to memory. In this way, the system does not swap Swap until there is not enough physical memory. In fact, the adjustment of Swap is very important to the performance of Linux servers, especially Web servers. By adjusting the Swap, you can sometimes overcome the system performance bottleneck and save the cost of system upgrade.
As we all know, modern operating systems have implemented the technology of "virtual memory", which not only breaks through the limitation of physical memory functionally, so that the program can manipulate the space larger than the actual physical memory. more importantly, "virtual memory" is a security protection net that isolates each process, so that each process is not disturbed by other programs.
Maybe computer users often encounter this phenomenon. For example, when using a Windows system, you can run multiple programs at the same time, and when you switch to a program that you haven't been paying attention to for a long time, you will hear the hard drive "clap". This is because the program's memory is "stolen" by frequently running programs and placed in the Swap area. Therefore, once the program is placed on the front end, it will retrieve its data from the Swap area, put it in memory, and then run it.
In addition, not all data swapped out of physical memory will be put into Swap (if so, Swap will be overwhelmed), and a considerable amount of data will be exchanged directly to the file system. For example, some programs will open some files to read and write files (in fact, each program has to open at least one file, that is to run the program itself). When you need to swap out the memory space of these programs, there is no need to put the data of the file part into the Swap space, but you can put it directly into the file. If it is a read file operation, then the in-memory data is released directly and does not need to be swapped out, because the next time it is needed, it can be directly recovered from the file system; if it is a write file, only the changed data needs to be saved to the file for recovery. However, the data of objects generated with malloc and new functions are different. They need Swap space because they do not have corresponding "storage" files in the file system, so they are called "Anonymous" in-memory data. This kind of data also includes some state and variable data in the stack. Therefore, the Swap space is the exchange space for "anonymous" data.
Break the 128m Swap limit
Some Linux (domestic Chinese version) installation manual has such instructions: Swap space can not exceed 128m. Why is there such a saying? Before explaining the origin of the number "128m", give an answer to the question: there is no limit of 128m at all! The current limit is 2G!
The Swap space in the Linux system is paginated, and the size of each page is the same as that of the memory page, which facilitates the data exchange between the Swap space and memory. When the old version of Linux implemented Swap space, the first page of Swap space was used as a "bit mapping" (Bit map) of all Swap space pages. This means that each person on the first page corresponds to a page of Swap space. If this bit is 1, the page Swap is available; if it is 0, the page is a bad block and cannot be used. So, the first Swap mapping bit should be 0, because the first page Swap is the mapping page. In addition, the last 10 mapping bits are also occupied to indicate the version of Swap (the original version is Swap_space and the current version is swapspace2). So, if the size of a page is s, this Swap implementation can manage a total of "8 * (s-10)-1" Swap pages. For i386 systems, the total space size is 133890048, which is exactly 128m if you think 1 MB= 2 ^ 20 Byte.
This way to achieve the management of Swap space is to prevent bad blocks in Swap space. If the system detects a bad block in the Swap, a 0 is marked on the corresponding bit map to indicate that the page is not available. In this way, when using Swap, it will not use bad blocks and cause errors in the system.
Today's system designers believe that:
1. Now the quality of the hard disk is very good, and there are few bad blocks.
two。 Even if there are, there are not many, only need to list the bad blocks, and do not need to establish a mapping for each page.
3. If there are many bad blocks, you should not use this hard drive as Swap space.
As a result, the current Linux removes the bit mapping method and removes the 128m limit. Access directly by address, limited to 2G.
The impact of Swap configuration on performance
If too much Swap space is allocated, disk space will be wasted, while too little Swap space will cause an error.
When the system runs out of physical memory, the system runs slowly but still runs; if the Swap space is used up, the system will have an error. For example, the Web server can derive multiple service processes (or threads) according to the number of requests. If the Swap space is used up, the service process cannot be started, and a "application is out of memory" error usually occurs. In serious cases, it will cause deadlock of the service process. So the allocation of Swap space is very important.
In general, Swap space should be greater than or equal to the size of physical memory, and the minimum should not be less than 64m. In general, the size of Swap space should be 2-2.5 times the size of physical memory. However, according to different applications, there should be different configurations: if it is a small desktop system, only a small Swap space is needed, while large server systems need different sizes of Swap space according to different circumstances. Especially the database server and Web server, with the increase of access volume, the requirement of Swap space will also increase. For specific configuration, please see the description of each server product.
In addition, the number of Swap partitions has a significant impact on performance. Because the operation of Swap exchange is the operation of disk IO, if there are multiple Swap exchanges, the allocation of Swap space will operate on all Swap in turn, which will greatly balance the load of IO and accelerate the speed of Swap exchange. If there is only one switching area, all the switching operations will make the switching area very busy, leaving the system waiting most of the time and inefficient. Using the performance monitoring tool, you will find that the CPU is not very busy at this time, but the system is slow. This shows that the bottleneck lies in IO, and the problem cannot be solved by increasing the speed of CPU.
System performance monitoring
Although the allocation of Swap space is very important, the performance monitoring at run time of the system is more valuable. Through the performance monitoring tool, we can check the performance indicators of the system and find the bottleneck of the system performance. This article only introduces some commands and uses related to Swap under Solaris.
The most commonly used is the Vmstat command (some of which are available on most Unix platforms), which allows you to view most performance metrics. For example:
Vmstat 3procs memory swap io system cpu r b w swpd free buff cache si so bi bo in cs us sy id 00 00 93880 3304 19372 00 10 2 131 100 0 99 00 93880 3304 19372 00 109 80 0 100 00 93880 3304 1972 00 00 112 6 00 100.
Command description:
The parameters after vmstat specify the time interval for performance metrics capture. 3 means that it is captured every three seconds. The first row of data does not need to be looked at and has no value, it only reflects the average performance since boot. Starting from the second line, reflect the system performance metrics within every three seconds. Among these performance metrics related to Swap are the following:
W under procs
It represents the number of processes currently (within three seconds) that need to free memory and swap out.
Swpd under memory
It represents the size of the Swap space used.
Si,so under Swap
Si represents the total amount of memory swapped back (Swap in) per second (within three seconds), in units of kbytes;so, the total amount of memory swapped out per second (Swap out) currently (within three seconds), in kbytes.
The greater the number of the above metrics, the busier the system is. The busy degree of the system shown by these indicators is related to the specific configuration of the system. The system administrator should write down the values of these indicators during the normal operation of the system, and when there is a problem in the system, he will quickly find the problem and establish the standard index value for the normal operation of the system for performance monitoring.
In addition, using Swapon-s, you can simply view the current usage of Swap resources. For example:
Swapon-s
Filename Type Size Used Priority
/ dev/hda9 partition 361420 0 3
You can easily see the size of used and unused resources in Swap space.
The Swap load should be kept below 30% to ensure the good performance of the system.
To increase the Swap space, follow these steps:
1) become a superuser
$su-root
2) create a Swap file
Dd if=/dev/zero of=swapfile bs=1024 count=65536
Create a swap file with contiguous space.
3) activate the Swap file
/ usr/sbin/swapon swapfile
Swapfile refers to the swap file created in the previous step.
4) now the newly added Swap file has worked, but the previous steps will not be remembered after the system is rebooted. So record the name of the file and the Swap type in the / etc/fstab file, such as:
/ path/swapfile none Swap sw,pri=3 0 0
5) verify whether the Swap file is added
/ usr/sbin/swapon-s
Delete excess Swap space.
1) become a superuser
2) use the Swapoff command to reclaim Swap space.
# / usr/sbin/swapoff swapfile
3) Edit the / etc/fstab file and remove the entity from the Swap file.
4) Recycle this file from the file system.
# rm swapfile
5) of course, if the Swap space is not a file, but a partition, you need to create a new file system and attach it to the original file system.
Summary
These are all the contents of this article about the detailed interpretation of the role of swap partition under linux. I hope it will be helpful to you. Interested friends can continue to refer to other related topics on this site, if there are any deficiencies, please leave a message to point out. Thank you for your support to this site!
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.