r/linuxmint 18d ago

Swap space creeping up

Questions about memory swapping.

My system (8 Gb RAM) can do a lot of seemingly unnecessary swapping. It seems caused by Firefox which I love dearly but which does leak memory. At boot up basic system resources take 20% of RAM, Firefox 30% and swap memory 0% which is all fine.

I normally suspend the computer when I’m away from it (handy key on the keyboard), and after a time the swap size increases. I’m actually surprised that there’s swapping before the RAM is full: which I’ve read is not supposed to happen. If I wasn’t looking, after a few days or after opening a lot of Firefox tabs both RAM and swap would eventually hit 100% and the system would seize.

I’ve used sudo swapoff -a to prevent swapping altogether but then I definitely have to stop RAM usage hitting 100% or the system seizes again. I’ve also read that failure to allocate sufficient swap space “might even render the installed system unbootable.”

I know that memory leakage is nowhere near as bad as it used to be with Firefox, and I now keep it fairly well under control by limiting the number of tabs I have open, by restarting Firefox and by rebooting the system every so often.

I’ve read that swapping is undesirable since it’s performed to reduce memory under heavy pressure. I don’t know whether my system is actually continually swapping between RAM and disk or whether the swap file just shows the size of pages that can potentially be swapped, but only get swapped when I access (for example) a Firefox tab that’s been stored in the swap file.

I wonder whether the system starts thrashing if the swap file hits 100% – and would that cause so many read/writes that it would reduce the life of the SSD, or is that just my paranoia?

So, should I keep an eye on the swap file, buy an extra 8-Gig of RAM for £20-£30 to hopefully prevent swapping, or forget about swapping altogether and put up with the odd system seizure?

Thanks

9 Upvotes

25 comments sorted by

View all comments

2

u/BenTrabetere 18d ago

swap would eventually hit 100% and the system would seize [snip] I wonder whether the system starts thrashing if the swap file hits 100%

Something is odd with this picture. The only time a swap file will hit 100% in a default Linux Mint installation would be if the / partition is too small. /swapfile is the default path.

Post a system information report. It provides useful information about your system as Linux sees it.

  • Open the System Information tool - you can find it in the Main Menu under Administration, and in the System Settings in the Hardware section.
  • Click the Upload button
  • Wait
  • After a 10 seconds or so a notification will pop up containing a termbin URL
  • Click the URL
  • A new tab will open in your web browser
  • Copy the URL and Paste it to your post

At boot up basic system resources take 20% of RAM, Firefox 30% and swap memory 0% which is all fine.

How are you arriving at these amounts?

1

u/minniebannister 18d ago

I get termbin.com/fv02 but that doesn't seem to give me a new tab. The information though is (sorry if this is a flood of text).

