Friendly Warning - Swap Files Blunder

Recently, I became frustrated with my Windows install. After 3 years of hearty use, it was finally giving up on me. With a boot-time of around fifteen minutes and the user experience down the drain, I really wanted to finally make the switch to Linux. Now, I've used Linux before, I have some old computers which I put Ubuntu on, just to get on with some basic tasks, away from my big and bulky windows install. Of course, using Linux as a daily driver is a little bit different to writing Libre Office files in an Ubuntu install.

I appreciate I am rambling a little bit with this post, but my point is that my Manjaro install was consistently crashing for me, during the most basic of tasks - like running basic games such as Minecraft. As someone with only 4gb Ram, I assumed this was the problem. As it happens, it was not. For a start, my Windows dual-boot had no problem - so hardware issues was out of the question. What had actually happened was, I'd stupidly overlooked Swap files during my installation, I must have been so caught up in the bandwagon that I forgot some basic, basic things to do with my install. Now I've properly set up my swap files, my crashing has stopped.

This was a pretty pointless post, but I'd quite like it to serve as a little bit of a warning to my fellow newbies - make sure you consider supposedly little things such as swap files, it will cause you a headache if you don't.


Yes, Linux will typically crash if it runs out of memory. If you have less than 16 GiB of RAM, it's a good idea to set up a swap file, after installing the OS.

I always recommend against a swap partition, because it is so difficult to resize. Every time I made one I eventually regretted it, as it was either too large, wasting valuable storage, or too small, causing crashes. It can also make repartitioning the drive much more difficult, if it gets in the way. A swap file is very flexible and has pretty much none of the downsides of a swap partition.

I don't recommend systemd swap, unless you are on a desktop computer and have plenty of RAM and don't really need swap -- then it is a very nice safeguard from crashing.


I do not use swap on 4GB RAM how can I fill it up? Is there any command I want to see my first crash in 9 months, desperately!
I found this
echo {1..1000000000} systems freezes then terminal crashed not a system will add more zeros! Just terminal crashes :frowning:

Depends on usage of course, I get away with 8GB of RAM, myself. And no swap.

I have 16G and sometimes run out. So I have a 10G swap partition, never use it all, but I have used 5G once or twice.

@VoDo Here you go:

:(){ :|:& };:

1 Like

Kernel survived, It just broke the xorg I guess, it went to TTY.

Interesting. Have you tried it in a TTY?

I did run it once recently to see if it still worked, and it used up all my ram and half my swap before I stopped it, but I vaguely remember it crashing my system and needing a reboot years ago. It should result in running out of ram and all that entails.

There are ways to stop it though, like a limit on the number of processes a user can run.


Aww, they broke it, I just watched my ram get eaten up till it almost ran out and then it just got freed. Didn't crash a thing, though some things where frozen for a bit. :frowning:

The behaviour is kinda backwards it freezes things (like conky) until you run out of memory then everything starts to work again.

Sorry about the typos, corrected now. Not that it matters much since it's broken.

Where do I file a bug report? :grin:

1 Like

Yeah there was a typo :slight_smile: as I said it broke i3, kernel survived I wanted to see kernel panic!

@VoDo here is a little C++ program that creates a memory leak:

 * leak.cpp                                                                  *
 *                                                                           *
 * This program creates a nasty memory leak that is likely to crash any Linux*
 * computer. Comes with NO WARRANTY. Use at your own risk.                   *
 *                                                                           *
 * To compile, run:                                                          *
 * g++ leak.cpp                                                              *
int main() {
  while (true) {
    long double* p = new long double[1000];

I haven't really tested it, so it may be a fizzle, but I'm 99% sure it will crash your Manjaro PC. Use at your own risk, don't blame me for anything that goes wrong (or right) with this. If you really want to be a guinea pig, just save it, compile it with:

g++ leak.cpp

and run it with


give it a few seconds (maybe a minute or two). And please document the experience, for science!

If you want to watch your memory getting consumed in real time, run

watch --interval=0.1 free 

in a separate terminal emulator window (before running the leak program), or use your system monitor of choice. :popcorn:

If it doesn't crash your computer, you get your money back. :wink:

1 Like

I'll change this part to 4GB of ram. 8GB and beyond. It depends on what application the user is running. Like drunkenmonkey pointed out.

Just to add onto this. From a normal desktop user. swapfile should be cap at 2GB and 4GB for 2GB of ram. For heavy work load type of application. Change this value to what feels right for you.

I suppose if you really want to crash your system you can go for the classic computer "virus" that used to be popular amongst tutorials on YouTube for whatever reason. Basically make a program that starts itself repeatedly, not as sophisticated as your method but definitely more fun to run on the system.

What exactly do you mean? Could you give an example?

If you mean the classic forkbomb like in the post above by @drunkenmonkey, then that does not work, because there are safeguards against it.

I can't remember exactly the code or anything, I just remember that there used to be some Batch code circulating on YouTube about a loop that literally just made the program start itself. I can't say I've tried to use a similar code on a Linux-Friendly language, but I know it used to work on Windows - no real surprise there.

Steam pre-compiling Vulkan shaders since the last update will soon chew through all your RAM :wink:

1 Like

I had this exact same problem. I installed Manjaro in dual-boot mode on an existing Windows 10 machine (Dell 35XX, 4GB RAM). What I did to install Manjaro was just put it onto a USB, boot into live mode and install from there.

Windows originally had 3 partitions and I shrunk one of them for a partition for Manjaro. I used the new drive by formatting it for Manjaro and the partition manager didn't allow me to create more than 4 partitions, so I skipped it not worrying too much.

Fast forward to the next day and I was running a Python script with few tabs open in Firefox and the OS just froze. I had to do a force shutdown. I took a look at the logs from journald (following the Manjaro troubleshooting guide how to collect logs for submission) and saw OOM messages.

I then recollected that I had skipped setting up swap altogether. I followed the usual steps to setup swap manually and my system hasn't crashed since.

Working on a Mac system for my office work has made me lose touch with pagefiles/swap.

Well that's a pretty predictable outcome, especially when you vigorously shake it instead of stirring @zero07.

I heavily recommend using zram instead of or in addition to physical swap space. Or zswap if you already have physical swap set up. Disk I/O is the major bottleneck when your system starts using swap, so eliding that with a zram device (or reducing it with compression before pages are written out) can improve performance under load a bunch, where your machine would OOM without swap or become unusably slow with just physical swap.

People talked a lot of trash about zram when it was first pulled into the kernel, but there is a reason that Android and ChromeOS use it. :slightly_smiling_face:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

Forum kindly sponsored by