porting an app that checks /proc/meminfo

Fernan Aguero fernan at iib.unsam.edu.ar
Wed Jan 25 06:27:03 PST 2006


+----[ Brooks Davis <brooks at one-eyed-alien.net> (24.Jan.2006 18:02):
|
| On Tue, Jan 24, 2006 at 02:23:17PM -0300, Fernan Aguero wrote:
| > Hi!
| > 
| > I've got a port ready for muscle
| > 
| > WWW: http://www.drive5.com/muscle/
| > Port: http://genoma.unsam.edu.ar/~fernan/freebsd/muscle.shar
| > 
| > The program builds fine, but because it uses /proc/meminfo
| > to check for available memory, when you run it, it will
| > complain about the lack of /proc/meminfo and won't let you
| > do anything. 
| > 
| > The author, has suggested a hack (see globalslinux.cpp
| > and patch-globalslinux.cpp in the port) that disables the
| > function that returns the amount of memory used by muscle
| > and the amount of RAM available in the computer. With this
| > patch muscle runs fine but i) the progress messages will
| > give incorrect values for current memory use & fraction of
| > available RAM and ii) muscle may fail to fail gracefully
| > when it runs out of memory, it may just crash.
| > 
| > I'm not a C programmer, and the author is not familiar with
| > BSD internals ... I'm trying to help by pointing him in the
| > right direction. So my question can be summarized as:
| > 
| > How does one gets the values of i) memory used by the
| > program/process and ii) amount of RAM available in the
| > computer without using /proc/meminfo in FreeBSD? 
| > 
| > Suggestion of places to look (man pages) and/or examples in
| > C are welcomed. The functions that need to be modified are
| > GetMemUseMB and GetRAMSizeMB in globalslinux.cpp. 

Brooks,

thanks for your reply. I just got (and replied) a message
CCed to me and now I get this that went to the list ...

| If you want the ram used by a particular process use getrusage(2).
| For total system memory use sysctl(3) to retrieve hw.physmem or maybe
| hw.usermem.  If you want to total memory is free, that's a fairly bogus
| concept [0]. vm.stats.vm.v_free_count gives memory that isn't used,
| but that includes cached memory that may never be reused.  Adding
| vm.stats.vm.v_inactive_count to that seems like a not too awful
| approximation.  Depending on what the application does with the values,
| you may also want to use getrlimit(2) to in conjunction with sysctl when
| calculating total memory since memory you can't use might as well not
| exist.

Thanks for all the suggestions, I'll contact the author and
see if we can work together on this (me testing and he
writing the code).  

| For some examples, find the FreeBSD specific code in
| sysutils/gangial-monitor-core or sysutils/sge.

Thanks! I just briefly browsed
ganglia-monitor-core/srclib/libmetrics and the are different
directories there (linux, freebsd, irix, etc.) each with a
different metrics.c file. The linux one uses /proc/meminfo
(similar to the port I'm interested in). The freebsd one
surprisingly uses what you've suggested before :) 

Thanks again,

Fernan
| 
| -- Brooks
| 
| [0] Free memory is wasted memory.  The continued propagation of the myth
| that free memory is a useful concept by people who try to
| programmatically publish system statistics is one of my pet peeves.
|
+----]


More information about the freebsd-ports mailing list