Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ How to properly set up a Linux swap partition     - XP virtual machine under VirtualBox solve occupy 100% CPU problem (Linux)

- Introduction to Linux Shell (Programming)

- How VMware extend disk without rebooting the system (Linux)

- Quagga use authentication on strengthening BGP session security (Linux)

- C ++ Supplements - locates the new expression (Programming)

- Source MongoDB 3.2.1 installed on CentOS6.5 (Database)

- Can not empty the Recycle Bin to repair problems in Ubuntu 14.04 (Linux)

- Oracle Database Performance Optimization of memory disk (Database)

- Ubuntu installed Gimp 2.6.11 (stable version) with PPA (Linux)

- Linux environment Duplex (multi-machine) automatic mutual backup scheme (Linux)

- Shell Scripting early experience (Programming)

- CentOS-based Kickstart automated installation practice (Linux)

- Linux iptables firewall settings to use (Linux)

- Ubuntu treated with cue file to ape and wav files automatically track points (Linux)

- The Java utility, JavaMail (Programming)

- OpenSUSE GPG Comments (Linux)

- Python interview must look at 15 questions (Programming)

- Learning Linux coding style (Programming)

- CentOS install expect (Linux)

- Go build the locale under Windows (Linux)

  How to properly set up a Linux swap partition
  Add Date : 2018-11-21      
  What is a Swap?

Swap, namely the exchange zone, in addition to the installation of Linux, how many people cared about it then? In fact, the adjustment Swap on Linux servers, especially Web server performance is critical. By adjusting the Swap, sometimes across the system performance bottleneck, saving system upgrade costs.

Swap principle is a more complex problem that requires a lot of space to explain. Here only a brief introduction, and discussed in detail Swap implementation details in a future article.

As we all know, modern operating systems to achieve a "virtual memory" of this technology, not only in function to break the limit of physical memory, so the program can manipulate larger than the actual physical memory space, and more importantly, the "virtual memory" is to isolate each a process safety net, so that each process are not subject to interference from other programs.

Role Swap space can be simply described as follows: When the system's physical memory is not enough when it needs to be part of the physical memory space freed up to use for the currently running program. Those spaces may be released from a number of a long time there is no operating procedures, which were released into space Swap space is temporarily stored in, wait until those programs to run, and then restore the data from Swap saved into memory. Thus, the system is always in physical memory is not enough only to carry out the exchange of Swap.

Computer users often encounter this phenomenon. For example, when using a Windows system, you can run multiple programs simultaneously, when you switch to a long time did not care about the program, you will hear the hard drive "rushing" direct sound. This is because the program's memory by those who frequently run program to "steal", and put the Swap area. Therefore, once the program is placed to the front, it will get their data from Swap area, www.linuxidc.com it into memory, and then run.

It should be noted that not all exchange from the physical memory of the data will be put Swap (if this is the case, it will be overwhelmed Swap), a considerable part of the data is exchanged directly to the file system. For example, some program will open some files, the file read and write (in fact, each program is at least open a file that runs the program itself), when these programs need to be swapped out of memory space, there is no need to Swap data file section into the space, and you can put it directly into the file to go. If the file is a read operation, the memory data to be released directly, without exchanging it, because next time you need, you can restore directly from the file system; if it is to write the file, save only need to change the data to a file in order to restore. But those data using malloc and new functions to generate the object is different, they need Swap space because they do not have the "reserve" in the file system, so called "Anonymous" (Anonymous) memory data. Such data also includes a stack of some of the state variables and data. So, Swap space Swap space is "anonymous" data.

How to Set Up Swap partition size

I remember someone comments on Swap partition size is set too: "As long as the waste is not afraid of the hard disk, then the bigger the better, because the linux kernel before physical memory is completely exhausted not to touch swap"

However, according to my experience, this may not be Oh! Much swap space will cause the kernel that has a huge memory space without restraint want to catch the data into memory, causing kernel has been doing memory swap, jointly slow down the system response time.

Honestly, 1G RAM if you do not run things like p2p, it set up a 256MB enough to use; even if there are 2G are provided not set.

Also because if you really do need a software huge memory space to operate, then the swap had hands and feet, but for the best performance spread across multiple physical disks (similar raid equal effect)!

In fact, how to set Swap partition size is the best way to check a Linux system administrator level test, Swap in the end how to set it? I think so: First, we need to know which server should run this program, their respective memory size is how much, after checking the exact size of Swap partition can be determined:

(Memory size + Swap partition size) * 70% = 80% or procedures need to take total memory

