[libgtop] freebsd: rework system memory usage
- From: Ting-Wei Lan <lantw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgtop] freebsd: rework system memory usage
- Date: Fri, 10 Jul 2015 16:22:16 +0000 (UTC)
commit a206cfc72822ab45d19d9700ccb348fa1cd290d9
Author: Ting-Wei Lan <lantw src gnome org>
Date: Sat May 2 21:36:22 2015 +0800
freebsd: rework system memory usage
Change the value of memory usage from:
Used = Wired
Free = Total - Wired
Shared = 0
Buffer = 0
Cached = Cache
User = Wired - Cache
Locked = Not Supported
To:
Used = Total - Free
Free = Free
Shared = 0
Buffer = Buf
Cached = Cache
User = Active + Wired
Locked = Not Supported
The left-hand side means fields in the glibtop_mem struct and the right-hand
side means the value showed by `top' command. This change should make the value
showed by gnome-system-monitor, which uses `User' field, become closer to
the real memory usage.
All sysctlbyname code in sysdeps/freebsd/mem.c has been moved to separate
functions to make the code cleaner.
sysdeps/freebsd/mem.c | 67 ++++++++++++++++++++++++++++--------------------
1 files changed, 39 insertions(+), 28 deletions(-)
---
diff --git a/sysdeps/freebsd/mem.c b/sysdeps/freebsd/mem.c
index 3e1d4ab..a9e9d25 100644
--- a/sysdeps/freebsd/mem.c
+++ b/sysdeps/freebsd/mem.c
@@ -45,46 +45,57 @@ _glibtop_init_mem_s (glibtop *server)
server->sysdeps.mem = _glibtop_sysdeps_mem;
}
+static gulong mem_get_by_bytes (glibtop *server, const char *name) {
+ gulong result = 0;
+ size_t len = sizeof (result);
+
+ if (sysctlbyname (name, &result, &len, NULL, 0)) {
+ glibtop_warn_io_r (server, "sysctl (%s)", name);
+ }
+ return result;
+}
+
+static gulong mem_get_by_pages (glibtop *server, const char *name) {
+ guint result = 0;
+ size_t len = sizeof (result);
+
+ if (sysctlbyname (name, &result, &len, NULL, 0)) {
+ glibtop_warn_io_r (server, "sysctl (%s)", name);
+ }
+ return (gulong) result * pagesize;
+}
+
void
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
{
gulong memtotal;
- guint memused;
- gulong buffers;
- guint cached;
- size_t len;
+ gulong memactive;
+ gulong meminactive;
+ gulong memwired;
+ gulong memcached;
+ gulong membuffer;
+ gulong memfree;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
memset (buf, 0, sizeof *buf);
- len = sizeof (memtotal);
- if (sysctlbyname ("hw.physmem", &memtotal, &len, NULL, 0)) {
- glibtop_warn_io_r (server, "sysctl (hw.physmem)");
- return;
- }
-
- len = sizeof (memused);
- if (sysctlbyname ("vm.stats.vm.v_wire_count", &memused, &len, NULL, 0)) {
- glibtop_warn_io_r (server, "sysctl (vm.stats.vm.v_wire_count)");
- return;
- }
-
- len = sizeof (cached);
- if (sysctlbyname ("vm.stats.vm.v_cache_count", &cached, &len, NULL, 0)) {
- glibtop_warn_io_r (server, "sysctl (vm.stats.vm.v_cache_count)");
- return;
- }
-
- buffers = 0;
+ memtotal = mem_get_by_bytes (server, "hw.physmem");
+ memactive = mem_get_by_pages (server, "vm.stats.vm.v_active_count");
+ meminactive = mem_get_by_pages (server, "vm.stats.vm.v_inactive_count");
+ memwired = mem_get_by_pages (server, "vm.stats.vm.v_wire_count");
+ memcached = mem_get_by_pages (server, "vm.stats.vm.v_cache_count");
+ membuffer = mem_get_by_bytes (server, "vfs.bufspace");
+ memfree = mem_get_by_pages (server, "vm.stats.vm.v_free_count");
buf->total = memtotal;
- buf->used = (memused * (gulong) pagesize);
- buf->free = (buf->total - buf->used);
+ buf->used = memtotal - memfree;
+ buf->free = memfree;
buf->shared = 0;
- buf->cached = (cached * (gulong) pagesize);
- buf->buffer = buffers;
+ buf->buffer = membuffer;
+ buf->cached = memcached;
+ buf->locked = 0;
- buf->user = buf->total - buf->free - buf->cached - buf->buffer;
+ buf->user = memactive + memwired;
buf->flags = _glibtop_sysdeps_mem;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]