{"id":478,"date":"2019-05-24T20:06:07","date_gmt":"2019-05-24T20:06:07","guid":{"rendered":"https:\/\/www.24x7serversupport.com\/24x7serversupport-blog\/?p=478"},"modified":"2019-05-24T20:06:07","modified_gmt":"2019-05-24T20:06:07","slug":"how-to-add-swap-space-on-centos-7","status":"publish","type":"post","link":"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-swap-space-on-centos-7\/","title":{"rendered":"How To Add Swap Space on CentOS 7"},"content":{"rendered":"\n<p>Swap is a space on a disk that is used when the amount of physical  RAM memory is full. When a Linux system runs out of RAM, inactive pages  are moved from the RAM to the swap space.<\/p>\n\n\n\n<p>Swap space can appear as either a committed swap partition or a swap file. Most of the time when running CentOS on a virtual machine a swap partition is absent so the only option is to make a swap file.<\/p>\n\n\n\n<p>Below are the steps to enable SWAP file on CentOS 7.<\/p>\n\n\n\n<p>Check if your CentOS installation already has swap enabled :<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p># swapon &#8211;show<\/p><\/blockquote>\n\n\n\n<p>The Output would be as below:<\/p>\n\n\n\n<p><strong>NAME      TYPE      SIZE USED PRIO<br \/> \/dev\/sda3 partition 4G   0B   -1<\/strong><\/p>\n\n\n\n<p>If the output is null, it means that the server does not have swap space enabled. <\/p>\n\n\n\n<p>In order to create SWAP file, the user you are logged in with should have sudo privileges or root access to the server.<\/p>\n\n\n\n<p>Follow the steps below to add swap space on a CentOS 7 system.<\/p>\n\n\n\n<p>Create a file which will be used as swap space: <\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p># fallocate -l 8G \/swapfile<\/p><\/blockquote>\n\n\n\n<p>You can replace the value 8G if you wish to add more swap space on server.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p># chmod 600 \/swapfile<\/p><\/blockquote>\n\n\n\n<p>Set up a Linux swap area on the file: <\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p># mkswap \/swapfile<\/p><\/blockquote>\n\n\n\n<p>To activate SWAP :<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p># swapon \/swapfile<\/p><\/blockquote>\n\n\n\n<p>To make the change permanent, edit the \/etc\/fstab file:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p># vi \/etc\/fstab<\/p><\/blockquote>\n\n\n\n<p><strong>\/swapfile swap swap defaults 0 0<\/strong><\/p>\n\n\n\n<p>Verify the swap is activated on server<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p># swapon &#8211;show<\/p><\/blockquote>\n\n\n\n<p><strong>NAME      TYPE  SIZE   USED PRIO<br \/> \/swapfile file \u202d8,192\u202cM 1055.8M   -1<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p># free -h<\/p><\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>     total        used        free      shared  buff\/cache   available \nMem:  4096M       547M       3549M      2.3M        541M        874M \nSwap: 8.0G        1055M        6845M<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Adjust Swappiness value<\/h4>\n\n\n\n<p>Swappiness is a Linux kernel property that defines how often the system will use the swap space. Swappiness can have a value between 0 and 100. A low value will make the kernel to try to avoid swapping whenever possible while a higher value will make the kernel to use the swap space more aggressively.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p># cat \/proc\/sys\/vm\/swappiness<\/p><\/blockquote>\n\n\n\n<p><strong>30<\/strong><\/p>\n\n\n\n<p>Set lower value on Production servers<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p># sysctl vm.swappiness=10<\/p><\/blockquote>\n\n\n\n<p>Also make the changes persistent after reboot:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p># vi \/etc\/sysctl.conf<\/p><\/blockquote>\n\n\n\n<p><strong>vm.swappiness=10<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p># sysctl -p<\/p><\/blockquote>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Swap is a space on a disk that is used when the amount of physical RAM memory is full. When a Linux system runs out of RAM, inactive pages are moved from the RAM to the swap space. Swap space can appear as either a committed swap partition or a swap file. Most of the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[30,34],"tags":[114,115],"class_list":["post-478","post","type-post","status-publish","format-standard","hentry","category-centos","category-linux","tag-centos-7","tag-swap"],"jetpack_publicize_connections":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Add Swap Space on CentOS 7 | 24x7serversupport Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-swap-space-on-centos-7\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Add Swap Space on CentOS 7 | 24x7serversupport Blog\" \/>\n<meta property=\"og:description\" content=\"Swap is a space on a disk that is used when the amount of physical RAM memory is full. When a Linux system runs out of RAM, inactive pages are moved from the RAM to the swap space. Swap space can appear as either a committed swap partition or a swap file. Most of the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-swap-space-on-centos-7\/\" \/>\n<meta property=\"og:site_name\" content=\"24x7serversupport Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-24T20:06:07+00:00\" \/>\n<meta name=\"author\" content=\"24x7support\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@24x7serversuppo\" \/>\n<meta name=\"twitter:site\" content=\"@24x7serversuppo\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"24x7support\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-swap-space-on-centos-7\/\",\"url\":\"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-swap-space-on-centos-7\/\",\"name\":\"How To Add Swap Space on CentOS 7 | 24x7serversupport Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/#website\"},\"datePublished\":\"2019-05-24T20:06:07+00:00\",\"dateModified\":\"2019-05-24T20:06:07+00:00\",\"author\":{\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/#\/schema\/person\/decfb5fad6bde6ac6822d4e965c6d401\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-swap-space-on-centos-7\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-swap-space-on-centos-7\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-swap-space-on-centos-7\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.24x7serversupport.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Add Swap Space on CentOS 7\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/#website\",\"url\":\"https:\/\/www.24x7serversupport.com\/blog\/\",\"name\":\"24x7serversupport Blog\",\"description\":\"Linux | CPanel | WHM | webhosting| Plesk | DirectAdmin | CentOs | Debian | Ubuntu Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.24x7serversupport.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/#\/schema\/person\/decfb5fad6bde6ac6822d4e965c6d401\",\"name\":\"24x7support\",\"url\":\"https:\/\/www.24x7serversupport.com\/blog\/author\/24x7support\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Add Swap Space on CentOS 7 | 24x7serversupport Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-swap-space-on-centos-7\/","og_locale":"en_US","og_type":"article","og_title":"How To Add Swap Space on CentOS 7 | 24x7serversupport Blog","og_description":"Swap is a space on a disk that is used when the amount of physical RAM memory is full. When a Linux system runs out of RAM, inactive pages are moved from the RAM to the swap space. Swap space can appear as either a committed swap partition or a swap file. Most of the [&hellip;]","og_url":"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-swap-space-on-centos-7\/","og_site_name":"24x7serversupport Blog","article_published_time":"2019-05-24T20:06:07+00:00","author":"24x7support","twitter_card":"summary_large_image","twitter_creator":"@24x7serversuppo","twitter_site":"@24x7serversuppo","twitter_misc":{"Written by":"24x7support","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-swap-space-on-centos-7\/","url":"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-swap-space-on-centos-7\/","name":"How To Add Swap Space on CentOS 7 | 24x7serversupport Blog","isPartOf":{"@id":"https:\/\/www.24x7serversupport.com\/blog\/#website"},"datePublished":"2019-05-24T20:06:07+00:00","dateModified":"2019-05-24T20:06:07+00:00","author":{"@id":"https:\/\/www.24x7serversupport.com\/blog\/#\/schema\/person\/decfb5fad6bde6ac6822d4e965c6d401"},"breadcrumb":{"@id":"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-swap-space-on-centos-7\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.24x7serversupport.com\/blog\/how-to-add-swap-space-on-centos-7\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-swap-space-on-centos-7\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.24x7serversupport.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How To Add Swap Space on CentOS 7"}]},{"@type":"WebSite","@id":"https:\/\/www.24x7serversupport.com\/blog\/#website","url":"https:\/\/www.24x7serversupport.com\/blog\/","name":"24x7serversupport Blog","description":"Linux | CPanel | WHM | webhosting| Plesk | DirectAdmin | CentOs | Debian | Ubuntu Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.24x7serversupport.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.24x7serversupport.com\/blog\/#\/schema\/person\/decfb5fad6bde6ac6822d4e965c6d401","name":"24x7support","url":"https:\/\/www.24x7serversupport.com\/blog\/author\/24x7support\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/posts\/478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/comments?post=478"}],"version-history":[{"count":0,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/posts\/478\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/media?parent=478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/categories?post=478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/tags?post=478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}