Swap not working properly - tuning required?

Have a system with 8 GB RAM and 8 GB swap space - the system uses swap quite a lot (because it has an instance of Chromium running with 100s of tabs + a few other programs)

Now the peculiar issue being faced is this : after running for a while, the new tabs/applications probably make the swap space go full.
After this the issue starts - Swap remains full after a couple of hours of use DESPITE RAM being available ...... tabs/apps start crashing (seems like due to swap being full) - Is there a way to make swap discard files it's holding so that new tabs/windows/applications don't crash every few minutes?

What is the solution ? Swap tuning? Something else?

Note : the RAM still has a few gigs sometimes, but the swap just doesn't empty out and remains (almost) full.
 
What version of FreeBSD?
What filesystem, UFS/ZFS?

See this thread, post #5
 
What version of FreeBSD?
What filesystem, UFS/ZFS?
13.1, ZFS

Seems like that thread says it's not such a bad thing - but for me it's bad because tabs just randomly keep crashing. I somehow need to empty out swap - not sure how, or if swap can be tuned for such behaviour?
 
You say 100s of tabs open. I'd guess that non-active tabs are considered idle processes so wind up in swap. I'd guess that forcefully emptying swap really isn't going to do what you think it will do.

What happens to swap, overall memory usage if you close chromium (bookmark all your tabs first I guess) and any other applications and then just walk away for a bit?

A typical way of clearing swap is the swapoff command but that has a bunch of implications like the data needs to go somewhere. You can also try adding more swap: external USB device, partition it for swap, plug it in and then use the swapon command. See what happens then.
 
You say 100s of tabs open. I'd guess that non-active tabs are considered idle processes so wind up in swap.
Is there some way to check which tabs/processes are in swap ? (and perhaps do something with them)
What happens to swap, overall memory usage if you close chromium (bookmark all your tabs first I guess) and any other applications and then just walk away for a bit?
I actually tried to kill the parent process of chromium using `pkill -P` - the result was that the RAM cleared up a bit but swap barely cleared, if at all it did - not enough for this problem to persist anyways.
You can also try adding more swap: external USB device, partition it for swap, plug it in and then use the swapon command. See what happens then.
USB might be slower - current disk is SSD, I'm afraid it might lead to worse user experience.
 
sysctl -d vm.overcommit

vm.overcommit: Configure virtual memory overcommit behavior. See tuning(7) for details.
 
sysctl -d vm.overcommit

vm.overcommit: Configure virtual memory overcommit behavior. See tuning(7) for details.

sysctl vm.swap_reserved
vm.swap_reserved: 77244533780480
sysctl vm.overcommit
vm.overcommit: 0

What should I change it to?
 
Overcommit won't change anything here, we have actual commits hit swapspace. Overcommitted memory just sits there doing nothing.

It sounds like what you want is a tuning parameter to reduce free memory held in reserve in favor of emptying swapspace. The far superior thing to do would be adding more swapspace.

If you want to play with them, here are the parameters controlling the free page reserve:
Code:
vm.v_free_min: 50732
vm.v_free_target: 171326
vm.v_free_reserved: 10534
vm.v_pageout_free_min: 34

Also be aware that you can kill the processes in Chrome backing a tab without losing the tab. Use the internal task manager, or just kill the biggest things in top(1) (usually facebook tabs).
 
overcommit will allow programs to reserve address space instead of memory and bomb when trying to access it
so i posted in relation to programs crashing not swap usage
 
overcommit will allow programs to reserve address space instead of memory and bomb when trying to access it
so i posted in relation to programs crashing not swap usage
Ah, OK. But I bet that Chrome is overcommitting so much that it is impractical to run it without it. Especially with a total of 16 GB physical memory.
 
If you want to play with them, here are the parameters controlling the free page reserve:
Code:
vm.v_free_min: 50732
vm.v_free_target: 171326
vm.v_free_reserved: 10534
vm.v_pageout_free_min: 34
Here are my values below - should I change them to what you wrote?
vm.v_free_min: 12304
vm.v_free_target: 41434
vm.v_free_reserved: 2594
vm.v_free_target: 41434

