4

I know Linux likes to eat my RAM, and that's great, but it doesn't quite account for what I'm seeing on a VPS (KVM) running CentOS 6.5. In fact, I'm missing at least 200MB on a 1GB VM. Where could it be?

             total       used       free     shared    buffers     cached
Mem:           996        907         89          0         76        379
-/+ buffers/cache:        451        545
Swap:         1023          5       1018

free -m suggests that, without buffers/cache, the system uses 451 MB of memory. However, there's no way the running programs (mostly nginx/php-fpm/mysqld/sshd) add up to that much RAM.

ps_mem reports that 90MB is currently in use by programs, and here's what smem says:

Area                           Used      Cache   Noncache
firmware/hardware                 0          0          0
kernel image                      0          0          0
kernel dynamic memory        820912     775204      45708
userspace memory              96300      27988      68312
free memory                  103168     103168          0
----------------------------------------------------------
                            1020380     906360     114020

Is there anything outside of the visible running processes that could be eating my RAM? Or is free -m incorrectly reporting memory usage? Any tips on reclaiming this memory (without rebooting)?

Results of cat /proc/meminfo: http://paste.ubuntu.com/6949236/

EDIT: Turns out to be a large slab cache, see: https://stackoverflow.com/questions/5463800/linux-memory-reporting-discrepancy. I was confused by it being much larger than I'm used to, and the fact that tools like free -m, htop and the like report this as used memory rather than cache/buffers.

redburn
  • 197
  • 1
  • 7
  • What do you expect to receive as an answer here? /proc/meminfo should answer questions about how your memory is being used. – sciurus Feb 17 '14 at 15:53
  • @sciurus I wasn't aware the slab cache wasn't part of the cache/buffers reported by `free -m`. – redburn Feb 17 '14 at 21:41

2 Answers2

4
  1. free -m is accurate. I'm not familiar with ps_mem, but suspect it's reporting only certain kinds of memory usage by the programs. Try using top -a, see if it gives you more information.

  2. The memory is likely used by programs' "resource" space. Restarting them will clear some of this out, but I'd be surprised if it wasn't back to the same place in an hour.

  3. Why do you want to "reclaim" this memory. You're not out of RAM. "Free" memory is wasted memory. You'd be better off using 100%, even if only to get the most marginal of performance gains (which is why Linux uses it for caching aggressively).

  4. See also: Why is Linux reporting "free" memory strangely?

    Sounds like you've got the same misunderstands of memory utilization as many people. This Q&A has a great explanation of what's going, on along with links to more information. But in short, unless OOM is killing processes let the OS do it's thing. Serious, kernel programmers have dedicated large portions of their lives to getting this right, I'd dare not question their expertise unless there's an obvious problem.

Chris S
  • 77,337
  • 11
  • 120
  • 212
  • 1) Adding up the memory used by all processes as listed by `top -a` doesn't even get me to 200 MB; that still leaves 250MB unaccounted for. 2) I've restarted all major daemons; no large difference. 3) I want to reclaim it if it's not doing something useful, right now I have no idea where it's at. 4) The question you linked doesn't seem particularly relevant to mine. I know Linux 'eats my RAM' for caching. In this case, about 25% of my total RAM is 'used' (as reported by `free -m`) but I can't figure out what for. – redburn Feb 17 '14 at 15:12
  • Which numbers are you adding up to get that 200M number? There's "virt", "res" and "shd" columns (normally). – Chris S Feb 17 '14 at 15:36
  • 2
    It turns out my question is similar to http://stackoverflow.com/questions/5463800/linux-memory-reporting-discrepancy and the memory I was "missing" was in fact the slab cache (mostly dentries, and ext4_inode_cache). Having cleared that, memory usage is back to 'normal'. What confused me, and prompted me to ask the question, is that all the tools (`free -m`, htop, etc.) reported this memory as 'used' rather than cache or buffers, and the size of the slabcache (at 300+MB of 1GB total) was much larger than I'd seen before. My misunderstanding, it seems. – redburn Feb 17 '14 at 17:53
3

try to check out:

cat /proc/meminfo

could give you the extra info you need :)

Semirke
  • 314
  • 1
  • 2