Linux – How large are the “watermark” memory reservations on the system

linux-kernelmemory

swappiness

This control is used to define how aggressive the kernel will swap
memory pages. Higher values will increase aggressiveness, lower values
decrease the amount of swap. A value of 0 instructs the kernel not to
initiate swap until the amount of free and file-backed pages is less
than the high water mark in a zone.

linux-5.0/Documentation/sysctl/vm.txt

MemAvailable

An estimate of how much memory is available for starting new
applications, without swapping. Calculated from MemFree,
SReclaimable, the size of the file LRU lists, and the low
watermarks
in each zone.
The estimate takes into account that the system needs some
page cache to function well, and that not all reclaimable
slab will be reclaimable, due to items being in use. The
impact of those factors will vary from system to system.

linux-5.0/Documentation/filesystems/proc.txt (file /proc/meminfo).

What are the current values of the low and high watermarks on my system? And what value are they relative to, e.g. if I want to express them as a percentage?

Best Answer

The watermarks are the low and high values in /proc/zoneinfo, shown in units of pages (4096 bytes on x86).

On my 8GB system, most of the pages are split between the DMA32 zone and the Normal zone. (And everything belongs to Node 0, because it is not a NUMA system).

# cat /proc/zoneinfo
Node 0, zone      DMA
...
  pages free     3961
        min      33
        low      41
        high     49
        spanned  4095
        present  3996
        managed  3961
...
Node 0, zone    DMA32
  pages free     139960
        min      7184
        low      8980
        high     10776
        spanned  1044480
        present  888973
        managed  866327
...
Node 0, zone   Normal
  pages free     33907
        min      31449
        low      33868
        high     36287
        spanned  1173504
        present  1173504
        managed  1140349
...

The watermarks are a proportion of managed.

Very broadly speaking, the watermarks on my system are somewhere between 1% and 3%.

See __setup_per_zone_wmarks(). (Also free_area_init_core(), set_dma_reserve(), and the commit mm: introduce new field "managed_pages" to struct zone.)

The kernel may dynamically increase the watermarks (boost_watermark()) if it appears necessary.

The behaviour is tunable by watermark_boost_factor and watermark_scale_factor in Documentation/sysctl/vm.txt. The scale factor defaults to 0.1%, and the boost factor defaults to 150% of the scale factor.

On my system the watermarks are dominated by min. The per-zone min watermark is set proportionally from min_free_kbytes. The kernel had calculated a default min_free_kbytes value of 67584. Related: an explanation of how this value of min_free_kbytes was calculated.

I do not know why the minimum watermark for the "Normal" zone appeared as 31449 pages = 125796 KiB! This appears to contradict the source code. So far, I can only think it was a bug or a hardware fault. See this question: My low and high watermarks seem higher than predicted by Documentation/sysctl/vm.txt