What is the swap space in Linux

10.5 Swap: The swap memory

Next:10.5.1 Set up swap spaceUp:10. Partitions and files Previous:10.4.2 fdformat
Memory is still expensive today. For this reason, especially in multitasking systems, the programs often require more memory than is available. To counteract this, the operating systems do not work with the physical main memory but with the virtual main memory. The virtual main memory consists of the RAM and a memory area on the hard disk. In Linux, the main memory on the hard disk is implemented by the swap partition. If the operating system requires more memory than is available, it swaps parts of the main memory onto the swap partition.

This method of increasing memory is called Paging designated. When the physical memory becomes scarce, memory pages are transferred to the hard disk. These memory pages usually have a size of 4096 bytes, i.e. 4 KByte. If necessary, the swapped-out pages are then reloaded into the physical main memory.

Of course, such a swap memory cannot replace physical memory. Access to the hard disk is on average 10,000 times slower than access to RAM memory. The swap memory works well when several programs are running at the same time. In the age of GUI programs, running programs often only use memory while they do not use much. This is because most of the time they are just waiting for the user to finally do something. When switching between the programs, you clearly notice the delay in writing and writing back the memory pages. The actual program execution of the active program is just as fast as it is otherwise, since its memory pages are located in the physical main memory.

There is a rule of thumb for the size of the swap partition. The swap memory should always be twice as large as the built-in main memory. The size of the swap partitions should not be less than 16 MB in order to ensure that the operating system functions properly.

Previously, the maximum size of the swap partition was limited to 128 MB. However, up to 16 swap partitions can be set up, so that a total capacity of 2 GB was available for the swap file. As of Kernel 2.1.117, the swap partition can be up to 2 GB in size. The number of swap partitions can be specified when the kernel is compiled. The corresponding entry in the 2.4.18 kernel10.3 in the kernel header file is:

#define MAX_SWAPFILES 32

After that, up to 32 swap partitions should be possible with this kernel. The kernel supports a maximum of 64 swap partitions.

To increase the access speed, it makes sense to distribute the swap partitions over several disks. Since the individual partitions are then pulled together to form a logical area, they practically form a RAID level 0. With IDE disks, it is then an advantage if both disks are attached to a separate controller.

If you think you have enough memory, then you can also work with the formula `` one to one ''. This is particularly useful for server systems that have been equipped with an extra large amount of memory in order to reduce hard disk access.

However, if you think you have too little space, you can set the swap partition to three times the memory size.10.4

If you do not have enough space or partition space on the hard disk, you can also use a swap file (swap file) set up. However, this is not as effective as having a separate partition. If your computer has 4 MB or less RAM, you definitely need a swap partition. examples

Your system has 8 MB of RAM. You therefore create a swap partition of 16 MB. The available virtual memory is then 24 MB.

You have a computer with 128 MB RAM. According to the formula, you should set up a swap space of 256MB. Since a swap partition can only be 128 MB in size, create two partitions with 128 MB each.

A file server was equipped with 512 MB RAM for fast file access. Since access to the hard disk should be avoided as far as possible, four swap partitions of 128 MB each are sufficient.

Your old 486 computer is to be used as a router. Since it only has 4 MB RAM, you have to set up a swap partition in order to be able to install Linux. The swap partition should be at least 16 MB in size.


Next:10.5.1 Set up swap spaceUp:10. Partitions and files Previous:10.4.2 fdformat