Construction of memory swap space
We know that CPU computing and data storage all use the memory, and the memory can greatly reduce the read time from the disk. However, when the physical memory is insufficient, you need to temporarily move unused programs and data to the memory swap space (swap)
Practice:
1. Create a partition (fdisk, file)
2. format it as swap
3. Start
4. View
Create a partition
Example
[Root @ bogon ~] # Fdisk/dev/sda
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
And coshould in certain setups cause problems:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(E.g., dos fdisk, OS/2 FDISK)
Command (m for help): p
Disk/dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device Boot Start End Blocks Id System
/Dev/sda1*1 13 104391 83 Linux
/Dev/sda2 14 1288 10241437 + 83 Linux
/Dev/sda3 1289 1925 5116702 + 83 Linux
/Dev/sda4 1926 2610 5502262 + 5 Extended
/Dev/sda5 1926 2052 1020096 82 Linux swap/Solaris
/Dev/sda6 2053 2115 506016 83 Linux
Command (m for help): t
Partition number (1-6): 6
Hex code (type L to list codes): 82
Changed system type of partition 6 to 82 (Linux swap/Solaris)
Command (m for help): p
Disk/dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device Boot Start End Blocks Id System
/Dev/sda1*1 13 104391 83 Linux
/Dev/sda2 14 1288 10241437 + 83 Linux
/Dev/sda3 1289 1925 5116702 + 83 Linux
/Dev/sda4 1926 2610 5502262 + 5 Extended
/Dev/sda5 1926 2052 1020096 82 Linux swap/Solaris
/Dev/sda6 2053 2115 506016 82 Linux swap/Solaris
Command (m for help): w
The partition table has been altered!
Calling ioctl () to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: the device or resource is busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
Part [root @ bogon ~] # Partprobe
You need to set the system ID here.
Format
Syntax: mkswap device name
Example
[Root @ bogon ~] # Mkswap/dev/sda6
Setting up swapspace version 1, size = 518156 kB
Start | close
Syntax: swapon [-s] device name
Swapoff device name
Options and parameters:
-S: view all swap file systems
Example 1: Start swap
[Root @ bogon ~] # Swapon/dev/sda6
Example 2: view all swap
[Root @ bogon ~] # Swapon-s
Filename Type Size Used Priority
/Dev/sda5 partition 1020088 0-1
/Dev/sda6 partition 506008 0-2
View
Syntax: free
Example
Total used free shared buffers cached
Mem: 2074972 1380996 693976 0 106740 1000288
-/+ Buffers/cache: 273968 1801004
Swap: 1526096 0 1526096
We can see that Swap space is increased by 1526096.