Introduction to Linux System Add swap section Tutorial

Source: Internet
Author: User


What is swap memory (swap)?

Virtual memory is a technology of computer system memory management. It makes the application think that it has contiguous available memory (a contiguous complete address space), which is usually separated into multiple physical memory fragments, and partly temporarily stored on external disk storage for data exchange when needed. Systems that use this technology make it easier to write large programs and use real physical memory (such as RAM) more efficiently than systems that do not use virtual memory technology.

Virtualmem01.png

Note: Virtual memory is not just about "extending physical memory with disk space"--it's just an expansion of the memory level to include the hard drive. Extending memory to disk is just one result of using virtual memory technology, and it can also be done by overwriting or swapping the inactive programs and their data to disk. The definition of virtual memory is based on the redefinition of the address space by defining the address space as a "continuous virtual memory address" to use this "spoofing" program to make them think they are using a large "contiguous" address.
is the swap partition appropriate size?

Swap partitions are not as big as possible. Generally there are a few suggestions for such a child to determine its size: (1) (Memory size + swap size) * 80% or 70% = program needs to occupy total memory, (2) Swap space should be greater than or equal to the size of physical memory, minimum should not be less than 64M, Usually the size of the swap space can be 2-2.5 times times the physical memory. For example, your memory has reached 4G, its size can be equal to or less than 4G, but some software (such as Oracle database) may be different in size for this requirement.

How do I create swap and settings?


[Root@iifocus ~]# Free-m
Total used free shared buffers Cached
mem:490 448 42 27 16 215
-/+ buffers/cache:216 273
swap:0 0 0
[Root@iifocus ~]# Mkdir/data
[Root@iiocus ~]# dd If=/dev/zero of=/data/swapfile bs=1m count=1024
1024+0 Records in
1024+0 Records out
1073741824 bytes (1.1 GB) copied, 1.51878, 707 MB/s
[Root@iifocus ~]# Mkswap/data/swapfile # #创建交换分区
[Root@iifocus ~]# Swapon/data/swapfile # #激活交换分区
[Root@iifocus ~]# chmod 0600/data/swapfile # #出于安全考虑, set permissions
[Root@iifocus ~]# Free-m
Total used free shared buffers Cached
mem:490 453 36 4 10 360
-/+ buffers/cache:82 407
swap:1023 0 1023
[Root@iifocus ~]# Swapoff/data/swapfile #关闭添加的交换分区
The following additions to the swap partition can take effect immediately, but after the system restarts, you must modify/etc/fstab to append the following:/data/swapfile none swap SW 0 0
[Root@iifocus ~]# Echo '/data/swapfile none swap sw 0 0 ' >>/etc/fstab

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.