Out Of Memory problems

The OOM has been a problem for me for a while now, ever since i started to have heavy workloads in my pc. The pc completely freezes and i have to force shutdown. This should not happen.

I have 16 GB of DDR4 memory in both my desktop and laptop, which are clearly not sufficient for my use case, right now im programming dotnet with Rider and VSCode, which can hog a lot of memory, and have a mssql database running in a container.

In other posts i have seen, the only “solution” people give is either to get more memory, totally unfeasible with 8 GB of DDR4 being $100 and/or laptops with soldered memory, or to just use less memory, which again, it is not a solution.

For comparisons sake, Windows11 handles this very well. Aside from it using more memory in general, It just becomes slightly sluggish when i have a lot open, but there are no freezes. It handles very well compiling, streamming in discord, having Rider, VSCode, Microsoft Management Studio, several browser tabs open, WhatsApp and Telegram open, Spotify, Obsidian, VLC, all at the same time. Fedora does feel way faster, but it freezes.

I am not sure if this is a Fedora problem or a linux kernel problem, but i came here because im using this distro.

So, why can’t this be solved? Or, if it can, why is it not solved?

Please provide the output of inxi -Fzxx as preformatted text (paste the text then highlight it before clicking the </> button on the toolbar)

I am not sure where you are pricing the RAM but I find 8GB ddr4 sodimm for laptop on amazon.com at ~$65 and for 8GB ddr4 dimm for desktop at ~$80.

We need a lot more info about what is happening – detailed – before we can assist.
What apps are open when this happens?
Is this on laptop or desktop? (inxi will tell us)
How long has the system been up?
Is the system fully updated?
Is your bios updated to the latest available for that motherboard? (inxi will tell us)

I’m not in the US, so RAM is more expensive.

What apps are open when this happens?

Basically the ones i mentioned i use on Windows.

How long has the system been up?

Not much, like an hour or two.

Is the system fully updated?

Updated before I started working.

Is your bios updated to the latest available for that motherboard?

Not sure, but last year i had to update it and it is a bit old.

This is the inxi -Fzxx output

System:
  Kernel: 7.0.4-200.fc44.x86_64 arch: x86_64 bits: 64 compiler: gcc v: 16.1.1
  Desktop: KDE Plasma v: 6.6.4 tk: Qt v: N/A wm: kwin_wayland dm: N/A
    Distro: Fedora Linux 44.20260510.0 (Kinoite)
Machine:
  Type: Desktop Mobo: Gigabyte model: B550M DS3H AC
    serial: <superuser required> Firmware: UEFI vendor: American Megatrends LLC.
    v: FEg date: 03/11/2025
CPU:
  Info: 6-core model: AMD Ryzen 5 5600X bits: 64 type: MT MCP arch: Zen 3+
    rev: 2 cache: L1: 384 KiB L2: 3 MiB L3: 32 MiB
  Speed (MHz): avg: 1738 min/max: 561/4654 boost: enabled cores: 1: 1738
    2: 1738 3: 1738 4: 1738 5: 1738 6: 1738 7: 1738 8: 1738 9: 1738 10: 1738
    11: 1738 12: 1738 bogomips: 88632
  Flags-basic: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a
    ssse3 svm
