View relevant parameters for swap memory in Linux

Source: Internet
Author: User

The main source of the content: Linux Memory Recovery and exchange

The Linux environments viewed by the commands are: Linux SUSE-33 2.6.32.12-0.7-defaul

Zone

The relevant logic for memory management is in zone, where zone means memory partition management. Linux divides memory into multiple zones, primarily with direct access (DMA), General (normal), and high-end memory (highmemory). The kernel accesses different areas of the memory because the hardware structure factors have addressing and efficiency differences. If you are on a NUMA architecture, the memory managed by different CPUs is also a different zone.

/proc/zoneinfo?

View the current system's memory water level markings.

[Email protected]:/sbin> cat/proc/ZoneinfoNode0, Zone DMAPages Free 3929Min 7Low 7High 10Scanned 0spanned 4096Present 3832Nr_free_pages 3929Nr_inactive_anon 0Nr_active_anon 0Nr_inactive_file 0Nr_active_file 0Nr_unevictable 0Nr_mlock 0Nr_anon_pages 0nr_mapped 0Nr_file_pages 0Nr_dirty 0Nr_writeback 0Nr_slab_reclaimable 0Nr_slab_unreclaimable 0Nr_page_table_pages 0Nr_kernel_stack 0Nr_unstable 0Nr_bounce 0Nr_vmscan_write 0Nr_writeback_temp 0Nr_isolated_anon 0Nr_isolated_file 0Nr_shmem 0Numa_hit 1Numa_miss 0Numa_foreign 0Numa_interleave 0Numa_local 1Numa_other 0Protection: (0, 3768, 4016, 4016) Pagesets cpu:0count:0high:0Batch:1VM Stats Threshold:4Cpu:1count:0high:0Batch:1VM Stats Threshold:4All_unreclaimable:1Prev_priority:12start_pfn:0Inactive_ratio:1Node 0, Zone DMA32Pages Free 16200Min 1898Low 1898High 2847Scanned 0Spanned 1044480Present 964664Nr_free_pages 16200Nr_inactive_anon 143811Nr_active_anon 698860Nr_inactive_file 18465Nr_active_file 16433Nr_unevictable 0Nr_mlock 0Nr_anon_pages 830848nr_mapped 2043Nr_file_pages 46721Nr_dirty 13Nr_writeback 0Nr_slab_reclaimable 5649Nr_slab_unreclaimable 3655Nr_page_table_pages 6618Nr_kernel_stack 371Nr_unstable 0Nr_bounce 0Nr_vmscan_write 26548123Nr_writeback_temp 0Nr_isolated_anon 0Nr_isolated_file 0Nr_shmem 18Numa_hit 12025255812Numa_miss 0Numa_foreign 0Numa_interleave 0Numa_local 12025255812Numa_other 0Protection: (0, 0, 248, 248) Pagesets cpu:0count:130high:186Batch:31VM Stats threshold:24Cpu:1count:133high:186Batch:31VM Stats threshold:24all_unreclaimable:0Prev_priority:12start_pfn:4096Inactive_ratio:5Node 0, Zone NormalPages Free 153Min 125Low 125High 187Scanned 0Spanned 64512Present 54158Nr_free_pages 153Nr_inactive_anon 11135Nr_active_anon 9662Nr_inactive_file 2144Nr_active_file 2137Nr_unevictable 0Nr_mlock 0Nr_anon_pages 18039nr_mapped 1155Nr_file_pages 7039Nr_dirty 26Nr_writeback 0Nr_slab_reclaimable 690 nr_slab_unreclaimable 21507  nr_page_table_pages 1063  nr_kernel_stack 205  nr_unstable 0  Nr_bounce 0  nr_vmscan_write 1879470  nr_writeback_temp 0  nr_isolated_anon 0  nr_isolated_file 0< span> nr_shmem 1  numa_hit 443690329  numa_miss 0  numa_foreign 0  numa_interleave 8539  Numa_lo Cal 443690329  numa_other 0  Protection: (0, 0, 0, 0 ) pagesets cpu:0  count:89  high:90  Batch:15  vm stats threshold:8  cpu:1  count:47  high:90  batch:15  vm stats Threshol D:8  all_unreclaimable:0  prev_priority:12  start_pfn:1048576  inactive_ratio:1  [email& nbsp;protected]:/sbin>              
from the top you can see that there is DMA, DMA32, normal these three memory areas. 

Swappiness?

/proc/sys/vm/swappiness This file, the value of this file is used to define how aggressively the kernel uses swap, and is a parameter that can be used to adjust swap-related parameters. The higher the value, the more aggressively the kernel will use swap, and the more must not the value, the less aggressive it will be to swap. The default value for this file is 60, and the range of values available is 0-100.

1) swappiness This parameter is actually to instruct the kernel to empty the memory when it is more inclined to empty file-backed memory or more prone to the exchange of anonymous pages. Of course, this is only a tendency, refers to in the two are enough cases, more willing to use which, if not enough, then the exchange is to be exchanged.

