Module Name: src Committed By: chs Date: Sat Dec 7 23:19:08 UTC 2024
Modified Files: src/sys/uvm: uvm_km.c Log Message: kmem: improve behavior when using all of physical memory as kmem On systems where kmem does not need to be limited by kernel virtual space (essentially 64-bit platforms), we currently try to size the "kmem" space to be big enough for all of physical memory to be allocated as kmem, which really means that we will always run short of physical memory before we run out of kernel virtual space. However this does not take into account that uvm_km_va_starved_p() starts reporting that we are low on kmem virtual space when we have used 90% of it, in an attempt to avoid kmem space becoming too fragmented, which means on large memory systems we will still start reacting to being short of virtual space when there is plenty of physical memory still available. Fix this by overallocating the kmem space by a factor of 10/9 so that we always run low on physical memory first, as we want. To generate a diff of this commit: cvs rdiff -u -r1.165 -r1.166 src/sys/uvm/uvm_km.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/uvm/uvm_km.c diff -u src/sys/uvm/uvm_km.c:1.165 src/sys/uvm/uvm_km.c:1.166 --- src/sys/uvm/uvm_km.c:1.165 Sun Apr 9 09:00:56 2023 +++ src/sys/uvm/uvm_km.c Sat Dec 7 23:19:07 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: uvm_km.c,v 1.165 2023/04/09 09:00:56 riastradh Exp $ */ +/* $NetBSD: uvm_km.c,v 1.166 2024/12/07 23:19:07 chs Exp $ */ /* * Copyright (c) 1997 Charles D. Cranor and Washington University. @@ -152,7 +152,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uvm_km.c,v 1.165 2023/04/09 09:00:56 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uvm_km.c,v 1.166 2024/12/07 23:19:07 chs Exp $"); #include "opt_uvmhist.h" @@ -227,7 +227,14 @@ kmeminit_nkmempages(void) } #if defined(NKMEMPAGES_MAX_UNLIMITED) && !defined(KMSAN) - npages = physmem; + /* + * The extra 1/9 here is to account for uvm_km_va_starved_p() + * wanting to keep 10% of kmem virtual space free. + * The intent is that on "unlimited" platforms we should be able + * to allocate all of physical memory as kmem without behaving + * as though we running short of kmem virtual space. + */ + npages = (physmem * 10) / 9; #else #if defined(KMSAN)