Your Linux system is secretly using your hard drive as RAM, and that’s a good thing


If you spend time around serious Linux users, you’ll likely hear a reference to “swap space.” Or maybe you wondered what the swap partition that your Linux installation program created is. Virtual memory and swap space can be confusing. Here’s what you need to know on Linux.

What is virtual memory?

A more flexible view of memory

A hand holding an LPCAMM2 RAM memory module above the Framework Laptop 13 Pro. Credit: Framework Computer Inc.

A lot of people conflate “swap” with “virtual memory.” Virtual memory is a technique that abstracts your computer’s memory over its physical RAM.

If you’re familiar with the concept of a virtual machine, where you can create an entire other computer in a program like VirtualBox to run different operating systems, virtual memory is a similar concept. Virtual memory is a representation of your computer’s memory that the operating system uses to present a picture of a memory that’s not limited by the RAM sticks in your machine.

There’s a piece of hardware on the CPU that makes this possible: the Memory Management Unit or MMU. The MMU splits the memory into “pages.” The MMU also prevents programs from interfering with each other, which is important in a multitasking, multiuser operating system like Linux.

AMD Ryzen 5 5600 CPU placed in a motherboard. Credit: Bertel King / How-To Geek

The page sizes tend to be the same size as storage blocks on hard drives and SSDs, which is the main advantage of virtual memory: creating a large, unified address space that includes both the system RAM and part of the hard drive. This approach allows your system to run more and larger programs even when there might not be enough physical RAM in your machine to do so.

The technique was first developed for mainframes and minicomputers that had to be shared among multiple users. Virtual memory meant that there was less need for physical memory, which allowed customers to save money by buying machines with less physical RAM.

The operating system, with memory pages scattered across the RAM and the disk (I’ll use the term “disk” to refer to main storage, whether on a traditional spinning hard drive or SSD), can “swap” these pages in and out of the main memory. The operating system will tend to try to keep the pages actively being used “swapped in”, or in the physical RAM. That’s because RAM has been traditionally faster than the disk, especially in the days before SSDs were readily available.

This approach allows the programs, and parts of programs, that you’re actually using are active in the fast RAM instead of the slow disk. Disabling virtual memory could paradoxically mean a slower system, since all of the active programs would need to be held in memory. Many programs will create a lot of pages on startup, but the kernel will move them into the background while the high priority pages remain in RAM with virtual memory, according to Linux.com.

If you don’t have enough physical RAM in your system, the OS will perpetually swap pages in and out of RAM, unable to keep up, a problem made even worse by the slow speed of traditional hard drives. This makes the system practically unusable, a problem known as “thrashing.” Thrashing with inadequate RAM was why virtual memory got a bad rap among power users, or at least people who thought they were expert computer users, with some people even avoiding disabling it entirely. This is a bad idea. Having the actively used parts in the RAM with virtual memory is more efficient.

The other main concern with virtual memory with the modern deployment of SSDs is possible premature wearing out of the SSD with lower RAM counts, especially on modern laptops where the RAM is soldered to the motherboard and can’t be upgraded. There’s less evidence that this is a practical concern with normal desktop usage. If you’re doing intensive work or AAA gaming, you’ll want more RAM anyway.

What is swap space?

Parking pages in files or partitions

The area of the storage that holds swapped-out pages is known as the swap space.

Linux has two approaches for implementing swap space. The most common is to dedicate a disk partition. The rule of thumb for swap partitions was twice the physical RAM in the machine. This is still what most Linux installations will propose by default when you partition your disk. The disadvantage of this approach is that if you upgrade the RAM, you’ll have to grow the swap partition as well. Swap partitions are often the first partitions on disks due to how traditional hard drives work. It’s faster to seek toward the inside of a platter, so this is where installation programs will place the swap partition.

The other approach is a swap file, which is as the name suggests, a dedicated file in the Linux filesystem. It’s more fleixible than a dedicated swap partition, since it can be resized easily if the physical RAM changes. This is the approach that Windows uses for virtual memory. It’s much less common than the dedicated partition approach in the Linux world.

Swap partition or swap file?

Tradition vs flexibility

The dedicated partition approach seems to be the most common in Linux. Most people will probably just do what their Linux installation program does. The vast majority of linux installations still prefer swap partitions.

If you upgrade your RAM frequently or just prefer a simpler partition scheme, you might opt for a swap file. It’s also possible to run a system without any swap space at all, but you might find yourself running out of memory altogether. Linux systems without any swap are typically in niche applications such as embedded systems controllers.

How much swap space?

Rethinking the traditional “twice the physical RAM” rule

