• DevOps
    Case Study

    How we built a resilient multi-account, multi-cloud solution for a Health Tech service provider!

    READ CASESTUDY
    icon

    24/7 DevOps as a Service

    Round-the-clock DevOps for uninterrupted efficiency.

    icon

    Infrastructure as a Code

    Crafting infrastructure with ingenious code.

    icon

    CI/CD Pipeline

    Automated CI/CD pipeline for seamless deployments.

    icon

    DevSecOps

    Integrated security in continuous DevOps practices.

    icon

    Hire DevOps Engineers

    Level up your team with DevOps visionaries.

    icon

    Consulting Services

    Navigate success with expert DevOps consulting.

  • TechOps
    Case Study

    How we built a scalable Odoo solution for a Travel Tech service provider!

    READ CASESTUDY

    WEB HOSTING SUPPORT

    icon

    HelpDesk Support

    Highly skilled 24/7 HelpDesk Support

    icon

    Product Support

    Boost your product support with our expertise.

    MANAGED SERVICES

    icon

    Server Management

    Don’t let server issues slow you down. Let us manage them for you.

    icon

    Server Monitoring

    Safeguard your server health with our comprehensive monitoring solutions.

    STAFF AUGMENTATION

    icon

    Hire an Admin

    Transform your business operations with our expert administrative support.

    icon

    Hire a Team

    Augment your workforce with highly skilled professionals from our diverse talent pool.

  • CloudOps
    Case Study

    How we helped a Private Deemed University in India, save US $3500/m on hosting charges!

    READ CASESTUDY
    icon

    AWS Well Architected Review

    Round-the-clock for uninterrupted efficiency

    icon

    Optimize

    Efficient CloudOps mastery for seamless cloud management

    icon

    Manage

    Automated CI/CD pipeline for seamless deployments

    icon

    Migrate

    Upgrade the journey, Migrate & Modernize seamlessly

    icon

    Modernize

    Simplify compliance complexities with our dedicated services

    icon

    FinOps as a Service

    FinOps as a Service

  • SecOps
    Case Study

    How we built a scalable Odoo solution for TravelTech service provider!

    READ CASESTUDY
    icon

    VAPT

    Vulnerability Assessment and Penetration Testing

    icon

    Source Code Review

    Ensuring source code security ans safe practices to reduce risks

    icon

    Security Consultation

    On demand services for improving server security

    icon

    System Hardening

    Reduced vulnerability and proactive protection

    icon

    Managed SoC

    Monitors and maintains system security. Quick response on incidents.

    icon

    Compliance as a Service

    Regulatory compliance, reduced risk

  • Insights
    Case Study

    How we helped a Private Deemed University in India, save US $3,500/m on hosting charges!

    READ CASESTUDY
    icon

    Blog

    Explore our latest articles and insights

    icon

    Case Studies

    Read about our client success stories

    icon

    Flipbook

    Explore our latest Flipbook

    icon

    Events

    Join us at upcoming events and conferences

    icon

    Webinars

    Watch our educational webinar series

  • Our Story
  • Contact Us

Interested to collaborate?

Get in touch with us!

Ready to elevate your business with certified cloud expertise? Contact us today to learn how our team can help you leverage cloud technology to drive growth, streamline operations, and enhance security.

  • AWSAWS
  • Azure CloudAzure Cloud
  • Google CloudGoogle Cloud
  • Akamai CloudAkamai Cloud
  • OVHOVH
  • Digital OceanDigital Ocean
  • HetznerHetzner
  • Kubernetes Consultancy Services
  • K8s & Cloud native Solutions
  • 24/7 Infrastructure Monitoring
  • DevOps as a Service
  • Cloud CI/CD Solutions
  • White Labeled MSP Support
  • Our story
  • Life@SupportSages
  • Insights
  • Careers
  • Events
  • Contact Us

Connect with us!


LinkedInFacebookXInstagramYouTube

aws partneraws advanced partner
SupportSages

