One place for hosting & domains

      Space

      How To Add Swap Space on Ubuntu 20.04


      Introduction

      One way to guard against out-of-memory errors in applications is to add some swap space to your server. In this guide, we will cover how to add a swap file to an Ubuntu 20.04 server.

      Warning: Although swap is generally recommended for systems using traditional spinning hard drives, placing swap on SSDs can cause issues with hardware degradation over time. Due to this, we do not recommend enabling swap on DigitalOcean or any other provider that uses SSD storage.

      What is Swap?

      Swap is a portion of hard drive storage that has been set aside for the operating system to temporarily store data that it can no longer hold in RAM. This lets you increase the amount of information that your server can keep in its working memory, with some caveats. 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.

      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. 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.

      Step 1 – Checking the System for Swap Information

      Before we begin, we can check if the system already has some swap space available. It is possible to have multiple swap files or swap partitions, but generally one should be enough.

      We can see if the system has any configured swap by typing:

      If you don’t get back any output, this means your system does not have swap space available currently.

      You can verify that there is no active swap using the free utility:

      Output

      total used free shared buff/cache available Mem: 981Mi 122Mi 647Mi 0.0Ki 211Mi 714Mi Swap: 0B 0B 0B

      As you can see in the Swap row of the output, no swap is active on the system.

      Step 2 – Checking Available Space on the Hard Drive Partition

      Before we create our swap file, we’ll check our current disk usage to make sure we have enough space. Do this by entering:

      Output

      Filesystem Size Used Avail Use% Mounted on udev 474M 0 474M 0% /dev tmpfs 99M 932K 98M 1% /run /dev/vda1 25G 1.4G 23G 7% / tmpfs 491M 0 491M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 491M 0 491M 0% /sys/fs/cgroup /dev/vda15 105M 3.9M 101M 4% /boot/efi /dev/loop0 55M 55M 0 100% /snap/core18/1705 /dev/loop1 69M 69M 0 100% /snap/lxd/14804 /dev/loop2 28M 28M 0 100% /snap/snapd/7264 tmpfs 99M 0 99M 0% /run/user/1000

      The device with / in the Mounted on column is our disk in this case. We have plenty of space available in this example (only 1.4G used). Your usage will probably be different.

      Although there are many opinions about the appropriate size of a swap space, it really depends on your personal preferences and your application requirements. Generally, an amount equal to or double the amount of RAM on your system is a good starting point. 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.

      Step 3 – Creating a Swap File

      Now that we know our available hard drive space, we can create a swap file on our filesystem. We will allocate a file of the size that we want called swapfile in our root (/) directory.

      The best way of creating a swap file is with the fallocate program. This command instantly creates a file of the specified size.

      Since the server in our example has 1G of RAM, we will create a 1G file in this guide. Adjust this to meet the needs of your own server:

      • sudo fallocate -l 1G /swapfile

      We can verify that the correct amount of space was reserved by typing:

      • -rw-r--r-- 1 root root 1.0G Apr 25 11:14 /swapfile

      Our file has been created with the correct amount of space set aside.

      Step 4 – Enabling the Swap File

      Now that we have a file of the correct size available, we need to actually turn this into swap space.

      First, we need to lock down the permissions of the file so that only users with root privileges can read the contents. This prevents normal users from being able to access the file, which would have significant security implications.

      Make the file only accessible to root by typing:

      Verify the permissions change by typing:

      Output

      -rw------- 1 root root 1.0G Apr 25 11:14 /swapfile

      As you can see, only the root user has the read and write flags enabled.

      We can now mark the file as swap space by typing:

      Output

      Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes) no label, UUID=6e965805-2ab9-450f-aed6-577e74089dbf

      After marking the file, we can enable the swap file, allowing our system to start using it:

      Verify that the swap is available by typing:

      Output

      NAME TYPE SIZE USED PRIO /swapfile file 1024M 0B -2

      We can check the output of the free utility again to corroborate our findings:

      Output

      total used free shared buff/cache available Mem: 981Mi 123Mi 644Mi 0.0Ki 213Mi 714Mi Swap: 1.0Gi 0B 1.0Gi

      Our swap has been set up successfully and our operating system will begin to use it as necessary.

      Step 5 – Making the Swap File Permanent

      Our recent changes have enabled the swap file for the current session. However, if we reboot, the server will not retain the swap settings automatically. We can change this by adding the swap file to our /etc/fstab file.

      Back up the /etc/fstab file in case anything goes wrong:

      • sudo cp /etc/fstab /etc/fstab.bak

      Add the swap file information to the end of your /etc/fstab file by typing:

      • echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

      Next we’ll review some settings we can update to tune our swap space.

      Step 6 – Tuning your Swap Settings

      There are a few options that you can configure that will have an impact on your system’s performance when dealing with swap.

      Adjusting the Swappiness Property

      The swappiness parameter configures how often your system swaps data out of RAM to the swap space. This is a value between 0 and 100 that represents a percentage.

      With values close to zero, the kernel will not swap data to the disk unless absolutely necessary. Remember, interactions with the swap file are “expensive” in that they take a lot longer than interactions with RAM and they can cause a significant reduction in performance. Telling the system not to rely on the swap much will generally make your system faster.

      Values that are closer to 100 will try to put more data into swap in an effort to keep more RAM space free. Depending on your applications’ memory profile or what you are using your server for, this might be better in some cases.

      We can see the current swappiness value by typing:

      • cat /proc/sys/vm/swappiness

      Output

      60

      For a Desktop, a swappiness setting of 60 is not a bad value. For a server, you might want to move it closer to 0.

      We can set the swappiness to a different value by using the sysctl command.

      For instance, to set the swappiness to 10, we could type:

      • sudo sysctl vm.swappiness=10

      Output

      vm.swappiness = 10

      This setting will persist until the next reboot. We can set this value automatically at restart by adding the line to our /etc/sysctl.conf file:

      • sudo nano /etc/sysctl.conf

      At the bottom, you can add:

      /etc/sysctl.conf

      vm.swappiness=10
      

      Save and close the file when you are finished.

      Adjusting the Cache Pressure Setting

      Another related value that you might want to modify is the vfs_cache_pressure. This setting configures how much the system will choose to cache inode and dentry information over other data.

      Basically, this is access data about the filesystem. This is generally very costly to look up and very frequently requested, so it’s an excellent thing for your system to cache. You can see the current value by querying the proc filesystem again:

      • cat /proc/sys/vm/vfs_cache_pressure

      Output

      100

      As it is currently configured, our system removes inode information from the cache too quickly. We can set this to a more conservative setting like 50 by typing:

      • sudo sysctl vm.vfs_cache_pressure=50

      Output

      vm.vfs_cache_pressure = 50

      Again, this is only valid for our current session. We can change that by adding it to our configuration file like we did with our swappiness setting:

      • sudo nano /etc/sysctl.conf

      At the bottom, add the line that specifies your new value:

      /etc/sysctl.conf

      vm.vfs_cache_pressure=50
      

      Save and close the file when you are finished.

      Conclusion

      Following the steps in this guide will give you some breathing room in cases that would otherwise lead to out-of-memory exceptions. Swap space can be incredibly useful in avoiding some of these common problems.

      If you are running into OOM (out of memory) errors, or if you find that your system is unable to use the applications you need, the best solution is to optimize your application configurations or upgrade your server.



      Source link

      Colocation Pricing Guide: Power, Space and Key Questions to Ask Your Provider


      Migration of infrastructure to colocation facilities will continue full force for the next few years, according to a survey put out to 500 IT professionals. Why? Because most on-prem data centers can’t compare to Tier 3-design facilities. The best colocation data centers offer high uptime, power efficiency and redundancy, as well as improve the physical security of infrastructure. With an enterprise colocation solution, companies also have access to greater networking capabilities and public cloud and/or other multi-platform solutions. This flexibility future-proofs your infrastructure for whatever needs may arise over time.

      Considering colocation as part of your infrastructure mix? Here’s our colo pricing guide to help you understand power, space and the key questions to ask your provider to decide the best fit for your company.

      What You Need to Know About Colocation Pricing

      Below, you’ll find the common types of billing for power, the spacing options you can choose from and two examples of how power and space are billed together.

      Start with Your Power Needs

      There are four standard ways to bill for power. When you’re working with your colocation provider, ensure they’re gathering your current and future power needs to appropriately size the power circuits. With that information in hand, they should work to offer you the best deal and least costly solution.

      There are four billing types for power:

      1. Per Circuit (Flat Rate) Power Billing

      The bill is a flat monthly fee per circuit provisioned for your solution and is the most common colo pricing structure. With this model, you have price predictability. You’ll pay the same amount whether you use five percent or 80 percent of your capacity. But be warned, there is no ability to burst above 80% of the delivered power without adding additional circuits.

      2. Power Capacity kW (Allocated kW) Billing

      In this model, you make a commitment to use a fixed amount of power (i.e.: 100kW), regardless of the electrical capacity of the circuits installed. Typically, you’ll see savings over flat rate model; however, the penalties for bursting above your committed rate can be quite steep.

      3. Metered Power (Usage Based) Billing

      Your bill will vary in this model. The monthly fee is based on actual usage and is determined on the present rate per kilowatt hour. Colocation providers typically only offer this pricing model on very large deployments and customers will still have to pay for space.

      4. All In Space & Power

      This is a simple calculation of the amount of space and power presented in a per kW number. It’s a very easy way for customers to compare pricing (assuming space and power delivered is equal). A con to this solution is that both the space and power are tied to a single rate per kW so there is a loss of flexibility.  If you ever need to upgrade just the power, you’ll end up paying more for the same amount of space.

      Explore Colocation Space Options

      Colo space is typically sold by:

      Cabinet: A single lockable cabinet on the data center floor. You can purchase contiguous cabinets if they are available in your chosen data center.

      Cage or Private Suite: An enclosed, lockable, segmented cage on the data center floor that provides superior flexibility and control without the capital investments that come with building and maintaining an enterprise-grade facility. A minimum of 5 racks/cabs is standard for cage deployments, assigned at 24 square feet per rack. Private data center suites, on the hand, are built to suit (complete with separate security access points) and are used typically for larger, wholesale colo deployments.

      Remember though, for some colocation pricing models, your bill may not have anything to do with square footage or rack usage. While cabinets or square feet are still required in order to allocate an area within the data center, the price is attached to the power that is being allocated for your use.

      Common Types of Colo Pricing Solutions

      Now that we understand the options for space and power billing, let’s explore how both aspects come together with two examples of popular billing models, relative to the deployment size. Work with your colocation provider to determine your best-fit solution.

      Cabinets with flat rate circuits

      For smaller deployments, typically one to four cabinets, colocation providers will deliver lockable cabinets, each with primary and redundant (optional) power feeds. A single power feed can deliver anywhere from 2kw – 17kw depending on the colocation provider’s power capacity and cooling capabilities. Your bill would consist of line items for the cabinet(s) and circuits delivered.

      Space/kw with Usage-based Power Pricing

      This solution is for larger deployments (100kw+), as providers will typically have minimums for this solution. You’ll be billed based on the number of square feet and a variable monthly fee based on actual power usage. This monthly fee is based on a preset dollar rate per kilowatt hour. Regardless of term, installs should be charged in this model.

      Typically, there is not much of a margin built into usage-based power. You should also expect install fees when adding more circuits.

      Beyond the Price Tag: What Can the Colocation Data Center You Choose Do for You?

      When you decide to move your infrastructure off-prem, there are many other economic and performance-based factors beyond the list price for space and power; however, they are just as important to consider and can even make or break your infrastructure strategy.

      Consider the following questions:

      1. Does the colo facility have Tier 3-attributes?

      To be a Tier 3-attribute data center, the facility must maintain N+1 fault tolerance, 72-hour protection from power outages and 99.982 percent uptime. Concurrent maintainability also ensures that a single critical component failure—electrical, cooling, power, etc.— will not disrupt service because of the redundant systems in place. How does the data center you are considering stack up?

      2. Does the colo provider offer multi-platform contract flexibility?

      Infrastructure needs can change fast. Make sure your provider gives you flexibility through implementation of different platforms (cloud, bare metal, etc.), as well as spend portability after you deploy so that you can switch up your infrastructure solutions to stay agile and keep pace with you company’s goals and workloads.

      3. Does the colo provider support High Power Density environments?

      With a high-power density configuration, you can fit more gear into a smaller space and reduce your overall footprint. This becomes especially important if you’re looking to deploy any type of hyper-converged solution.

      4. Can I get high-performance, low-latency bandwidth?

      Bandwidth is an essential cost that you cannot overlook when sourcing any data center or cloud solution. If you’re powering any mission-critical applications with your colocation deployment, look for a colocation data center that has quality blend of ISPs and inquire about latency averages.

      5. Does the colo provider offer interconnectivity solutions?

      Ideally, you’ll want a provider who offers a high-capacity private network that allows you to connect across various data centers throughout the country or around the globe. If your colo provider lacks interconnectivity solutions, you’ll need to partner with other vendors for interconnectivity options, which can be a future pain point.

      6. Does your provider offer geographically dispersed data centers for disaster recovery?

      Ultimately, you may require some sort of secondary site for any disaster recovery solution as part of your overall business continuity plan. Look for a provider that either has multiple sites across the a geographically dispersed area or some sort of off-site DRaaS product that works for your company.

      7. What about onsite support?

      Onsite expert support technicians can keep your infrastructure online, secure and always operating at peak efficiency when your own IT staff is unable to. Make sure your colo provider offers remote hands support and don’t leave it out of your colo budgetary considerations. You’ll also want to ensure that your data is protected by 24/7/365 onsite security/personnel.

      For more information on colocation pricing, or to find the best solution for you, chat now.

      Explore INAP Colocation.

      LEARN MORE

      Jeff Bettencourt
      • Director, Solution Engineering


      READ MORE



      Source link

      How To Add Swap Space on Debian 10


      Introduction

      One of the easiest way of guarding against out-of-memory errors in applications is to add some swap space to your server. In this guide, we will cover how to add a swap file to a Debian 10 server.

      Warning: Although swap is generally recommended for systems using traditional spinning hard drives, using swap with SSDs can cause issues with hardware degradation over time. Due to this consideration, we do not recommend enabling swap on DigitalOcean or any other provider that uses SSD storage. Doing so can impact the reliability of the underlying hardware for you and your neighbors. This guide is provided as reference for users who may have spinning disk systems elsewhere.

      If you need to improve the performance of your server on DigitalOcean, we recommend upgrading your Droplet. This will lead to better results in general and will decrease the likelihood of contributing to hardware issues that can affect your service.

      What is Swap?

      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. Basically, this gives you the ability to increase the amount of information that your server can keep in its working “memory”, with some caveats. 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.

      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. 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.

      Step 1 – Checking the System for Swap Information

      Before we begin, we can check if the system already has some swap space available. It is possible to have multiple swap files or swap partitions, but generally one should be enough.

      We can see if the system has any configured swap by typing:

      If you don't get back any output, this means your system does not have swap space available currently.

      You can verify that there is no active swap using the free utility:

      Output

      total used free shared buff/cache available Mem: 990Mi 36Mi 863Mi 4.0Mi 89Mi 837Mi Swap: 0B 0B 0B

      As you can see in the Swap row of the output, no swap is active on the system.

      Step 2 – Checking Available Space on the Hard Drive Partition

      Before we create our swap file, we'll check our current disk usage to make sure we have enough space. Do this by entering:

      Output

      Filesystem Size Used Avail Use% Mounted on udev 488M 0 488M 0% /dev tmpfs 100M 4.5M 96M 5% /run /dev/vda1 25G 989M 23G 5% / tmpfs 499M 0 499M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 499M 0 499M 0% /sys/fs/cgroup tmpfs 100M 0 100M 0% /run/user/1001

      The device with / in the Mounted on column is our disk in this case. We have plenty of space available in this example (only 1.4G used). Your usage will probably be different.

      Although there are many opinions about the appropriate size of a swap space, it really depends on your personal preferences and your application requirements. Generally, an amount equal to or double the amount of RAM on your system is a good starting point. 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.

      Step 3 – Creating a Swap File

      Now that we know our available hard drive space, we can create a swap file on our filesystem. We will allocate a file of the swap size that we want called swapfile in our root (/) directory.

      The best way of creating a swap file is with the fallocate program. This command instantly creates a file of the specified size.

      Since the server in our example has 1G of RAM, we will create a 1G file in this guide. Adjust this to meet the needs of your own server:

      • sudo fallocate -l 1G /swapfile

      We can verify that the correct amount of space was reserved by typing:

      Output

      -rw-r--r-- 1 root root 1.0G May 29 17:34 /swapfile

      Our file has been created with the correct amount of space set aside.

      Step 4 – Enabling the Swap File

      Now that we have a file of the correct size available, we need to actually turn this into swap space.

      First, we need to lock down the permissions of the file so that only the users with root privileges can read the contents. This prevents normal users from being able to access the file, which would have significant security implications.

      Make the file only accessible to root by typing:

      Verify the permissions change by typing:

      Output

      -rw------- 1 root root 1.0G May 29 17:34 /swapfile

      As you can see, only the root user has the read and write flags enabled.

      We can now mark the file as swap space by typing:

      Output

      Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes) no label, UUID=b591444e-c12b-45a6-90fc-e8b24c67c006f

      After marking the file, we can enable the swap file, allowing our system to start using it:

      Verify that the swap is available by typing:

      Output

      NAME TYPE SIZE USED PRIO /swapfile file 1024M 0B -2

      We can check the output of the free utility again to corroborate our findings:

      Output

      total used free shared buff/cache available Mem: 990Mi 37Mi 860Mi 4.0Mi 92Mi 834Mi Swap: 1.0Gi 0B 1.0Gi

      Our swap has been set up successfully and our operating system will begin to use it as necessary.

      Step 5 – Making the Swap File Permanent

      Our recent changes have enabled the swap file for the current session. However, if we reboot, the server will not retain the swap settings automatically. We can change this by adding the swap file to our /etc/fstab file.

      Back up the /etc/fstab file in case anything goes wrong:

      • sudo cp /etc/fstab /etc/fstab.bak

      Add the swap file information to the end of your /etc/fstab file by typing:

      • echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

      Next we'll review some settings we can update to tune our swap space.

      Step 6 – Tuning your Swap Settings

      There are a few options that you can configure that will have an impact on your system's performance when dealing with swap.

      Adjusting the Swappiness Property

      The swappiness parameter configures how often your system swaps data out of RAM to the swap space. This is a value between 0 and 100 that represents a percentage.

      With values close to zero, the kernel will not swap data to the disk unless absolutely necessary. Remember, interactions with the swap file are "expensive" in that they take a lot longer than interactions with RAM and they can cause a significant reduction in performance. Telling the system not to rely on the swap much will generally make your system faster.

      Values that are closer to 100 will try to put more data into swap in an effort to keep more RAM space free. Depending on your applications' memory profile or what you are using your server for, this might be better in some cases.

      We can see the current swappiness value by typing:

      • cat /proc/sys/vm/swappiness

      Output

      60

      For a Desktop, a swappiness setting of 60 is not a bad value. For a server, you might want to move it closer to 0.

      We can set the swappiness to a different value by using the sysctl command.

      For instance, to set the swappiness to 10, we could type:

      • sudo sysctl vm.swappiness=10

      Output

      vm.swappiness = 10

      This setting will persist until the next reboot. We can set this value automatically at restart by adding the line to our /etc/sysctl.conf file:

      • sudo nano /etc/sysctl.conf

      At the bottom, you can add:

      /etc/sysctl.conf

      vm.swappiness=10
      

      Save and close the file when you are finished.

      Adjusting the Cache Pressure Setting

      Another related value that you might want to modify is the vfs_cache_pressure. This setting configures how much the system will choose to cache inode and dentry information over other data.

      Basically, this is access data about the filesystem. This is generally very costly to look up and very frequently requested, so it's an excellent thing for your system to cache. You can see the current value by querying the proc filesystem again:

      • cat /proc/sys/vm/vfs_cache_pressure

      Output

      100

      As it is currently configured, our system removes inode information from the cache too quickly. We can set this to a more conservative setting like 50 by typing:

      • sudo sysctl vm.vfs_cache_pressure=50

      Output

      vm.vfs_cache_pressure = 50

      Again, this is only valid for our current session. We can change that by adding it to our configuration file like we did with our swappiness setting:

      • sudo nano /etc/sysctl.conf

      At the bottom, add the line that specifies your new value:

      /etc/sysctl.conf

      vm.vfs_cache_pressure=50
      

      Save and close the file when you are finished.

      Conclusion

      Following the steps in this guide will give you some breathing room in cases that would otherwise lead to out-of-memory exceptions. Swap space can be incredibly useful in avoiding some of these common problems.

      If you are running into OOM (out of memory) errors, or if you find that your system is unable to use the applications you need, the best solution is to optimize your application configurations or upgrade your server.



      Source link