get ram usage using getrusage()
Claus Guttesen
kometen at gmail.com
Mon Dec 20 09:29:00 UTC 2010
> > 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.
> > struct thread *td;
> > td = curthread;
> > p = td->td_proc;
> > vm = p->p_vmspace;
> > rss = pgtok(vmspace_resident_count(vm));
>
> That's a piece of kernel source code. It 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=FREEBSD70) but not on
8-stable.
> I think asking for an app's "memory usage" is not proper in
> the first place. :-)
Maybe the reason userland apps have their own accounting system? Can
you elaborate? :-)
--
regards
Claus
When lenity and cruelty play for a kingdom,
the gentler gamester is the soonest winner.
Shakespeare
twitter.com/kometen
More information about the freebsd-stable
mailing list