{"id":522,"date":"2019-01-14T08:35:29","date_gmt":"2019-01-14T08:35:29","guid":{"rendered":"http:\/\/linuxresellerwebhosting.in\/blog\/?p=522"},"modified":"2019-02-13T03:51:55","modified_gmt":"2019-02-13T03:51:55","slug":"how-to-create-swap-memory-on-linux","status":"publish","type":"post","link":"https:\/\/linuxresellerwebhosting.in\/blog\/how-to-create-swap-memory-on-linux\/","title":{"rendered":"How to Create SWAP Memory on Linux"},"content":{"rendered":"\n<p>\nA <strong>swap<\/strong> file (or <strong>swap<\/strong> space or, in Windows NT, a pagefile) is a space on a hard disk used as the virtual <strong>memory<\/strong> extension of a computer&#8217;s real <strong>memory<\/strong> (<strong>RAM<\/strong>). Having a <strong>swap<\/strong> file allows your computer&#8217;s operating system to pretend that you have more <strong>RAM<\/strong> than you actually do\n\n<\/p>\n\n\n\n<p> So here it is a simple tutorial you can follow.  The most common practice is to add half of your existing RAM up to 4GB.  For example: if you have 1GB actual RAM allocated to your vps, then you  can create about 512MB swap file. <\/p>\n\n\n\n<p>The simple calculation is:  <\/p>\n\n\n\n<p>1024 block size x 512MB = 524288 block size. Now add that to the command: <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>[root@server ~]#  dd if=\/dev\/zeroof=\/swapfilebs=1024 count=524288<\/p>\n\n\n\n<p>\nNext, create a swap file area using this command syntax:\n\n<\/p>\n\n\n\n<p> [root@server~ ]# mkswap \/swapfile<\/p>\n\n\n\n<p>\nDefine the owner of the newly created swap file and swap area then set correct permission on it:\n\n<\/p>\n\n\n\n<p>  [root@server~ ]# chown root:root \/swapfile<br>   [root@server~ ]# chmod 0600 \/swapfile<\/p>\n\n\n\n<p>\nActivate Swap you newly setup using this command:\n\n<\/p>\n\n\n\n<p>  [root@server~ ]# swapon \/swapfile<\/p>\n\n\n\n<p>Finally, issue command below to verify that Swap has been setup and enabled:<\/p>\n\n\n\n<p>  [root@server~ ]# swapon -s<\/p>\n\n\n\n<p>\nThe last thing to do is to configure Swap to run and enabled each time \nyour server reboots. Use Nano editor (or vi) to adjust fstab setting:\n\n<\/p>\n\n\n\n<p>  [root@server~ ]# vi \/etc\/fstab<\/p>\n\n\n\n<p> then add following line at the very bottom <\/p>\n\n\n\n<p>  [root@server~ ]# \/swapfile none swap sw 0 0<\/p>\n\n\n\n<p>\nFrom here on, each time you check your RAM usage using <strong>free -m<\/strong> command, it should display your swap too.\n\n<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A swap file (or swap space or, in Windows NT, a pagefile) is a space on a hard disk used<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[1],"tags":[],"class_list":["post-522","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/comments?post=522"}],"version-history":[{"count":3,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/522\/revisions"}],"predecessor-version":[{"id":525,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/522\/revisions\/525"}],"wp:attachment":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/media?parent=522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/categories?post=522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/tags?post=522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}