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
Real Estate - Pakistan | Statista Market Forecast
How Do You Know If You Have A Good Settlement Offer? - McCready Law
Melson Funeral Services Obituaries
DEA closing 2 offices in China even as the agency struggles to stem flow of fentanyl chemicals
Exam With A Social Studies Section Crossword
Chase Bank Operating Hours
Mama's Kitchen Waynesboro Tennessee
Black Gelato Strain Allbud
How to change your Android phone's default Google account
Poe Pohx Profile
Craigslist Kennewick Pasco Richland
Kristine Leahy Spouse
Call Follower Osrs
Aiken County government, school officials promote penny tax in North Augusta
Slapstick Sound Effect Crossword
Day Octopus | Hawaii Marine Life
Audrey Boustani Age
Slag bij Plataeae tussen de Grieken en de Perzen
Munich residents spend the most online for food
Why Is 365 Market Troy Mi On My Bank Statement
Dallas Craigslist Org Dallas
Qhc Learning
Isaidup
Best Transmission Service Margate
2013 Ford Fusion Serpentine Belt Diagram
11 Ways to Sell a Car on Craigslist - wikiHow
Drying Cloths At A Hammam Crossword Clue
DIY Building Plans for a Picnic Table
Bfri Forum
Used 2 Seater Go Karts
Jt Closeout World Rushville Indiana
Cbs Trade Value Chart Week 10
Haley Gifts :: Stardew Valley
Watchdocumentaries Gun Mayhem 2
Jr Miss Naturist Pageant
Drabcoplex Fishing Lure
Maybe Meant To Be Chapter 43
Giantess Feet Deviantart
Oxford Alabama Craigslist
Entry of the Globbots - 20th Century Electro​-​Synthesis, Avant Garde & Experimental Music 02;31,​07 - Volume II, by Various
How Does The Common App Work? A Guide To The Common App
3 bis 4 Saison-Schlafsack - hier online kaufen bei Outwell
2013 Honda Odyssey Serpentine Belt Diagram
Oklahoma City Farm & Garden Craigslist
Ssc South Carolina
Displacer Cub – 5th Edition SRD
Cara Corcione Obituary
Tito Jackson, member of beloved pop group the Jackson 5, dies at 70
116 Cubic Inches To Cc
Understanding & Applying Carroll's Pyramid of Corporate Social Responsibility
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.