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
What Is Maximum Credit Limit on a Credit Card?
Why Can’t My Credit Score Be Calculated? - Experian
Sdn Md 2023-2024
Ron Martin Realty Cam
From Algeria to Uzbekistan-These Are the Top Baby Names Around the World
Evil Dead Rise Showtimes Near Massena Movieplex
Wells Fargo Careers Log In
Sissy Transformation Guide | Venus Sissy Training
Women's Beauty Parlour Near Me
Miles City Montana Craigslist
Athletic Squad With Poles Crossword
Katie Boyle Dancer Biography
Chicken Coop Havelock Nc
Hca Florida Middleburg Emergency Reviews
Huge Boobs Images
Fear And Hunger 2 Irrational Obelisk
Craigslist Malone New York
Craigslist Red Wing Mn
Gopher Hockey Forum
Ups Print Store Near Me
C&T Wok Menu - Morrisville, NC Restaurant
Engineering Beauties Chapter 1
When Does Subway Open And Close
Koninklijk Theater Tuschinski
Sessional Dates U Of T
Elite Dangerous How To Scan Nav Beacon
Margaret Shelton Jeopardy Age
Intel K vs KF vs F CPUs: What's the Difference?
Unreasonable Zen Riddle Crossword
Yayo - RimWorld Wiki
Jamielizzz Leaked
Mkvcinemas Movies Free Download
Orange Pill 44 291
Poster & 1600 Autocollants créatifs | Activité facile et ludique | Poppik Stickers
Selfservice Bright Lending
Chilangos Hillsborough Nj
Sadie Sink Doesn't Want You to Define Her Style, Thank You Very Much
Wisconsin Women's Volleyball Team Leaked Pictures
Merkantilismus – Staatslexikon
Taylor University Baseball Roster
Danielle Ranslow Obituary
Shipping Container Storage Containers 40'HCs - general for sale - by dealer - craigslist
Comanche Or Crow Crossword Clue
Fluffy Jacket Walmart
3367164101
116 Cubic Inches To Cc
St Als Elm Clinic
Lux Funeral New Braunfels
Wrentham Outlets Hours Sunday
Lsreg Att
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.