Linux is kind of dogshit at memory management unfortunately, due to a thing called overcommit it can essentially commit more memory than there actually exists on the system, cue potential for hard locks, stutters and freezing, there are some mitigations
Now the common recommendation is brute forcing the issue by making a swap partition or file, this is generally a bad idea on a modern system, due to the speed of ssds and even some fast spinning hard drives its possible for the kernel to get confused and think there’s enough memory spare where it becomes less snappy about clearing memory, often ironically making the problem worse, generally only use a swap partition if you need something else like hibernation
What should instead be done these days is setting up zram which essentially does compression of your memory in ram so that it stays clear for as long as possible, zswap does something similar but will also fallback to a swap partition soon after, the two are very similar so just setup zram on installs that dont have or need a swap partition, and setup zswap on ones that need or already have a swap partition(as they’re annoying to remove in an existing install)
But we’re not done yet because while this will buy you a lot of time there is still another massive issue at play, the linux kernel’s oom killer doesn’t generally care how full your memory is unless it starts biting into the kernel’s needs, this means it can take ages before it does anything even if everything is so overloaded where your display server has been hard frozen for 20 minutes, and since it has no real priority outside of the kernel it may force shut off vital processes first rather than secondary ones
To fix this you want a userspace oom killer that keeps in mind the entire OS and prioritises what needs to go first, many exist but if you want something that just works then EarlyOOM is great
With these mitigations in place your OS should become much less prone to freezing and stutters, if you really want a nuclear option there’s also cgroups
Linux is kind of dogshit at memory management unfortunately, due to a thing called overcommit it can essentially commit more memory than there actually exists on the system, cue potential for hard locks, stutters and freezing, there are some mitigations
Now the common recommendation is brute forcing the issue by making a swap partition or file, this is generally a bad idea on a modern system, due to the speed of ssds and even some fast spinning hard drives its possible for the kernel to get confused and think there’s enough memory spare where it becomes less snappy about clearing memory, often ironically making the problem worse, generally only use a swap partition if you need something else like hibernation
What should instead be done these days is setting up zram which essentially does compression of your memory in ram so that it stays clear for as long as possible, zswap does something similar but will also fallback to a swap partition soon after, the two are very similar so just setup zram on installs that dont have or need a swap partition, and setup zswap on ones that need or already have a swap partition(as they’re annoying to remove in an existing install)
But we’re not done yet because while this will buy you a lot of time there is still another massive issue at play, the linux kernel’s oom killer doesn’t generally care how full your memory is unless it starts biting into the kernel’s needs, this means it can take ages before it does anything even if everything is so overloaded where your display server has been hard frozen for 20 minutes, and since it has no real priority outside of the kernel it may force shut off vital processes first rather than secondary ones
To fix this you want a userspace oom killer that keeps in mind the entire OS and prioritises what needs to go first, many exist but if you want something that just works then EarlyOOM is great
With these mitigations in place your OS should become much less prone to freezing and stutters, if you really want a nuclear option there’s also cgroups