Swap partition during the test program is also a great use, for example, administrators can partition by usage Swap, monitoring whether the system memory leaks, while the Web application projects can also provide a better traffic spikes buffer. A Linux system administrator should be able to monitor the situation through the use of Swap partition on the system, the program has a reasonable assessment.

System performance monitoring

Swap space allocation is very important, and performance monitoring system is in operation but more valuable. Through performance monitoring tool that can check the performance of the system to find the system performance bottleneck. This article only introduce under Solaris and Swap-related commands and uses.

The most common is Vmstat command (in most Unix platforms have such a number of command), this command can view most performance indicators.


# Vmstat 3

procs memory swap io system cpu

r b w swpd free buff cache si so bi bo in cs us sy id

0 0 0 0 93,880 3304 1,937,200,102,131,100,099

0 0 0 0 93,880 3,304,193,720,000,109,800 100

0 0 0 0 93,880 3,304,193,720,000,112,600 100


Command Description:

vmstat back parameter specifies the performance capture interval. 3 shows capture every three seconds. Do not look at the first row of data, there is no value, it simply reflects the average performance since boot. From the second line reflects the system performance within every three seconds. Swap these performance indicators and relevant include the following:

w procs under

It represents the current number of processes (within three seconds) needs to free memory, swap out.

swpd memory under

It indicates the size of the use of Swap space.

Swap under si, so

si represents the current (within three seconds) per second, the total return swap memory (Swap in), in units of kbytes; so represents the current (within three seconds) the exchange of the total amount of memory (Swap out) per second, units of kbytes.

More than the number of indicators, the more that the system is busy. System busy these performance indicators, and the specific system configuration. System administrators should be in the normal system during normal operation, write down the value of these indicators, while the system is a problem, and then to compare, it will quickly identify problems and develop standards index value of the system normal operation, for performance monitor usage.

In addition, the use of Swapon-s can easily view the current usage Swap resources. E.g:

# Swapon -s

Filename Type Size Used Priority

/ Dev / hda9 partition 361420 0 3

It can easily be seen that the size of the Swap space used and unused resources.

Swap should make the load was maintained at 30% or less, so as to ensure good performance of the system.

Swap-related operating system commands

Swap space increases, divided into the following steps:

1) Become superuser

$ Su - root

2) Create a Swap File

# Dd if = / dev / zero of = swapfile bs = 1024 count = 65536

Create a continuous space swap file.

3) Activate Swap File

# / Usr / sbin / swapon swapfile

swapfile refers to the swap file is created in the previous step. 4) Now the newly added Swap file already worked, but after the system reboots and does not remember the first few steps of the operation. Therefore, to be recorded in the file / etc / fstab file name, and Swap types, such as:

/ Path / swapfile none Swap sw, pri = 3 0 0

Whether 5) test file with Swap

/ Usr / sbin / swapon -s

Remove the extra space Swap.

1) Become superuser

2) Use Swapoff order resumption Swap space.

# / Usr / sbin / swapoff swapfile

3) Edit / etc / fstab file, remove the entities in this Swap files.

4) recovering the 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 then attached to the original file system.
- Ubuntu Tutorial: E: Failed to get lock / var / lib / apt / lists / lock - open (Linux)
- Java Database Programming JDBC configuration (Programming)
- Installed FFmpeg 2.6.3 on Ubuntu / Debian / Fedora system (Linux)
- Linux compiler installation Redis (Database)
- Linux --- process handle limit summary (Linux)
- Elaborate .NET Multithreading: Using Task (Programming)
- How UTorrent download the ISO image from the command line (Linux)
- Go constructed using an interpreted language (Programming)
- Java in the final qualifier (Programming)
- HTTP and HTTPS request response process difference (Linux)
- Default permissions Linux file and directory permissions and hide - umask, chattr, lsattr, SUID, SGID, SBIT, file (Linux)
- How to use static, class, abstract method in Python (Programming)
- Open container cluster management system architecture and components introduced Kubernetes (Server)
- These days have been tossing in the Linux under the ASP.NET 5, on the next in the other operating systems in the ASP.NET 5 or. NET applications, in order to complete the MS VM (CoreCLR) run is not far Reach, the effect of the application.

- Do you know how to build the Linux kernel (Programming)
- Changes in C # asynchronous programming model (Programming)
- Linux kernel IPv6 protocol closed manner (Linux)
- Kubernetes resolve application deployment model (Server)
- How to become a better Node.js developers in 2016 (Programming)
- CentOS7 + Redis Live Installation and Configuration (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.