The traditional rule of thumb for how much swap space you need has been twice the physical memory. This was from an era where machines tended to have much less RAM than they do now. It might still hold because modern OSes, including Linux are much more capable. Most modern machines support hibernation, and that feature uses swap space to store the state of the system. If you make use of this feature, more swap space is better. You should regard the amount of physical RAM as the bare minimum of swap space.

The only way to fix thrashing

System stuttering? You probably need more RAM

A stack of older RAM on a table. Credit: Nick Lewis/How-To Geek

If you are suffering from thrashing, you might think to try adjusting the “swappiness” of the system, or how aggressive it will swap pages in and out. This would only be a temporary fix.

You might not like the answer, especially with the price of RAM, but the only reliable way to fix swapping is to add more RAM


Linux’s unsung hero

Swap space is something that most people on modern Linux systems don’t think about until something goes wrong. Virtual memory makes modern desktop usage possible, but it can only go so far. Understanding how it works and its limitations will help you use swap space on Linux more effectively on your next installation.

Dell XPS 13 Plus 2023

Operating System

Ubuntu Linux 22.04 LTS

CPU

13th Gen Intel Core i7-1360P

GPU

Intel Iris Xe Graphics

RAM

16GB DDR5

Storage

512GB SSD

Weight

2.71 lbs

The Dell XPS 13 Plus with Linux combines powerful hardware and a great screen in a lightweight, great-looking chassis to create a fantastic Linux laptop.




Source link

Leave a Reply

Subscribe to Our Newsletter

Get our latest articles delivered straight to your inbox. No spam, we promise.

Recent Reviews


The Toyota Corolla Cross Hybrid has quickly become the default choice for buyers looking to step into an affordable hybrid SUV. It’s practical, efficient, and backed by a reputation that makes it an easy recommendation. But when you look beyond the badge, it’s no longer the clear-cut value leader it appears to be.

One Korean rival from Kia quietly outperforms it where it matters most. It’s cheaper to buy, significantly more fuel-efficient, and offers a more refined and spacious experience, despite targeting the same budget-conscious buyers. Instead of just meeting expectations, it raises them for what an entry-level hybrid SUV should deliver.

That’s what makes this comparison so one-sided. When a vehicle costs less while doing more, using less fuel, offering more room, and feeling more polished, it stops being an alternative and starts looking like the obvious choice.

In order to give you the most up-to-date and accurate information possible, the data used to compile this article was sourced from various manufacturer websites, including the EPA.


2026 Toyota Crown Signia


This Toyota hybrid beats Acura, Genesis, and even Lexus where it matters most

The Toyota Crown Signia does more than keep up. In several categories, it sets the pace.

There aren’t many small hybrid SUVs, but the Kia Niro is the best

Easily the most budget-friendly crossover on the market

Hybrid crossovers are a really attractive proposition. You get the added practicality of an SUV and fuel efficiency that keeps your monthly fuel bills low. Perhaps the most obvious choice here, especially if you’re on a tight budget, is the Toyota Corolla Cross Hybrid. However, if you’re looking for the best bang for your buck, and the most efficiency, then the Kia Niro remains king of the subcompact SUV segment.

2026 Kia Niro Hybrid trims and pricing

Models

Starting MSRP

LX

$27,390

EX

$30,190

SX

$33,390

SX Touring

$35,790

As we’ve already mentioned, the Corolla Cross Hybrid is kind of the benchmark for small hybrid SUVs, with its badge definitely helping make it so popular. The Toyota has a starting price of $29,395, meaning it is just over $2,000 more expensive than the Kia. Despite this, we think even the most affordable Niro Hybrid feels more refined, better equipped, and, to top it all off, its more efficient.

With the Niro being one of the most affordable crossovers on the market, you have a little wiggle room when it comes to trims. We still wouldn’t climb the ladder far, as we think the EX offers the best bang for your buck. It comes with niceties like a smartphone charging pad, faux-leather upholstery, and an upgraded infotainment screen. The Premium package is also definitely worth the extra $2,000, adding things like a panoramic sunroof, a power-operated tailgate, and a premium sound system.


Front 3/4 shot of a red 2024 Mazda MX-5 Miata RF driving on a winding road with the ocean in the background.


These 5 sporty cars keep smiles high and fuel bills low

Fun behind the wheel doesn’t have to mean pain at the pump.

Neither are particularly entertaining, but the Niro is lighter on fuel

Beating Toyota at the hybrid game isn’t easy

Toyota is one of the most experienced automakers out there when it comes to building hybrid powertrains, with the Japanese brand being a big proponent of the setup. This is why it’s so impressive that the little Niro comes out ahead when it comes to efficiency. On top of this, Kia has delivered a more refined driving experience that feels better than you’d expect considering the price you pay.

