From a76f94c31f5e1b2da03a560e6b379595e0077e1f Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Sun, 16 Mar 2008 19:56:28 +0000 Subject: Add the semi-standard _SC_PHYS_PAGES and _SC_AVPHYS_PAGES, sysconf(3) variable. ok espie@ --- lib/libc/gen/sysconf.3 | 8 ++++++-- lib/libc/gen/sysconf.c | 28 +++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/gen/sysconf.3 b/lib/libc/gen/sysconf.3 index 7bfc70fe446..a083149c00f 100644 --- a/lib/libc/gen/sysconf.3 +++ b/lib/libc/gen/sysconf.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sysconf.3,v 1.22 2007/05/31 19:19:28 jmc Exp $ +.\" $OpenBSD: sysconf.3,v 1.23 2008/03/16 19:56:27 kettenis Exp $ .\" .\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: May 31 2007 $ +.Dd $Mdocdate: March 16 2008 $ .Dt SYSCONF 3 .Os .Sh NAME @@ -148,6 +148,10 @@ does not support the Semaphores Option. .It Li _SC_SEM_VALUE_MAX The maximum value a semaphore may have or \-1 if the system does not support the Semaphores Option. +.It Li _SC_PHYS_PAGES +The number of pages of physical memory. +.It Li _SC_AVPHYS_PAGES +The number of pages of physical memory not currently in use by the system. .El .Sh RETURN VALUES If the call to diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c index 16dbc8c6673..f888ab4c780 100644 --- a/lib/libc/gen/sysconf.c +++ b/lib/libc/gen/sysconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sysconf.c,v 1.8 2005/08/08 08:05:34 espie Exp $ */ +/* $OpenBSD: sysconf.c,v 1.9 2008/03/16 19:56:27 kettenis Exp $ */ /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -198,6 +199,31 @@ yesno: if (sysctl(mib, namelen, &value, &len, NULL, 0) == -1) KERN_SEMINFO_SEMMNS : KERN_SEMINFO_SEMVMX; namelen = 3; break; + +/* Extensions */ + case _SC_PHYS_PAGES: + { + int64_t physmem; + + mib[0] = CTL_HW; + mib[1] = HW_PHYSMEM64; + len = sizeof(physmem); + if (sysctl(mib, namelen, &physmem, &len, NULL, 0) == -1) + return (-1); + return (physmem / getpagesize()); + } + case _SC_AVPHYS_PAGES: + { + struct vmtotal vmtotal; + + mib[0] = CTL_VM; + mib[1] = VM_METER; + len = sizeof(vmtotal); + if (sysctl(mib, namelen, &vmtotal, &len, NULL, 0) == -1) + return (-1); + return (vmtotal.t_free); + } + default: errno = EINVAL; return (-1); -- cgit v1.2.3