Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Jan 2006 12:59:37 -0800
From:      Brooks Davis <brooks@one-eyed-alien.net>
To:        FreeBSD Ports <ports@FreeBSD.ORG>
Subject:   Re: porting an app that checks /proc/meminfo
Message-ID:  <20060124205937.GC21232@odin.ac.hmc.edu>
In-Reply-To: <20060124172317.GF72149@iib.unsam.edu.ar>
References:  <20060124172317.GF72149@iib.unsam.edu.ar>

next in thread | previous in thread | raw e-mail | index | archive | help

--1ccMZA6j1vT5UqiK
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Jan 24, 2006 at 02:23:17PM -0300, Fernan Aguero wrote:
> Hi!
>=20
> I've got a port ready for muscle
>=20
> WWW: http://www.drive5.com/muscle/
> Port: http://genoma.unsam.edu.ar/~fernan/freebsd/muscle.shar
>=20
> 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.=20
>=20
> 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.
>=20
> 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:
>=20
> 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?=20
>=20
> 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.=20

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.

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

-- 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.

--=20
Any statement of the form "X is the one, true Y" is FALSE.
PGP fingerprint 655D 519C 26A7 82E7 2529  9BF0 5D8E 8BE9 F238 1AD4

--1ccMZA6j1vT5UqiK
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFD1pUlXY6L6fI4GtQRAt6MAJoD5Y7aog1u4BG1hawhi1uvu42IcgCfSGme
e4ls+hAC+bqZm71FCQOVTOo=
=tQt/
-----END PGP SIGNATURE-----

--1ccMZA6j1vT5UqiK--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060124205937.GC21232>