How to set/Modify swap partition on Linux

Source: Internet
Author: User

How to set up swap partition on CentOS

As the most stable server version in the Linux world, RHAS5 has always had a large application surface, previously focused on FreeBSD, because of the need for applications, especially with MySQL and Oracle on the Red Hat has too many advantages.

Using CentOS instead of Red Hat as, because CENTOS5 is the use of RHAS5 source code, remove the Redhat logo, icon compiled after the release, is the most source compiled version, I use CentOS 5.2

When installing CentOS 5.2, forget to set swap swap partition, in the case of small memory, increase the role of swap more effective.

First step to create a file block

#cd/var (enter a folder)

#dd If=/dev/zero of=swapfile bs=1024 count=524288 (creates 512M swap, typically twice times the memory)

#/sbin/mkswap swapfile (Create swap file)

#/sbin/swapon swapfile (activating swap file)

#/sbin/swapon-s (check if swap is correct)

Results:

Filename Type Size used priority

/var/swapfile file 524016 0-1

#vi/etc/fstab (add to Fstab file to start automatically when the system boots)

Add the following at the end:

/var/swapfile swap swap defaults 0 0

#reboot

After reboot, the top command looks at the size of the swap partition.



Swap problem has been resolved (originated from the network)

Workaround:

2. Format China and start swap file

Next, execute the mkswap command, format the Myswap file into the S file system, which the system can use, switch to the/tmp directory, and execute the following command:

# Mkswap Swapfree (#将文件格式化为swap文件格式)

Setting up Swapspace version 1, size = 262144 KB

# Swapon/tmp/swapfree (#启动swap分区)

To stop using the newly created swap file, simply execute the swapoff/tmp/swapfree command and delete the swap file if it is no longer in use.

3. Check Swap

#swapon-S

4. Automatically start the newly added swap partition when booting

If you have to execute the swapon command to start the swap partition or file after each boot, it's too much trouble. You can use the text editor to add a line to the/etc/fstab file, so that the swap partition and file will be started automatically when you start it:

/DEC/HDB5 swap swap defaults 0 0 (start this swap partition at boot time)

/tmp/swapfree swap swap defaults 0 0 (start this swap file at boot).

Swap space Size:

Typically, the swap space should be greater than or equal to the size of the physical memory, the minimum should not be less than 64M, usually the size of the swap space should be 2-2 of physical memory. 5 times times. However, depending on the application, there should be different configurations: if it is a small desktop system, you only need a small swap space, while the large server system requires different sizes of swap space depending on the situation. In particular, the database server and Web server, with the increase in traffic, the swap space requirements will also increase, the specific configuration see the description of the server products.

Swap quantity:

The number of swap partitions also has a significant impact on performance. Because swap operations are disk IO operations, if there are multiple swap zones, the swap space is allocated in a rotating manner to all swaps, which greatly balances the IO load and speeds up swap. If there is only one swap area, all switching operations will make the swap area very busy, leaving the system most of the time in a waiting state and inefficient. With 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 on the IO, relying on the speed of the CPU can not solve the problem.

Note:

View Swap space Size (total):
# free-m default unit is K,-m unit is m
Total used free shared buffers Cached
mem:377 180 197 0 19 110
-/+ buffers/cache:50 327
swap:572 0 572

The Mem line shows how memory is used from a system point of view, and total is the amount of memory available to the system, equal to the system physical memory minus the kernel's reserved memory.
Buffers and cached are memory used by the system as buffers. The buffers is associated with a block device, contains the file system metadata, and tracks changes in the block. The cache contains only the file itself.

-/+ buffers/cache rows Display memory information from the user's perspective, and the available memory is equal to the number of mem rows used column values minus the size of buffers and cached memory.

Because buffers and cached are set up by the operating system to speed up system operation, they can only be used by users when they need it.

Top Displays the dynamic, real-time status (CPU, memory) of each process in the system runtime

Top has 3 columns VIRT RES SHR, indicating the memory used by the process.
VIRT identifies the total amount of memory that the process can use, including the memory that the process is using, mapped files, and other processes that share memory.
RES identifies the size of this process that really consumes memory.
The SHR identifies the memory and library sizes that can be shared with other processes.

Vmstat Display of memory usage

These commands read memory information from the/proc/meminfo.

The meanings of the lines in/proc/meminfo are described in the Documentation/filesystems/proc.txt file of the kernel source code.

The real memory size of the system can be used DMESG | grep [mm][ee][mm] Saw

/proc/pid/status shows the detailed status of a process

How to set/Modify swap partition on Linux

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.