4

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).

4

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.

0

The basic kernel is the vmlinuz file under /boot. The 'z' stands for 'compressed with the z library'. Unfortunately, I do not know how to decompress it to see the size once uncompressed.

Also as mentioned by @type_outcast, the kernel uses modules to access the hardware and handle some other features. These are found under /lib/modules/<version>. You can determine which modules are loaded using lsmod. That list includes a Size column with the size of each module.

So if you wanted to know the size the kernel is using, that would be a relatively close approximation.

Also, you have the memory file. Try cat /proc/meminfo. This will give you two additional parameters: KernelStack and Buffers.

Further, you can get the info from various processes, such as process 1. This is the init process and it can be considered part of the kernel. Its info can be found under /proc/1. The memory usage shows a few numbers which are explained below. You can find a list of such low level processes using ps -ef | less and looking at the CMD column. Things that appear between brackets '[...name...]' are really low level entries (module related entries, it may actually be tasks created by the modules, but I do not know for sure about that.)

me $ cat /proc/1
46511 1381 790 348 0 37483 0

Note that those numbers are measured in pages. In most cases, that means you want to multiply the number by 4096 to have the size in bytes.

   /proc/[pid]/statm
          Provides information about memory usage, measured in pages.
          The columns are:

              size       (1) total program size
                         (same as VmSize in /proc/[pid]/status)
              resident   (2) resident set size
                         (same as VmRSS in /proc/[pid]/status)
              shared     (3) number of resident shared pages (i.e., backed by a file)
                         (same as RssFile+RssShmem in /proc/[pid]/status)
              text       (4) text (code)
              lib        (5) library (unused since Linux 2.6; always 0)
              data       (6) data + stack
              dt         (7) dirty pages (unused since Linux 2.6; always 0)

If you're interested in various other processes, all the data will be available under /proc.

2
  • /proc/1/statm (not just /proc/1) is the init process, conventionally /sbin/init, not the kernel Dec 13 '16 at 11:07
  • Good point. The kernel is like a "static library" which is not included in init which is really a task as far as Linux is concerned. Dec 13 '16 at 21:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.