{"id":6390,"date":"2020-04-23T12:44:48","date_gmt":"2020-04-23T04:44:48","guid":{"rendered":"https:\/\/www.mondoze.com\/guide\/?post_type=kb&#038;p=6390"},"modified":"2022-10-07T08:11:08","modified_gmt":"2022-10-07T00:11:08","slug":"5-commands-to-check-linux-memory-usage","status":"publish","type":"kb","link":"https:\/\/www.mondoze.com\/guide\/kb\/5-commands-to-check-linux-memory-usage","title":{"rendered":"5 Commands to check Linux Memory Usage"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"6390\" class=\"elementor elementor-6390\" data-elementor-settings=\"[]\">\n\t\t\t\t\t\t<div class=\"elementor-inner\">\n\t\t\t\t\t\t\t<div class=\"elementor-section-wrap\">\n\t\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-34c314fb elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"34c314fb\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t\t\t<div class=\"elementor-row\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-139daa35\" data-id=\"139daa35\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-column-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t<div class=\"elementor-widget-wrap\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-c4dd5bb elementor-widget elementor-widget-heading\" data-id=\"c4dd5bb\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">5 Commands to Check Linux Memory Usage<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f29d96f elementor-widget elementor-widget-heading\" data-id=\"f29d96f\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Memory Usage<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-159359ec elementor-widget elementor-widget-text-editor\" data-id=\"159359ec\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<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 \/>Checking 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&#8217;s just like what happens on your desktop PC.<\/p>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c23e00a elementor-widget elementor-widget-heading\" data-id=\"c23e00a\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h4 class=\"elementor-heading-title elementor-size-default\">1. Free Command<\/h4>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0e0dfeb elementor-widget elementor-widget-text-editor\" data-id=\"0e0dfeb\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<p>The Free Command is the easiest and simplest command to use for checking memory use on Linux. Here&#8217;s just a short example:<\/p><pre class=\"terminal\"><strong>$ free -m\n             total       used       free     shared    buffers     cached\nMem:          7976       6459       1517          0        865       2248\n-\/+ buffers\/cache:       3344       4631\nSwap:         1951          0       1951<\/strong><\/pre><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 \/>Linux has the habit of catching lots of things for faster performance, so that memory can be freed and used if needed.<br \/>The last line is the swap memory, which in this case is lying entirely free.<\/p>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-05dd243 elementor-widget elementor-widget-heading\" data-id=\"05dd243\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h4 class=\"elementor-heading-title elementor-size-default\">2. \/proc\/meminfo<\/h4>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c2c0203 elementor-widget elementor-widget-text-editor\" data-id=\"c2c0203\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<p>The next way to check the use of memory is to read the &#8220;\/proc\/meminfo&#8221; file. Know that there are no actual files in the\/proc file system. These are rather virtual files that contain dynamic kernel and system information.<\/p><pre class=\"terminal\"><strong>$ cat \/proc\/meminfo\nMemTotal:        8167848 kB\nMemFree:         1409696 kB\nBuffers:          961452 kB\nCached:          2347236 kB\nSwapCached:            0 kB\nActive:          3124752 kB\nInactive:        2781308 kB\nActive(anon):    2603376 kB\nInactive(anon):   309056 kB\nActive(file):     521376 kB\nInactive(file):  2472252 kB\nUnevictable:        5864 kB\nMlocked:            5880 kB\nSwapTotal:       1998844 kB\nSwapFree:        1998844 kB\nDirty:              7180 kB\nWriteback:             0 kB\nAnonPages:       2603272 kB\nMapped:           788380 kB\nShmem:            311596 kB\nSlab:             200468 kB\nSReclaimable:     151760 kB\nSUnreclaim:        48708 kB\nKernelStack:        6488 kB\nPageTables:        78592 kB\nNFS_Unstable:          0 kB\nBounce:                0 kB\nWritebackTmp:          0 kB\nCommitLimit:     6082768 kB\nCommitted_AS:    9397536 kB\nVmallocTotal:   34359738367 kB\nVmallocUsed:      420204 kB\nVmallocChunk:   34359311104 kB\nHardwareCorrupted:     0 kB\nAnonHugePages:         0 kB                 \nHugePages_Total:       0\nHugePages_Free:        0\nHugePages_Rsvd:        0\nHugePages_Surp:        0\nHugepagesize:       2048 kB\nDirectMap4k:       62464 kB\nDirectMap2M:     8316928 kB<\/strong><\/pre><p>Check the values of MemTotal, MemFree, Buffers, Cached, SwapTotal, SwapFree.<br \/>They indicate the same values of memory usage as the free command.<\/p>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b36b0bc elementor-widget elementor-widget-heading\" data-id=\"b36b0bc\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h4 class=\"elementor-heading-title elementor-size-default\">3. vmstat<\/h4>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6ccd501 elementor-widget elementor-widget-text-editor\" data-id=\"6ccd501\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<p>The vmstat command with the s option lays out the memory usage statistics much like the proc command. Here is an example:<\/p><pre class=\"terminal\"><strong>$ vmstat -s\n      8167848 K total memory\n      7449376 K used memory\n      3423872 K active memory\n      3140312 K inactive memory\n       718472 K free memory\n      1154464 K buffer memory\n      2422876 K swap cache\n      1998844 K total swap\n            0 K used swap\n      1998844 K free swap\n       392650 non-nice user cpu ticks\n         8073 nice user cpu ticks\n        83959 system cpu ticks\n     10448341 idle cpu ticks\n        91904 IO-wait cpu ticks\n            0 IRQ cpu ticks\n         2189 softirq cpu ticks\n            0 stolen cpu ticks\n      2042603 pages paged in\n      2614057 pages paged out\n            0 pages swapped in\n            0 pages swapped out\n     42301605 interrupts\n     94581566 CPU context switches\n   1382755972 boot time\n         8567 forks\n$<\/strong><\/pre><p>The top few lines indicate total memory, free memory, etc, and so on.<\/p>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-438c8be elementor-widget elementor-widget-heading\" data-id=\"438c8be\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h4 class=\"elementor-heading-title elementor-size-default\">4. top command<\/h4>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0c1fb28 elementor-widget elementor-widget-text-editor\" data-id=\"0c1fb28\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<p>Typically, the top command is used to check the memory and CPU consumption per cycle. But it also records the total use of memory and can be used to track the total usage of RAM. The output header has the requisite information. The sample output here is:<\/p><pre class=\"terminal\"><strong>top - 15:20:30 up  6:57,  5 users,  load average: 0.64, 0.44, 0.33\nTasks: 265 total,   1 running, 263 sleeping,   0 stopped,   1 zombie\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\nKiB Mem:   8167848 total,  6642360 used,  1525488 free,  1026876 buffers\nKiB Swap:  1998844 total,        0 used,  1998844 free,  2138148 cached\n\n  PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+  COMMAND                                                                                 \n 2986 enlighte  20   0  584m  42m  26m S  14.3  0.5   0:44.27 yakuake                                                                                 \n 1305 root      20   0  448m  68m  39m S   5.0  0.9   3:33.98 Xorg                                                                                    \n 7701 enlighte  20   0  424m  17m  10m S   4.0  0.2   0:00.12 kio_thumbnail<\/strong><\/pre><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>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8ee9da8 elementor-widget elementor-widget-heading\" data-id=\"8ee9da8\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h4 class=\"elementor-heading-title elementor-size-default\">5. htop<\/h4>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-474ff96 elementor-widget elementor-widget-text-editor\" data-id=\"474ff96\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<p>Similar to the top command, the htop command also shows memory usage along with various other details.<\/p>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c268c83 elementor-widget elementor-widget-image\" data-id=\"c268c83\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-image\">\n\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" loading=\"lazy\" width=\"300\" height=\"201\" src=\"https:\/\/www.mondoze.com\/guide\/wp-content\/uploads\/2021\/06\/htop-command.png\" class=\"attachment-large size-large\" alt=\"linux command htop command\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d4dd3dc elementor-widget elementor-widget-text-editor\" data-id=\"d4dd3dc\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<p>The header on top shows CPU usage along with RAM and swap usage with the corresponding figures.<\/p>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fb24e0b elementor-widget elementor-widget-heading\" data-id=\"fb24e0b\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">RAM Information<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-86ac0f6 elementor-widget elementor-widget-text-editor\" data-id=\"86ac0f6\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<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><pre class=\"terminal\"><strong>$ sudo dmidecode -t 17\n# dmidecode 2.11\nSMBIOS 2.4 present.\n\nHandle 0x0015, DMI type 17, 27 bytes\nMemory Device\n        Array Handle: 0x0014\n        Error Information Handle: Not Provided\n        Total Width: 64 bits\n        Data Width: 64 bits\n        Size: 2048 MB\n        Form Factor: DIMM\n        Set: None\n        Locator: J1MY\n        Bank Locator: CHAN A DIMM 0\n        Type: DDR2\n        Type Detail: Synchronous\n        Speed: 667 MHz\n        Manufacturer: 0xFF00000000000000\n        Serial Number: 0xFFFFFFFF\n        Asset Tag: Unknown\n        Part Number: 0x524D32474235383443412D36344643FFFFFF<\/strong><\/pre><p>Provided information includes the size (2048MB), type (DDR2) , speed(667 Mhz) etc.<\/p>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-96ab47a elementor-widget elementor-widget-heading\" data-id=\"96ab47a\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Summary<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-158d911 elementor-widget elementor-widget-text-editor\" data-id=\"158d911\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<p>All of the above commands operate from the terminal and have no interface. When dealing with a GUI on a desktop, the 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>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1d4d0f2 elementor-widget elementor-widget-text-editor\" data-id=\"1d4d0f2\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<p>If you would like to read more articles about Linux and some tips for using it, kindly visit our <a href=\"https:\/\/www.mondoze.com\/guide\/\">Knowledge Base.<\/a><\/p>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>5 Commands to Check Linux Memory Usage 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 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/www.mondoze.com\/guide\/kb\/5-commands-to-check-linux-memory-usage\"> <span class=\"screen-reader-text\">5 Commands to check Linux Memory Usage<\/span> Read More \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"default","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}}},"kbtopic":[113],"kbtag":[110],"mkb_version":[],"_links":{"self":[{"href":"https:\/\/www.mondoze.com\/guide\/wp-json\/wp\/v2\/kb\/6390"}],"collection":[{"href":"https:\/\/www.mondoze.com\/guide\/wp-json\/wp\/v2\/kb"}],"about":[{"href":"https:\/\/www.mondoze.com\/guide\/wp-json\/wp\/v2\/types\/kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.mondoze.com\/guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mondoze.com\/guide\/wp-json\/wp\/v2\/comments?post=6390"}],"version-history":[{"count":16,"href":"https:\/\/www.mondoze.com\/guide\/wp-json\/wp\/v2\/kb\/6390\/revisions"}],"predecessor-version":[{"id":21868,"href":"https:\/\/www.mondoze.com\/guide\/wp-json\/wp\/v2\/kb\/6390\/revisions\/21868"}],"wp:attachment":[{"href":"https:\/\/www.mondoze.com\/guide\/wp-json\/wp\/v2\/media?parent=6390"}],"wp:term":[{"taxonomy":"kbtopic","embeddable":true,"href":"https:\/\/www.mondoze.com\/guide\/wp-json\/wp\/v2\/kbtopic?post=6390"},{"taxonomy":"kbtag","embeddable":true,"href":"https:\/\/www.mondoze.com\/guide\/wp-json\/wp\/v2\/kbtag?post=6390"},{"taxonomy":"mkb_version","embeddable":true,"href":"https:\/\/www.mondoze.com\/guide\/wp-json\/wp\/v2\/mkb_version?post=6390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}