git: a6cc4c6e98eb - main - vm: make vm.overcommit available externally

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Fri, 16 Sep 2022 20:25:32 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=a6cc4c6e98eb65d7cc15c16262ad6053763fe18a

commit a6cc4c6e98eb65d7cc15c16262ad6053763fe18a
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-09-12 19:31:30 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-09-16 20:22:49 +0000

    vm: make vm.overcommit available externally
    
    Reviewed by:    brooks, imp (previous version)
    Discussed with: markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      2 weeks
    Differential revision:  https://reviews.freebsd.org/D36540
---
 sys/vm/swap_pager.c | 11 +++--------
 sys/vm/vm.h         |  6 ++++++
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c
index 67cc3bf017d2..071296ad6443 100644
--- a/sys/vm/swap_pager.c
+++ b/sys/vm/swap_pager.c
@@ -169,8 +169,8 @@ SYSCTL_PROC(_vm, OID_AUTO, swap_total, CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_MPSAFE
     &swap_total, 0, sysctl_page_shift, "QU",
     "Total amount of available swap storage.");
 
-static int overcommit = 0;
-SYSCTL_INT(_vm, VM_OVERCOMMIT, overcommit, CTLFLAG_RW, &overcommit, 0,
+int vm_overcommit = 0;
+SYSCTL_INT(_vm, VM_OVERCOMMIT, overcommit, CTLFLAG_RW, &vm_overcommit, 0,
     "Configure virtual memory overcommit behavior. See tuning(7) "
     "for details.");
 static unsigned long swzone;
@@ -190,11 +190,6 @@ SYSCTL_COUNTER_U64(_vm_stats_swap, OID_AUTO, free_completed,
     CTLFLAG_RD, &swap_free_completed,
     "Number of deferred frees completed");
 
-/* bits from overcommit */
-#define	SWAP_RESERVE_FORCE_ON		(1 << 0)
-#define	SWAP_RESERVE_RLIMIT_ON		(1 << 1)
-#define	SWAP_RESERVE_ALLOW_NONWIRED	(1 << 2)
-
 static int
 sysctl_page_shift(SYSCTL_HANDLER_ARGS)
 {
@@ -286,7 +281,7 @@ swap_reserve_by_cred(vm_ooffset_t incr, struct ucred *cred)
 	prev = atomic_fetchadd_long(&swap_reserved, pincr);
 	r = prev + pincr;
 	s = swap_total;
-	oc = atomic_load_int(&overcommit);
+	oc = atomic_load_int(&vm_overcommit);
 	if (r > s && (oc & SWAP_RESERVE_ALLOW_NONWIRED) != 0) {
 		s += vm_cnt.v_page_count - vm_cnt.v_free_reserved -
 		    vm_wire_count();
diff --git a/sys/vm/vm.h b/sys/vm/vm.h
index d0cc399dab79..df53dc340ecd 100644
--- a/sys/vm/vm.h
+++ b/sys/vm/vm.h
@@ -165,6 +165,12 @@ extern int old_mlock;
 
 extern int vm_ndomains;
 
+/* bits from overcommit */
+#define	SWAP_RESERVE_FORCE_ON		(1 << 0)
+#define	SWAP_RESERVE_RLIMIT_ON		(1 << 1)
+#define	SWAP_RESERVE_ALLOW_NONWIRED	(1 << 2)
+extern int vm_overcommit;
+
 #ifdef _KERNEL
 struct ucred;
 bool swap_reserve(vm_ooffset_t incr);