Module Name: src Committed By: simonb Date: Wed Oct 25 08:19:34 UTC 2023
Modified Files: src/lib/libc/gen: sysconf.3 sysconf.c src/sys/sys: unistd.h src/usr.bin/getconf: getconf.c Log Message: Add _SC_AVPHYS_PAGES. getconf(1) add this and SC_PHYS_PAGES. libc: Use vm.uvmexp2 over vm.meter is it's twice as fast on my setup. getconf.3: Tidy up wording for SC_PHYS_PAGES. To generate a diff of this commit: cvs rdiff -u -r1.51 -r1.52 src/lib/libc/gen/sysconf.3 cvs rdiff -u -r1.43 -r1.44 src/lib/libc/gen/sysconf.c cvs rdiff -u -r1.63 -r1.64 src/sys/sys/unistd.h cvs rdiff -u -r1.35 -r1.36 src/usr.bin/getconf/getconf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/gen/sysconf.3 diff -u src/lib/libc/gen/sysconf.3:1.51 src/lib/libc/gen/sysconf.3:1.52 --- src/lib/libc/gen/sysconf.3:1.51 Wed Aug 3 12:40:42 2016 +++ src/lib/libc/gen/sysconf.3 Wed Oct 25 08:19:34 2023 @@ -1,4 +1,4 @@ -.\" $NetBSD: sysconf.3,v 1.51 2016/08/03 12:40:42 ryoon Exp $ +.\" $NetBSD: sysconf.3,v 1.52 2023/10/25 08:19:34 simonb Exp $ .\" .\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)sysconf.3 8.3 (Berkeley) 4/19/94 .\" -.Dd August 3, 2016 +.Dd October 25, 2023 .Dt SYSCONF 3 .Os .Sh NAME @@ -291,9 +291,15 @@ The number of processors configured. .It Li _SC_NPROCESSORS_ONLN The number of processors online (capable of running processes). .It Li _SC_PHYS_PAGES -The amount of physical memory on the system in +The total number of pages of physical memory. +See .Li _SC_PAGESIZE -bytes. +for the system page size. +.It Li _SC_AVPHYS_PAGES +The number of available pages of physical memory. +See +.Li _SC_PAGESIZE +for the system page size. .It Li _SC_TIMER_MAX The number of timers available for .Xr timer_create 2 . Index: src/lib/libc/gen/sysconf.c diff -u src/lib/libc/gen/sysconf.c:1.43 src/lib/libc/gen/sysconf.c:1.44 --- src/lib/libc/gen/sysconf.c:1.43 Sun Dec 15 20:25:25 2019 +++ src/lib/libc/gen/sysconf.c Wed Oct 25 08:19:34 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: sysconf.c,v 1.43 2019/12/15 20:25:25 joerg Exp $ */ +/* $NetBSD: sysconf.c,v 1.44 2023/10/25 08:19:34 simonb Exp $ */ /*- * Copyright (c) 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)sysconf.c 8.2 (Berkeley) 3/20/94"; #else -__RCSID("$NetBSD: sysconf.c,v 1.43 2019/12/15 20:25:25 joerg Exp $"); +__RCSID("$NetBSD: sysconf.c,v 1.44 2023/10/25 08:19:34 simonb Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -46,6 +46,7 @@ __RCSID("$NetBSD: sysconf.c,v 1.43 2019/ #include <sys/sysctl.h> #include <sys/time.h> #include <sys/resource.h> +#include <uvm/uvm_extern.h> #include <errno.h> #include <limits.h> @@ -79,6 +80,7 @@ sysconf(int name) int mib[CTL_MAXNAME], value; unsigned int mib_len; struct clockinfo tmpclock; + struct uvmexp_sysctl uvmexp; static int clk_tck; len = sizeof(value); @@ -380,6 +382,13 @@ yesno: if (sysctl(mib, mib_len, &value, return sysctl(mib, 2, &mem, &len, NULL, 0) == -1 ? -1 : (long)(mem / _getpagesize()); + case _SC_AVPHYS_PAGES: + len = sizeof(uvmexp); + mib[0] = CTL_VM; + mib[1] = VM_UVMEXP2; + return sysctl(mib, 2, &uvmexp, &len, NULL, 0) == -1 ? -1 : + (long)(uvmexp.free); + /* Native */ case _SC_SCHED_RT_TS: if (sysctlgetmibinfo("kern.sched.rtts", &mib[0], &mib_len, Index: src/sys/sys/unistd.h diff -u src/sys/sys/unistd.h:1.63 src/sys/sys/unistd.h:1.64 --- src/sys/sys/unistd.h:1.63 Sat May 16 18:31:53 2020 +++ src/sys/sys/unistd.h Wed Oct 25 08:19:34 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: unistd.h,v 1.63 2020/05/16 18:31:53 christos Exp $ */ +/* $NetBSD: unistd.h,v 1.64 2023/10/25 08:19:34 simonb Exp $ */ /* * Copyright (c) 1989, 1993 @@ -328,7 +328,8 @@ #define _SC_RTSIG_MAX 95 /* Extensions found in Solaris and Linux. */ -#define _SC_PHYS_PAGES 121 +#define _SC_PHYS_PAGES 121 +#define _SC_AVPHYS_PAGES 122 #ifdef _NETBSD_SOURCE /* Commonly provided sysconf() extensions */ Index: src/usr.bin/getconf/getconf.c diff -u src/usr.bin/getconf/getconf.c:1.35 src/usr.bin/getconf/getconf.c:1.36 --- src/usr.bin/getconf/getconf.c:1.35 Thu Dec 19 19:11:50 2013 +++ src/usr.bin/getconf/getconf.c Wed Oct 25 08:19:34 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: getconf.c,v 1.35 2013/12/19 19:11:50 rmind Exp $ */ +/* $NetBSD: getconf.c,v 1.36 2023/10/25 08:19:34 simonb Exp $ */ /*- * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: getconf.c,v 1.35 2013/12/19 19:11:50 rmind Exp $"); +__RCSID("$NetBSD: getconf.c,v 1.36 2023/10/25 08:19:34 simonb Exp $"); #endif /* not lint */ #include <err.h> @@ -177,6 +177,10 @@ static const struct conf_variable conf_t { "GETGR_R_SIZE_MAX", SYSCONF, _SC_GETGR_R_SIZE_MAX }, { "GETPW_R_SIZE_MAX", SYSCONF, _SC_GETPW_R_SIZE_MAX }, + /* Extensions found in Solaris and Linux. */ + { "SC_PHYS_PAGES", SYSCONF, _SC_PHYS_PAGES }, + { "SC_AVPHYS_PAGES", SYSCONF, _SC_AVPHYS_PAGES }, + #ifdef _NETBSD_SOURCE /* Commonly provided extensions */ { "NPROCESSORS_CONF", SYSCONF, _SC_NPROCESSORS_CONF },