Definitions of swap partitions and files in Linux

Source: Internet
Author: User
Article Title: definitions of swap partitions and files in Linux. Linux is a technology channel of the IT lab in China. Including desktop applications, Linux system management, kernel research, embedded systems, open source, and other basic categories when the program requires a larger memory than the physical memory on the computer, whether it is Windows or, for Linux, the solution is to transfer the memory that cannot be stored to the "virtual memory" on the hard disk. Although the speed of the hard disk is much slower than that of the memory, the capacity is at least much larger.
 
In addition, the operating system can also transfer some unactive programs to the virtual memory, leaving more primary memory to buffer the required programs and disks.
 
During Linux installation, a partition is usually used as the "swap partition" of Linux and as the storage partition of the virtual memory content.
 
The swapon-s command allows you to view the virtual memory of the current system. This Command needs to be run by root.
 
Filename Type Size Used Priority
 
/Dev/sda3 partition 1004052 0-1
 
We can see that the current swap partition is/dev/sda3, And the Type in Column 2nd is displayed as partition. It indicates this is a swap partition. Are there other types?
 
Of course, Linux can also use swap files to store virtual memory content like Windows, so that even if you forget to plot swap partitions, it doesn't matter, and it will be more flexible. Next, let's take a look at how to create swap files.
 
The size of the swap file is fixed like that of the SWAp partition. For example, if you want a 1G swap file, you must first create a 1G blank file, we use the dd tool to complete this task:
 
Dd if =/dev/zero of =/swapfile bs = 1024 count = 1048576
 
1048576 is the size of 1 GB in KB. If you want other size files, change this number.
 
The above command will create the swapfile file in the root directory. Then, we need to format it as the format of the swap file:
 
Mkswap/swapfile
 
Then mount the file to apply the swap file immediately:
 
Swapon/swapfile
 
Run swapon-s to view the information:
 
Filename Type Size Used Priority
 
/Dev/sda3 partition 1004052 0-1
 
/Swapfile file 1048486 0-2
 
The Type is file, which is indeed the swap file we created and is already in use by the system.
 
If you want to automatically mount the swap file when starting the instance, add the following sentence to/etc/fstab:
 
/Swapfile none swap sw 0 0
 
In this case, OK.
 
It is often asked how big the virtual memory should be, which is the best cloud for the performance of the primary memory at a few times. In fact, as a general purpose, 1 ~ 2G is on the top. It is impossible to improve the system performance from the virtual memory. It is king to buy a memory stick.
 
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.