Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Dec 2010 10:28:57 +0100
From:      Claus Guttesen <kometen@gmail.com>
To:        freebsd-stable@freebsd.org
Subject:   Re: get ram usage using getrusage()
Message-ID:  <AANLkTimyL6gkHRMfv7z-2SMOL3hRar9b3h3D6Hwoqw9j@mail.gmail.com>
In-Reply-To: <201012200809.oBK890AJ015323@lurza.secnetix.de>
References:  <AANLkTi=6rnad2fWcL444BZBK6PzHFRNkf-F3uvEbEAC6@mail.gmail.com> <201012200809.oBK890AJ015323@lurza.secnetix.de>

next in thread | previous in thread | raw e-mail | index | archive | help
>=A0> I'm trying to read how much ram an app is using reading
>
> Could you phrase that question more precisely?
> It might be helpful to know *WHY* you are interested
> in the app's RAM usage, in order to be able to give the
> most appropriate advice.

I'm testing the redis key-value-store with the (upcoming 2.2)
maxmemory directive and redis - at least on FreeBSD - seems to report
less ram used than what is shown in top (SIZE column). ru.ru_maxrss is
more accurate at least when redis grows.

Redis is useful with an expire in the key (setex) in my case where I
want to store as much as
possible and retain used key and have redis delete unused keys (LRU)

In freeMemoryIfNeeded() redis deletes keys until allocated memory <
maxmemory. I used ru.ru_maxrss for testing allocated memory but I
ended up deleting all keys since ru.ru_maxrss is not counting down
"fast enough", probably for quite reasonable reasons. But not what I
wanted. :-)

When I used redis zmalloc_used_memory() the server starts swapping.

>=A0> struct thread *td;
>=A0> td =3D curthread;
>=A0> p =3D td->td_proc;
>=A0> vm =3D p->p_vmspace;
>=A0> rss =3D pgtok(vmspace_resident_count(vm));
>
> That's a piece of kernel source code. =A0It won't work in
> user space.

Saw #ifdef _KERNEL in older versions of sys/pcpu.h that explicitly
told it was kernel-related code
(http://fxr.watson.org/fxr/source/sys/pcpu.h?v=3DFREEBSD70) but not on
8-stable.

> I think asking for an app's "memory usage" is not proper in
> the first place. =A0:-)

Maybe the reason userland apps have their own accounting system? Can
you elaborate? :-)

--=20
regards
Claus

When lenity and cruelty play for a kingdom,
the gentler gamester is the soonest winner.

Shakespeare

twitter.com/kometen



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