How Much Swap Should You Use in Linux? (2024)

How much should be the swap size? Should the swap be double of the RAM size or should it be half of the RAM size? Do I need swap at all if my system has got several GBs of RAM?

Perhaps these are the most common asked questions about choosing swap size while installing Linux.

It’s nothing new. There has always been a lot of confusion around swap size.

For a long time, the recommended swap size was double of the RAM size but that golden rule is not applicable to modern computers anymore. We have systems with RAM sizes up to 128 GB, many old computers don’t even have this much of hard disk.

But what swap size would you allotto a system with 32 GB of RAM? 64GB? That would be a ridiculous waste of hard disk, won’t it?

Before we see how much swap size you should have, let’s first quickly know a thing or two about swapmemory. This will help you understand why swap is used.

The explanation has been simplified for (almost) everyone’s understanding.

What is swap? When is swap used?

How Much Swap Should You Use in Linux? (1)

Your system uses Random Access Memory(aka RAM) when it runs an application. When there are only a few applications running your system manages with the available RAM.

But if there are too many applications running or if the applications need a lot of RAM, then your system gets into trouble. If an application needs more memory but entire RAM is already in use, the application will crash.

Swap acts as a breather to your system when the RAM is exhausted. What happens here is that when the RAM is exhausted, your Linux systemuses part of the hard disk memory and allocates it to the running application.

That sounds cool. This means if you allocate like 50GB of swap size, your system can run hundreds or perhaps thousands of applications at the same time? WRONG!

You see, the speed matters here. RAM access data in the order of nanoseconds. An SSD access data in microseconds while as a normal hard disk accesses the data in milliseconds. This means that RAM is 1000 times faster than SSD and 100,000 times faster than the usual HDD.

If an application relies too much on the swap, its performance will degrade as it cannot access the data at the same speed as it would have in RAM. So instead of taking 1 second for a task, it may take several minutes to complete the same task. It will leave the application almost useless. This is known as thrashing in computing terms.

In other words, a little swap is helpful. A lot of it will be of no good use.

Why is swap needed?

There are several reasons why you would need swap.

  • If your system has RAM less than 1 GB, you must use swap as most applications would exhaust the RAM soon.
  • If your system uses resource heavy applications like video editors, it would be a good idea to use some swap space as your RAM may be exhausted here.
  • If you use hibernation, then you must add swap because the content of the RAM will be written to the swap partition. This also means that the swap size should be at least the size of RAM.
  • Avoid strange events like a program going nuts and eating RAM.

Do you need swap if you have lots of RAM?

This is a good question indeed. If you have 32GB or 64 GB of RAM, chances are that your system would perhaps never use the entire RAM and hence it would never use the swap partition.

But will you take the chance? I am guessing if your system has 32GB of RAM, it should also be having a hard disk of 100s of GB. Allocating a couple of GB of swap won’t hurt. It will provide an extra layer of ‘stability’ if a faulty program starts misusing RAM.

Can you use Linux without swap?

Yes, you can, especially if your system has plenty of RAM. But as explained in the previous section, a little bit of swap is always advisable.

In fact, a distribution like Ubuntu automatically creates a swap file of 2 GB in size. This should give you an indication that having some swap space is recommended.

Don’t worry if you didn’t create a swap partition while installing Linux. You can always create swap file in Linux at any time.

Recommended Read

Swap files allow you to create and use swap space on the fly in Linux. You can easily create them, resize them or delete them as per your need.

How Much Swap Should You Use in Linux? (2)

How much should be the swap size?

Now comes the big question. What should be the ideal swap space for a Linux install?

And the problem here is that there is no definite answer to this swap size question. There are just recommendations.

Different people have a different opinion on ideal swap size. Even the major Linux distributions don’t have the same swap size guideline.

If you go by Red Hat’s suggestion, they recommend a swap size of 20% of RAM for modern systems (i.e. 4GB or higher RAM).

CentOS has a different recommendation for the swap partition size. It suggests swap size to be:

  • Twice the size of RAM if RAM is less than 2 GB
  • Size of RAM + 2 GB if RAM size is more than 2 GB i.e. 5GB of swap for 3GB of RAM

Ubuntu has an entirely different perspective on the swap size as it takes hibernation into consideration. If you need hibernation, a swap of the size of RAM becomes necessary for Ubuntu.

