{"id":13252,"date":"2019-04-01T09:49:41","date_gmt":"2019-04-01T09:49:41","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13252"},"modified":"2019-04-01T09:49:41","modified_gmt":"2019-04-01T09:49:41","slug":"how-to-permanently-disable-swap-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/how-to-permanently-disable-swap-in-linux\/","title":{"rendered":"How to Permanently Disable Swap in Linux"},"content":{"rendered":"<p>Swapping or swap space represents a physical memory page that lives on top of disk partition or a special disk file used for extending the RAM memory of a system when the physical memory fills up.<\/p>\n<p>Using this method of extending RAM resources, inactive memory pages are frequently dumped into the swap area when no RAM is available. However, do to the spinning speed of classical hard disks, swap space is way lower in transfer speeds and access time compared to RAM.<\/p>\n<p>On newer machines with fast SSD hard disks, reserving a small partition for swapping can greatly improve access time and speed transfer compared to classical HDD, but the speed is still more magnitudes lower than RAM memory. Some suggest that the swap space should be set as twice the amount of machine RAM. However, on systems with more than 4 GB or RAM, swap space should be set between\u00a0<strong>2<\/strong>\u00a0or\u00a0<strong>4<\/strong>\u00a0GB.<\/p>\n<p>In case your server has sufficient RAM memory or does not require the use of swap space or the swapping greatly decreases your system performance, you should consider disabling the swap area.<\/p>\n<p>Before actually disabling swap space, first you need to visualize your memory load degree and then identify the partition that holds the swap area, by issuing the below commands.<\/p>\n<pre># free -h \r\n<\/pre>\n<p>Look for Swap space used size. If the used size is\u00a0<strong>0B<\/strong>\u00a0or close to\u00a0<strong>0<\/strong>\u00a0bytes, it can be assumed that swap space is not used intensively and can be safety disabled.<\/p>\n<div id=\"attachment_28135\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/12\/Check-Swap-Space.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28135\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/12\/Check-Swap-Space.png\" alt=\"Check Swap Space\" width=\"619\" height=\"75\" aria-describedby=\"caption-attachment-28135\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28135\" class=\"wp-caption-text\">Check Swap Space<\/p>\n<\/div>\n<p>Next, issue following\u00a0<strong>blkid command<\/strong>, look for\u00a0<code>TYPE=\u201dswap\u201d<\/code>\u00a0line in order to identify the swap partition, as shown in the below screenshot.<\/p>\n<pre># blkid \r\n<\/pre>\n<div id=\"attachment_28136\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/12\/Check-Swap-Partition-Type.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28136\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/12\/Check-Swap-Partition-Type.png\" alt=\"Check Swap Partition Type\" width=\"634\" height=\"76\" aria-describedby=\"caption-attachment-28136\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28136\" class=\"wp-caption-text\">Check Swap Partition Type<\/p>\n<\/div>\n<p>Again, issue the following\u00a0<strong>lsblk command<\/strong>\u00a0to search and identify the\u00a0<code>[SWAP]<\/code>\u00a0partition as shown in the below screenshot.<\/p>\n<pre># lsblk\r\n<\/pre>\n<div id=\"attachment_28137\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/12\/Search-Confirm-Swap-Partition.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28137\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/12\/Search-Confirm-Swap-Partition.png\" alt=\"Search Confirm Swap Partition\" width=\"456\" height=\"124\" aria-describedby=\"caption-attachment-28137\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28137\" class=\"wp-caption-text\">Search Confirm Swap Partition<\/p>\n<\/div>\n<p>After you\u2019ve identified the swap partition or file, execute the below command to deactivate the swap area.<\/p>\n<pre># swapoff \/dev\/mapper\/centos-swap  \r\n<\/pre>\n<p>Or disable all swaps from \/proc\/swaps<\/p>\n<pre># swapoff -a \r\n<\/pre>\n<p>Run\u00a0<a href=\"https:\/\/www.tecmint.com\/check-memory-usage-in-linux\/\" target=\"_blank\" rel=\"noopener\">free command<\/a>\u00a0in order to check if the swap area has been disabled.<\/p>\n<pre># free -h\r\n<\/pre>\n<div id=\"attachment_28138\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/12\/Disable-Swap-Partition.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28138\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/12\/Disable-Swap-Partition.png\" alt=\"Disable Swap Partition\" width=\"697\" height=\"107\" aria-describedby=\"caption-attachment-28138\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28138\" class=\"wp-caption-text\">Disable Swap Partition<\/p>\n<\/div>\n<p>In order to permanently disable swap space in Linux, open\u00a0<strong>\/etc\/fstab<\/strong>\u00a0file, search for the swap line and comment the entire line by adding a\u00a0<code>#<\/code>\u00a0(hashtag) sign in front of the line, as shown in the below screenshot.<\/p>\n<pre># vi \/etc\/fstab\r\n<\/pre>\n<div id=\"attachment_28139\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/12\/Disable-Swap-Partition-Permanently.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28139\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/12\/Disable-Swap-Partition-Permanently.png\" alt=\"Disable Swap Partition Permanently\" width=\"647\" height=\"166\" aria-describedby=\"caption-attachment-28139\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28139\" class=\"wp-caption-text\">Disable Swap Partition Permanently<\/p>\n<\/div>\n<p>Afterwards,\u00a0<strong>reboot<\/strong>\u00a0the system in order to apply the new swap setting or issuing\u00a0<code>mount -a<\/code>\u00a0command in some cases might do the trick.<\/p>\n<pre># mount -a\r\n<\/pre>\n<p>After system reboot, issuing the commands presented in the beginning of this tutorial should reflect that the swap area has been completely and permanently disabled in your system.<\/p>\n<pre># free -h\r\n# blkid \r\n# lsblk<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/disable-swap-partition-in-centos-ubuntu\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Swapping or swap space represents a physical memory page that lives on top of disk partition or a special disk file used for extending the RAM memory of a system when the physical memory fills up. Using this method of extending RAM resources, inactive memory pages are frequently dumped into the swap area when no &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/how-to-permanently-disable-swap-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Permanently Disable Swap 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-13252","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\/13252","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=13252"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13252\/revisions"}],"predecessor-version":[{"id":13253,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13252\/revisions\/13253"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}