Linux Swap partition swap virtual memory deep analysis

Source: Internet
Author: User

The swap partition is a Linux swap partition. The swap partition actually exists on the disk, but the Linux system can use it as memory, and swapping partitions can exchange data with real memory when the physical real memory is low. To put it simply is to take a space out of the disk as a storage area for memory. Although the disk is used as memory, the speed is still the speed of the disk. Imagine one of the following everyday situations:
When you work, you must take the things in the table hole and put them on the desktop, and hold a part of the things in your hand, and then the things in your desk and table hole are exchanging in exchange for the things in your hand and the things on your desk.
You can think so: you take out from the table hole in a "5 years of college entrance examination 3 years of simulation-the comprehensive" put on the desktop, and then pick up the pen to start brushing questions. And then you took it out of a table hole. A "5-year college entrance examination for 3 years of simulation-mathematics" put on the table, ready to write two together (this is the cow??) Haste to anxiety filled walks Ben Haste, аt Shung learn the die? 悄惴⑾帜愕淖烂嫔弦丫?挥辛四敲创蟮目占洌?椭荒馨延镂姆诺阶蓝蠢铮?看文贸隼从镂木鸵?咽?Щ蚴抢碜鄯诺阶蓝粗小?br /> 计算机实际上是这样。 Open a program from disk (a book), the operating system (another person) to run the program into memory (put on the desktop), the CPU will (part) of the program loaded into the register (pick up the pen to start doing questions). Then run a program, the CPU in the two programs between the switch (to finish a math on a different topic). Then run a program, found out of memory (the desktop is not enough) will be memory and disk Exchange partition start Exchange (put the language into the table hole, every time to take out the language will be math or a comprehensive put into the table hole)

0X00 Create a Partition | | Create a piece of file

To create a swap partition, you can have two ways of allocating space, one that is separated directly from the disk and used as a swap, and then formatted as a swap format.
# Partition the disk SDB
Fdisk/dev/sdb
Enter n at the prompt and then prompt for the P or E option, p is the primary partition, only 4 can be created, and E is the logical partition, unlimited number.
We create a logical partition on the line. Then you will be prompted for the start sector of the new partition, using the default, direct carriage return
Next is the terminating sector, which supports the direct input of the sector area code and input size two ways, we generally directly enter the partition size
Enter +512M Press ENTER to create a 512M partition. Now Fdisk is back to the beginning of the prompt, if the previous operation has errors can be entered directly Q exit, if there is no problem can be entered W save and exit.
According to your command, you create a file called SDB *, which is the partition file.
Another way is to create a file and then format the file in swap format
# Create a 512M data type file
DD If=/dev/zero of=swapfile bs=1024 count=523288
# if-> input_file input file of-> output_file output file bs-> block_size block size Count-> count
Explain the special file/Dev/zero
/dev/zero This file is placed in the directory of Linux storage devices, if he is the output source, the output is all binary 0
Cat/dev/zero > Test This command generates a test file and continuously enters binary 0 into the file.

0X01 formatting && activation && mounting swap partitions

# format just the file
# Select commands based on how they are created
mkswap/dev/sdb*
Mkswap Swapfile
# Activate swap partition equivalent to mount
# Select commands based on how they are created
swapon/dev/sdb*
Swapon Swapfile
0X02 set up automatic mount

Everyone is lazy, who would like to manually mount a partition each time? So we can once and for all, set mount to Automatic
# Open configuration file
Vim/etc/fstab
# Add a line like this
# Select commands based on how they are created
/dev/sdb* Swap Defaults 0 0
/home/swapfile Swap Defaults 0 0
Each column of this configuration file is explained below
The first column is the location of the data block file
The second column is the mount point
The third column is the partition type
The fourth column is that the mount parameter is usually default
The fifth column is backup option 0 for the standby 1 rep backup is usually 0
The sixth column is the self-test sequence 0, which means that the self-test 1 and 2 represent self-test if the root partition is to be set to 1, the other partitions can only be 2, usually 0

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.