Ubuntu – A way to know how much memory Linux OS is using

commandlinuxmemoryUbuntu

I am looking for a way to know the size of the memory that Linux OS is using (I'm not worried about the other applications memory size).

I am using Ubuntu distribution (Ubuntu 15.10).

Best Answer

OS Memory v. Ubuntu Memory v. Kernel Memory

You have asked to know how much the "Linux OS" is using (and not how much memory is being used by "applications"). "Linux" is just a kernel (albeit not a monolithic one; kernel modules contribute to the effective footprint). Many things that end users see as "the OS" are not part of the kernel, but part of the larger Ubuntu distribution. In a typical desktop installation, this includes the windowing system (commonly xorg), the window manager and desktop environment (Unity on Ubuntu by default, others include Gnome and KDE), as well as a whole host of other processes that perform essential operations so that you can interact with your system.

The word "applications", to end users, usually means things like "web browser", "spreadsheet", etc. I'll refer to these as "user applications".

There are ways to estimate your kernel size, but if you wish to come up with an estimate to how much memory Ubuntu is using, you would have to identify and add up all of the related processes (xorg, init, etc.). The other option is to use something like top when you have no other user applications running, and subtract the memory used by top and your terminal emulator and shell.

Total Memory

There are many ways, some more precise than others, to see a Linux system's memory usage. There are also many definitions of "memory in use". That said, for most non-technical uses, top(1) will do the job just fine:

top - 17:23:50 up 7 days, 19:15,  3 users,  load average: 0.00, 0.01, 0.05
Tasks: 172 total,   2 running, 170 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.8 us,  0.1 sy,  0.0 ni, 99.1 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:   2049992 total,  1735420 used,   314572 free,   372420 buffers
KiB Swap:  2095100 total,      192 used,  2094908 free.   679116 cached Mem

As an added bonus, since the next question is often "what is using up the memory?", the next lines show the running processes and (among other things), how much virtual memory they are using.

Note that "free" memory on Linux is often a very small number, and that's a good thing. Free memory is essentially a wasted resource, so Linux instead allocates it to various caching uses. If an application needs that memory, it's still available; Linux is just putting it to good use in the meantime.