Understanding Swap Files (2024)

Understanding Swap Files (2)

What is a Swap File?

A swap file is also known as a swap space, page file, or paging file. It is a space allocated to your operating system to take over processes of lesser priority or LRU applications from the RAM, leaving ample space for high-priority processes.

Why do I need a Swap File?

Have you ever wondered why your PC lags and slows down when processes are being run sometimes? Whilst there might be a lot of other factors that might be causing this, the most probable cause would be that your RAM is full. This is where swapping or swap files comes in handy. When we allocate some space on our HDD or SSD for swapping, it cushions the effect of RAM overloading and swaps out some processes from the RAM allowing higher-priority processes to run. Whilst there are a lot of technicalities largely decided by the operating system or kernel properties as to what processes should be swapped and at what time, it is most common to swap low-priority processes. Swap files or partitions are not compulsory, especially if you have a large RAM, but they are a desirable feature to have on your device.

How do I create a Swap file?

Whilst swap files can be used on both Windows and Linux OS, I will be focusing on the Linux operating system in this article. To create a swap file in the Linux OS we need to follow these steps:

Step 1: Check if you already have space or partition allocated on your HDD or SSD for swapping. How do you do this?

Understanding Swap Files (3)

From the image above, on the Swap line, we can see that I have 0B (Zero bytes) allocated which indicates that I do not have a swap file or partition on my virtual box.

Step 2: Create the swap file. When creating a swap file we need superuser (root) privileges because we would be modifying low-level system resources. The command to create a swap is:

sudo fallocate -l 1G /swapfile

fallocate is used to deallocate, reallocate, or preallocate disk space for a file. In our case, we are preallocating disk space of 1Gigabyte to the file swapfile. The -l flag depicts the length or amount of disk space we want to allocate. How do we know how much disk space to allocate?

We can use the following guide:

Understanding Swap Files (4)

Step 3: Set user permissions. To set user permissions we use the chmod command:

sudo chmod 600 /swapfile

chmod 600 gives the user read and write access.

Step 4: Format the file we created to swap using the mkswap command.

sudo mkswap /swapfile

Step 5: Enable or activate the swap file using the swapon command.

sudo swapon /swapfile

Step 6: Make disk space allocation permanent i.e. for the changes to persist despite system reboots. To effect this we must go into the /etc/fstab directory, using the command:

vi /etc/fstab

Next, we would do the following:

Understanding Swap Files (5)

Step 7: Finally, to check the disk space allocated for swapping, we run the command “swapon” or “free -h”.

Understanding Swap Files (6)

Cool right :), Explore the world of swapping.

How Do I delete my Swap Space?

We can do this with 2 simple steps:

Step 1: Deactivate the Swap Space.

sudo swapoff -v /swapfile

Step 2: Delete the Swap file.

sudo rm /swapfile
Understanding Swap Files (7)

NOTE:

  • Swap files will not be displayed by running the ls command. The swap file is not a regular file.
  • It is desirable to have a swap file rather than a swap partition hardcoded into the HDD or SSD during the installation of the OS. This is because changes to previously allocated disk space can be easily done on swap files rather than a swap partition
  • You could also read about Swappiness.
Understanding Swap Files (2024)
Top Articles
ExamTopics - Biggest Actual IT Exams Database
Repetitive Strain Injury Symptoms Causes Prevention
Dainty Rascal Io
Whas Golf Card
Section 4Rs Dodger Stadium
Skylar Vox Bra Size
El Paso Pet Craigslist
How Many Cc's Is A 96 Cubic Inch Engine
Jeremy Corbell Twitter
PRISMA Technik 7-10 Baden-Württemberg
Ati Capstone Orientation Video Quiz
Sotyktu Pronounce
Craigslist Blackshear Ga
Letter F Logos - 178+ Best Letter F Logo Ideas. Free Letter F Logo Maker. | 99designs
Everything We Know About Gladiator 2
Chelactiv Max Cream
Where Is The Nearest Popeyes
Where Is George The Pet Collector
Georgia Cash 3 Midday-Lottery Results & Winning Numbers
Clare Briggs Guzman
Jc Green Obits
Glover Park Community Garden
Imouto Wa Gal Kawaii - Episode 2
Del Amo Fashion Center Map
Wiseloan Login
Inkwell, pen rests and nib boxes made of pewter, glass and porcelain.
Greensboro sit-in (1960) | History, Summary, Impact, & Facts
Watertown Ford Quick Lane
Cvs Sport Physicals
Myaci Benefits Albertsons
Mastering Serpentine Belt Replacement: A Step-by-Step Guide | The Motor Guy
UPS Drop Off Location Finder
Gyeon Jahee
Wbli Playlist
Giantess Feet Deviantart
Santa Cruz California Craigslist
Laurin Funeral Home | Buried In Work
Hell's Kitchen Valley Center Photos Menu
Dollar Tree's 1,000 store closure tells the perils of poor acquisitions
Nearest Ups Office To Me
Directions To Advance Auto
Jason Brewer Leaving Fox 25
Pa Legion Baseball
Anthem Bcbs Otc Catalog 2022
Csgold Uva
Reli Stocktwits
Zeeks Pizza Calories
The Bold and the Beautiful
Washington Craigslist Housing
2121 Gateway Point
How Did Natalie Earnheart Lose Weight
Varsity Competition Results 2022
Latest Posts
Article information

Author: Ray Christiansen

Last Updated:

Views: 6537

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Ray Christiansen

Birthday: 1998-05-04

Address: Apt. 814 34339 Sauer Islands, Hirtheville, GA 02446-8771

Phone: +337636892828

Job: Lead Hospitality Designer

Hobby: Urban exploration, Tai chi, Lockpicking, Fashion, Gunsmithing, Pottery, Geocaching

Introduction: My name is Ray Christiansen, I am a fair, good, cute, gentle, vast, glamorous, excited person who loves writing and wants to share my knowledge and understanding with you.