Script to pagein any used swap to prevent kernel crashes

rogerh

Guru
Joined
Apr 18, 2014
Messages
1,111
If you've got mirrored boot drives the risk of corrupted swap is greatly reduced. There would be no point in this script provided that a failed boot drive was immediately replaced. And, of course, if they both fail you have more problems than just swap.
 

LIGISTX

Guru
Joined
Apr 12, 2015
Messages
525
If you've got mirrored boot drives the risk of corrupted swap is greatly reduced. There would be no point in this script provided that a failed boot drive was immediately replaced. And, of course, if they both fail you have more problems than just swap.

Unfortunately I don’t have mirrored boot drives. Just a single SSD.


Sent from my iPhone using Tapatalk
 

Stux

MVP
Joined
Jun 2, 2016
Messages
4,367
If you've got mirrored boot drives the risk of corrupted swap is greatly reduced. There would be no point in this script provided that a failed boot drive was immediately replaced. And, of course, if they both fail you have more problems than just swap.

If your single boot disk fails... you're going down, whether you have swap or not. Chances of a lightly used SSD failing are much lower than any of the the spinning rust disks that make up your pool.
 

Jacopx

Patron
Joined
Feb 19, 2016
Messages
367
How can i read this data?

Code:
2018-10-05 13:44:14: Paging in 130728 KiBs on /dev/mirror/swap0.eli
2018-10-05 13:44:17: Paging in 131312 KiBs on /dev/mirror/swap1.eli
2018-10-05 13:44:20: Paging in 130368 KiBs on /dev/mirror/swap2.eli
2018-10-05 13:44:26: Paging in 130144 KiBs on /dev/mirror/swap3.eli
 

Stux

MVP
Joined
Jun 2, 2016
Messages
4,367
How can i read this data?

Code:
2018-10-05 13:44:14: Paging in 130728 KiBs on /dev/mirror/swap0.eli
2018-10-05 13:44:17: Paging in 131312 KiBs on /dev/mirror/swap1.eli
2018-10-05 13:44:20: Paging in 130368 KiBs on /dev/mirror/swap2.eli
2018-10-05 13:44:26: Paging in 130144 KiBs on /dev/mirror/swap3.eli

You were using half a gigabyte of swap.
 

Jacopx

Patron
Joined
Feb 19, 2016
Messages
367

psoni

Dabbler
Joined
Mar 5, 2019
Messages
13
I ran the script but getting the following output - swap still 96% used
Thoughts?

root@freenas:~ # ./page_in_swap.pl
2019-03-05 18:18:16: Paging in 2033856 KiBs on /dev/mirror/swap0.eli
swapoff: /dev/mirror/swap0.eli: Cannot allocate memory
swapon: /dev/mirror/swap0.eli: Device already in use
2019-03-05 18:18:16: Paging in 2031380 KiBs on /dev/mirror/swap1.eli
swapoff: /dev/mirror/swap1.eli: Cannot allocate memory
swapon: /dev/mirror/swap1.eli: Device already in use
2019-03-05 18:18:16: Paging in 1996544 KiBs on /dev/mirror/swap2.eli
swapoff: /dev/mirror/swap2.eli: Cannot allocate memory
swapon: /dev/mirror/swap2.eli: Device already in use
2019-03-05 18:18:16: Paging in 1996372 KiBs on /dev/mirror/swap3.eli
swapoff: /dev/mirror/swap3.eli: Cannot allocate memory
swapon: /dev/mirror/swap3.eli: Device already in use
root@freenas:~ #
 

Stux

MVP
Joined
Jun 2, 2016
Messages
4,367
I’m guessing you don’t have enough memory available to page in all the swap that is in use.

You should run the swapinfo command
 

psoni

Dabbler
Joined
Mar 5, 2019
Messages
13
Thanks. Here is the output of swapinfo

root@freenas:~ # swapinfo
Device 1K-blocks Used Avail Capacity
/dev/mirror/swap0.eli 2097152 2031680 65472 97%
/dev/mirror/swap1.eli 2097152 2029960 67192 97%
/dev/mirror/swap2.eli 2097152 1994824 102328 95%
/dev/mirror/swap3.eli 2097152 1994932 102220 95%
Total 8388608 8051396 337212 96%
root@freenas:~ #

and the output of top command
63 processes: 1 running, 62 sleeping
CPU: 1.0% user, 0.0% nice, 0.1% system, 0.1% interrupt, 98.8% idle
Mem: 154M Active, 1284M Inact, 8222M Laundry, 21G Wired, 535M Free
ARC: 15G Total, 2284M MFU, 11G MRU, 489K Anon, 198M Header, 1239M Other
12G Compressed, 31G Uncompressed, 2.65:1 Ratio
Swap: 8192M Total, 7863M Used, 329M Free, 95% Inuse
 

Chris Moore

Hall of Famer
Joined
May 2, 2015
Messages
10,080

Stux

MVP
Joined
Jun 2, 2016
Messages
4,367
You have an excessive amount of swap in use. You probably have a memory leak in a vm or something like that.
 

psoni

Dabbler
Joined
Mar 5, 2019
Messages
13
Information about system -

Motherboard make and model - manufacturer: ASRock ; product name: C2750D4I
CPU make and model - Intel(R) Atom(TM) CPU C2750 @ 2.40GHz
RAM quantity - 32703MB
Hard drives - 8 disks, raidz2-0 4TB WD drives
Hard disk controllers - Marvell technology group ltd. 88se9230 pcie sata 6gb/s controller
Network cards - 'Intel I210 Gigabit Network Connection'

We don't have any VMs running.

I added a tunable vfs.zfs.arc_free_target as described in https://www.ixsystems.com/community/threads/swap-with-9-10.42749/page-5
but it didn't change the usage

here's the output of top
Mem: 4496M Active, 3998M Inact, 1246M Laundry, 21G Wired, 462M Free
ARC: 17G Total, 6395M MFU, 9142M MRU, 235M Anon, 283M Header, 1255M Other
13G Compressed, 55G Uncompressed, 4.10:1 Ratio
Swap: 8192M Total, 8192M Used, K Free, 100% Inuse
 

Apollo

Wizard
Joined
Jun 13, 2013
Messages
1,450
Are you pre Freenas 11.2? If so, that would be the reason.
 

Hazimil

Contributor
Joined
May 26, 2014
Messages
172
Hi,

Been using the script for a while now and wondered if its still needed in FreeNAS v11.2-U2.1?

Cheers
Jonathan
 

Chris Moore

Hall of Famer
Joined
May 2, 2015
Messages
10,080
Been using the script for a while now and wondered if its still needed in FreeNAS v11.2-U2.1?
The reason for paging in swap was to prevent crashes and the cause of the crashes was corrected when they introduced mirrored swap space.
There may be other reasons for paging in the swap, but I think the main reason for it has been gone for a while now.
 
Top