Article directory
The previous blog [Linux Kernel Memory Management] Partition Partner Allocator ⑤ (Zone Watermark | Zone Watermark Data Structure zone_watermarks Enumeration | Zone Watermark Member in Memory Zone Zone) The concept of zone watermark is explained in this article. The blog starts to analyze the mechanism of water level control according to the water line;
WMARK_HIGH
high water level, WMARK_LOW
low water level, WMARK_MIN
minimum water level, 3 33 watermarks, dividing the "memory area" into4 44 parts;
enum zone_watermarks {
WMARK_MIN,
WMARK_LOW,
WMARK_HIGH,
NR_WMARK
};
#define min_wmark_pages(z) (z->watermark[WMARK_MIN])
#define low_wmark_pages(z) (z->watermark[WMARK_LOW])
#define high_wmark_pages(z) (z->watermark[WMARK_HIGH])
Source code path: linux-4.12\include\linux\mmzone.h #255
1. Waterline control related members in the zone structure ( managed_pages | spanned_pages | present_pages )
In the structure describing the "memory area" struct zone
in , there are several important parameters for controlling the water level of the area :
managed_pages
Member represents the number of physical partner allocator ; it is calculated using the following formula:
z o n e _ e n d _ p f n − z o n e _ s t a r t _ p f n \rm zone\_end\_pfn - zone\_start\_pfn zone_end_pfn−zone_start_pfn
spanned_pages
The member represents the number of all available physical pages in the memory area , including memory holes; it is calculated using the following formula:
s p a n n e d _ p a g e s − h o l e _ p a g e s \rm spanned\_pages - hole\_pages spanned_pages−hole_pages
present_pages
The member represents the number of physical pages in the current memory area , excluding memory holes; it is the physical page managed by the partner allocator; it is calculated using the following formula:
p r e s e n t _ p a g e s − r e s e r v e d _ p a g e s \rm present\_pages - reserved\_pages present_pages−reserved_pages
present_pages
, spanned_pages
, and the managed_pages
three have the following relationship :
spanned_pages
(all available physical pages in the memory region have holes) >
present_pages
(the number of physical pages in the current region has no holes) >
managed_pages
(the number of physical pages managed by the partner allocator)
struct zone
Structure related source code:
struct zone {
/* Read-mostly fields */
/* zone watermarks, access with *_wmark_pages(zone) macros */
unsigned long watermark[NR_WMARK];
...
unsigned long managed_pages;
unsigned long spanned_pages;
unsigned long present_pages;
...
}
Source code path: linux-4.12\include\linux\mmzone.h #427
2. View the memory area watermark in Ubuntu
From the Ubuntu command line, execute
cat /proc/zoneinfo
command, to view "memory area" information;
In the output, the information in the Normal area is as follows:
Node 0, zone Normal
pages free 5754
min 4615
low 5768
high 6921
spanned 262144
present 262144
managed 236760
protection: (0, 0, 0, 0, 0)
The information of the DMA32 area is as follows:
Node 0, zone DMA32
pages free 43834
min 12202
low 15252
high 18302
spanned 1044480
present 782288
managed 759709
protection: (0, 0, 924, 924, 924)
The information of the DMA area is as follows:
Node 0, zone DMA
per-node stats
nr_inactive_anon 10820
nr_active_anon 320858
nr_inactive_file 231022
nr_active_file 234555
nr_unevictable 16
nr_slab_reclaimable 44884
nr_slab_unreclaimable 18674
nr_isolated_anon 0
nr_isolated_file 0
Complete output:
han@ubuntu:~$ cat /proc/zoneinfo
Node 0, zone DMA
per-node stats
nr_inactive_anon 10820
nr_active_anon 320858
nr_inactive_file 231022
nr_active_file 234555
nr_unevictable 16
nr_slab_reclaimable 44884
nr_slab_unreclaimable 18674
nr_isolated_anon 0
nr_isolated_file 0
workingset_nodes 0
workingset_refault 0
workingset_activate 0
workingset_restore 0
workingset_nodereclaim 0
nr_anon_pages 320578
nr_mapped 153680
nr_file_pages 476705
nr_dirty 26878
nr_writeback 0
nr_writeback_temp 0
nr_shmem 11129
nr_shmem_hugepages 0
nr_shmem_pmdmapped 0
nr_file_hugepages 0
nr_file_pmdmapped 0
nr_anon_transparent_hugepages 0
nr_unstable 0
nr_vmscan_write 0
nr_vmscan_immediate_reclaim 0
nr_dirtied 287542
nr_written 244390
nr_kernel_misc_reclaimable 0
pages free 3968
min 77
low 96
high 115
spanned 4095
present 3997
managed 3976
protection: (0, 2445, 3369, 3369, 3369)
nr_free_pages 3968
nr_zone_inactive_anon 0
nr_zone_active_anon 0
nr_zone_inactive_file 0
nr_zone_active_file 0
nr_zone_unevictable 0
nr_zone_write_pending 0
nr_mlock 0
nr_page_table_pages 0
nr_kernel_stack 0
nr_bounce 0
nr_zspages 0
nr_free_cma 0
numa_hit 1
numa_miss 0
numa_foreign 0
numa_interleave 0
numa_local 1
numa_other 0
pagesets
cpu: 0
count: 0
high: 0
batch: 1
vm stats threshold: 6
cpu: 1
count: 0
high: 0
batch: 1
vm stats threshold: 6
cpu: 2
count: 0
high: 0
batch: 1
vm stats threshold: 6
cpu: 3
count: 0
high: 0
batch: 1
vm stats threshold: 6
node_unreclaimable: 0
start_pfn: 1
Node 0, zone DMA32
pages free 43834
min 12202
low 15252
high 18302
spanned 1044480
present 782288
managed 759709
protection: (0, 0, 924, 924, 924)
nr_free_pages 43834
nr_zone_inactive_anon 8454
nr_zone_active_anon 245858
nr_zone_inactive_file 181846
nr_zone_active_file 177532
nr_zone_unevictable 4
nr_zone_write_pending 26534
nr_mlock 4
nr_page_table_pages 5641
nr_kernel_stack 8472
nr_bounce 0
nr_zspages 0
nr_free_cma 0
numa_hit 4159869
numa_miss 0
numa_foreign 0
numa_interleave 192366
numa_local 4159869
numa_other 0
pagesets
cpu: 0
count: 50
high: 378
batch: 63
vm stats threshold: 36
cpu: 1
count: 335
high: 378
batch: 63
vm stats threshold: 36
cpu: 2
count: 300
high: 378
batch: 63
vm stats threshold: 36
cpu: 3
count: 121
high: 378
batch: 63
vm stats threshold: 36
node_unreclaimable: 0
start_pfn: 4096
Node 0, zone Normal
pages free 5754
min 4615
low 5768
high 6921
spanned 262144
present 262144
managed 236760
protection: (0, 0, 0, 0, 0)
nr_free_pages 5754
nr_zone_inactive_anon 2366
nr_zone_active_anon 75000
nr_zone_inactive_file 49176
nr_zone_active_file 57023
nr_zone_unevictable 12
nr_zone_write_pending 344
nr_mlock 12
nr_page_table_pages 5556
nr_kernel_stack 7096
nr_bounce 0
nr_zspages 0
nr_free_cma 0
numa_hit 839519
numa_miss 0
numa_foreign 0
numa_interleave 223408
numa_local 839519
numa_other 0
pagesets
cpu: 0
count: 253
high: 378
batch: 63
vm stats threshold: 24
cpu: 1
count: 202
high: 378
batch: 63
vm stats threshold: 24
cpu: 2
count: 325
high: 378
batch: 63
vm stats threshold: 24
cpu: 3
count: 291
high: 378
batch: 63
vm stats threshold: 24
node_unreclaimable: 0
start_pfn: 1048576
Node 0, zone Movable
pages free 0
min 0
low 0
high 0
spanned 0
present 0
managed 0
protection: (0, 0, 0, 0, 0)
Node 0, zone Device
pages free 0
min 0
low 0
high 0
spanned 0
present 0
managed 0
protection: (0, 0, 0, 0, 0)
han@ubuntu:~$