Also be aware that you can kill the processes in Chrome backing a tab without losing the tab. Use the internal task manager, or just kill the biggest things in top(1) (usually facebook tabs).
Have above 1k tabs - usually I kill the tabs from htop or the parent process of Chromium with pkill -P - but the swap not emptying is the main issue I think.
overcommit will allow programs to reserve address space instead of memory and bomb when trying to access it
so i posted in relation to programs crashing not swap usage
If you think this will work - what value should I set it to?
 
Here are my values below - should I change them to what you wrote?
vm.v_free_min: 12304
vm.v_free_target: 41434
vm.v_free_reserved: 2594
vm.v_free_target: 41434


Have above 1k tabs - usually I kill the tabs from htop or the parent process of Chromium with pkill -P - but the swap not emptying is the main issue I think.

If you think this will work - what value should I set it to?

No, you want to reduce those numbers even further. Mine are from a lightly loaded system with 16 GB.

It is a little odd that killing tabs does not free up paging space. Wondering why that is.

I think you need more swap space.
 
It is a little odd that killing tabs does not free up paging space. Wondering why that is.
The last time I killed Chromium process with pkill -P pid - it only freed up ~100MB from Swap Space from the 8 GB
No, you want to reduce those numbers even further. Mine are from a lightly loaded system with 16 GB.
Any idea how much I should reduce it to - or just play around with numbers and observe if it has an effect on swap acting correctly?
I think you need more swap space.
Yes, option of last resort perhaps - maybe I could increase swap space and resize partition - but too cumbersome.
Wait, why do you say you have ZFS in your swap partition? Are you paging into a vnode file on a ZFS filesystem?
Sorry, nothing fancy - I just meant i'm using a zfs based filesystem with geli encryption and swap encrypted option that is presented during installation.
 
The last time I killed Chromium process with pkill -P pid - it only freed up ~100MB from Swap Space from the 8 GB

Well, I'm not talking about the Chromium master process (the top level one). That one uses relatively little memory, not to mention you don't preserve tabs when killing it. I am more interested in selectively getting rid processes driving fat tabs.
 
overcommit will allow programs to reserve address space instead of memory and bomb when trying to access it
so i posted in relation to programs crashing not swap usage
Oops. I actually tried to set overcommit value to 1 - now crashed tabs won't even load!

Trying to set it to 0 again gives an error - saying "bash: fork: cannot allocate memory"

What do I do to fix it? Sigh
 
Oops. I actually tried to set overcommit value to 1 - now crashed tabs won't even load!

Trying to set it to 0 again gives an error - saying "bash: fork: cannot allocate memory"

What do I do to fix it? Sigh

It is trying to overcommit too much, and bash probably, too. You are probably screwed until a reboot.
 
Actually after making overcommit= 1 ..... no process is even able to start now, only can close processes .Is there any way to salvage the situation?

Have a few tabs id like to save that are in incognito mode.
It is trying to overcommit too much, and bash probably, too. You are probably screwed until a reboot.
 
Fwiw I can still see RAM being occupied only 2.5 GB of 8 GB.

Even closed a couple of programs that made some swap available (about 7gb occupied now instead of 8 gb earlier) - but somehow unable to open any new application/terminal :/
 
Actually after making overcommit= 1 ..... no process is even able to start now, only can close processes .Is there any way to salvage the situation?

Have a few tabs id like to save that are in incognito mode.

Try /bin/sh, maybe it overcommits less than bash. Incognito tabs will be hard to salvage.

Fwiw I can still see RAM being occupied only 2.5 GB of 8 GB.

Even closed a couple of programs that made some swap available (about 7gb occupied now instead of 8 gb earlier) - but somehow unable to open any new application/terminal :/

Yeah, pretty much all programs try to overcommit too much. Because the malloc(2) implementations do that.
 
Back
Top