Otherwise, it recommends:

  • If RAM is less than 1 GB, swap size should beat least the size of RAM and at most double the size of RAM
  • If RAM is more than 1 GB, swap size should be at least equal to thesquare root of the RAM size and at most double the size of RAM
  • If hibernation is used, swap size should be equal to size of RAM plus the square root of the RAM size

Confused? I know it is confusing. This is why I have created this table that will give you the Ubuntu recommended swap size based on your RAM size and hibernation need.

RAM SizeSwap Size (Without Hibernation)Swap size (With Hibernation)
256MB256MB512MB
512MB512MB1GB
1GB1GB2GB
2GB1GB3GB
3GB2GB5GB
4GB2GB6GB
6GB2GB8GB
8GB3GB11GB
12GB3GB15GB
16GB4GB20GB
24GB5GB29GB
32GB6GB38GB
64GB8GB72GB
128GB11GB139GB

How much swap size do you use?

The answer is never simple. As I stated earlier, for a long time, swap has been recommended to be of double the size of RAM. In fact my Dell XPS 13 Ubuntu edition has 16GB of swap size for an 8GB of RAM. So even Dell decided to go with the golden rule of swap=2xRAM.

What swap size do you prefer for your Linux system?

How Much Swap Should You Use in Linux? (2024)

FAQs

How much swap usage is normal? ›

What Is an Acceptable Swap Usage Percentage?
Amount of RAM in the systemRecommended swap space
<=2GB2 times the amount of RAM
2GB – 8GBEqual to the amount of RAM
8GB – 64GBAt least 4 GB
> =64GB
May 11, 2021

Is 2GB swap enough? ›

Normally your system will get soooo slow once it has to swap out even only 2GB that it's barely usable any more, so you would go exit some applications anyway. So 2GB plus a bit extra to be safe should be enough.

How Big Should Linux swap space be? ›

For more modern systems (>1GB), your swap space should be at a minimum be equal to your physical memory (RAM) size "if you use hibernation", otherwise you need a minimum of round(sqrt(RAM)) and a maximum of twice the amount of RAM.

What is the recommended amount of swap memory? ›

What is the right amount of swap space?
Amount of system RAMRecommended swap space
less than 2 GB2 times the amount of RAM
2 GB - 8 GBEqual to the amount of RAM
8 GB - 64 GB0.5 times the amount of RAM
more than 64 GBworkload dependent
Sep 26, 2018

Why is my swap usage so high? ›

Swap usage is often associated with system performance problems because the majority of the time high swap usage occurs during and after the server has run low on memory.

How do I reduce swap usage? ›

To clear the swap memory on your system, you simply need to cycle off the swap. This moves all data from swap memory back into RAM. It also means that you need to be sure you have the RAM to support this operation. An easy way to do this is to run 'free -m' to see what is being used in swap and in RAM.

Does swap improve performance? ›

Swap space will be useful for systems with less amount of RAM but it is never a replacement for RAM. Swap space resists on hard drives which have slower access time than physical memory. Once the RAM is used up, the swap space gets used. Since swap is slower than RAM, the performance of the system goes down.

Is 4GB swap enough? ›

For a long time, the recommended swap size was double of the RAM size but that golden rule is not applicable to modern computers anymore.
...
How much should be the swap size?
RAM SizeSwap Size (Without Hibernation)Swap size (With Hibernation)
2GB1GB3GB
3GB2GB5GB
4GB2GB6GB
6GB2GB8GB
10 more rows

Is 2GB better than 1GB? ›

10yr 1GB and 2GB have the same performance, the only difference is the memory which is used mostly when hooking it up to an external monitor. Although some say that certain games use alot of VRAM aswell such as BF3 and that the 2GB performs better on such games so it may be something to research and consider aswell.

Can I put 4GB RAM in 2GB slot? ›

YES! you can install a 2gb and 4gb RAM chip together. As long as the frequency is the same there isn't going to be any issues. However, if you add 2gb 1066 and 4gb 1600 the system will read the 2gb and 4gb has 1066.

How much size is enough for Linux? ›

A basic installation needs around 10G of disk space, if you add your own data you should be needing at least 20G of disk space. If you don't store personal files (music, movies, photos), 20G would suffice.

How do you calculate swap size? ›

