Having problems with swap file

So when I installed Manjaro I didn’t add a swap partition because the disk I was installing to was small. I tried to add a swap file but it never gets used. I’m using the systemd swap that’s supposed to automatically manage itself but I’m not sure it’s working. Also swappiness is set top the default 60 value.

Here’s what htop reports…


Even when you’re loading up all of it? It won’t necessarily use it until it starts seriously running out of memory.

Isn’t the point of swap supposed to be able efficiently using Ram now feeling so when it’s full?

The OS tries to use RAM as much as possible all the time, if you’re doing something, whatever the applications themselves don’t use will be used for filesystem caching (it appears yellow in htop). It will cache less and less as you’re increasing your usage, and when there’s a threat of running out, swap will start to be used bit by bit (that behaviour is influenced by swappiness). When swap is heavily used, you’ll notice (everything gets really slow). If there was no swap at that point, OS would start killing your processes to free up space, that’s something you don’t want usually. That’s what swap is for.


There are a few different algorithms for making use of swap.

Linux seems to be reluctant to touch swap.

macOS seems to (based on obvservation) pro-actively swap (or rather, COPY to disk) inactive pages so they can be dropped from ram without needing to wait to swap them out when the pages need to be reclaimed.

But yeah, Linux won’t touch swap until you really push it quite hard.

This is not true, just because the algoritm used is more surgical does not mean the swap will not be used. It all depend on configuration and workload.

Usage 0 bytes is actually not a good sign, that means there are no sleeping threads on your computer. Something that should not happen, but happens all the time in production (especially when using X window system.)

You can increase swappiness if you want to almost garantee a swap.
For test you can run a thread that consumes at least 2MB of memory and put it to sleep.

Not necessarily.

This box has 307 sleeping threads and 0 swap

top - 14:49:54 up 2:24, 3 users, load average: 0.12, 0.73, 0.97
Tasks: 308 total, 1 running, 307 sleeping, 0 stopped, 0 zombie
%Cpu(s): 2.2 us, 1.5 sy, 0.0 ni, 96.4 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 64301.6 total, 55932.5 free, 3262.3 used, 5106.8 buff/cache
MiB Swap: 32216.0 total, 32216.0 free, 0.0 used. 60200.6 avail Mem


sure it isn’t memory pressed at the moment, but… in my experience linux is much more reluctant to touch swap at all (even when i’m using 50+ GB of RAM) compared to macOS, which seems to proactively get swap ready so it can just dump in-memory pages if they’re idle when required rather than having to page out at the point the ram needs to be reallocated (because they’re already on disk from being idle).

For comparison, macOS…

1 [|||||||||||||||||||| 28.1%] Tasks: 417, 1142 thr; 1 running
2 [||||| 5.3%] Load average: 0.98 1.05 1.07
3 [|||||||||||||| 19.7%] Uptime: 1 day, 00:22:51
4 [|||| 4.6%]
Swp[|||||||||||||||||||||| 316M/1.00G]

If you are using swap… you dont have enough RAM.

You dont want to use swap, its bad for performance.

1 Like

Swap is used as a backup to when your ram is full. You’re not supposed to be using it.


Pretty sure Windows pages a lot to disk, even with lots of memory available. Annoying when the image is on rust, and it keeps read/writing pages rather than doing its job loading levels…

1 Like

Everything I have read on Hacker News says that Linux has problems taking care of things rationally when RAM gets full. I’m pretty sure there are articles on Phoronix about it, and I believe I read something about people from Fedora(?) talking on the LKML about changing certain default swap behaviors. Even when it isn’t full, it can have issues if you don’t provision for any swap at all. Unless you have some specific case like some sort of massive business or super computer use case, is it really that hard to spare half a GB for a swap partition?

It doesn’t really matter if something is supposed to work, if it causes you problems and you refuse to do a simple fix merely on principle then you are just shooting yourself in the foot. I frequently do that myself, just not with swap. I occasionally see swap being used when I have less than a quarter of my RAM used, usually just a few MB. If a drive is so small you can’t spare even half a GB then you will likely run into other issues besides swap. Heck, 100MB is better than 0.

I think the common consensus of people never making a swap partition is why Ubuntu has been forcing ZRAM drives for swap. The space will be taken up one way or another because they don’t want to deal with people having problems and refusing to make a swap partition. If you do an install and forget to make a small swap partition, you could either try to resize the partition(s), or save your configs then nuke and pave. Still way faster than installing Windows.

This is something that really impressed me about MacOS. I used a Macbook for the first time over the summer, and I never once ran into a situation where using too much memory locked up my computer. Maybe it swapped too aggressively, but I’ll take that over having my system freeze up. Can’t say the same about Linux. Here’s a Phoronix post discussing it: https://www.phoronix.com/scan.php?page=news_item&px=Linux-Does-Bad-Low-RAM.


If the end result is “never having my system freeze up” then it isn’t swapping too aggressively. It is “working properly”.

Apple cop a lot of flack for various things and a lot of it is well deserved. But how macOS handles high memory consumption situations is an example to everyone else in the industry of how to do it in my opinion.

The only time i ever notice my macbook is working hard is when the fan cranks up. Memory can be maxed out and deep into swap and it is still super responsive because it seems to page in advance… so when a new allocation needs to happen, the idle stuff is already paged out and can be ditched from RAM instantly.

this is fortunate, because i would describe apple’s pricing on ram upgrades as being akin to “prison rape” (only tolerated because you’re locked into the ecosystem)… so there is that. but from the software side, it works great.

Also… re: not using swap. Swapping out inactive pages to disk means you can free that RAM up for disk cache for programs actually running. Or be able to instantly fill a memory allocation (larger than available free RAM) rather than trying to juggle memory requirements at that point in time, while the user waits.

I’m pretty sure Apple changed this behaviour around macOS Lion. Because of the new machines being almost all SSD. It made Lion run like shit on old platforms because the disk was getting hammered with pro-active swapping. But if you have/had SSD the new behaviour was an improvement. They tweaked it a bit in Mountain Lion to work better on old machines.

1 Like

Lol yeah, that was one of my major gripes. The fan whines like hell and when the laptop was working hard, you better not have it anywhere near your actual lap. Never had a laptop get so hot before.

1 Like

You have 16GB RAM. You should be fine with Manjaro for the life of this PC unless you find some kind of RAM hog program, you run VM’s or docker or some hog that uses too much RAM. At that point you will just need to start buying servers because trying to run something from swap is so unbearable it’s not worth it.