Linux swap space
Linux memory uses virtual memory to manage the entire memory. physical RAM physical memory and swap space are the total amount of virtual memory. Swap application scenarios: swap has two main functions: 1. When the system needs more memory space than the physical memory, the kernel will use less memory pages in the memory to switch out the swap partition, so as to empty the physical memory for the current application to run quickly. 2. Some memory pages that are initialized during application startup but are no longer used during subsequent application running, and the system will also switch these pages out to the swap space, to leave a physical memory page to cache other applications or disks. This memory management policy in linux is mainly used to save physical memory and improve the execution speed of the current application. However, swap cannot be used as a means to expand memory, because swap reads and writes are disk io, which is much slower than physical memory io. If the system frequently switches out memory pages to swap partitions, and then swap in swap partitions to the Memory Page, this indicates that the system is searching for idle memory to run multiple applications at the same time, that is to say, the current system task is busy, but the available memory is insufficient. At this time, the only way is to increase the physical memory. Therefore, to determine whether the memory usage of a system has reached a bottleneck, we can evaluate it by observing the swap usage and the si so frequency. Swap space is generated in two forms: swap partition and swap file. In short, the read and write operations on it are disk operations. 1. Swap partitions can be allocated when the operating system is installed, or you can enter the system and use fdisk to divide a swap partition, for example, dividing a/dev/sda5 partition on the disk, then mark it as a swap partition. Then run the mkswap command to create a swap partition File System on the partition: mkswap/dev/sda5 and finally activate the swap partition: swapon/dev/sda5 2. The swap space can also be a file, you only need to use the dd command to create a file allocated size on the disk/home/swapfile to create a swap partition File System mkswap/home/swapfile and finally activate it. the allocation policy swap space has different opinions, some say that the physical memory is twice, some say that the physical memory is the same size, and some say that the physical memory is half. These statements are correct in different scenarios. (Therefore, the examiner may not really understand swap when taking an absolute statement as an interview question.) The following is a red hat distribution strategy: swap shoshould equal 2x physical RAM for up to 2 GB of physical RAM, and then an additional 1x physical RAM for any amount above 2 GB, but never less than 32 MB. so, if: M = Amount of RAM in GB, and S = Amount of swap in GB, then If M <2 S = M * 2 ElseS = M + 2 actually has a pseudo code of if else to calculate swap. Finally, there is a sentence: for systems with really large amounts of RAM (more than 32 GB) you c An likely get away with a smaller swap partition. Note: Important File systems and LVM2 volumes assigned as swap space cannot be in use when being modified. for example, no system processes can be assigned the swap space, as well as no amount of swap shoshould be allocated and used by the kernel. use the free and cat/proc/swaps commands to verify how much and where swap is in use. the best way to achieve swap space modifications is to boot you R system in rescue mode, and then follow the instructions (for each scenario) in the remainder of this chapter. refer to the Red Hat Enterprise Linux Installation Guide for instructions on booting into rescue mode. when prompted to mount the file system, select Skip. the following is another swap allocation policy suitable for most systems and scenarios: A rule of thumb is as follows: 1) for a desktop system, use a swap space of double system memory, as it w Ill allow you to run a large number of applications (values of which may be idle and easily swapped), making more RAM available for the active applications; 2) for a server, have a smaller amount of swap available (say half of physical memory) so that you have some flexibility for swapping when needed, but monitor the amount of swap space used and upgrade your RAM if necessary; 3) for older des Ktop machine (with say only 128 MB), use as much swap space as you can spare, even up to 1 GB. swap optimizes linux 2.6 by adding a new parameter to manage swap, called swappiness. Swappiness can have a value between 0 and 100. Setting this parameter to a lower value will reduce memory swap and improve the responsiveness of some systems. The higher the value, the more pages in the memory, the more swap out to the swap space. The lower the value, the more applications use the physical memory space. Therefore, to maximize the use of physical memory, we should minimize the value of swappiness and even set it to 0. Linux is set to 60 by default, and its value is temporarily modified: echo 10>/proc/sys/vm/swappiness to be permanently modified. You can modify the vm. swappiness parameter in the/etc/sysctl. conf file.