Do I need extra RAM?

Hello,

I am running my site on a linode 300 and I am wondering whether I should upgrade to a linode with more RAM. I understand that I cannot go wrong with more RAM, but I'd like to make a more educated decision.

free returns:

total used free shared buffers cached

Mem: 288 254 34 0 47 140

-/+ buffers/cache: 65 222

Swap: 255 0 255

Would you upgrade reading that report?

What should I do to gather more evidence?

The other solution is to reduce the "used" amount, but I don't really know how to find that the breakout of the used memory.

Thanks

5 Replies

I, too, have a Linode 300, running Gentoo with a 2.4 kernel and a 1GB swap partition. My output of free looks like this at the moment (the -m switch forces it to display values in MB):

kimandre@edison ~ $ free -m
             total       used       free     shared    buffers     cached
Mem:           288        278         10          0         11         25
-/+ buffers/cache:        241         47
Swap:         1023         23       1000
kimandre@edison ~ $

No apparent problems at the moment, and the server monitoring site I'm running on it has no problems loading on any given day.

I think this tends to be one of those things that nobody can agree on, partially because linux tends to report memory usage in a fairly obtuse way. It's often difficult to find out how much memory you are actually used, because of shared libraries, memory, disk buffers, etc.

I find that using several tools helps to manage memory.

To see the different output, here's a couple different commands on my linode 450

:::: cdmoyer:5 ~ :::: free -m
             total       used       free     shared    buffers     cached
Mem:           439        430          8          0         80        224
-/+ buffers/cache:        125        313
Swap:          899          0        899

:::: cdmoyer:5 ~ :::: vmstat -a -S M
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free  inact active   si   so    bi    bo   in   cs us sy id wa
 2  0      0      8     65    328    0    0     0     1   10    2  0  0 100  0

:::: cdmoyer:5 ~ :::: vmstat -S M
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 1  0      0      8     80    224    0    0     0     1   10    2  0  0 100  0

:::: cdmoyer:5 ~ :::: cat /proc/meminfo
MemTotal:       449604 kB
MemFree:          8604 kB
Buffers:         82828 kB
Cached:         229456 kB
SwapCached:        548 kB
Active:         336360 kB
Inactive:        66676 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:       449604 kB
LowFree:          8604 kB
SwapTotal:      921592 kB
SwapFree:       920992 kB
Dirty:              44 kB
Writeback:           0 kB
AnonPages:       90204 kB
Mapped:          37308 kB
Slab:            27536 kB
SReclaimable:    20232 kB
SUnreclaim:       7304 kB
PageTables:       1508 kB
NFS_Unstable:        0 kB
Bounce:              0 kB
CommitLimit:   1146392 kB
Committed_AS:   195216 kB
VmallocTotal:   397304 kB
VmallocUsed:      2836 kB
VmallocChunk:   394468 kB

What you'll see, the longer your system runs, the less free memory you'll have, even if you don't add any processes. This is because of the cache and buffers. These are used by the kernel to speed things up, and not necessarily memory "used" by the system. Especially the cache (pagecache). The kernel is just taking advantage of the fact that you have spare memory and keeping things read from disk in memory, for performance. Should you fire up more processes (or they start automatically under load), the kernel will give up parts of that space holding older files that haven't been used in a while.

The other thing to note, is in that both of your cases, basically not swap has/is being used. That's indicative that even though free claims you have limited memory free, you actually have alot more headroom.

edit: A way that I also like to keep tabs on memory usage is to occasionally run top, and then hit M to sort by memory, and keep tabs on what the top memory users in my system are.

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
  350 postgres  20   0 36192  19m  18m S    0  4.5   0:00.96 postgres
