{"id":2294,"date":"2020-06-09T21:38:54","date_gmt":"2020-06-09T13:38:54","guid":{"rendered":"https:\/\/www.wesbytes.com\/guide\/?post_type=kb&#038;p=2294"},"modified":"2026-01-09T16:55:16","modified_gmt":"2026-01-09T08:55:16","slug":"5-commands-to-check-linux-memory-usage","status":"publish","type":"kb","link":"https:\/\/www.servergigabit.com\/guide\/kb\/5-commands-to-check-linux-memory-usage","title":{"rendered":"5 Commands to check Linux Memory Usage"},"content":{"rendered":"<div class=\"mkb-anchor mkb-clearfix mkb-back-to-top-inline\">\n<h3 class=\"mkb-anchor__title\">Linux Memory Usage<\/h3>\n<\/div>\n<p>There are commands for virtually everything on Linux, since the GUI may not always be available. Only shell access is available while operating on servers, so anything must be done from those commands. So today we are going to check commands that can be used on a Linux system to check memory use. Memory includes swap and RAM.<br \/>\nChecking the memory use and memory used per process on servers is also important so that resources are not shortened and users can access the server. For example a website. If you run a Webserver then the server must have enough memory to support the site visitors. If not, the site would become very slow or even go down when there is a traffic spike, simply because memory would fall short. It\u2019s just like what happens on your desktop PC.<\/p>\n<div class=\"mkb-anchor mkb-clearfix mkb-back-to-top-inline\">\n<h6 class=\"mkb-anchor__title\">1. Free Command<\/h6>\n<\/div>\n<p>The Free Command is the easiest and simplest command to use for checking memory use on Linux. Here\u2019s just a short example:<\/p>\n<pre class=\"terminal\"><strong>$ free -m\r\n             total       used       free     shared    buffers     cached\r\nMem:          7976       6459       1517          0        865       2248\r\n-\/+ buffers\/cache:       3344       4631\r\nSwap:         1951          0       1951<\/strong><\/pre>\n<p>&nbsp;<\/p>\n<p>The m option displays all data in MBs. The total os 7976 MB is the total amount of RAM installed on the system, that is 8GB. The used column shows the amount of RAM that has been used by Linux, in this case around 6.4 GB. The output is pretty self-explanatory. The catch over here is the cached and buffers column. The second line tells that 4.6 GB is free. This is the free memory in the first line added with the buffers and cached amount of memory.<br \/>\nLinux has the habit of catching lots of things for faster performance, so that memory can be freed and used if needed.<br \/>\nThe last line is the swap memory, which in this case is lying entirely free.<\/p>\n<div class=\"mkb-anchor mkb-clearfix mkb-back-to-top-inline\">\n<h6 class=\"mkb-anchor__title\">2. \/proc\/meminfo<\/h6>\n<\/div>\n<p>The next way to check the use of memory is to read the \u201c\/proc\/meminfo\u201d file. Know that there are no actual files in \/proc file system. These are rather virtual files which contain dynamic kernel and system information.<\/p>\n<pre class=\"terminal\"><strong>$ cat \/proc\/meminfo\r\nMemTotal:        8167848 kB\r\nMemFree:         1409696 kB\r\nBuffers:          961452 kB\r\nCached:          2347236 kB\r\nSwapCached:            0 kB\r\nActive:          3124752 kB\r\nInactive:        2781308 kB\r\nActive(anon):    2603376 kB\r\nInactive(anon):   309056 kB\r\nActive(file):     521376 kB\r\nInactive(file):  2472252 kB\r\nUnevictable:        5864 kB\r\nMlocked:            5880 kB\r\nSwapTotal:       1998844 kB\r\nSwapFree:        1998844 kB\r\nDirty:              7180 kB\r\nWriteback:             0 kB\r\nAnonPages:       2603272 kB\r\nMapped:           788380 kB\r\nShmem:            311596 kB\r\nSlab:             200468 kB\r\nSReclaimable:     151760 kB\r\nSUnreclaim:        48708 kB\r\nKernelStack:        6488 kB\r\nPageTables:        78592 kB\r\nNFS_Unstable:          0 kB\r\nBounce:                0 kB\r\nWritebackTmp:          0 kB\r\nCommitLimit:     6082768 kB\r\nCommitted_AS:    9397536 kB\r\nVmallocTotal:   34359738367 kB\r\nVmallocUsed:      420204 kB\r\nVmallocChunk:   34359311104 kB\r\nHardwareCorrupted:     0 kB\r\nAnonHugePages:         0 kB                 \r\nHugePages_Total:       0\r\nHugePages_Free:        0\r\nHugePages_Rsvd:        0\r\nHugePages_Surp:        0\r\nHugepagesize:       2048 kB\r\nDirectMap4k:       62464 kB\r\nDirectMap2M:     8316928 kB<\/strong><\/pre>\n<div class=\"display-ad-unit mobile-wide\"><\/div>\n<p>Check the values of MemTotal, MemFree, Buffers, Cached, SwapTotal, SwapFree.<br \/>\nThey indicate the same values of memory usage as the free command.<\/p>\n<div class=\"mkb-anchor mkb-clearfix mkb-back-to-top-inline\">\n<h6 class=\"mkb-anchor__title\">3. vmstat<\/h6>\n<\/div>\n<p>The vmstat command with the s option lays out the memory usage statistics much like the proc command. Here is an example:<\/p>\n<pre class=\"terminal\"><strong>$ vmstat -s\r\n      8167848 K total memory\r\n      7449376 K used memory\r\n      3423872 K active memory\r\n      3140312 K inactive memory\r\n       718472 K free memory\r\n      1154464 K buffer memory\r\n      2422876 K swap cache\r\n      1998844 K total swap\r\n            0 K used swap\r\n      1998844 K free swap\r\n       392650 non-nice user cpu ticks\r\n         8073 nice user cpu ticks\r\n        83959 system cpu ticks\r\n     10448341 idle cpu ticks\r\n        91904 IO-wait cpu ticks\r\n            0 IRQ cpu ticks\r\n         2189 softirq cpu ticks\r\n            0 stolen cpu ticks\r\n      2042603 pages paged in\r\n      2614057 pages paged out\r\n            0 pages swapped in\r\n            0 pages swapped out\r\n     42301605 interrupts\r\n     94581566 CPU context switches\r\n   1382755972 boot time\r\n         8567 forks\r\n$<\/strong><\/pre>\n<p>The top few lines indicate total memory, free memory etc and so on.<\/p>\n<div class=\"mkb-anchor mkb-clearfix mkb-back-to-top-inline\">\n<h6 class=\"mkb-anchor__title\">4. top command<\/h6>\n<\/div>\n<p>Typically, the top command is used to check the memory and CPU consumption per cycle. But it also records total use of memory and can be used to track total usage of RAM. The output header has the requisite information. The sample output here is:<\/p>\n<pre class=\"terminal\"><strong>top - 15:20:30 up  6:57,  5 users,  load average: 0.64, 0.44, 0.33\r\nTasks: 265 total,   1 running, 263 sleeping,   0 stopped,   1 zombie\r\n%Cpu(s):  7.8 us,  2.4 sy,  0.0 ni, 88.9 id,  0.9 wa,  0.0 hi,  0.0 si,  0.0 st\r\nKiB Mem:   8167848 total,  6642360 used,  1525488 free,  1026876 buffers\r\nKiB Swap:  1998844 total,        0 used,  1998844 free,  2138148 cached\r\n\r\n  PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+  COMMAND                                                                                 \r\n 2986 enlighte  20   0  584m  42m  26m S  14.3  0.5   0:44.27 yakuake                                                                                 \r\n 1305 root      20   0  448m  68m  39m S   5.0  0.9   3:33.98 Xorg                                                                                    \r\n 7701 enlighte  20   0  424m  17m  10m S   4.0  0.2   0:00.12 kio_thumbnail<\/strong><\/pre>\n<p>Check the KiB Mem and KiB Swap lines on the header. They indicate total, used and free amounts of the memory. The buffer and cache information is present here too, like the free command.<\/p>\n<div class=\"mkb-anchor mkb-clearfix mkb-back-to-top-inline\">\n<h6 class=\"mkb-anchor__title\">5. htop<\/h6>\n<\/div>\n<p>Similar to the top command, the htop command also shows memory usage along with various other details.<\/p>\n<p>&nbsp;<\/p>\n<p>The header on top shows CPU usage along with RAM and swap usage with the corresponding figures.<\/p>\n<div class=\"mkb-anchor mkb-clearfix mkb-back-to-top-inline\">\n<h4 class=\"mkb-anchor__title\">RAM Information<\/h4>\n<\/div>\n<p>To find out hardware information about the installed RAM, use the demidecode command. It reports lots of information about the installed RAM memory.<\/p>\n<pre class=\"terminal\"><strong>$ sudo dmidecode -t 17\r\n# dmidecode 2.11\r\nSMBIOS 2.4 present.\r\n\r\nHandle 0x0015, DMI type 17, 27 bytes\r\nMemory Device\r\n        Array Handle: 0x0014\r\n        Error Information Handle: Not Provided\r\n        Total Width: 64 bits\r\n        Data Width: 64 bits\r\n        Size: 2048 MB\r\n        Form Factor: DIMM\r\n        Set: None\r\n        Locator: J1MY\r\n        Bank Locator: CHAN A DIMM 0\r\n        Type: DDR2\r\n        Type Detail: Synchronous\r\n        Speed: 667 MHz\r\n        Manufacturer: 0xFF00000000000000\r\n        Serial Number: 0xFFFFFFFF\r\n        Asset Tag: Unknown\r\n        Part Number: 0x524D32474235383443412D36344643FFFFFF<\/strong><\/pre>\n<p>Provided information includes the size (2048MB), type (DDR2) , speed(667 Mhz) etc.<\/p>\n<div class=\"mkb-anchor mkb-clearfix mkb-back-to-top-inline\">\n<h4 class=\"mkb-anchor__title\">Summary<\/h4>\n<\/div>\n<p>All of the above commands operate from the terminal and have no interface. When dealing with a GUI on a desktop, use of a graphical display Interface tool is much simpler. Gnome-system-monitor on gnome and keyguard on KDE are the commonest tools. Both provide information about the resource use of CPU, RAM, swap, and network bandwidth in a graphical and easy to understand visual performance.<\/p>\n<p>Please refer to the following articles <a href=\"https:\/\/www.servergigabit.com\/guide\/kb\/how-to-set-up-private-nameserver-for-linux-server\/\">How to set up private nameserver for Linux server<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux Memory Usage There are commands for virtually everything on Linux, since the GUI may not always be available. Only shell access is available while operating on servers, so anything must be done from those commands. So today we are going to check commands that can be used on a Linux system to check memory use. Memory includes swap and&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"kbtopic":[57],"kbtag":[],"class_list":["post-2294","kb","type-kb","status-publish","hentry","kbtopic-linux-server"],"_links":{"self":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb\/2294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb"}],"about":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/types\/kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/comments?post=2294"}],"version-history":[{"count":5,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb\/2294\/revisions"}],"predecessor-version":[{"id":4460,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb\/2294\/revisions\/4460"}],"wp:attachment":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/media?parent=2294"}],"wp:term":[{"taxonomy":"kbtopic","embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kbtopic?post=2294"},{"taxonomy":"kbtag","embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kbtag?post=2294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}