![]() Now that we have a file of the correct size available, we need to actually turn this into swap space.įirst, we need to lock down the permissions of the file so that only the users with root privileges can read the contents. Our file has been created with the correct amount of space set aside. We can verify that the correct amount of space was reserved by typing: Adjust this to meet the needs of your own server: Since the server in our example has 1G of RAM, we will create a 1G file in this guide. This command instantly creates a file of the specified size. The best way of creating a swap file is with the fallocate program. We will allocate a file of the swap size that we want called swapfile in our root (/) directory. Now that we know our available hard drive space, we can create a swap file on our filesystem. Another good rule of thumb is that anything over 4G of swap is probably unnecessary if you are just using it as a RAM fallback. Generally, an amount equal to or double the amount of RAM on your system is a good starting point. Your usage will probably be different.Īlthough there are many opinions about the appropriate size of a swap space, it really depends on your personal preferences and your application requirements. We have plenty of space available in this example (only 1.4G used). The device with / in the Mounted on column is our disk in this case. OutputFilesystem Size Used Avail Use% Mounted on You can verify that there is no active swap using the free utility: If you don’t get back any output, this means your system does not have swap space available currently. We can see if the system has any configured swap by typing: It is possible to have multiple swap files or swap partitions, but generally one should be enough. Step 1 – Checking the System for Swap Informationīefore we begin, we can check if the system already has some swap space available. Overall, having swap space as a fallback for when your system’s RAM is depleted can be a good safety net against out-of-memory exceptions on systems with non-SSD storage available. The information written to disk will be significantly slower than information kept in RAM, but the operating system will prefer to keep running application data in memory and use swap for the older data. The swap space on the hard drive will be used mainly when there is no longer sufficient space in RAM to hold in-use application data. Basically, this gives you the ability to increase the amount of information that your server can keep in its working “memory”, with some caveats. Swap is an area on a hard drive that has been designated as a place where the operating system can temporarily store data that it can no longer hold in RAM. In this guide, we will cover how to add a swap file to an Ubuntu 18.04 server. One of the easiest way of guarding against out-of-memory errors in applications is to add some swap space to your server. A previous version of this tutorial was written by Justin Ellingwood Introduction
0 Comments
Leave a Reply. |