{"id":13242,"date":"2019-04-01T09:31:21","date_gmt":"2019-04-01T09:31:21","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13242"},"modified":"2019-04-01T09:31:21","modified_gmt":"2019-04-01T09:31:21","slug":"8-useful-commands-to-monitor-swap-space-usage-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/8-useful-commands-to-monitor-swap-space-usage-in-linux\/","title":{"rendered":"8 Useful Commands to Monitor Swap Space Usage in Linux"},"content":{"rendered":"<p>Memory management is an essential aspect of every System Administrator to improve the performance of a Linux system. It is always a good practice to monitor swap space usage in Linux to ensure that your system operates relative to its memory demands.<\/p>\n<div id=\"attachment_16231\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Check-Linux-Swap-Space-Usage.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-16231\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Check-Linux-Swap-Space-Usage.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Check-Linux-Swap-Space-Usage.png 718w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Check-Linux-Swap-Space-Usage-620x295.png 620w\" alt=\"Check Linux Swap Space Usage\" width=\"620\" height=\"295\" aria-describedby=\"caption-attachment-16231\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-16231\" class=\"wp-caption-text\">8 Commands to Check Linux Swap Space Usage<\/p>\n<\/div>\n<p>Therefore in this article we are going to look at ways to monitor swap space usage in a Linux systems.<\/p>\n<h4>What is Swap space?<\/h4>\n<p><strong>Swap<\/strong>\u00a0space is a restricted amount of physical memory that is allocated for use by the operating system when available memory has been fully utilized. It is memory management that involves swapping sections of memory to and from physical storage.<\/p>\n<p>On most distributions of Linux, it is recommended that you set swap space when installing the operating system. The amount of swap space you can set for your Linux system may depend on the architecture and kernel version.<\/p>\n<h3>How do I check Swap space usage in Linux?<\/h3>\n<p>We shall look at different commands and tools that can help you to monitor your swap space usage in your Linux systems as follows:<\/p>\n<h4>1. Using the swapon Command<\/h4>\n<p>This command helps you to specify the devices on which paging and swapping will be done and we shall look at few important options.<\/p>\n<p>To view all devices marked as swap in the\u00a0<strong>\/etc\/fstab<\/strong>\u00a0file you can use the\u00a0<code>--all<\/code>\u00a0option. Though devices that are already working as swap space are skipped.<\/p>\n<pre># swapon --all\r\n<\/pre>\n<p>If you want to view a summary of swap space usage by device, use the\u00a0<code>--summary<\/code>\u00a0option as follows.<\/p>\n<pre><strong># swapon --summary<\/strong>\r\n\r\nFilename\t\t\t\tType\t\tSize\tUsed\tPriority\r\n\/dev\/sda10                              partition\t8282108\t0\t-1\r\n<\/pre>\n<p>Use\u00a0<code>--help<\/code>\u00a0option to view help information or open the manpage for more usage options.<\/p>\n<h4>2. Using \/proc\/swaps which is equivalent to swapon<\/h4>\n<p>The\u00a0<strong>\/proc<\/strong>\u00a0filesystem is a very special virtual filesystem in Linux. It is also referred to as a process information pseudo-file system.<\/p>\n<p>It actually does not contain \u2018real\u2019 files but runtime system information, for example system memory, devices mounted, hardware configuration and many more. Therefore you can also refer to it as a control and information base for the kernel.<\/p>\n<p>To understand more about this filesystem read our article:\u00a0<a href=\"https:\/\/www.tecmint.com\/exploring-proc-file-system-in-linux\/\" target=\"_blank\" rel=\"noopener\">Understanding \/proc File System in Linux<\/a>.<\/p>\n<p>To check swap usage information, you can view the\u00a0<strong>\/proc\/swaps<\/strong>\u00a0file using the\u00a0<a href=\"https:\/\/www.tecmint.com\/13-basic-cat-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">cat utility<\/a>.<\/p>\n<pre><strong># cat \/proc\/swaps<\/strong>\r\n\r\nFilename\t\t\t\tType\t\tSize\tUsed\tPriority\r\n\/dev\/sda10                              partition\t8282108\t0\t-1\r\n<\/pre>\n<h4>3. Using \u2018free\u2019 Command<\/h4>\n<p>The\u00a0<strong>free<\/strong>\u00a0command is used to display the amount of free and used system memory. Using the free command with\u00a0<strong>-h<\/strong>\u00a0option, which displays output in a human readable format.<\/p>\n<pre><strong># free -h<\/strong>\r\n\r\n             total       used       free     shared    buffers     cached\r\nMem:          7.7G       4.7G       3.0G       408M       182M       1.8G\r\n-\/+ buffers\/cache:       2.7G       5.0G\r\nSwap:         7.9G         0B       7.9G\r\n<\/pre>\n<p>From the output above, you can see that the last line provides information about the system swap space. For more usage and examples of free command can be found at:\u00a0<a href=\"https:\/\/www.tecmint.com\/check-memory-usage-in-linux\/\" target=\"_blank\" rel=\"noopener\">10 free Command to Check Memory Usage in Linux<\/a>.<\/p>\n<h4>4. Using top Command<\/h4>\n<p>The top command displays processor activity of your Linux system, tasks managed by kernel in real-time. To understand how the top command works, read this article:\u00a0<a href=\"https:\/\/www.tecmint.com\/12-top-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">12 top Commands to Check Linux Process Activity<\/a><\/p>\n<p>To check swap space usage with the help of \u2018top\u2019 command run the following command.<\/p>\n<pre># top\r\n<\/pre>\n<div id=\"attachment_16129\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Check-Swap-Space-Using-Top-Command.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-16129\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Check-Swap-Space-Using-Top-Command-620x344.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Check-Swap-Space-Using-Top-Command-620x344.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Check-Swap-Space-Using-Top-Command.png 826w\" alt=\"Check Swap Space Using Top Command\" width=\"620\" height=\"344\" aria-describedby=\"caption-attachment-16129\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-16129\" class=\"wp-caption-text\">Check Swap Space Using Top Command<\/p>\n<\/div>\n<h4>5. Using atop Command<\/h4>\n<p>The\u00a0<strong>atop<\/strong>\u00a0command is a system monitor that reports about activities of various processes. But importantly it also shows information about free and used memory space.<\/p>\n<pre># atop\r\n<\/pre>\n<div id=\"attachment_16130\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Atop-Check-Swap-Usage.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-16130\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Atop-Check-Swap-Usage-620x344.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Atop-Check-Swap-Usage-620x344.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Atop-Check-Swap-Usage.png 826w\" alt=\"Atop Check Swap Usage\" width=\"620\" height=\"344\" aria-describedby=\"caption-attachment-16130\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-16130\" class=\"wp-caption-text\">Atop Check Swap Usage<\/p>\n<\/div>\n<p>To know more about how to install and use atop command in Linux, read this article:\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-install-atop-to-monitor-logging-activity-of-linux-system-processes\/\" target=\"_blank\" rel=\"noopener\">Monitor Logging Activity of Linux System Processes<\/a><\/p>\n<h4>6. Using htop Command<\/h4>\n<p>The htop command is used to view processes in an interactive mode and also displays information about memory usage.<\/p>\n<pre># htop\r\n<\/pre>\n<div id=\"attachment_16131\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Htop-Check-Swap-Usage.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-16131\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Htop-Check-Swap-Usage-620x344.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Htop-Check-Swap-Usage-620x344.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Htop-Check-Swap-Usage.png 826w\" alt=\"Htop Check Swap Usage\" width=\"620\" height=\"344\" aria-describedby=\"caption-attachment-16131\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-16131\" class=\"wp-caption-text\">Htop Check Swap Usage<\/p>\n<\/div>\n<p>For more information regarding installation and usage about htop command, read this article:\u00a0<a href=\"https:\/\/www.tecmint.com\/install-htop-linux-process-monitoring-for-rhel-centos-fedora\/\" target=\"_blank\" rel=\"noopener\">Htop \u2013 Interactive Linux Process Monitoring<\/a><\/p>\n<h4>7. Using the Glances Command<\/h4>\n<p>This is a cross-platform system monitoring tool that displays information about running processes, cpu load, storage space usage, memory usage, swap space usage and many more.<\/p>\n<pre># glances\r\n<\/pre>\n<div id=\"attachment_16132\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Glances-Check-Swap-usage.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-16132\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Glances-Check-Swap-usage-620x344.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Glances-Check-Swap-usage-620x344.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Glances-Check-Swap-usage.png 826w\" alt=\"Glances Check Swap Usage\" width=\"620\" height=\"344\" aria-describedby=\"caption-attachment-16132\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-16132\" class=\"wp-caption-text\">Glances Check Swap Usage<\/p>\n<\/div>\n<p>For more information regarding installation and usage about\u00a0<strong>glances<\/strong>\u00a0command, read this article:\u00a0<a href=\"https:\/\/www.tecmint.com\/glances-an-advanced-real-time-system-monitoring-tool-for-linux\/\" target=\"_blank\" rel=\"noopener\">Glances \u2013 An Advanced Real Time Linux System Monitoring Tool<\/a><\/p>\n<h4>8. Using the vmstat Command<\/h4>\n<p>This command is used to display information about virtual memory statistics. To install vmstat on your Linux system, you can read the article below and see more usage examples:<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/linux-performance-monitoring-with-vmstat-and-iostat-commands\/https:\/\/www.tecmint.com\/linux-performance-monitoring-with-vmstat-and-iostat-commands\/\" target=\"_blank\" rel=\"noopener\">Linux Performance Monitoring with Vmstat<\/a><\/p>\n<pre># vmstat\r\n<\/pre>\n<div id=\"attachment_16133\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/VmStat-Check-Swap-Usage.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-16133\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/VmStat-Check-Swap-Usage-620x344.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/VmStat-Check-Swap-Usage-620x344.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/VmStat-Check-Swap-Usage.png 826w\" alt=\"VmStat Check Swap Usage\" width=\"620\" height=\"344\" aria-describedby=\"caption-attachment-16133\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-16133\" class=\"wp-caption-text\">VmStat Check Swap Usage<\/p>\n<\/div>\n<p>You need to take note of the following in the swap field from the output of this command.<\/p>\n<ol>\n<li><strong>si<\/strong>: Amount of memory swapped in from disk (s).<\/li>\n<li><strong>so<\/strong>: Amount of memory swapped to disk (s).<\/li>\n<\/ol>\n<h3>Summary<\/h3>\n<p>These are easy methods one can use and follow to monitor swap space usage and hope this article was helpful. In case you need help or want to add any information relating to memory management in Linux systems, please post a comment.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/commands-to-monitor-swap-space-usage-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Memory management is an essential aspect of every System Administrator to improve the performance of a Linux system. It is always a good practice to monitor swap space usage in Linux to ensure that your system operates relative to its memory demands. 8 Commands to Check Linux Swap Space Usage Therefore in this article we &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/8-useful-commands-to-monitor-swap-space-usage-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;8 Useful Commands to Monitor Swap Space Usage in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13242","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13242"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13242\/revisions"}],"predecessor-version":[{"id":13243,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13242\/revisions\/13243"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}