1

My machine has roughly 8GB of RAM. Why is min_free_kbytes set to 67584? The kernel code comment says I should expect to see min_free_kbytes set to around 11584. It also says the largest it would set it to is 65536.

$ cat /proc/sys/vm/min_free_kbytes
67584

$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.7Gi       3.2Gi       615Mi       510Mi       3.9Gi       3.7Gi
Swap:         2.0Gi       707Mi       1.3Gi

$ grep -r min_free_kbytes /etc/sysctl*  # No manual configuration
$

$ uname -r  # My kernel version
5.0.17-200.fc29.x86_64

https://elixir.bootlin.com/linux/v5.0.17/source/mm/page_alloc.c#L7567

/*
 * Initialise min_free_kbytes.
 *
 * For small machines we want it small (128k min).  For large machines
 * we want it large (64MB max).  But it is not linear, because network
 * bandwidth does not increase linearly with machine size.  We use
 *
 *  min_free_kbytes = 4 * sqrt(lowmem_kbytes), for better accuracy:
 *  min_free_kbytes = sqrt(lowmem_kbytes * 16)
 *
 * which yields
 *
 * 16MB:    512k
 * 32MB:    724k
 * 64MB:    1024k
 * 128MB:   1448k
 * 256MB:   2048k
 * 512MB:   2896k
 * 1024MB:  4096k
 * 2048MB:  5792k
 * 4096MB:  8192k
 * 8192MB:  11584k
 * 16384MB: 16384k
 */
0

On systems using huge pages, it is recommended that min_free_kbytes is higher and it is tuned with hugeadm --set-recommended-min_free_kbytes. With the introduction of transparent huge page support, this recommended value is also applied [...]

On X86-64 with 4G of memory, min_free_kbytes becomes 67584.

https://www.spinics.net/lists/linux-mm/msg14044.html

/* Ensure 2 pageblocks are free to assist fragmentation avoidance */
recommended_min = pageblock_nr_pages * nr_zones * 2;

/*
 * Make sure that on average at least two pageblocks are almost free
 * of another type, one for a migratetype to fall back to and a
 * second to avoid subsequent fallbacks of other types There are 3
 * MIGRATE_TYPES we care about.
 */
recommended_min += pageblock_nr_pages * nr_zones *
           MIGRATE_PCPTYPES * MIGRATE_PCPTYPES;

linux-5.0.17/mm//mm/khugepaged.c:1862

A "pageblock" is a potential huge page: 2MiB on x86-64. This calculation says min_free is 2MiB * 11 * nr_zones. "With 4G of memory" you have at least three zones: "normal", "DMA32", and "DMA" (DMA16).

2 * 11 * 3 = 66 MiB.

66 MiB = 66 * 1024 = 67584 KiB.

The reason separate "normal" and DMA32 zones appear even on 4G systems is: "the tiny pci32 zone that materialize on 4g systems that relocate some little memory over 4g to make space for the pci32 mmio."

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.