From a554ff2e8bee2332f11c3774b7f4e9edbb6f59ec Mon Sep 17 00:00:00 2001 From: Landry Breuil Date: Thu, 4 Dec 2014 20:35:17 +0100 Subject: [PATCH] Repair memory and swap size calculation on OpenBSD. --- src/task-manager-bsd.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/task-manager-bsd.c b/src/task-manager-bsd.c index f37e4c2..e8a06c7 100644 --- a/src/task-manager-bsd.c +++ b/src/task-manager-bsd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2010 Landry Breuil + * Copyright (c) 2008-2014 Landry Breuil * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -241,10 +241,10 @@ gboolean get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64 if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) errx(1,"failed to get vm.uvmexp"); /* cheat : rm = tot used, add free to get total */ - *memory_total = pagetok(uvmexp.npages); - *memory_free = pagetok(uvmexp.free); + *memory_free = pagetok((guint64)uvmexp.free); + *memory_total = pagetok((guint64)uvmexp.npages); *memory_cache = 0; - *memory_buffers = pagetok(uvmexp.npages - uvmexp.free -uvmexp.active); + *memory_buffers = 0; /*pagetok(uvmexp.npages - uvmexp.free - uvmexp.active);*/ #else size = sizeof(vmtotal); if (sysctl(mib, 2, &vmtotal, &size, NULL, 0) < 0) @@ -272,10 +272,12 @@ gboolean get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64 *swap_total = *swap_free = 0; for (i = 0; i < nswap; i++) { if (swdev[i].se_flags & SWF_ENABLE) { - *swap_free += ((swdev[i].se_nblks - swdev[i].se_inuse) / DEV_BSIZE); - *swap_total += (swdev[i].se_nblks / DEV_BSIZE); + *swap_free += (swdev[i].se_nblks - swdev[i].se_inuse); + *swap_total += swdev[i].se_nblks; } } + *swap_total *= DEV_BSIZE; + *swap_free *= DEV_BSIZE; free(swdev); return TRUE; }