Bug 252227

Summary: Default value of vm.max_wired is too low since 12.2
Product: Base System Reporter: Vladimir Druzenko <vvd>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Some People CC: grahamperrin, kern, kevans, kib, markj, virtualization, vsasjason
Priority: ---    
Version: 12.2-RELEASE   
Hardware: amd64   
OS: Any   
See Also: https://reviews.freebsd.org/D26424
https://reviews.freebsd.org/D40751

Description Vladimir Druzenko freebsd_committer freebsd_triage 2020-12-28 04:53:58 UTC
On 12.2 look like vm.max_wired is a hard limit for number of wired pages for user processes.
With 48GB of RAM default value is 9727317 - it's 9727317*4096/1024/1024/1024 = ~37.1GB only.
Use case:
1) I see 9GB of free RAM
2) started VM in VirtualBox with 8GB
3) started applications in VM
4) VM freezes with VERR_NO_MEMORY error in VBox.log
5) stopped VM
6) 46*1024*1024*1024/4096 = 12058624
sysctl vm.max_wired=12058624
7) repeat 2) and 3)
8) VM work fine now

/usr/src/sys/vm/vm_pageout.c (2082):
vm_page_max_user_wired = 4 * freecount / 5;

From dmesg: avail memory = 50130972672 (47808 MB)
47808 MB * 4/5/1024 = 37.35GB ~= 37.1GB

IMHO, it's very incorrect!
Something like 99/100 look more correct for VM servers with total RAM 48GB: 47808*99/100/1024 = 46.220625
Comment 1 Vladimir Druzenko freebsd_committer freebsd_triage 2021-01-19 13:56:35 UTC
I want get solution before 13.0 release.

1) Increase default value for vm.max_wired:
vm_page_max_user_wired = 99 * freecount / 100;

Or

2) Write warning with very big and bold letters about this issue in release notes, in documentation on web-site, in manual pages and etc.

It's really critical regression for virtualization servers.

P.S. Sorry for my poor english.
Comment 2 Kyle Evans freebsd_committer freebsd_triage 2021-01-20 15:49:26 UTC
Tagging in some VM folks to start with.
Comment 3 Vladimir Druzenko freebsd_committer freebsd_triage 2021-01-20 16:57:48 UTC
1GB max reserved from wired ram:
-vm_page_max_user_wired = 4 * freecount / 5;
+vm_page_max_user_wired = freecount - min(freecount, 5 * 1048576 / PAGE_SIZE) / 5;
Comment 4 Vladimir Druzenko freebsd_committer freebsd_triage 2021-01-20 17:09:16 UTC
(In reply to VVD from comment #3)
Fast fix.

1GB max reserved from wired ram:
-vm_page_max_user_wired = 4 * freecount / 5;
+vm_page_max_user_wired = freecount - min(freecount, 5 * 1024 * 1024 * 1024 / PAGE_SIZE) / 5;
Comment 6 Vladimir Druzenko freebsd_committer freebsd_triage 2023-06-24 19:17:55 UTC
As a workaround: added entry in pkg-message in "Troubleshooting" about "VERR_NO_MEMORY" in ports emulators/virtualbox-ose{,-legacy}.
Comment 7 commit-hook freebsd_committer freebsd_triage 2023-06-28 12:02:55 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=23eed6a75321443d7c6c45b92b28ff0e314e0496

commit 23eed6a75321443d7c6c45b92b28ff0e314e0496
Author:     Vladimir Druzenko <vvd@FreeBSD.org>
AuthorDate: 2023-06-28 11:57:14 +0000
Commit:     Vladimir Druzenko <vvd@FreeBSD.org>
CommitDate: 2023-06-28 12:02:00 +0000

    emulators/virtualbox-ose{,-legacy}: sort out options

    Sort out options: order (portlint), convert to OPTION_*.
    Add entry in "Troubleshooting" about "VERR_NO_MEMORY".
    Force devel/llvm15 for emulators/virtualbox-ose-legacy on recent 14 with
    llvm16 in base.

    PR:                     200764 252227
    Approved by:            arrowd (mentor)
    Differential Revision:  https://reviews.freebsd.org/D40751

 emulators/virtualbox-ose-legacy/Makefile           | 98 ++++++++++------------
 .../virtualbox-ose-legacy/files/patch-configure    | 26 ++++--
 emulators/virtualbox-ose-legacy/pkg-message        | 30 ++++++-
 emulators/virtualbox-ose/Makefile                  | 91 +++++++++-----------
 emulators/virtualbox-ose/files/patch-configure     | 26 ++++--
 emulators/virtualbox-ose/files/pkg-message.in      | 32 ++++++-
 6 files changed, 176 insertions(+), 127 deletions(-)