porting an app that checks /proc/meminfo

Gary Jennejohn garyj at jennejohn.org
Tue Jan 24 12:58:47 PST 2006


Fernan Aguero writes:
> 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. 
> 
> OTOH, I know we have linprocfs ... but AFAIK it will mount under 
> /compat/linux/proc ... and given that the muscle executable
> is FreeBSD native it will not check there ... am I right?
> 

A good place to look at is /usr/src/usr.bin/top/machine.c. This is
FreeBSD specific and grabs the memory and process information from
the kernel.

top uses sysctlbyname(3) to get the memory info and kvm_getprocs(3) to
get the process-specific stuff.

There seem to be 3 sysctl's of interest: hw.physmem, hw.usermem and
hw.realmem. Here's output on my machine:

hw.physmem: 2138202112
hw.usermem: 1953370112
hw.realmem: 2147155968

realmem > physmem > usermem.

---
Gary Jennejohn / garyjATjennejohnDOTorg gjATfreebsdDOTorg garyjATdenxDOTde



More information about the freebsd-ports mailing list