From 0eb54384593a0ae5944731e0e7cd527970b05b73 Mon Sep 17 00:00:00 2001 From: er-azh <80633916+er-azh@users.noreply.github.com> Date: Sat, 4 Feb 2023 15:56:06 +0330 Subject: Implement shared memory for FreeBSD --- freebsd/FreeBSDProcessList.c | 10 ++++++++++ freebsd/Platform.c | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'freebsd') diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 2575d8fe..b7643222 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -25,6 +25,7 @@ in the source distribution for its full text. #include #include #include +#include #include "CRT.h" #include "Compat.h" @@ -49,6 +50,7 @@ static int MIB_vm_stats_vm_v_active_count[4]; static int MIB_vm_stats_vm_v_cache_count[4]; static int MIB_vm_stats_vm_v_inactive_count[4]; static int MIB_vm_stats_vm_v_free_count[4]; +static int MIB_vm_vmtotal[2]; static int MIB_vfs_bufspace[2]; @@ -82,6 +84,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* dynamicMeters, H len = 4; sysctlnametomib("vm.stats.vm.v_cache_count", MIB_vm_stats_vm_v_cache_count, &len); len = 4; sysctlnametomib("vm.stats.vm.v_inactive_count", MIB_vm_stats_vm_v_inactive_count, &len); len = 4; sysctlnametomib("vm.stats.vm.v_free_count", MIB_vm_stats_vm_v_free_count, &len); + MIB_vm_vmtotal[0] = CTL_VM; + MIB_vm_vmtotal[1] = VM_TOTAL; + len = 2; sysctlnametomib("vfs.bufspace", MIB_vfs_bufspace, &len); @@ -330,6 +335,7 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) { u_int memActive, memWire, cachedMem; long buffersMem; size_t len; + struct vmtotal vmtotal; //disabled for now, as it is always smaller than phycal amount of memory... //...to avoid "where is my memory?" questions @@ -360,6 +366,10 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) { cachedMem *= pageSizeKb; pl->cachedMem = cachedMem; + len = sizeof(vmtotal); + sysctl(MIB_vm_vmtotal, 2, &(vmtotal), &len, NULL, 0); + pl->sharedMem = vmtotal.t_vmshr * pageSizeKb; + if (fpl->zfs.enabled) { fpl->memWire -= fpl->zfs.size; pl->cachedMem += fpl->zfs.size; diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 38d06169..646163af 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -232,7 +232,7 @@ void Platform_setMemoryValues(Meter* this) { this->total = pl->totalMem; this->values[MEMORY_METER_USED] = pl->usedMem; this->values[MEMORY_METER_BUFFERS] = pl->buffersMem; - // this->values[MEMORY_METER_SHARED] = "shared memory, like tmpfs and shm" + this->values[MEMORY_METER_SHARED] = pl->sharedMem; this->values[MEMORY_METER_CACHE] = pl->cachedMem; // this->values[MEMORY_METER_AVAILABLE] = "available memory" -- cgit v1.2.3