summaryrefslogtreecommitdiffstats
path: root/freebsd
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2020-12-10 11:57:48 +1100
committerNathan Scott <nathans@redhat.com>2020-12-10 11:57:48 +1100
commit75e9f9a8d92cda6ae8b161f1bf662597ac67c0f2 (patch)
tree397da395644c86f292d26bfe9226cfb5084c9735 /freebsd
parentdb5687a3556385521c42ee729aaa75a282b47c8c (diff)
Cull the definitions of pageSize and pageSizeKB from CRT.c
By storing the per-process m_resident and m_virt values in the form htop wants to display them in (KB, not pages), we no longer need to have definitions of pageSize and pageSizeKB in the common CRT code. These variables were never really CRT (i.e. display) related in the first place. It turns out the darwin platform code doesn't need to use these at all (the process values are extracted from the kernel in bytes not pages) and the other platforms can each use their own local pagesize variables, in more appropriate locations. Some platforms were actually already doing this, so this change is removing duplication of logic and variables there.
Diffstat (limited to 'freebsd')
-rw-r--r--freebsd/FreeBSDProcessList.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c
index 9aaab5dd..d8fadb33 100644
--- a/freebsd/FreeBSDProcessList.c
+++ b/freebsd/FreeBSDProcessList.c
@@ -72,12 +72,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
len = 2; sysctlnametomib("hw.physmem", MIB_hw_physmem, &len);
len = sizeof(pageSize);
- if (sysctlbyname("vm.stats.vm.v_page_size", &pageSize, &len, NULL, 0) == -1) {
- pageSize = CRT_pageSize;
- pageSizeKb = CRT_pageSize;
- } else {
- pageSizeKb = pageSize / ONE_K;
- }
+ if (sysctlbyname("vm.stats.vm.v_page_size", &pageSize, &len, NULL, 0) == -1)
+ CRT_fatalError("Cannot get pagesize by sysctl");
+ pageSizeKb = pageSize / ONE_K;
// usable page count vm.stats.vm.v_page_count
// actually usable memory : vm.stats.vm.v_page_count * vm.stats.vm.v_page_size
@@ -526,13 +523,13 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
}
// from FreeBSD source /src/usr.bin/top/machine.c
- proc->m_virt = kproc->ki_size / pageSize;
- proc->m_resident = kproc->ki_rssize;
+ proc->m_virt = kproc->ki_size / ONE_K;
+ proc->m_resident = kproc->ki_rssize * pageSizeKb;
proc->nlwp = kproc->ki_numthreads;
proc->time = (kproc->ki_runtime + 5000) / 10000;
proc->percent_cpu = 100.0 * ((double)kproc->ki_pctcpu / (double)kernelFScale);
- proc->percent_mem = 100.0 * (proc->m_resident * pageSizeKb) / (double)(super->totalMem);
+ proc->percent_mem = 100.0 * proc->m_resident / (double)(super->totalMem);
/*
* TODO

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