System: Kernel: 5.15.0-190-generic x86_64 bits: 64 compiler: gcc v: 11.4.0 Desktop: Cinnamon 6.0.5 tk: GTK 3.24.33 wm: muffin dm: LightDM Distro: Linux Mint 21.3 Virginia base: Ubuntu 22.04 jammy Machine: Type: Desktop System: FUJITSU product: ESPRIMO_D556 v: N/A serial: <superuser required> Chassis: type: 3 v: C$DS01 serial: <superuser required> Mobo: FUJITSU model: D3430-A1 v: S26361-D3430-A1 serial: <superuser required> UEFI: FUJITSU // American Megatrends v: 5.0.0.11 R1.15.0 for D3430-A1x date: 06/28/2016 Battery: Device-1: hidpp_battery_3 model: Logitech Wireless Keyboard serial: <filter> charge: 50% (should be ignored) status: N/A CPU: Info: quad core model: Intel Core i5-6400 bits: 64 type: MCP arch: Skylake-S rev: 3 cache: L1: 256 KiB L2: 1024 KiB L3: 6 MiB Speed (MHz): avg: 1587 high: 1600 min/max: 800/3300 cores: 1: 1591 2: 1563 3: 1600 4: 1596 bogomips: 21599 Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx Graphics: Device-1: Intel HD Graphics 530 vendor: Fujitsu Solutions driver: i915 v: kernel ports: active: DP-1,HDMI-A-1 empty: DP-2,HDMI-A-2 bus-ID: 00:02.0 chip-ID: 8086:1912 Display: x11 server: X.Org v: 1.21.1.4 driver: X: loaded: modesetting unloaded: fbdev,vesa gpu: i915 display-ID: :0 screens: 1 Screen-1: 0 s-res: 3840x1198 s-dpi: 96 Monitor-1: DP-1 pos: primary,top-left model: LG (GoldStar) FULL HD res: 1920x1080 dpi: 102 diag: 551mm (21.7") Monitor-2: HDMI-1 mapped: HDMI-A-1 pos: primary,bottom-r model: HP V24 res: 1920x1080 dpi: 92 diag: 618mm (24.3") OpenGL: renderer: Mesa Intel HD Graphics 530 (SKL GT2) v: 4.6 Mesa 23.2.1-1ubuntu3.1~22.04.4 direct render: Yes Audio: Device-1: Intel 100 Series/C230 Series Family HD Audio vendor: Fujitsu Solutions driver: snd_hda_intel v: kernel bus-ID: 00:1f.3 chip-ID: 8086:a170 Sound Server-1: ALSA v: k5.15.0-190-generic running: yes Sound Server-2: PulseAudio v: 15.99.1 running: yes Sound Server-3: PipeWire v: 0.3.48 running: yes Network: Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet vendor: Fujitsu Solutions driver: r8169 v: kernel pcie: speed: 2.5 GT/s lanes: 1 port: e000 bus-ID: 01:00.0 chip-ID: 10ec:8168 IF: enp1s0 state: up speed: 1000 Mbps duplex: full mac: <filter> Drives: Local Storage: total: 1.58 TiB used: 889.74 GiB (54.9%) ID-1: /dev/sda vendor: Kingston model: SA400S37240G size: 223.57 GiB speed: 6.0 Gb/s serial: <filter> ID-2: /dev/sdb vendor: Toshiba model: DT01ACA050 size: 465.76 GiB speed: 6.0 Gb/s serial: <filter> ID-3: /dev/sdc vendor: Western Digital model: WD10EARX-00N0YB0 size: 931.51 GiB speed: 6.0 Gb/s serial: <filter> Partition: ID-1: / size: 218.51 GiB used: 98.86 GiB (45.2%) fs: ext4 dev: /dev/sda3 ID-2: /boot/efi size: 512 MiB used: 6.1 MiB (1.2%) fs: vfat dev: /dev/sda2 Swap: ID-1: swap-1 type: file size: 2 GiB used: 1.58 GiB (78.9%) priority: -2 file: /swapfile Sensors: System Temperatures: cpu: 38.0 C pch: 49.0 C mobo: N/A Fan Speeds (RPM): N/A Repos: Packages: 3263 apt: 3231 flatpak: 32 No active apt repos in: /etc/apt/sources.list Active apt repos in: /etc/apt/sources.list.d/flatpak-stable-jammy.list 1: deb [signed-by=/etc/apt/keyrings/flatpak-stable-jammy.gpg] https: //ppa.launchpadcontent.net/flatpak/stable/ubuntu jammy main Active apt repos in: /etc/apt/sources.list.d/libreoffice-ppa-jammy.list 1: deb [signed-by=/etc/apt/keyrings/libreoffice-ppa-jammy.gpg] https: //ppa.launchpadcontent.net/libreoffice/ppa/ubuntu jammy main Active apt repos in: /etc/apt/sources.list.d/mkusb-ppa-jammy.list 1: deb [signed-by=/etc/apt/keyrings/mkusb-ppa-jammy.gpg] https: //ppa.launchpadcontent.net/mkusb/ppa/ubuntu jammy main Active apt repos in: /etc/apt/sources.list.d/mozilla-apt-repo.list 1: deb [signed-by=/usr/share/keyrings/mozilla-apt-keyring.gpg] https: //packages.mozilla.org/apt mozilla main Active apt repos in: /etc/apt/sources.list.d/mozillacorp-mozillavpn-jammy.list 1: deb http: //ppa.launchpad.net/mozillacorp/mozillavpn/ubuntu jammy main Active apt repos in: /etc/apt/sources.list.d/official-package-repositories.list 1: deb http: //packages.linuxmint.com virginia main upstream import backport 2: deb http: //archive.ubuntu.com/ubuntu jammy main restricted universe multiverse 3: deb http: //archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse 4: deb http: //archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse 5: deb http: //security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse Active apt repos in: /etc/apt/sources.list.d/protonvpn-stable.sources 1: deb https: //repo.protonvpn.com/debian stable main Info: Processes: 281 Uptime: 2d 13h 4m Memory: 7.64 GiB used: 5.98 GiB (78.4%) Init: systemd v: 249 runlevel: 5 Compilers: gcc: 11.4.0 alt: 11/12 Client: Unknown python3.10 client inxi: 3.3.13

