PDA

View Full Version : [Solved] htop memory usage error


instain
February 19th, 2009, 15:31
I've had htop installed on two different machines now, one running FreeBSD 6.3 and one 7.1. On both of them htop reports memory usage that is off by a factor of 1024.

Here's an example comparing top to htop

top:
PID USERNAME THR PRI NICE SIZE RES STATE C TIME WCPU COMMAND
61920 apaulsen 7 52 0 258M 199M ucond 0 0:00 0.59% firefox-bin

htop:
PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command
61920 apaulsen 128 0 270608M 209856M 0 S 11.0 100. 23h24:07 /usr/local/lib/firefox/firefox-bin

Any ideas on how to fix this?

instain
February 25th, 2009, 01:24
I found the problem and attempted to push a patch upstream. In case anyone is interested:

--- Process.c~ 2008-09-22 22:43:34.000000000 -0500
+++ Process.c 2009-02-24 18:14:51.000000000 -0600
@@ -33,8 +33,9 @@
// This works only with glibc 2.1+. On earlier versions
// the behavior is similar to have a hardcoded page size.
#ifndef PAGE_SIZE
-#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) / 1024 )
+#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) )
#endif
+#define PAGE_SIZE_KB ( PAGE_SIZE / ONE_K )

#define PROCESS_COMM_LEN 300

@@ -351,13 +352,13 @@
: attr;
break;
}
- case M_DRS: Process_printLargeNumber(this, str, this->m_drs * PAGE_SIZE); return;
- case M_DT: Process_printLargeNumber(this, str, this->m_dt * PAGE_SIZE); return;
- case M_LRS: Process_printLargeNumber(this, str, this->m_lrs * PAGE_SIZE); return;
- case M_TRS: Process_printLargeNumber(this, str, this->m_trs * PAGE_SIZE); return;
- case M_SIZE: Process_printLargeNumber(this, str, this->m_size * PAGE_SIZE); return;
- case M_RESIDENT: Process_printLargeNumber(this, str, this->m_resident * PAGE_SIZE); return;
- case M_SHARE: Process_printLargeNumber(this, str, this->m_share * PAGE_SIZE); return;
+ case M_DRS: Process_printLargeNumber(this, str, this->m_drs * PAGE_SIZE_KB); return;
+ case M_DT: Process_printLargeNumber(this, str, this->m_dt * PAGE_SIZE_KB); return;
+ case M_LRS: Process_printLargeNumber(this, str, this->m_lrs * PAGE_SIZE_KB); return;
+ case M_TRS: Process_printLargeNumber(this, str, this->m_trs * PAGE_SIZE_KB); return;
+ case M_SIZE: Process_printLargeNumber(this, str, this->m_size * PAGE_SIZE_KB); return;
+ case M_RESIDENT: Process_printLargeNumber(this, str, this->m_resident * PAGE_SIZE_KB); return;
+ case M_SHARE: Process_printLargeNumber(this, str, this->m_share * PAGE_SIZE_KB); return;
case ST_UID: snprintf(buffer, n, "%4d ", this->st_uid); break;
case USER: {
if (Process_getuid != this->st_uid)

--- ProcessList.c~ 2008-09-23 01:23:14.000000000 -0500
+++ ProcessList.c 2009-02-24 18:14:13.000000000 -0600
@@ -698,7 +698,7 @@
period * 100.0;
process->percent_cpu = MAX(MIN(percent_cpu, processors*100.0), 0.0);

- process->percent_mem = (process->m_resident * PAGE_SIZE) /
+ process->percent_mem = (process->m_resident * PAGE_SIZE_KB) /
(float)(this->totalMem) *
100.0;

vj
April 9th, 2009, 07:14
Nice job!
Just discovered this wonderful utility, installed it and spotted the problem. Google leaded me to your post that have completely solved the problem.
Thanks!

instain
April 9th, 2009, 16:41
The patch was applied upstream so it should work properly on the next release.

instain
June 8th, 2009, 16:47
The patch was applied upstream so it should work properly on the next release.

Htop now reports memory correctly in version 0.8.2 (in ports already).