15237 cdmoyer   20   0 24068  17m 3872 S    0  4.0   0:36.74 centerim
  349 cdmoyer   20   0 16912  13m 2600 S    0  3.0   0:00.42 perl
 1173 cdmoyer   20   0 14248  12m 1988 S    0  2.8   0:00.46 perl
 2461 cdmoyer   20   0 10180 8420  740 S    0  1.9   0:04.68 screen
 3302 cdmoyer   20   0 13608 7684 3956 S    0  1.7   2:19.88 centerim
 2332 postgres  20   0 35580 7552 7004 S    0  1.7   0:37.08 postgres
 7113 root      20   0 59968 7356 4656 S    0  1.6   0:00.34 php-cgi
 7110 root      20   0 59968 7272 4572 S    0  1.6   0:00.32 php-cgi

– Here you can see that some of my biggest offenders are a stupid command line IM client. ;)

-Chris

total used free shared buffers cached Mem: 288 254 34 0 47 140

That says 140 MB is cached. Linux will generally cache remaining memory, but as soon as something needs that memory, it will give back cached memory to the app that needs memory.

So that's like 140 MB in reserve, ready to be given out. 140 MB out of 288 MB – that's about 50% that isn't really being used. I don't see memory pressure; you should be fine with what you have now for the foreseenable future.

Linux memory reporting is pretty simple. Unfortunately many people mis-read the data.

Linux uses spare memory for buffer cache. Both report very low values of free memory on a machine that's been up for a while. But this isn't a problem.

Let's take a machine. This is a pretty idle machine; 1Gb of RAM and it's not doing much at all.````
% free
total used free shared buffers cached
Mem: 1003316 906428 96888 0 213900 528004
-/+ buffers/cache: 164524 838792
Swap: 2024148 12968 2011180

The "free" column on the "Mem" line isn't useful. free+buffers+cached is more interesting. Fortunately the command works this out for us; the "buffers/cache" has already done the sums. The number "838792" is the real amount of free memory on this box.

Now there are two things which might be of interest; are we running short of physical memory? Are we running short of virtual memory?

The first could simply be the number from the "free" output, above, but it might make more sense to also take into account how much has been swapped (which might have indicated a temporary short-fall), so "real free - swap usage" might be a more useful indicator of free RAM. A %age value could be taken by dividing that by "total" from the Mem: field.

In my case (838792-12968)/ 1003316 * 100 = 82% free memory.

However, this isn't necessarily useful. Many machines might be short of physical memory (especially for programs that allocated and use multi-Gbyte data tables) and the users are more concerned with free virtual memory. Here we need to consider free memory and free swap, so "real free + swap free" is the number. A %age value could be taken by dividing that by the totals of "Mem+Swap".

In my case (838792+2011180)/ (1003316+2024148) * 100 = 94% free virtual memory. This is clearly a box with no memory issues.

My workstation, however, isn't so lucky:````
             total       used       free     shared    buffers     cached
Mem:        506200     472792      33408          0       4076      57184
-/+ buffers/cache:     411532      94668
Swap:      1012084     117660     894424

Free memory = (94668-117660)/506200*100 = -5% - negative! My requirements exceed physical memory, but not by much.

Free virtual memory = (94668+894424)/(506200+1012084)*100 = 65% - Not too bad.

Hmmph. My desktop would achieve better performance with more memory, but since I don't do a lot of heavy I/O (except backups) it's not really an issue.

On a normal machine, "running short of VM" is normally more interesting, but on a linode swapping has a heavy performance penalty so I'd look more at the "real free - swap usage" figure.

My linode is… pretty idle! % free total used free shared buffers cached Mem: 296020 287344 8676 0 17916 162152 -/+ buffers/cache: 107276 188744 Swap: 263160 576 262584
I built the config back when it was a linode64 and gradually increased stuff on it (eg lighttpd instead of thttpd) as we got more and more bang for buck. But still…

These measures are "snapshot" measures and only an indication. They can be used to determine if a process is likely to die with "out of memory" issues, for example. For more detailed analysis, a continuous track of swap in/swap out activity (from vmstat) is a more dynamic measure of memory shortfall issues and a more likely indicator of application performance issues (a short burst of paging is normal; long term continuous paging indicates the machine could be spending more time paging data in/out than actually processing and is indicative of a real memory shortfall (as opposed to virtual memory). That's a lot more difficult question :-)

thank you to all for the answers; I better understand this area of my linode

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct