diff options
author | Nathan Scott <nathans@redhat.com> | 2020-12-10 11:57:48 +1100 |
---|---|---|
committer | Nathan Scott <nathans@redhat.com> | 2020-12-10 11:57:48 +1100 |
commit | 75e9f9a8d92cda6ae8b161f1bf662597ac67c0f2 (patch) | |
tree | 397da395644c86f292d26bfe9226cfb5084c9735 /solaris | |
parent | db5687a3556385521c42ee729aaa75a282b47c8c (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 'solaris')
-rw-r--r-- | solaris/SolarisProcessList.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 4249fa60..793b1b3b 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -25,9 +25,11 @@ in the source distribution for its full text. #include "CRT.h" - #define MAXCMDLINE 255 +static int pageSize; +static int pageSizeKB; + char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) { char* zname; @@ -50,13 +52,18 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui spl->kd = kstat_open(); - pl->cpuCount = sysconf(_SC_NPROCESSORS_ONLN); + pageSize = sysconf(_SC_PAGESIZE); + if (pageSize == -1) + CRT_fatalError("Cannot get pagesize by sysconf(_SC_PAGESIZE)"); + pageSizeKB = pageSize / 1024; - if (pl->cpuCount == 1 ) { + pl->cpuCount = sysconf(_SC_NPROCESSORS_ONLN); + if (pl->cpuCount == -1) + CRT_fatalError("Cannot get CPU count by sysconf(_SC_NPROCESSORS_ONLN)"); + else if (pl->cpuCount == 1) spl->cpus = xRealloc(spl->cpus, sizeof(CPUData)); - } else { + else spl->cpus = xRealloc(spl->cpus, (pl->cpuCount + 1) * sizeof(CPUData)); - } return pl; } @@ -169,9 +176,9 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { freemem_pgs = kstat_data_lookup(meminfo, "freemem"); pages = kstat_data_lookup(meminfo, "pagestotal"); - pl->totalMem = totalmem_pgs->value.ui64 * CRT_pageSizeKB; - if (pl->totalMem > freemem_pgs->value.ui64 * CRT_pageSizeKB) { - pl->usedMem = pl->totalMem - freemem_pgs->value.ui64 * CRT_pageSizeKB; + pl->totalMem = totalmem_pgs->value.ui64 * pageSizeKB; + if (pl->totalMem > freemem_pgs->value.ui64 * pageSizeKB) { + pl->usedMem = pl->totalMem - freemem_pgs->value.ui64 * pageSizeKB; } else { pl->usedMem = 0; // This can happen in non-global zone (in theory) } @@ -179,13 +186,13 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { pl->cachedMem = 0; // Not really "buffers" but the best Solaris analogue that I can find to // "memory in use but not by programs or the kernel itself" - pl->buffersMem = (totalmem_pgs->value.ui64 - pages->value.ui64) * CRT_pageSizeKB; + pl->buffersMem = (totalmem_pgs->value.ui64 - pages->value.ui64) * pageSizeKB; } else { // Fall back to basic sysconf if kstat isn't working - pl->totalMem = sysconf(_SC_PHYS_PAGES) * CRT_pageSize; + pl->totalMem = sysconf(_SC_PHYS_PAGES) * pageSize; pl->buffersMem = 0; pl->cachedMem = 0; - pl->usedMem = pl->totalMem - (sysconf(_SC_AVPHYS_PAGES) * CRT_pageSize); + pl->usedMem = pl->totalMem - (sysconf(_SC_AVPHYS_PAGES) * pageSize); } // Part 2 - swap @@ -215,8 +222,8 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { } free(spathbase); free(sl); - pl->totalSwap = totalswap * CRT_pageSizeKB; - pl->usedSwap = pl->totalSwap - (totalfree * CRT_pageSizeKB); + pl->totalSwap = totalswap * pageSizeKB; + pl->usedSwap = pl->totalSwap - (totalfree * pageSizeKB); } static inline void SolarisProcessList_scanZfsArcstats(ProcessList* pl) { @@ -323,8 +330,8 @@ int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo, void* proc->pgrp = _psinfo->pr_pgid; proc->nlwp = _psinfo->pr_nlwp; proc->tty_nr = _psinfo->pr_ttydev; - proc->m_resident = _psinfo->pr_rssize / CRT_pageSizeKB; - proc->m_virt = _psinfo->pr_size / CRT_pageSizeKB; + proc->m_resident = _psinfo->pr_rssize; // KB + proc->m_virt = _psinfo->pr_size; // KB if (!preExisting) { sproc->realpid = _psinfo->pr_pid; |