Bug 157195 - [PATCH] sysutils/htop miscalculates available memory
Summary: [PATCH] sysutils/htop miscalculates available memory
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Pav Lucistnik
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-20 01:10 UTC by freebsd
Modified: 2011-08-12 09:40 UTC (History)
0 users

See Also:


Attachments
file.diff (1.33 KB, patch)
2011-05-20 01:10 UTC, freebsd
no flags Details | Diff
patch-ProcessList.c (2.98 KB, text/x-csrc; charset=US-ASCII)
2011-07-24 09:43 UTC, Sayetsky Anton
no flags Details
patch-Makefile.am (445 bytes, application/octet-stream)
2011-07-24 09:43 UTC, Sayetsky Anton
no flags Details
patch-ProcessList.c (3.76 KB, text/x-csrc; charset=US-ASCII)
2011-07-24 10:41 UTC, Sayetsky Anton
no flags Details
patch-configure.ac (1005 bytes, application/octet-stream)
2011-08-11 11:16 UTC, Sayetsky Anton
no flags Details
patch-ProcessList.c (2.47 KB, text/x-csrc; charset=US-ASCII)
2011-08-11 11:16 UTC, Sayetsky Anton
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description freebsd 2011-05-20 01:10:09 UTC
The sysutils/htop port reads /compat/linux/proc/meminfo to calculate the amount of memory used.

The code that generates this file resides in sys/compat/linprocfs/linprocfs.c. Here, the amount of available memory is intentionally misreported:

/*
 * The correct thing here would be:
 *
memfree = cnt.v_free_count * PAGE_SIZE;
memused = memtotal - memfree;
 *
 * but it might mislead linux binaries into thinking there
 * is very little memory left, so we cheat and tell them that
 * all memory that isn't wired down is free.
 */
memused = cnt.v_wire_count * PAGE_SIZE;
memfree = memtotal - memused;

Fix: The attached patch uses sysctl to read the actual amount of available memory, just as top does.

Patch attached with submission follows:
How-To-Repeat: Run top and htop simultaneously. Notice that htop reports very low memory usage while top reports the correct value.
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2011-05-20 01:10:19 UTC
Responsible Changed
From-To: freebsd-ports-bugs->yzlin

Over to maintainer (via the GNATS Auto Assign Tool)
Comment 2 Sayetsky Anton 2011-07-24 09:43:21 UTC
Here is my rewritten patch. It uses sysctl and llibkvm for memory
info, without linux proc.
I think that there is a need to include it to sysutils/htop and bump
portversion.
Comment 3 Sayetsky Anton 2011-07-24 10:41:36 UTC
2011/7/24 Sayetsky Anton <jason@linux.lg.ua>:
> Here is my rewritten patch. It uses sysctl and llibkvm for memory
> info, without linux proc.
> I think that there is a need to include it to sysutils/htop and bump
> portversion.
>

Sorry, there is a small difference (about 40 mbytes) between used mem
that reports top and htop with previous patch. I've attached a new
version of ProcessList.c patch.

Also, may we need to add special counter for inactive memory?
Comment 4 Pav Lucistnik freebsd_committer freebsd_triage 2011-08-08 12:34:30 UTC
Responsible Changed
From-To: yzlin->pav

Maintainer was changed
Comment 5 Pav Lucistnik freebsd_committer freebsd_triage 2011-08-08 12:34:40 UTC
State Changed
From-To: open->feedback

Is this still valid for 0.9? If yes, can you contact the new maintainer about it?
Comment 6 Sayetsky Anton 2011-08-10 17:17:11 UTC
Yes, htop-0.9 still has bug with memory calculation. I will write a
patch for new version as soon as possible.
Comment 7 Sayetsky Anton 2011-08-11 11:16:29 UTC
Here is a patch for htop-0.9, with it htop calculates all memory usage
correctly ("used mem" in htop means freebsd's active memory).
Please, bump portrevision and commit.
Comment 8 Pav Lucistnik freebsd_committer freebsd_triage 2011-08-12 09:29:38 UTC
State Changed
From-To: feedback->closed

Committed, thanks!
Comment 9 dfilter service freebsd_committer freebsd_triage 2011-08-12 09:30:43 UTC
pav         2011-08-12 08:30:34 UTC

  FreeBSD ports repository

  Modified files:
    sysutils/htop        Makefile 
    sysutils/htop/files  patch-configure.ac 
  Added files:
    sysutils/htop/files  patch-ProcessList.c 
  Log:
  - Fix calculation of available memory
  
  PR:             ports/157195
  Submitted by:   Sayetsky Anton <jason@linux.lg.ua>
  Approved by:    Hung-Yi Chen <gaod@hychen.org> (maintainer)
  
  Revision  Changes    Path
  1.21      +1 -0      ports/sysutils/htop/Makefile
  1.5       +87 -0     ports/sysutils/htop/files/patch-ProcessList.c (new)
  1.4       +11 -3     ports/sysutils/htop/files/patch-configure.ac
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"