Score:1

System freezes when RAM limit reached, doesn't use swap

ru flag

I have a 16GB RAM system and whenever I hit the limit of RAM the whole system freezes even the mouse cursor starts to become jittery until it doesn't move at all. Keyboard, mouse, nothing. So I am forced to do a hard power-off which isn't probably good for the electronics. I've set up a 16GB swap which shows up properly in free -m and in top but it's always at 0 usage.

              total        used        free      shared  buff/cache   available
Mem:          15960        5823        3915         704        6220        9104
Swap:         16383           0       16383

Any ideas why my system doesn't want to use the swap to save me from a total crash?

More info:

$ grep -i swap /etc/fstab
/swapfile                                 none            swap    sw              0       0

$ sysctl vm.swappiness
vm.swappiness = 80

$ swapon -s
Filename                                Type            Size    Used    Priority
/swapfile                               file            16777212        0       -2

$ ls -al /swapfile
-rw------- 1 root root 17179869184 Jan 16  2021 /swapfile

Output of sudo lshw -C memory: https://pastebin.com/TGbjiLdm

I've played with the swappiness from 10 to 40 to 60 to 80 and it doesn't seem to make much difference.

Also, the system isn't hitting the limit very often. Only when I am editing very large video files with Kdenlive or running VirtualBox and things of that nature. I'm usually careful about it, but sometimes I accidentally hit that threshold of 16GB (with swap unused) and my system crashes.

us flag
It does use SWAP, but SWAP is very slow, and the system would freeze anyway. Try ZRAM instead. Since you have a lot of RAM, it would not freeze so easily with ZRAM (as per my experience).
ru flag
Oops, sorry @user535733 the copy-paste was off and the column headers were poorly aligned. Now it shows `used` is `0` in my post.
waltinator avatar
it flag
Read `man swapon` and, if swap is setup in `/etc/fstab`, `sudo swapon -a`.
oldfred avatar
cn flag
What are you doing to use 16GB? Although Linux caches closed apps in RAM as you may use it again. Linux ate my RAM! - memory use cache http://www.linuxatemyram.com/ Difference between Details screen on RAM and free command http://askubuntu.com/questions/743649/new-16gb-of-ram-installed-yet-i-see-15-3-on-my-system-why?noredirect=1#comment1106622_743649 & https://askubuntu.com/questions/184217/why-most-people-recommend-to-reduce-swappiness-to-10-20/184221#184221 Leave top or htop open in separate window to see what is trashing system.
heynnema avatar
ru flag
Edit your question and show me `grep -i swap /etc/fstab` and `sysctl vm.swappiness` and `swapon -s` and `sudo lshw -C memory`. Start comments to me with @heynnema or I'll miss them.
ru flag
@heynnema I added the output to your commands.
heynnema avatar
ru flag
Please see my initial answer. Report back.
Score:1
ru flag

SWAP

Edit /etc/fstab...

sudo -H gedit /etc/fstab

And edit this line to remove tabs, and use only spaces...

/swapfile                                 none            swap    sw              0       0

Reduce your /swapfile... it's way too big...

Note: Incorrect use of the rm and dd commands can cause data loss. Suggest copy/paste.

In the terminal...

sudo swapoff -a           # turn off swap
sudo rm -i /swapfile      # remove old /swapfile

sudo dd if=/dev/zero of=/swapfile bs=1M count=4096

sudo chmod 600 /swapfile  # set proper file protections
sudo mkswap /swapfile     # init /swapfile
sudo swapon /swapfile     # turn on swap
free -h                   # confirm 16G RAM and 4G swap

Edit /etc/fstab, using sudo -H gedit /etc/fstab or sudo pico /etc/fstab.

Confirm this /swapfile line in /etc/fstab... and confirm no other “swap” lines... use SPACES in this line... confirm NO TABS...

/swapfile  none  swap  sw  0  0

reboot                    # reboot and verify operation

Reset your vm.swappiness...

Edit /etc/sysctl.conf...

sudo -H gedit /etc/sysctl.conf

Find the line that contains vm.swappiness=80 and change it to =60.

Save the file.

sudo sysctl -p

BIOS

ThinkPenguin Snares https://www.thinkpenguin.com/gnu-linux/snares-penguin-gnu-linux-notebook

You have a very old BIOS version 1.03.06 dated 06/25/2014. Tell me the EXACT make/model of your computer or motherboard, and we'll check for a newer BIOS.

Update #1:

Let's check your file system...

  • boot to a Ubuntu Live DVD/USB in “Try Ubuntu” mode
  • open a terminal window by pressing Ctrl+Alt+T
  • type sudo fdisk -l
  • identify the /dev/sdXX device name for your "Linux Filesystem"
  • type sudo fsck -f /dev/sdXX, replacing sdXX with the number you found earlier
  • repeat the fsck command if there were errors
  • type reboot

Update #2:

Initial failure during dd command. Freeze at login screen. fsck fixed some errors. Swap is now working correctly. BIOS appears to be old, but current. Runs ok when booted to Ubuntu Live DVD/USB. Needs Ubuntu reinstall.

ru flag
I did the commands but got stuck on the dd line. It was hanging at the terminal. And after about a minute, the system was freezing up and now I can't move the mouse or even alt-tab. Even the clock is frozen on the status bar. Should I keep waiting?
heynnema avatar
ru flag
@thorie Did you copy/paste the `dd` line, or type it in manually?
ru flag
It was a copy paste. I did a hard reboot and it looks like it did about 70% of the file and then died.
heynnema avatar
ru flag
@thorie There may have been a leftover problem due to the swap line in /etc/fstab. You edited that first, correct? Start the procedure over again.
ru flag
I was able to do the steps from scratch again. But after rebooting, it goes to the Ubuntu login screen and I can't move the mouse or type anything. The system seems to be frozen.
heynnema avatar
ru flag
@thorie Do you remember the output of the last `free -h` in the procedure? It should have said 16G with a 4G swap. See Update #1 in my answer.
ru flag
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/128314/discussion-between-thorie-and-heynnema).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.