Go Linux Partition Swap

Source: Internet
Author: User

How to reasonably set up the original work of the swap partition of Linux, allow reprint, please be sure to use hyperlinks in the form of the original source of the article, the author information and this statement. Otherwise, the legal liability will be investigated. http://commandos.blog.51cto.com/154976/115288 what is swap?
Swap, the swap area, how many people cared about it, in addition to installing Linux? In fact, swap adjustments are critical to the performance of Linux servers, especially Web servers. By adjusting swap, you can sometimes bypass system performance bottlenecks and save on system upgrade costs. The principle of swap is a more complex issue that needs a lot of space to illustrate. Here is a brief introduction to the details of the swap implementation in a future article. As we all know, the modern operating system has realized the "virtual memory" this technology, not only in the function of the physical memory limit, so that the program can manipulate more than the actual physical memory space, more importantly, "virtual memory" is to isolate each process of the security network, so that each process is not affected by other programs interference. The function of swap space can be simply described as: when the physical memory of the system is not enough, it is necessary to release some of the space in physical memory for use by the currently running program. The freed space may come from programs that have not been manipulated for a long time, and the freed space is temporarily saved in the swap space until those programs run, recovering the saved data from the swap into memory. In this way, the system always does swap swap when physical memory is not enough. 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 has been ignored for a long time, you hear the hard drive "rushing" straight. This is because the memory of the program is "stolen" by those programs that are running frequently and placed in the swap area. Therefore, once the program is placed on the front end, it will retrieve its own data from the swap area, put it in memory, and then run. It is important to note that not all data exchanged from physical memory will be put into swap (if so, the swap will be overwhelmed), and a significant portion of the data is exchanged directly to the file system. For example, some programs will open some files to read and write to the file (in fact, each program to open at least one file, that is, running the program itself), when the need to swap out the memory space of these programs, there is no need to put the file part of the data into the swap space, and can directly put it into the file. If it is a read file operation, then the memory data is released directly, do not need to swap out, because the next time you need to recover from the file system directly, if you are writing files, only need to save the changed data to a file in order to recover. However, the data for objects generated with malloc and the new function are different, they require swap space because they do not have a corresponding "reserve" file in the file system and are therefore referred to as "anonymous" (Anonymous) memory data. This type of data also includes some state and variable data in the stack. So the swap space is the swap space for "anonymous" data.
how to set the swap partition size
I remember someone who commented on the size of the swap partition: "As long as you're not afraid to waste a hard disk, the bigger the better, because the Linux kernel won't be able to move the swap until the physical memory is completely exhausted" but according to my experience, it may not be so! Too much swap space can cause kernel to think that there is a huge amount of memory space in which you want to capture data in memory, causing the kernel to always be doing memories swap and slowing down system response times.
To be honest, 1G RAM if do not run peer-to kind of things, that set a 256MB is enough, there are 2G words even set not set.
In addition, if it is true because a software does require a huge amount of memory space to operate, it has to be on the swap, but for the best performance scattered on multiple physical hard disk (equal to the raid effect)! In fact, how to set the size of the swap partition is the most able to check the level of a Linux system administrator test, swap in the end how to set it? I think so: first we need to know which programs the server is running, how much memory they occupy, and after the exact check, the size of the swap partition can be determined as follows: (Memory size + swap partition size) * 80% or 70% = Program needs to occupy total memory the swap partition is also useful during program testing, such as the ability of an administrator to monitor system memory for leaks through the use of a swap partition, and also provides a good traffic peak buffering effect for applications such as Web projects. A Linux system administrator should be able to monitor the use of the swap partition, the system, the program has a reasonable evaluation.
System Performance Monitoring
While the allocation of the
swap space is important, performance monitoring while the system is running is more valuable. Through the Performance monitoring tool, you can check the performance indicators of the system to find the bottleneck of system performance. This article only describes some of the commands and uses that are related to swap under Solaris.   
Most commonly used is the Vmstat command (which has commands on most UNIX platforms), which allows you to see most of the performance metrics.   
For example:  
# vmstat 3  
procs memory swap IO system cpu  
R B W SWPD free Buff the cache si so bi bo in cs us sy id  
0 0 0 0 93880 3304 19372 0 0 2 131 0 0 99 &nbs P
0 0 0 0 93880 3304 19372 0 0 0 0 109 8 0 0 100  
0 0 0 0 93880 3304 19372 0 0 0 0 6 0 0 100 &N Bsp The
............  
Command explains that the parameters that follow:  
Vmstat Specify the time interval at which performance metrics are captured. 3 indicates a capture every three seconds. The first line of data does not have to look, it has no value, it only reflects the average performance since the boot. Starting from the second line, the system performance metrics are reflected every three seconds. These performance indicators are related to swaps and include the following: 
w   under Procs
It represents the number of processes that need to free up memory and swap out in the current (three seconds).   
swpd   under Memory
It represents the size of the swap space used. The si,so  
Si in the   
Swap represents the total amount of swap memory (swap in) per second (within three seconds), in Kbytes;so for the current (three seconds) swap out memory per second (swap Out) of the total, in units of Kbytes.   
The larger the number of indicators above, the busier the system is. The performance of these indicators is related to the system's specific configuration. System administrators should be in normal operation of the system, note the values of these indicators, in the event of system problems, and then compare, will quickly find the problem, and set up the normal operation of the system standard indicator values for performance monitoring use.   
In addition, using Swapon-s is a simple way to see how the current swap resource is being used. For example:  
# swapon-s  
Filename Type Size used priority  
/DEV/HDA9 partition 36 1420 0 3  
makes it easy to see the size of the used and unused resources of the swap space. The   
should keep the swap load below 30% to ensure good system performance.   
System commands for swap operations  
Add swap space, in the following steps:
1) become a Super User
$su-root
2) Create swap file
# dd If=/dev/zero of=swapfile bs=1024 count=65536
Create a swap file that has contiguous space.
3) Activate swap file
#/usr/sbin/swapon Swapfile
Swapfile refers to the interchange file that was created in the previous step. 4) Now that the new swap file has worked, the previous steps will not be remembered after the system restarts. So to record the name of the file in the/etc/fstab file, and the swap type, such as:
/path/swapfile None Swap sw,pri=3 0 0
5) Check if the swap file is added
/usr/sbin/swapon-s
Delete the extra swap space.
1) become a Super User
2) Use the Swapoff command to retract the swap space.
#/usr/sbin/swapoff Swapfile
3) Edit the/etc/fstab file to remove the entity from this swap file.
4) Reclaim this file from the file system.
#rm Swapfile
5) Of course, if this swap space is not a file, but a partition, you need to create a new file system and then attach it to the original file system.

This article is from the "Xuanwu" blog, please be sure to keep this source http://commandos.blog.51cto.com/154976/115288

[Go]linux partition swap

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.