{"id":3796,"date":"2015-06-25T15:54:06","date_gmt":"2015-06-25T15:54:06","guid":{"rendered":"http:\/\/www.deuzebranaweb.com.br\/?p=3796"},"modified":"2015-06-25T15:54:06","modified_gmt":"2015-06-25T15:54:06","slug":"definicao-temporaria-da-prioridade-da-swap-no-centos","status":"publish","type":"post","link":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/2015\/06\/25\/definicao-temporaria-da-prioridade-da-swap-no-centos\/","title":{"rendered":"De\u00adfi\u00adni\u00e7\u00e3o tem\u00adpo\u00adr\u00e1ria da pri\u00ado\u00adri\u00addade da Swap no centos"},"content":{"rendered":"<p>About Linux Swapping<\/p>\n<p>Linux RAM is composed of chunks of memory called pages. To free up pages of RAM, a \u201clinux swap\u201d can occur and a page of memory is copied from the RAM to preconfigured space on the hard disk. Linux swaps allow a system to harness more memory than was originally physically available.<\/p>\n<p>However, swapping does have disadvantages. Because hard disks have a much slower memory than RAM, server performance may slow down considerably. Additionally, swap thrashing can begin to take place if the system gets swamped from too many files being swapped in and out.<\/p>\n<p>Check for Swap Space<br \/>\nBefore we proceed to set up a swap file, we need to check if any swap files have been enabled by looking at the summary of swap usage.<\/p>\n<p>swapon -s<br \/>\nIf nothing is returned, the summary is empty and no swap file exists.<\/p>\n<p>Check the File System<br \/>\nAfter we know that we do not have a swap file enabled, we can check how much space we have on the server with the df command. The swap file will take 512MB\u2014 since we are only using up about 7% of the \/dev\/hda, we can proceed.<\/p>\n<p>df<br \/>\nFilesystem 1K-blocks Used Available Use% Mounted on<br \/>\n\/dev\/hda 20642428 1347968 18245884 7% \/<br \/>\nCreate and Enable the Swap File<br \/>\nNow it\u2019s time to create the swap file itself using the dd command :<\/p>\n<p>sudo dd if=\/dev\/zero of=\/swapfile bs=1024 count=512k<br \/>\n\u201cof=\/swapfile\u201d designates the file\u2019s name. In this case the name is swapfile.<\/p>\n<p>Subsequently we are going to prepare the swap file by creating a linux swap area:<\/p>\n<p>sudo mkswap \/swapfile<br \/>\nThe results display:<\/p>\n<p>Setting up swapspace version 1, size = 536866 kB<br \/>\nFinish up by activating the swap file:<\/p>\n<p>sudo swapon \/swapfile<br \/>\nYou will then be able to see the new swap file when you view the swap summary.<\/p>\n<p>swapon -s<br \/>\nFilename Type Size Used Priority<br \/>\n\/swapfile file 524280 0 -1<br \/>\nThis file will last on the server until the machine reboots. You can ensure that the swap is permanent by adding it to the fstab file.<\/p>\n<p>Open up the file:<\/p>\n<p>sudo nano \/etc\/fstab<br \/>\nPaste in the following line:<\/p>\n<p>\/swapfile swap swap defaults 0 0<br \/>\nTo prevent the file from being world-readable, you should set up the correct permissions on the swap file:<\/p>\n<p>chown root:root \/swapfile<br \/>\nchmod 0600 \/swapfile<br \/>\nHow To Configure Swappiness<br \/>\nThe operating system kernel can adjust how often it relies on swap through a configuration parameter known as swappiness.<\/p>\n<p>To find the current swappiness settings, type:<\/p>\n<p>cat \/proc\/sys\/vm\/swappiness<br \/>\n60<br \/>\nSwapiness can be a value from 0 to 100. Swappiness near 100 means that the operating system will swap often and usually, too soon. Although swap provides extra resources, RAM is much faster than swap space. Any time something is moved from RAM to swap, it slows down.<\/p>\n<p>A swappiness value of 0 means that the operating will only rely on swap when it absolutely needs to. We can adjust the swappiness with the sysctl command:<\/p>\n<p>sysctl vm.swappiness=10<br \/>\nvm.swappiness=10<br \/>\nIf we check the system swappiness again, we can confirm that the setting was applied:<\/p>\n<p>cat \/proc\/sys\/vm\/swappiness<br \/>\n10<br \/>\nTo make your VPS automatically apply this setting every time it boots up, you can add the setting to the \/etc\/sysctl.conf file:<\/p>\n<p>sudo nano \/etc\/sysctl.conf<br \/>\n# Search for the vm.swappiness setting. Uncomment and change it as necessary.<br \/>\nvm.swappiness=10<\/p>\n<p>https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-add-swap-on-centos-6<\/p>\n","protected":false},"excerpt":{"rendered":"<p>About Linux Swapping Linux RAM is composed of chunks of memory called pages. To free up pages of RAM, a \u201clinux swap\u201d can occur and a page of memory is copied from the RAM to preconfigured space on the hard disk. Linux swaps allow a&#8230;<\/p>\n","protected":false},"author":2,"featured_media":3829,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_angie_page":false,"page_builder":"","footnotes":""},"categories":[18,19],"tags":[],"class_list":["post-3796","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-comandos-linux","category-whmcapenel"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/posts\/3796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/comments?post=3796"}],"version-history":[{"count":0,"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/posts\/3796\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/media\/3829"}],"wp:attachment":[{"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/media?parent=3796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/categories?post=3796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/tags?post=3796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}