[collectd] memory.c and /proc/meminfo

Hanik, Filip Filip.Hanik at laquinta.com
Thu Nov 17 22:53:02 CET 2005

On fedora 4, you get the following output

[root at filip sbin]# free -m
             total       used       free     shared    buffers     cached
Mem:          2026       1969         56          0         43       1270
-/+ buffers/cache:        655       1370
Swap:         1983          0       1983

[root at filip sbin]# cat /proc/meminfo
MemTotal:      2074728 kB
MemFree:         57524 kB
Buffers:         44148 kB
Cached:        1301648 kB

So as you can see, the buffers and cached are not necessarily part of the memory that is "used".
To get the true usage from the stats (ie percentage free RAM) I had to do the modification.

We are using collectd to report back the stats to nagios, so a few bytes here and there wont make a difference,
But we need to report correcly on memory utilization (ie, memory taken up by apps) in case a process starts leaking.

Before we made this modification, we would have numbers like 97% memory used, cause collectd didn't take into consideration that cached/buffered memory might be available for us.


Filip Hanik
Sr Software Engineer
La Quinta Corporation 


-----Original Message-----
From: collectd-bounces at verplant.org [mailto:collectd-bounces at verplant.org] On Behalf Of Florian Forster
Sent: Thursday, November 17, 2005 3:45 PM
To: The system statistics collection daemon " collectd" ' list.
Subject: Re: [collectd] memory.c and /proc/meminfo

Hello Filip,

On Thu, Nov 17, 2005 at 02:17:37PM -0600, Hanik, Filip wrote:
> I was getting really funky results, I found that this code worked 
> better on Fedora Core 4.

how exactly were those results `funky'? All Linux 2.4/2.6 Boxes I've seen so far worked perfectly fine..

> ---line 106 memory.c
> 	if (mem_used >= (mem_free + mem_buffered + mem_cached))
> 	{
> 		//mem_used is the total, if mem_used is the biggest number
> 		mem_free = mem_free + mem_buffered + mem_cached;
> 		//mem_used -= mem_free + mem_buffered + mem_cached;
> 		mem_used -= mem_free;
> 		memory_submit (mem_used, mem_buffered, mem_cached, mem_free);
> 	}
> Memory total, is the total of mem_free and mem_used

It's always a bit hard talking about memory utilization, mostly due to an inconsistent nomenclature. When talking about `used' memory I mean memory that's actually used by programs. `free' memory is space that's actually idle, i.e. just sitting there and warming the room.

Given this definition the equation `free + used = total' is NOT true, since the operating system will use some memory to buffer IO operations.
Under Linux the equation is `free + cached + buffered + used = total', where `cached' and `buffered' are caches maintained by the kernel. I won't get too much into Linux memory management, but if you're curious you'll find many answers in the gentoo `FAQ Linux Memory Management'

Hope this raises the fog a bit ;) Regards, -octo

P.S.: If anyone feels like getting confused, try to understand the Solaris swap model ;) I hear that those values might be a little `funky', but the guy telling me wasn't sure either ;)
Florian octo Forster
Hacker in training
GnuPG: 0x91523C3D

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.3/173 - Release Date: 11/16/2005

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.3/173 - Release Date: 11/16/2005

More information about the Collectd mailing list