Copyright © 2008 – 2026 SupportSages Pvt Ltd. All Rights Reserved.
Privacy PolicyLegal TermsData ProtectionCookie Policy
How to add swap space on live server

How to add swap space on live server

Hariram JR

  • 5 min read
How to add swap space on live server

Generating audio, please wait...

One of my client experienced frequent MySQL downtime on his server. The VPS server had  a couple of accounts with relatively normal traffic. The MySQL error log and server load during the MySQL crash too failed to show up any unusual events.

On further investigation, the server log /var/log/messages, indicated that the server had been suffering from resource scarcity and hence OutOfMemory (OOM) killer was triggered at multiple occassions.  The time of MySQL crash was in perfect synchronization with the OOM killer entries in the server logs and which made me to suspect a link between the two.

Below is the screen shot of the error message we received

2

As you can see from the above screen shot the MySQL process 11079 had been killed due to Out Of Memory issues.

As usual I had checked the available primary memory for the VPS and the output showed nearly zero/low free memory availability.

1

Strikingly, there were no swap partition enabled for the server and the client was not in a position to increase the RAM allocation.  So to improve the server performance a swapping system is the only available choice and hence I had decided to move forward with setting up a new swap partition for the server. Moving the inactive process to swap space, even when sufficient RAM is available,  will help the physical RAM to spend its penny available memory to some other process.

Swap partition or Swap file?

Normally swap partitions are created during installation during disk partitioning. Or you can dedicate a new entire hard disk or partition for swap partition. However since its VPS there is no scope for attaching a new HDD or partition to be used as a Swap partition.

A swap file is file on the HDD which acts as temporary storage location for the less frequently used memory pages from your primary memory. New  Linux kernels support swap files to a great extend and swap files are now just as fast as swap partition. Hence I decided to proceed with creation of a swap file to  add swap space on the live server.

Before that, I would like to make you familiarize with the below commands.

===
swapon & swapoff – The commands which is used to enable and disable the swap files.
fallocate – The command utility which helps to preallocate the space to a file.
mkswap – The command used to create a swap area on the device
===

How to Add Swap space?

Before creating a swap file, check the disk usage in the server.

3.

This is an important check as the size of swap is usually double the size of RAM. Here the RAM size is approx. 1G and the proposed swap file size is 2 GB, so it is essential that the space is available. Here the free space is much more beyond the required space and hence we can proceed with add swap space.

Promotional banner

Swap file creation

1. Use fallocate command to preallocate space to the swapfile.

 #fallocate -l 2G /swapfile 

2. List the created swap file and identify permissions

 #ls -lh /swapfile 

3. Change the permission of /swapfile to 600 so as to allow only the root user to read and make changes to the file.

 #chmod 600 /swapfile 

4. Use mkswap command to instruct the server to designate and mark the file “/swapfile” to be used for swapping

 #mkswap /swapfile 

5.After the successful creation, we have to enable the swap file using the command swapon to take effect.

 #swapon /swapfile 
Below the the screen shot of the steps for your reference
 

4

Mounting the Swap

6. To mount the swap partition permanently, add the swap information in the /etc/fstab

 /swapfile swap swap sw 0 0 

Verification

6. Finally we need to confirm whether swapping actually happens or not

If you get the result of swapon -s in the terminal then the swap space is successfully configured in the server.

5

7. Then, run the free or vmstat command to check the usage of swap memory in the server.

final

Hope, this article helps you. Thanks for your time 🙂

Get 24/7 expert server management

  • Howtos
  • Linux
  • VPS
Promotional banner
Promotional banner

Migration from cPanel to Virtualmin

Migration from cPanel to Virtualmin
  • cPanel
  • Howtos
  • Linux
logo

WordPress- Admin interface access permission issues

WordPress- Admin interface access permission issues
  • Linux
  • Troubleshooting
  • WordPress
logo

Posts by Hariram JR

System Engineer with two years of experience in deploying and managing hundreds of Linux servers. Currently working in Cloud technologies, especially with AWS platform. His work includes installing application server, scaling and configuring it for high availability and fault tolerance.