summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2016-03-07 15:03:50 -0300
committerHisham Muhammad <hisham@gobolinux.org>2016-03-07 15:03:50 -0300
commitef1e62d1fad91bd53e7d608b16816ec96d0bbe62 (patch)
tree1e173f09e4c5247a36a6561c749d859450192651
parent453105e77a961f0c4fc075c29d579ed5585e949c (diff)
parent4ad7aa6432f580a4178204400f070073fcbf120b (diff)
Merge branch 'juanfra684-openbsd-mem-used'
-rw-r--r--openbsd/OpenBSDProcessList.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c
index 548a1eea..14d9c2dc 100644
--- a/openbsd/OpenBSDProcessList.c
+++ b/openbsd/OpenBSDProcessList.c
@@ -10,19 +10,20 @@ in the source distribution for its full text.
#include "OpenBSDProcessList.h"
#include "OpenBSDProcess.h"
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/types.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/mount.h>
#include <sys/param.h>
#include <sys/proc.h>
+#include <sys/resource.h>
#include <sys/sysctl.h>
+#include <sys/types.h>
#include <sys/user.h>
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
#include <limits.h>
+#include <stdlib.h>
#include <string.h>
-#include <sys/resource.h>
+#include <unistd.h>
/*{
@@ -114,15 +115,27 @@ void ProcessList_delete(ProcessList* this) {
static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
static int uvmexp_mib[] = {CTL_VM, VM_UVMEXP};
struct uvmexp uvmexp;
- size_t size = sizeof(uvmexp);
+ size_t size_uvmexp = sizeof(uvmexp);
- if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL, 0) < 0) {
+ if (sysctl(uvmexp_mib, 2, &uvmexp, &size_uvmexp, NULL, 0) < 0) {
err(1, "uvmexp sysctl call failed");
}
- pl->usedMem = uvmexp.active * PAGE_SIZE_KB;
pl->totalMem = uvmexp.npages * PAGE_SIZE_KB;
+ // Taken from OpenBSD systat/iostat.c, top/machine.c and uvm_sysctl(9)
+ static int bcache_mib[] = {CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT};
+ struct bcachestats bcstats;
+ size_t size_bcstats = sizeof(bcstats);
+
+ if (sysctl(bcache_mib, 3, &bcstats, &size_bcstats, NULL, 0) < 0) {
+ err(1, "cannot get vfs.bcachestat");
+ }
+
+ pl->cachedMem = bcstats.numbufpages * PAGE_SIZE_KB;
+ pl->freeMem = uvmexp.free * PAGE_SIZE_KB;
+ pl->usedMem = (uvmexp.npages - uvmexp.free - uvmexp.paging) * PAGE_SIZE_KB;
+
/*
const OpenBSDProcessList* opl = (OpenBSDProcessList*) pl;

© 2014-2024 Faster IT GmbH | imprint | privacy policy