{"id":1134,"date":"2011-06-10T23:49:10","date_gmt":"2011-06-10T15:49:10","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=1134"},"modified":"2023-06-23T10:34:38","modified_gmt":"2023-06-23T10:34:38","slug":"how-to-check-memory-usage-in-linux","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-check-memory-usage-in-linux\/","title":{"rendered":"How to Check Memory Usage In Linux"},"content":{"rendered":"<p>In Linux server administration, understanding how to monitor and manage memory usage is a critical skill. This comprehensive guide will walk you through the process of checking memory usage on a Linux server, including free memory, used physical memory, swap memory, and buffers used by the kernel. This knowledge is essential for maintaining optimal server performance and troubleshooting issues.<\/p>\n<p>For a deeper understanding of server types, you may want to explore our articles on the <a href=\"https:\/\/webhostinggeeks.com\/best\/web-server\/\">best web servers<\/a>, including <a href=\"https:\/\/webhostinggeeks.com\/blog\/apache-http-server-explained\/\">Apache<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/nginx-server-explained\/\">Nginx<\/a>, and <a href=\"https:\/\/webhostinggeeks.com\/blog\/litespeed-web-server-explained\/\">LiteSpeed<\/a>. Also, consider learning about different hosting types such as <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-dedicated-server-hosting\/\">dedicated server<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-vps-hosting\/\">VPS server<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-cloud-hosting\/\">cloud hosting<\/a>, and <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-shared-hosting\/\">shared hosting<\/a>.<\/p>\n<h2>Checking Memory Usage with the &#8216;top&#8217; Command<\/h2>\n<p>The &#8216;top&#8217; command is a powerful tool for monitoring system activity in real-time. It provides a dynamic, real-time view of the running system, displaying system summary information and a list of processes currently managed by the Linux kernel.<\/p>\n<p>To use the &#8216;top&#8217; command, simply type &#8216;top&#8217; into the terminal or SSH login:<\/p>\n<pre>\r\n[root@server ~]# top\r\n<\/pre>\n<p>This command will display a variety of information, including the total number of tasks, the number of running tasks, CPU usage, and detailed memory usage.<\/p>\n<pre>top - 23:35:48 up  1:36,  1 user,  load average: 0.00, 0.01, 0.02\r\nTasks:  67 total,   1 running,  66 sleeping,   0 stopped,   0 zombie\r\nCpu(s):  0.4%us,  1.8%sy,  0.1%ni, 95.6%id,  2.1%wa,  0.1%hi,  0.0%si,  0.0%st\r\nMem:    604324k total,   329952k used,   274372k free,    65428k buffers\r\nSwap:  1052248k total,        0k used,  1052248k free,   208324k cached\r\n\r\n  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND\r\n    1 root      15   0  2156  640  548 S  0.0  0.1   0:01.03 init\r\n    2 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 migration\/0\r\n    3 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd\/0\r\n    4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog\/0\r\n    5 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 events\/0\r\n    6 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 khelper\r\n    7 root      11  -5     0    0    0 S  0.0  0.0   0:00.00 kthread\r\n   10 root      10  -5     0    0    0 S  0.0  0.0   0:00.01 kblockd\/0\r\n   11 root      20  -5     0    0    0 S  0.0  0.0   0:00.00 kacpid\r\n  170 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 cqueue\/0\r\n  173 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 khubd\r\n  175 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 kseriod\r\n  240 root      15   0     0    0    0 S  0.0  0.0   0:00.00 khungtaskd\r\n  241 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pdflush\r\n  242 root      15   0     0    0    0 S  0.0  0.0   0:00.20 pdflush\r\n  243 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 kswapd0\r\n  244 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 aio\/0\r\n<\/pre>\n<h2>Using the &#8216;vmstat&#8217; Command to Monitor Memory<\/h2>\n<p>The &#8216;vmstat&#8217; command, short for &#8216;virtual memory statistics&#8217;, provides information about system processes, memory, paging, block IO, traps, and CPU activity.<\/p>\n<p>To use the &#8216;vmstat&#8217; command, type &#8216;vmstat&#8217; into the terminal or SSH login:<\/p>\n<pre>\r\n[root@server ~]# vmstat\r\n<\/pre>\n<p>The output of this command provides a snapshot of the system&#8217;s memory usage, including swap memory.<\/p>\n<pre>procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------\r\n r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st\r\n 0  0      0 273256  65688 208884    0    0    79    39 1039   84  0  2 96  2  0\r\n<\/pre>\n<h2>Displaying Memory Usage with the &#8216;free&#8217; Command<\/h2>\n<p>The &#8216;free&#8217; command is a simple and easy-to-use tool that displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel.<\/p>\n<p>The &#8216;free&#8217; command can display the output in various units (bytes, KB, MB, or GB) using the -b, -k, -m, or -g options. For instance, to display the total memory in MB, use the following command:<\/p>\n<pre>\r\n[root@server ~]# free -m -t\r\n<\/pre>\n<p>The &#8216;-t&#8217; option adds a line at the bottom of the output, showing the total physical and swap memory.<\/p>\n<pre>             total       used       free     shared    buffers     cached\r\nMem:           590        323        266          0         64        204\r\n-\/+ buffers\/cache:         54        535\r\nSwap:         1027          0       1027\r\nTotal:        1617        323       1294\r\n<\/pre>\n<h2>Checking Memory Usage via &#8216;\/proc\/meminfo&#8217;<\/h2>\n<p>The &#8216;\/proc\/meminfo&#8217; file contains real-time information about the system&#8217;s memory usage. You can view its contents with the &#8216;cat&#8217; command:<\/p>\n<pre>\r\n[root@server ~]# cat \/proc\/meminfo\r\n<\/pre>\n<p>The output provides detailed information aboutthe system&#8217;s memory, including total memory, free memory, memory used for buffers, and cached memory. It also provides information about swap memory and various other memory-related statistics.<\/p>\n<pre>\r\nMemTotal:       604324 kB\r\nMemFree:        272512 kB\r\nBuffers:         66040 kB\r\nCached:         209256 kB\r\nSwapCached:          0 kB\r\nActive:          61864 kB\r\nInactive:       222596 kB\r\nHighTotal:           0 kB\r\nHighFree:            0 kB\r\nLowTotal:       604324 kB\r\nLowFree:        272512 kB\r\nSwapTotal:     1052248 kB\r\nSwapFree:      1052248 kB\r\nDirty:            1032 kB\r\nWriteback:           0 kB\r\nAnonPages:        9172 kB\r\nMapped:           6468 kB\r\nSlab:            39896 kB\r\nPageTables:        972 kB\r\nNFS_Unstable:        0 kB\r\nBounce:              0 kB\r\nCommitLimit:   1354408 kB\r\nCommitted_AS:    76248 kB\r\nVmallocTotal:   417784 kB\r\nVmallocUsed:      4052 kB\r\nVmallocChunk:   413304 kB\r\nHugePages_Total:     0\r\nHugePages_Free:      0\r\nHugePages_Rsvd:      0\r\nHugepagesize:     4096 kB\r\n<\/pre>\n<h2>Commands Mentioned<\/h2>\n<ul>\n<li><span class=\"fw-bold\">top<\/span> \u2013 Displays real-time system summary information and a list of processes currently managed by the Linux kernel.<\/li>\n<li><span class=\"fw-bold\">vmstat<\/span> \u2013 Provides information about system processes, memory, paging, block IO, traps, and CPU activity.<\/li>\n<li><span class=\"fw-bold\">free<\/span> \u2013 Displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel.<\/li>\n<li><span class=\"fw-bold\">cat \/proc\/meminfo<\/span> \u2013 Displays real-time information about the system&#8217;s memory usage.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Monitoring memory usage is a vital part of Linux server administration. It allows you to understand how your server&#8217;s resources are being utilized and helps in identifying any potential issues that might affect performance. The &#8216;top&#8217;, &#8216;vmstat&#8217;, &#8216;free&#8217;, and &#8216;cat \/proc\/meminfo&#8217; commands are powerful tools that provide detailed and real-time information about your server&#8217;s memory usage.<\/p>\n<p>By understanding how to use these commands effectively, you can ensure that your server is running efficiently and troubleshoot any issues that arise. Whether you&#8217;re running a <a href=\"https:\/\/webhostinggeeks.com\/blog\/apache-http-server-explained\/\">Apache<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/nginx-server-explained\/\">Nginx<\/a>, or <a href=\"https:\/\/webhostinggeeks.com\/blog\/litespeed-web-server-explained\/\">LiteSpeed<\/a> server, on a <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-dedicated-server-hosting\/\">dedicated<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-vps-hosting\/\">VPS<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-cloud-hosting\/\">cloud<\/a>, or <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-shared-hosting\/\">shared hosting<\/a> environment, these skills will be invaluable.<\/p>\n<p>Remember, regular monitoring and maintenance are the keys to a healthy and high-performing server. Stay tuned for more in-depth tutorials and guides to help you navigate the world of web server administration.<\/p>\n<h2>FAQs<\/h2>\n<ol itemscope itemtype=\"https:\/\/schema.org\/FAQPage\">\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What does the &#8216;top&#8217; command do in Linux?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The &#8216;top&#8217; command in Linux provides a dynamic real-time view of the running system. It displays system summary information and a list of processes currently being managed by the Linux kernel, including information about CPU usage and detailed memory usage.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">How does the &#8216;vmstat&#8217; command help in monitoring memory?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The &#8216;vmstat&#8217; command, short for &#8216;virtual memory statistics&#8217;, provides information about system processes, memory, paging, block IO, traps, and CPU activity. It gives a snapshot of the system&#8217;s memory usage, including swap memory, which can be useful for monitoring and troubleshooting.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What information does the &#8216;free&#8217; command provide?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The &#8216;free&#8217; command in Linux displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel. The output can be displayed in various units such as bytes, KB, MB, or GB.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">How can I check memory usage via &#8216;\/proc\/meminfo&#8217;?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The &#8216;\/proc\/meminfo&#8217; file in Linux contains real-time information about the system&#8217;s memory usage. You can view its contents with the &#8216;cat&#8217; command, which provides detailed information about total memory, free memory, memory used for buffers, cached memory, and various other memory-related statistics.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">Why is monitoring memory usage important?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">Monitoring memory usage is crucial for maintaining optimal server performance. It helps in identifying processes that are consuming excessive memory, which could slow down or even crash the system. Regular monitoring can help in troubleshooting issues, planning for upgrades, and ensuring efficient resource utilization.<\/span>\n            <\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In Linux server administration, understanding how to monitor and manage memory usage is a critical skill. This comprehensive guide will walk you through the process of checking memory usage on&#8230;<\/p>\n","protected":false},"author":6,"featured_media":323,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[996],"tags":[1536,1691],"class_list":["post-1134","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-linux","tag-ram"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/1134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=1134"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/1134\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/323"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=1134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=1134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=1134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}