2) If swappiness is set to 100, then anonymous pages and files will be recycled with the same priority . Obviously, the use of empty files will help reduce the IO pressure that can be caused by memory recycling . Because if the data in the file-backed is not dirty data, then can not write back, so that no IO occurs, and once exchanged, it will certainly cause IO. Therefore, the system defaults to set the value of Swappiness to 60, so that when the memory is reclaimed, the file-backed file cache memory will be emptied more, the kernel will be more prone to cache emptying rather than swapping.

3) If this value is 0, the swap will not occur in the presence of free and file-backed (the size of the file Map page) until the total number of pages used is less than the high water mark (higher water mark). Swap may occur with the remaining memory.

[Email protected] :/proc/sys/vm>/proc/sys/vm/
60

Min_free_kbytes?

/proc/sys/vm/min_free_kbytes, this parameter itself determines the value of watermark[min] in each zone in the system, The kernel then calculates the low and high water levels for each zone according to the size of min and the memory size of each zone.

[Email protected] :/proc/sys/vm> cat/proc/sys/vm/8127

Zone_reclaim_mode?

The Zone_reclaim_mode mode is a pattern that begins to join the kernel at the end of the 2.6 release and can be used to manage when memory is exhausted inside a memory area (zone), whether it is a memory recycle from its internal or an option that can be reclaimed from another zone, and we can/proc/ This parameter is adjusted by the Sys/vm/zone_reclaim_mode file.

[Email protected] :/proc/sys/vm> cat/proc/sys/vm/zone_reclaim_mode0

When memory is requested, the kernel does not have enough memory available in the current zone, depending on the settings of the Zone_reclaim_mode to decide whether to find free memory from the next zone or to recycle within the zone. A value of 0 indicates that available memory can be found from the next zone, and non-0 is reclaimed locally. The value that this file can set and its meaning is as follows:

    1. echo 0 >/proc/sys/vm/zone_reclaim_mode: means to turn off Zone_reclaim mode and reclaim memory from other zone or NUMA nodes.
    2. echo 1 >/proc/sys/vm/zone_reclaim_mode: Indicates that Zone_reclaim mode is turned on so that memory reclamation occurs only within the local node.
    3. Echo 2 >/proc/sys/vm/zone_reclaim_mode: When the memory is reclaimed locally, the dirty data in the cache can be written back to the hard disk to reclaim memory.
    4. echo 4 >/proc/sys/vm/zone_reclaim_mode: Memory can be reclaimed by swap.

Different parameter configurations can have different effects on the memory usage of other memory nodes in a NUMA environment. By default, the Zone_reclaim mode is off. This can improve efficiency in many scenarios, such as file servers, or applications that rely on memory caches for more. This scenario relies on memory cache speed more than the process itself relies on memory speed, so we would rather let the memory be used from another zone and not be willing to clear the local cache.

You can turn on Zone_reclaim mode if you determine that the memory requirements are greater than the cache and try to avoid performance degradation caused by memory accesses across NUMA nodes. The page allocator will first reclaim recyclable memory that is easy to recycle (mainly the page cache pages that are not currently used), and then reclaim other memory.

Opening writeback in local recycle mode may cause a large amount of dirty data writeback processing on other memory nodes. If a memory zone is full, the writeback of dirty data can also cause process processing speed to be affected, resulting in processing bottlenecks. This reduces the performance of the processes associated with one memory node because the process is no longer able to use memory on other nodes. However, the isolation between nodes is increased, and the related processes running on other nodes will not degrade performance because of memory reclamation on the other node.

Min_unmapped_ratio

This parameter is only valid on the core of the NUMA architecture. This value represents the percentage of the total number of pages per memory area on NUMA. In Zone_reclaim_mode mode, zone memory reclamation occurs only if memory usage in the relevant area reaches this percentage. When Zone_reclaim_mode is set to 4, the kernel compares all of the file-backed and anonymous mapping pages, including whether the Swapcache occupied pages and the total memory usage of TMPFS files exceeds this percentage. In the case of other settings, only unmapped pages based on generic files are compared, regardless of other related pages.

[Email protected] :/proc/sys/vm> cat/proc/sys/vm/min_unmapped_ratio1

Page-cluster

The page-cluster is used to control the number of consecutive pages to be read when swapping data from swap space, which is equivalent to pre-reading the swap space. The continuation here refers to the continuous on the swap space, not on the memory address. Because the swap space is usually on the hard disk, continuous reading of the hard disk device will reduce the head's addressing and improve the reading efficiency. The value set in this file is the exponent of 2. That is, if set to 0, the pre-read swap page is 2 0, which equals 1 pages. If set to 3, it is 2 of 3, equal to 8 pages. At the same time, setting to 0 also means turning off the read-ahead feature.

The file default value is 3. We can set the number of pre-read page sizes based on our system load status.

[Email protected] :/proc/sys/vm> cat/proc/sys/vm/page-cluster3

View relevant parameters for swap memory in Linux

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.