mallinfo equivalent on FreeBSD

dhruva dhruvakm at gmail.com
Wed Jun 30 07:42:18 UTC 2010


Hello,
 I would like to know the memory usage (total virtual memory) inside a
process and make decisions accordingly.
To be more specific, I am using BerkeleyDB backed set or std::set (C++
STL) depending on my current memory usage
as my process will need to run in a resource constrained environment.
By the way, this is user mode application.

Some things I am considering/tried:
1. GNU/Linux has mallinfo and I had my code working based on the
information I get from the call.
2. I tried using getrusage() and it does not give the total virtual
memory usage.
3. Another approach is to set the memory soft limit to the watermark I
am interested, trap SIGSEGV
and increase the watermark to the original value (save it before
modifying). The problem here would be
to differentiate between different causes for SIGSEGV and handling
them differently. In M$ (Windoze), I
could have done this using structured exception handling around the
call to malloc.

The problem in #3 would be to revert once the memory usage has gone
below the watermark.

Any suggestions would help me progress.

with best regards,
dhruva


More information about the freebsd-hackers mailing list