Swap should equal 2x physical RAM for up to 2 GB of physical RAM, and then an additional 1x physical RAM for any amount above 2 GB, but never less than 32 MB. Using this formula, a system with 2 GB of physical RAM would have 4 GB of swap, while one with 3 GB of physical RAM would have 5 GB of swap.

What is swap file size? ›

Usually, the minimum swap file size is 1.5 times the RAM capacity and the maximum is 4 times the RAM. For example: RAM = 1 gigabyte (GB) Minimum swap file = 1.5 GB.

How much memory usage is optimal? ›

Generally, we recommend 8GB of RAM for casual computer usage and internet browsing, 16GB for spreadsheets and other office programs, and at least 32GB for gamers and multimedia creators.

Why swap partition is important in Linux? ›

The swap partition serves as overflow space for your RAM. If your RAM fills up completely, any additional applications will run off the swap partition rather than RAM. This may sound like an easy way to increase your computer's amount of usable memory without actually getting more RAM, but that isn't the case.

What happens if swap space is full? ›

If your disks arn't fast enough to keep up, then your system might end up thrashing, and you'd experience slowdowns as data is swapped in and out of memory. This would result in a bottleneck. The second possibility is you might run out of memory, resulting in wierdness and crashes.

How can I improve my swap? ›

Another way to increase the swap size is to use the GParted partition Editor. In short, you resize the swap partition, then right click on it and choose "Swapon". You must be able to increase the size of swap partition only if there is an unallocated space present before or after the swap partition.

Is swap as fast as RAM? ›

It offers a slower access time compared to RAM and located in the disk memory. Swap space is actually a part of the virtual memory. There are several applications of swap space. It stores the applications which the OS doesn't use frequently.

Should swap always be enabled? ›

The short answer is, No. There are performance benefits when swap space is enabled, even when you have more than enough ram. Update, also see Part 2: Linux Performance: Almost Always Add Swap (ZRAM). …so in this case, as in many, swap usage is not hurting Linux server performance.

What is the fair value of a swap? ›

The value of a swap is its market value at any point in time. At inception, the value of an interest rate swap is zero.

How do you calculate fair swap rate? ›

At inception, the aggregate cash flows are an asset to the company, so the bank's credit spread is used to calculate the discount factor. The fair value of the interest rate swap is then calculated by multiplying the risk-adjusted discount factor and the net cash flows.

What are the 2 commonly used swaps? ›

An amortizing swap is an interest rate swap where the notional principal amount is reduced at the underlying fixed and floating rates. An asset swap is a derivative contract through which fixed and floating investments are being exchanged.

Is swap partition faster than file? ›

According to Linus Torvalds, “all the normal distributions set things up with swap partitions, not files”. In addition, “swapfiles tend to be slower and have various other complexity issues.”

Is swap harmful to SSD? ›

If the swap was used often, then the SSD may fail sooner. This might be why you heard it could be bad to use an SSD for swap. Modern SSDs don't have this issue, and they should not fail any faster than a comparable HDD.

Is it possible to run Linux without swap partition? ›

If you don't want to use a swap partition, you can use a swap file: a filesystem image stored on a regular file and used as your swap space. The following articles explain how to do it in detail: Linux Add a Swap File – Howto. How to use hibernation without a swap partition (this also uses a swap file)

Does 4GB to 8GB make a difference? ›

8GB is best for most users compared to 4GB because it provides enough RAM for most applications, tasks, and less demanding games. Many of the most commonly used applications don't have much RAM. However, it is common for users to run many applications at once.

How much swap is needed for 4GB RAM? ›

It is recommended to have an equal amount of swap space as you do RAM. You can feel free to assign 8GB if you wish; however, this is not as applicable today as it was in the past when RAM was more expensive and some processes ran in swap space. In 4GB there is 2^32 bytes which is 4,294,967,296.

Can I upgrade my RAM from 4GB to 16GB? ›

Because of the way memory fits into your laptop or computer, it's actually quite easy to remove and expand. One of the most common ways to upgrade your RAM is to replace your 4GB strips with 8GB strips, giving you a total 16GB.

Is 16 GB RAM good? ›

16GB is the recommended amount of RAM for playing most games and will provide a noticeable increase in performance from 8GB. You will also be able to run applications in the background without affecting gameplay.

