Why does the memory usage in "top" not add up?

Solution 1:

From the memory usage related lines in top:

Mem: 16432032k total, 16340144k used, 91888k free, 21736k buffers
Swap: 18481144k total, 1112k used, 18480032k free, 15624488k cached

Let's ignore the swap. Total memory equals the sum of used and free memory. Used, on the other hand, is the sum of "really used by applications" and cached and buffers. So, in your case goes like this:

  • Mem = 16432032k = 16340144k + 91888k;
  • "Really used by applications" = Used - (cached + buffers) = 16340144k - (15624488k + 21736k) = 693920k.

The other 15.5 GB are cached. This improves performance. However, in the very moment an application requires part of the cached memory it is immediately given to it. You will notice this if you run some memory hungry application and monitor top.

Solution 2:

That list doesn't look like 274 total processes to me. Top usually only displays what fits on your terminal/screen. Use ps aux instead and add up the rss value (or whatever resident memory column your version displays).

You also don't want to add up the virtual memory size, it seems you're actually interested in the resident (RES) column.