Kia Niro Hybrid performance and efficiency


980919-1.jpg

kia-logo.jpeg

Base Trim Engine

1.6L I4 Hybrid

Base Trim Transmission

6-speed auto-shift manual

Base Trim Drivetrain

Front-Wheel Drive

Base Trim Horsepower

103.5 HP @5700 RPM

Base Trim Torque

106.3 lb.-ft. @ 4000 RPM

Base Trim Fuel Economy (city/highway/combined)

53/54/53 MPG

Base Trim Battery Type

Lithium polymer (LiPo)

Make

Kia

Model

Niro



The Corolla Cross Hybrid has a little more grunt than the Kia, putting down 196 horsepower versus the Niro’s dinky 139 horses. The 1.6-liter engine in the Korean crossover is an underachiever, which is why it takes around 8.9 seconds to get up to 60 miles per hour. With both of these crossovers being more urban crawlers than highway cruisers, we don’t think that lack of power is the end of the world.

There really isn’t a winner when it comes to driving engagement here, with both small SUVs being exceptionally dull to drive. However, the Kia Niro does come feature a pretty plush ride quality. It also gets a six-speed DCT instead of the CVT in the Corolla, which results in less droning when accelerating, resulting in a more refined experience.

Fuel economy

Model

City

Highway

Combined

Kia Niro FE

53 MPG

54 MPG

53 MPG

Kia Niro

53 MPG

45 MPG

49 MPG

Toyota Corolla Cross Hybrid

46 MPG

39 MPG

42 MPG

Efficiency is a massive reason to pick a Kia Niro over a Corolla Cross Hybrid. The base model Niro is rated for up to 53 miles per gallon combined, with every other model managing 49 miles per gallon combined. This means that even the least efficient Niro is rated to get seven more miles per gallon than a Toyota Corolla Cross Hybrid.


2027 Hyundai IONIQ 9 AWD Performance Calligraphy Black Ink


This Hyundai SUV takes three-row EV luxury into new territory

Hyundai IONIQ 9 AWD Performance Calligraphy Black Ink reveal

Kia delivers a sleek and stylish interior in the 2026 Niro

Meanwhile, the Corolla Cross is a bit boring

Toyota has always been known to value simplicity, and this has often resulted in somewhat underwhelming interiors. While there isn’t anything wrong with the cabin of the Corolla Cross, and it does come well-equipped, it does lean a little too far in the utilitarian direction. The Niro, on the other hand, finds a good middle ground between simplicity and modernity.

Interior dimensions and comfort

Model

Kia Niro Hybrid

Toyota Corolla Cross Hybrid

Front row headroom

40.5 inches

38.6 inches

Front row legroom

41.5 inches

42.9 inches

Second row headroom

39.6 inches

39 inches

Second row legroom

39.8 inches

32 inches

Cargo capacity (behind second row)

22.8 cubic feet

21.5 cubic feet

Both the Niro and the Corolla Cross feel very practical for cheap subcompact SUVs, but the Kia has a pretty clear advantage. The Niro offers a much more spacious rear row of seats, with tons of legroom. You’d have no problem fitting even particularly tall passengers in the rear seats. It also does have a slightly more spacious cargo hold, though the difference here is much smaller.

Both the Corolla Cross and Niro have similar philosophies regarding interior design, but with some differences in execution. Both aim for basic functionality, but the Kia does it in a much more contemporary way. It’s obvious at all times that both crossovers are budget-oriented, in no small part thanks to the cheap plastics used, but build quality is good. The Kia also offers a few upscale touches that put it ahead of its Japanese rival, especially on higher trim levels.

Infotainment and technology

There is very little competition between the Niro and Corolla Cross when it comes to tech features. Both come standard with an eight-inch infotainment screen to start, with a 10.3-inch screen available on every trim but the base Niro and a 10.5-inch screen being optional in the Corolla Cross.

The two budget crossovers are fairly evenly matched when it comes to other tech features. Things like smartphone mirroring and a wireless smartphone charging pad are available on the Kia and Toyota. One key difference is the optional sound systems, with the Niro’s seven-speaker Harman/Kardon sound system performing much better than the optional JBL system in the Corolla Cross.


Cheaper, more efficient, and more refined

When comparing these two small crossovers side-by-side, it’s really hard to make a case for the Toyota. The Corolla Cross does have more power and comes with the peace of mind you get from the Toyota badge, but in just about every other way the Kia feels like the better deal. For less money, you’re getting a crossover that is more spacious, less boring on the inside, and far more efficient. In just about every way, the Niro is a more successful budget hybrid crossover.



Source link