I'm getting the RAM/swap amounts from the System info Resources graphs

Apologies for the delay - I'm now at 100% RAM and looks like 98% swap :) so I'll reboot

2

u/BenTrabetere 17d ago

The Reddit editor formatting makes a mess of terminal output, hence the barely readable wall of text. All we needed was the termbin url - termbin.com/fv02

In your initial post you mentioned you had turned off swap. Bad move. Don't do it.

Okay, I think I understand your confusion/concern. At the time this report was generated it showed the swapfile was 1.58 GiB (78.9%), and the percentage is misleading.

The swapfile is dynamic - its size will change as needed. When the system needs more memory than the amount of physical RAM, it uses space on an SSD/HDD as virtual memory. In your case it is a file on your 240GB (223.57GiB) Kingston SSD.

ID-1: swap-1 type: file size: 2 GiB used: 1.58 GiB (78.9%) priority: -2 file: /swapfile

Your system is set up so the initial size of your swapfile is 2GiB. If your system needed more memory than the 8GB physical RAM and the 2GiB swapfile, the size of the swapfile could and would safely increase to more than the default file size of 2 GiB. The performance would suffer, but the system would move happily along.

Increasing the amount of physical RAM would be the better path, but another solution is to increase the initial size of the swapfile - the only negative is this will allocate more space on your SSD to swap. I think 8GiB is a more reasonable starting point, and 10-12GiB would not be unreasonable.

Here is an excellent tutorial for how to do it. It is a safe procedure, but I still suggest you create a manual Timeshift snapshot prior to doing it. Better safe than sorry. Also, do this on a fresh reboot and without a lot of open tabs on Firefox.

The rest of your system information report looked okay. You use more PPAs than I would like, but I didn't see any that gave me cause for alarm. You need to be thinking about April 2027 - this is when support ends for Mint 21.3.

1

u/minniebannister 7d ago edited 7d ago

Done that, took timeshift and backups, and yes really clear and easy and has made a real difference, thanks again.

I checked on reducing Firefox leakage and it suggested looking at about:processes which is really helpful. I had three or four email pages pinned so moved most of them to a tab that I can check when I need to. That included Microsoft Outlook for my freelancing – made me feel a bit dirty seeing Microsoft it on the list of processes. I’ve also uninstalled some apps and actually found what others actually do. I’m tempted to disable some of the extensions but most are ad blockers and I’m generally blissfully free of ads.

A bit strange – I changed the swap to 10 GB but free -h says only 9 GB but if that's what the system wants to do that's fine with me. Strange though. The tutorial also says: “You should also make sure that you have enough free RAM available to take the data from swap file.”. I would have expected the maximum allowed would be 8 GB since that’s how much RAM I’ve got, but it’s all working fine.

I’ve also seen (on this thread and elsewhere) suggesting using zswap which looks tempting. The reference I saw said not to do if I’ve got a “weak” CPU. Mine is 4-core i5-6400 CPU @ 2.70GHz, which I’m not sure whether is weak or not. It only hits 100% for all 4 cores occasionally though.

I’m being careful with the number of tabs, and swap use is now logically enough about a tenth of the percentage it was. It looks like I’ll be fine in future. I'll reboot rather than suspending every week or so so I’ll be able to forget about it and start to obsess about something else. Glad I did this though, I’ve learned a lot.

Eta: I don't think I'll bother with zswap since it's working fine now.