Is DDR5 graphics card good? ›

DDR5 or GDDR5 has more memory bandwidth and memory clock speed, which is why it is used for gaming purpose than DDR3. DDR5 is only used in graphics cards, on the other hand DDR3 is also used in computers. Despite the low latency of DDR3, DDR5 provides better performance than DDR3.

Is 1GB good internet? ›

Gigabit Internet literally means that you are downloading 1,000,000,000 bits per second or 1,000 megabits per second. That's 100 times faster than the average Internet speed in the United States.

How much RAM can 64 bit use? ›

A 64-bit system can access 264 different memory addresses, i.e actually 18-Quintillion bytes of RAM. In short, any amount of memory greater than 4 GB can be easily handled by it.

Is 2 GB a lot of RAM? ›

2GB: Not Enough to Get Much Done

2GB is enough to get some work done, like running your productivity suite and having plenty of open browser tabs, but you'll still be held back significantly in terms of running more powerful software solutions.

Can I run 32gb on 4GB RAM? ›

A 32Bit operation system supports up to 4GB of memory, however not all of it may be available for use by applications.

How much swap space for 8gb RAM? ›

You should be fine with just 2 or 4 Gb of swap size, or none at all (since you don't plan hibernating). An often-quoted rule of thumb says that the swap partition should be twice the size of the RAM.

Is 32 GB enough for Linux? ›

32GBs plenty of space for installing, but suggest getting an external drive for placing the home partition and/or a data partition if you think you will download a lot.

Is 1 GB RAM enough for Linux? ›

You'll need a PC with at least 512MB of RAM, and around 2GB of disk space. A Pentium 4 or later is recommended, although some older CPUs can run Arch Linux.

What is a swap rate example? ›

ABC Company and XYZ Company enter into one-year interest rate swap with a nominal value of $1 million. ABC offers XYZ a fixed annual rate of 5% in exchange for a rate of LIBOR plus 1%, since both parties believe that LIBOR will be roughly 4%. At the end of the year, ABC will pay XYZ $50,000 (5% of $1 million).

How do you calculate swap time? ›

This is the reason why swapping is also referred to as memory compaction.
...
Now we will calculate how long it will take to transfer from main memory to secondary memory.
  1. User process size is 2048Kb.
  2. Data transfer rate is 1Mbps = 1024 kbps.
  3. Time = process size / transfer rate.
  4. = 2048 / 1024.
  5. = 2 seconds.
  6. = 2000 milliseconds.

Is swap a disk or memory? ›

Virtual memory is a combination of RAM and disk space that running processes can use. Swap space is the portion of virtual memory that is on the hard disk, used when RAM is full.

Is swap file volatile? ›

While the contents of these files may resemble or originate from volatile data, the page/swap file is nonvolatile and is preserved in its last operating state when power is removed.

Is swap good for Linux? ›

Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM.

Does swap make Linux faster? ›

We know that using Linux swap space instead of RAM (memory) can severely slow down performance. So, one might ask, since I have more than enough memory available, wouldn't it better to delete swap space? The short answer is, No.

How much RAM is good for Linux? ›

Linux requires very little memory to run compared to other advanced operating systems. You should have at the very least 8 MB of RAM; however, it's strongly suggested that you have at least 16 MB. The more memory you have, the faster the system will run.

How do I choose a swap size? ›

How much should be the swap size?
  1. If RAM is less than 1 GB, swap size should be at least the size of RAM and at most double the size of RAM.
  2. If RAM is more than 1 GB, swap size should be at least equal to the square root of the RAM size and at most double the size of RAM.
Jun 6, 2021

Can I run Linux without swap? ›

Without swap, the OS has no choice but to keep the modified private memory mappings associated with those services in RAM forever. That's RAM that can never be used as disk cache. So you want swap whether you need it or not. In that case, you don't need a swap file.

How do I reduce swap usage in Linux? ›

To clear the swap memory on your system, you simply need to cycle off the swap. This moves all data from swap memory back into RAM. It also means that you need to be sure you have the RAM to support this operation. An easy way to do this is to run 'free -m' to see what is being used in swap and in RAM.

How much swap space for 8GB RAM? ›

You should be fine with just 2 or 4 Gb of swap size, or none at all (since you don't plan hibernating). An often-quoted rule of thumb says that the swap partition should be twice the size of the RAM.

Is swap slower than RAM? ›

It offers a slower access time compared to RAM and located in the disk memory. Swap space is actually a part of the virtual memory. There are several applications of swap space. It stores the applications which the OS doesn't use frequently.

Does swap file increase RAM? ›

The file swaps a section of RAM storage from an idle program and frees up memory for other programs. By using a swap file, the computer can use more memory than is physically installed. In other words, it can run more programs than it could run with just the limited resources of the installed RAM.

Which Linux OS is faster? ›

About: Manjaro Linux is a fast, desktop-oriented operating system based on Arch Linux. The distro provides all the benefits of cutting-edge software to get started quickly and automated tools to minimise manual intervention. It is completely free and is available for 64 Bit architectures. Know more here.

How much load is too much Linux? ›

As long as your server and applications are performing as expected, you don't need to worry too much about it. The load average values should be within 75% of the number of CPUs. If a server has 4 CPUs, then 75% of 4 is 3. The load average values should not exceed 3 in that case.

Is 64 GB RAM overkill? ›

Is 64/128 GB of RAM Overkill? For the majority of users, it is. If you plan on building a PC purely for gaming and some general, basic, everyday activity, 64 GB of RAM is just too much. The amount of RAM you need will ultimately depend on your workload.

Which Linux is best for 4GB RAM? ›

There are a number light Distros that will run on 4GB of RAM...Linux Lite... Lubuntu... Xubuntu... Peppermint.

How much RAM is free Linux? ›

Linux free -m

1024 MB is the total system memory available, which would be physical RAM. 1 MB and 823 MB both show free because an application has access to both for memory storage.

Top Articles
6 reasons to consider a credit card with no annual fee
All about GST Form PMT-03 and PMT-03A under GST
9.4: Resonance Lewis Structures
Enrique Espinosa Melendez Obituary
Ups Dropoff Location Near Me
Loves Employee Pay Stub
Missing 2023 Showtimes Near Cinemark West Springfield 15 And Xd
Aadya Bazaar
PontiacMadeDDG family: mother, father and siblings
Mileage To Walmart
25X11X10 Atv Tires Tractor Supply
Craigslist Portales
Craigslist Kennewick Pasco Richland
Stolen Touches Neva Altaj Read Online Free
J Prince Steps Over Takeoff
Xrarse
Overzicht reviews voor 2Cheap.nl
Does Publix Have Sephora Gift Cards
Everything You Need to Know About Holly by Stephen King
This Modern World Daily Kos
Saberhealth Time Track
D10 Wrestling Facebook
Best Suv In 2010
Gon Deer Forum
Aldi Süd Prospekt ᐅ Aktuelle Angebote online blättern
97226 Zip Code
Yog-Sothoth
11 Ways to Sell a Car on Craigslist - wikiHow
R/Airforcerecruits
R Baldurs Gate 3
Rs3 Bring Leela To The Tomb
Neteller Kasiinod
Kaiser Infozone
Of An Age Showtimes Near Alamo Drafthouse Sloans Lake
Tra.mypatients Folio
Joplin Pets Craigslist
Blue Beetle Movie Tickets and Showtimes Near Me | Regal
Bimmerpost version for Porsche forum?
Watchseries To New Domain
8005607994
Snohomish Hairmasters
Hindilinks4U Bollywood Action Movies
Davis Fire Friday live updates: Community meeting set for 7 p.m. with Lombardo
Gym Assistant Manager Salary
Pulaski County Ky Mugshots Busted Newspaper
Is Chanel West Coast Pregnant Due Date
25100 N 104Th Way
Wwba Baseball
Morbid Ash And Annie Drew
King Fields Mortuary
Bunbrat
Latest Posts
Article information

Author: Arline Emard IV

Last Updated:

Views: 6086

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Arline Emard IV

Birthday: 1996-07-10

Address: 8912 Hintz Shore, West Louie, AZ 69363-0747

Phone: +13454700762376

Job: Administration Technician

Hobby: Paintball, Horseback riding, Cycling, Running, Macrame, Playing musical instruments, Soapmaking

Introduction: My name is Arline Emard IV, I am a cheerful, gorgeous, colorful, joyous, excited, super, inquisitive person who loves writing and wants to share my knowledge and understanding with you.