Graphics:
  Device-1: Advanced Micro Devices [AMD/ATI] Navi 22 [Radeon RX 6700/6700
    XT/6750 XT / 6800M/6850M XT] vendor: XFX driver: amdgpu v: kernel
    arch: RDNA-2 pcie: speed: 16 GT/s lanes: 16 ports:
    active: DP-2,DP-3,HDMI-A-1 empty: DP-1,Writeback-1 bus-ID: 09:00.0
    chip-ID: 1002:73df
  Display: wayland server: Xwayland v: 24.1.11 compositor: kwin_wayland
    driver: gpu: amdgpu d-rect: 5292x1440 display-ID: 0
  Monitor-1: DP-2 pos: center model: MSI G27CQ4 E2 res: 2560x1440 hz: 170
    dpi: 109 diag: 685mm (27")
  Monitor-2: DP-3 pos: primary,left model: BenQ GL950A res: 1366x768 hz: 60
    dpi: 85 diag: 470mm (18.5")
  Monitor-3: HDMI-A-1 pos: right model: BenQ GL930A res: 1366x768 hz: 60
    dpi: 85 diag: 470mm (18.5")
  API: EGL v: 1.5 platforms: device: 0 drv: radeonsi device: 1 drv: swrast
    gbm: drv: kms_swrast surfaceless: drv: radeonsi wayland: drv: radeonsi x11:
    drv: radeonsi
  API: OpenGL v: 4.6 compat-v: 4.5 vendor: amd mesa v: 26.0.6 glx-v: 1.4
    direct-render: yes renderer: AMD Radeon RX 6750 XT (radeonsi navi22 ACO DRM
    3.64 7.0.4-200.fc44.x86_64) device-ID: 1002:73df display-ID: :0.0
  API: Vulkan v: 1.4.341 surfaces: N/A device: 0 type: discrete-gpu
    driver: mesa radv device-ID: 1002:73df device: 1 type: cpu
    driver: mesa llvmpipe device-ID: 10005:0000
  Info: Tools: api: clinfo, eglinfo, glxinfo, vulkaninfo
    de: kscreen-console,kscreen-doctor wl: wayland-info x11: xdriinfo,
    xdpyinfo, xprop, xrandr
Audio:
  Device-1: Advanced Micro Devices [AMD/ATI] Navi 21/23 HDMI/DP Audio
    driver: snd_hda_intel v: kernel pcie: speed: 16 GT/s lanes: 16
    bus-ID: 09:00.1 chip-ID: 1002:ab28
  Device-2: Advanced Micro Devices [AMD] Starship/Matisse HD Audio
    vendor: Gigabyte driver: snd_hda_intel v: kernel pcie: speed: 16 GT/s
    lanes: 16 bus-ID: 0b:00.4 chip-ID: 1022:1487
  Device-3: Logitech Headset H390 driver: hid-generic,snd-usb-audio,usbhid
    type: USB rev: 1.1 speed: 12 Mb/s lanes: 1 bus-ID: 1-8:4 chip-ID: 046d:0a44
  Device-4: Texas Instruments PCM2902 Audio Codec
    driver: hid-generic,snd-usb-audio,usbhid type: USB rev: 1.1 speed: 12 Mb/s
    lanes: 1 bus-ID: 3-4:2 chip-ID: 08bb:2902
  API: ALSA v: k7.0.4-200.fc44.x86_64 status: kernel-api
  Server-1: PipeWire v: 1.6.4 status: active with: 1: pipewire-pulse
    status: active 2: wireplumber status: active 3: pipewire-alsa type: plugin
    4: pw-jack type: plugin
Network:
  Device-1: Realtek RTL8821CE 802.11ac PCIe Wireless Network Adapter
    vendor: AzureWave driver: rtw88_8821ce v: kernel pcie: speed: 2.5 GT/s
    lanes: 1 port: e000 bus-ID: 05:00.0 chip-ID: 10ec:c821
  IF: wlo1 state: down mac: <filter>
  Device-2: Realtek RTL8111/8168/8211/8411 PCI Express Gigabit Ethernet
    vendor: Gigabyte driver: r8169 v: kernel pcie: speed: 2.5 GT/s lanes: 1
    port: d000 bus-ID: 06:00.0 chip-ID: 10ec:8168
  IF: enp6s0 state: up speed: 1000 Mbps duplex: full mac: <filter>
  IF-ID-1: br-ac0afd0c2d43 state: down mac: <filter>
  IF-ID-2: docker0 state: down mac: <filter>
Bluetooth:
  Device-1: IMC Networks Bluetooth Radio driver: btusb v: 0.8 type: USB
    rev: 1.1 speed: 12 Mb/s lanes: 1 bus-ID: 1-9:5 chip-ID: 13d3:3558
  Report: btmgmt ID: hci0 rfk-id: 0 state: down bt-service: enabled,running
    rfk-block: hardware: no software: no address: <filter> bt-v: 4.2 lmp-v: 8
Drives:
  Local Storage: total: 2.59 TiB used: 344.77 GiB (13.0%)
  ID-1: /dev/nvme0n1 vendor: Kingston model: SNV3S1000G size: 931.51 GiB
    speed: 63.2 Gb/s lanes: 4 serial: <filter> temp: 34.9 C
  ID-2: /dev/nvme1n1 vendor: TeamGroup model: TM8FPK001T size: 953.87 GiB
    speed: 63.2 Gb/s lanes: 4 serial: <filter> temp: 55.9 C
  ID-3: /dev/sda vendor: Western Digital model: WD3200AAKX-001CA0
    size: 298.09 GiB speed: 6.0 Gb/s serial: <filter>
  ID-4: /dev/sdb vendor: Seagate model: ST3500418AS size: 465.76 GiB
    speed: 3.0 Gb/s serial: <filter>
Partition:
  ID-1: / size: 37.9 MiB used: 37.9 MiB (100.0%) fs: overlay source: ERR-102
  ID-2: /boot size: 973.4 MiB used: 748.2 MiB (76.9%) fs: ext4
    dev: /dev/nvme1n1p5
  ID-3: /boot/efi size: 1.05 GiB used: 46.9 MiB (4.4%) fs: vfat
    dev: /dev/nvme1n1p1
  ID-4: /var size: 365.79 GiB used: 341.46 GiB (93.3%) fs: btrfs
    dev: /dev/nvme1n1p6
Swap:
  ID-1: swap-1 type: zram size: 8 GiB used: 0 KiB (0.0%) priority: 100
    dev: /dev/zram0
Sensors:
  Src: /sys System Temperatures: cpu: 43.0 C mobo: 33.0 C gpu: amdgpu
    temp: 51.0 C mem: 46.0 C
  Fan Speeds (rpm): N/A gpu: amdgpu fan: 679
Info:
  Memory: total: 16 GiB available: 15.53 GiB used: 4.79 GiB (30.8%)
  Processes: 449 Power: uptime: 30m wakeups: 0 Init: systemd v: 259
    default: graphical
  Packages: pm: rpm pkgs: N/A note: see --rpm pm: flatpak pkgs: 129
    Compilers: gcc: 16.1.1 Shell: Bash v: 5.3.9 running-in: konsole inxi: 3.3.40

Fastfetch output:

   1 │  ,clll:.          .,::::::::::::'
   2 │ :ooooooo        .;::::::::::::::
   3 │ looooooo       ,:::::::::::::::'
   4 │ looooooo      .::::::::::::::::
   5 │ looooooo      ;:::::::::::::::.
   6 │ looooooo     .::::::::::::::::
   7 │ looooool;;;;,::::::::::::::::
   8 │ looool::,   .::::::::::::::
   9 │ looooc::     ;::
  10 │ looooc::;.  .::;
  11 │ loooool:::::::::::.
  12 │ looooooo.    .::::::'
  13 │ looooooo       .::::::,;,..
  14 │ looooooo          :::;' ';:;.
  15 │ looooooo          :::     :::
  16 │ cooooooo          .::'   '::.
  17 │  .ooooc             ::, ,::
  18 │                       ''''jc-bazziteDsk@fedora
  19 │ --------------------
  20 │ OS: Fedora Linux 44.20260510.0 (Kinoite) x86_64
  21 │ Host: B550M DS3H AC (Default string-CF)
  22 │ Kernel: Linux 7.0.4-200.fc44.x86_64
  23 │ Uptime: 38 mins
  24 │ Packages: 6 (appimage), 84 (brew), 129 (flatpak), 2417 (rpm)
  25 │ Shell: bash 5.3.9
  26 │ Display (BenQ GL930A): 1366x768 in 19", 60 Hz [External]
  27 │ Display (BenQ GL950A): 1366x768 in 19", 60 Hz [External]
  28 │ Display (MSI4CB0): 2560x1440 in 27", 170 Hz [External] *
  29 │ DE: KDE Plasma 6.6.4
  30 │ WM: KWin (Wayland)
  31 │ WM Theme: Breeze
  32 │ Theme: Breeze (Light) [Qt], Breeze [GTK3/4]
  33 │ Icons: breeze [Qt], breeze [GTK3/4]
  34 │ Font: Noto Sans (10pt) [Qt], Noto Sans (10pt) [GTK3/4]
  35 │ Cursor: breeze (24px)
  36 │ Terminal: konsole 26.4.0
  37 │ Terminal Font: MesloLGL Nerd Font (10pt)
  38 │ CPU: AMD Ryzen 5 5600X (12) @ 4.65 GHz
  39 │ GPU: AMD Radeon RX 6750 XT [Discrete]
  40 │ Memory: 4.66 GiB / 15.53 GiB (30%)
  41 │ Swap: 0 B / 8.00 GiB (0%)
  42 │ Disk (/): 37.95 MiB / 37.95 MiB (100%) - overlay [Read-only]
  43 │ Disk (/etc): 341.48 GiB / 365.79 GiB (93%) - btrfs
  44 │ Disk (/run/media/jc-bazziteDsk/small_backup): 2.54 GiB / 292.35 GiB (1%) - ext4
  45 │ Local IP (enp6s0): 192.168.100.31/24
  46 │ Locale: en_US.UTF-8

To add to the issue, this has beeing happening since fedora 42 (the first time i noticed it was a ram issue).

TLDR: Consider disabling ZRAM and replacing it with ZSwap+swapfile

Fedora desktops enable ZRAM out of the box, this is generally useful for most users.

  • When the system is under high memory pressure, the kernel will evict inactive memory out of cache and into swap.
  • ZRAM uses a portion of RAM itself as compressed swap device.
    • On Fedora, the default ZRAM portion is half of total RAM with an 8GB cap
    • Perfect scenario: an 8GB swap device can be filled with 16GB+ of data
      • Allowing for a 16GB system to hold onto 20GB+ of data without slower drive-backed swap
    • Worst case scenario, 8GB of system memory is actively used by swap
      • On a 16GB system, that’s half of the available memory that applications can no longer use

You can see how this may pose an issue for developers.

Zswap can provide most of the benefits of ZRAM without that fatal drawback.
ZSwap doesn’t provide a swap device like ZRAM, it acts as a cache in front of a standard swap partition or swap file. ZSwap can hold onto data like ZRAM and dump it into drive-backed swap when the cache starts filling up.

Instead of a 8GB ZRAM device, you can configure a smaller Zswap cache and a larger drive-backed swap file/partition. I personally configure a ZSwap and 48GB swap file on my BTRFS drive’s root partition/subvolume

Do you still have (the default) zram-based swap enabled? If so, consider getting rid of it in favour of using using a traditional swap partition with zswap, as that will likely better suit your particular use case.

You can use GNOME Disks or KDE Partition Manager to resize partitions and set up a swap partition that’s at least as big as the amount of RAM you have installed as a backstop, then disable zram and set up zswap in its place.

See here for how to disable zram on Fedora: Changes/SwapOnZRAM - Fedora Project Wiki?

Then, see here for setting up zswap: Zswap - Fedora Project Wiki

This will give you a virtual memory management style very similar to how Windows 11 operates, where least recently used memory is first compressed and then quickly swapped to disk (in an already compressed form) as pressure increases.

You can tune things further if you want by adjusting the vm.swappiness sysctl. If you happen to have a very fast NVMe SSD, you can bias it to favour disk cache (a more macOS-like way of handling things) by increasing the value to something above 100, which will cause more proactive compression and swapping. If you do choose to do this, just be sure to increase your swap partition to 1.5x-2x the amount of RAM you have so that systemd-oomd doesn’t falsely kick in and terminate processes you intend to keep running.

You might also want to configure SQL Server to have a memory limit of no more than 8GB, so that you’ve at least got 50% of your RAM available to other processes at all times, even while it’s chugging away. On Windows, Microsoft SQL Server uses specialised APIs to detect and respond to memory pressure in a very effective way by yielding its memory allocations on-the-fly. I have a sneaking suspicion it doesn’t have anywhere near as mature automatic back-off mechanisms for its Linux port.

For added context: The default zram configuration works better for a typical end-user desktop workload (where there’s many desktop applications each using little bits of RAM) where compression gives a noticeable speedup and much more responsiveness when switching between applications.

Why have a system that will fail, and when it fails, have such a fatal failure, as default?

I’m clearly not the first one with the problem, so i don’t understand why have zram instead of zswap, or a combination of the two (i don’t think i know enough of this, just an idea), and risk the system freezing completely.

Also, why is systemd-oomd not doing its job of freeing memory? As far as i know, it should kill something before the freezing happens.

Security is the main key to that decision though speed of swap is part of it as well.

ZRAM resides purely in RAM and thus is 100% wiped out when the system is powered off or rebooted. Zram is also directly connected to the kernel with no intermediate software so it is as fast a possible when processing swap.

ZSWAP on the other hand uses a physical swap space in addition to some swap in ram. Anything written onto the physical device is static and does not get wiped out with a power off or reboot. It potentially can lead to a security issue. Additionally, zswap is a layer between the kernel and swap space so it inherently adds some measurable delay with managing swap. Physical swap is always slower than RAM swap.

For the majority or users OOM never activates as they have sufficient RAM for the work they do.

zram if fast and avoids stalling the OS when mmeory pressure is high and a short period.

When memory pressure is high, even zram can’t perform miracles. It does compress the data, but it also takes away memory space. You can use zram when memory pressure is medium or less, but when the pressure is high, a swap space on the hard disk will become necessary.

I used high in the sense of spike in demand, not a need for a large amount of memory.

zram is not a magic solution as you say.

The easiest workaround right now is to add a swapfile of 10 or 20 gb and see if speed is acceptable or if swap to disk will slow down your machine too much.

Hi Flow, thanks for the workaround tips !

  • How the effective the swapfile can help from OOM (out of memory) Killer ?
  • it’s the swapfile is recommended for high workload vm / running databases workload ?

Thanks !

What is interesting is the actual swapping activity, meaning how many memory pages is written out to the swap device per second and how may is read back in per second. If a program is not active at all, most of its memory is written to the swap device and because it is not active, the memory will stay on the swap device and not brought back into the main memory.

The only tool I know about that can show this is the sar command from the sysstat package. This is a daemon which collects performance statistics and which can show them. For example sar -W could for example show

12:20:19     pswpin/s pswpout/s
12:30:04         0,00      0,00
12:40:19         0,00      0,00
12:50:04         0,00      0,00
13:00:24         0,00      0,00
13:10:09         0,00      0,00
13:20:24         0,00      0,00
13:30:09         0,00      0,00
13:40:29         0,00      0,00
13:50:10         0,00      0,00
14:00:29         0,00      0,00
Average:         0,00      0,00

and sar -d can show io statistics per device

12:30:04          DEV       tps     rkB/s     wkB/s     dkB/s   areq-sz    aqu-sz     await     %util
12:40:19      nvme0n1      4,82      0,08    418,52   1132,81    322,03      0,02      3,33      0,30
12:40:19        zram0      0,00      0,00      0,00      0,00      0,00      0,00      0,00      0,00
12:50:04      nvme0n1      5,00      0,08    447,86    699,07    229,24      0,01      2,53      0,30
12:50:04        zram0      0,00      0,00      0,00      0,00      0,00      0,00      0,00      0,00
13:00:24      nvme0n1      5,10      0,05    454,54   1189,81    322,32      0,01      2,60      0,25
13:00:24        zram0      0,00      0,00      0,00      0,00      0,00      0,00      0,00      0,00
13:10:09      nvme0n1      4,71      0,02    418,93   1056,56    313,43      0,02      4,39      0,36
13:10:09        zram0      0,00      0,00      0,00      0,00      0,00      0,00      0,00      0,00

sar tool is nice, however if you are in a production like environment (or over engineering your home network for fun) then it’s likely that you are using prometheus and can use prometheus-node-exporter to get all these stats.

Note that when running a VM the RAM allocated to that VM may (and usually does) become unusable to the host, thus reducing the host abilities. Each VM must also be able to function within the allocated amount of RAM and drive space.

I have a host with 32GB RAM and several VMs, each of which I defined with 8GB RAM. I never run more than one of those at a time since it would impact the host seriously if 2 or more were active.

It is important that with a heavily loaded machine (either host or VM) that the user ensure adequate resources are available to support the planned workload. This planning must include both RAM and drive space (and potential needs for swap)

If the OP is using a btrfs partition, it is pretty easy to set up a swapfile on it that is encrypted at boot time. See Setting Up a Swap File on BTRFS – Guy Rutenberg for more on how to do it.

This what I’m doing in concert with zswap on a laptop with 8gb of memory that I have occasionally encountered the OOMD. Seems to work fine.

Is it possible to have both the benefits of zram being fast and zswap as a fallback for when my memory is full? That seems like the best way, unless having both enabled present a problem.

While I was researching this, I ran into this blog post. That post contains the following on combining:

Combining Zswap and Zram (Advanced)

While zswap and zram can operate independently, combining them requires careful consideration. Using both for swap is generally discouraged, as it can lead to complex configurations and potential performance issues. If you do combine them, configure zswap to prioritize RAM compression before using zram or disk swap.

Good luck!

I came accross this post that recommends to use a swap file (for btrfs)

Is just using a swap file for spill, instead of moving to zswap, while keeping zram, viable? Which has better performance?

I personally don’t advise ZRAM+Swapfile.

It’s more a bandaid, as significant percentage of RAM is used for SWAP, as such systems still retain the issues I described in the comment above.
The secord swap device does not reduce the pressure on the ZRAM device. it’s just extra capacity.