Page 1 of 1

[Solved] Swap File issue

Posted: 30 Nov 2018 09:31
by xendistar
I am running SolydX, my PC has three hard disk in it SDA, SDB & SDC and their layout was as follows

sda1 fat32 /boot/efi
sda2 ext4 /
sda3 ext /home
sda4 swap


sdc1 ext4 /media/backup

I decided to move the swap file from sda to a new swap partition I made on sdb which was set up as sdb1 (made the swap file with gparted, 10gb same size as the one on sda) .

I turned swap off

I edited the fstab file and entered the new uuid for the swap file on sdb1 then turned swap back on again.

I can see the swap file is on and being used (below) and as I use the PC during the day I see the amount of swap usage increase.

Code: Select all

mit@andora:~$ free -m
              total        used        free      shared  buff/cache   available
Mem:           7687        4117         942         519        2626        2781
Swap:          9999           3        9996
Now since making the change every morning when I come down to my PC both my open web browsers will have crashed and swap is turned off (nothing is programmed to run in browsers overnight), I did not have this issue when swap was on sda4 I simply do sudo swapon -a in the morning and the swap file is back up and running.

I have had a look in my log but to be honest I am not sure what log to look at, I have looked on line but was unable to see anything obvious.

Can anybody advise please?

Re: Swap File issue

Posted: 30 Nov 2018 15:59
by ilu
Post the content of fstab and the result of sudo blkid. Just for checking. You never shutdown?

Not to derail your thread but I'm also having swap problems. Swap is on (and stays on) but more than about 1 gb is never used. Especially not when needed. Instead the system hard freezes if it runs out of memory. Very annoying. I can't find anything in syslog but I might use the wrong grep command. What ways are there to track swap operation and log swap failure? kurotsugi, maybe?

Re: Swap File issue

Posted: 30 Nov 2018 17:43
by xendistar
Hi ilu

Here is the details you requested (yes my pc runs 24/7)

Code: Select all

# <file system>	<mount point>	<type>	<options>	<dump>	<pass>
UUID=e18165a8-5c2c-44ca-b336-d4ac15c2f3c8	/	ext4	rw,errors=remount-ro	0	1
UUID=C7EC-1B9C	/boot/efi	vfat	defaults	0	0
UUID=3e207549-90af-4da4-806f-3afef5d1bb62	/home	ext4	rw,errors=remount-ro	0	2
#swap on sdb1 
UUID=b6c8b50c-bffe-464c-95b8-f7a34677f123	swap	swap	sw	0	0
#nas			/media/nas	nfs	users,rw,auto	0	3
#backup sdc
UUID=f22ea48d-db0a-42d0-8cb8-04c16630f2e5	/media/backup	ext4	rw,errors=remount-ro	0	4

Code: Select all

mit@andora:~$ sudo blkid
/dev/sda1: LABEL="EFI" UUID="C7EC-1B9C" TYPE="vfat" PARTUUID="e37ff1d8-d4a6-4ad0-892f-c53fdae86e44"
/dev/sda2: LABEL="SolydX EE 082018" UUID="e18165a8-5c2c-44ca-b336-d4ac15c2f3c8" TYPE="ext4" PARTUUID="818ff4fe-9350-4c4c-b94b-43922c32e9e4"
/dev/sda3: LABEL="Home" UUID="3e207549-90af-4da4-806f-3afef5d1bb62" TYPE="ext4" PARTUUID="bebddbe0-1eb3-4741-b944-5cb8e9dc1485"
/dev/sda4: UUID="f2c4ca8c-1ef1-48f3-8977-ee880128a579" TYPE="swap" PARTUUID="a92519e6-4450-422f-940c-668ffb5f6a1b"
/dev/sdc1: LABEL="Home-backup" UUID="f22ea48d-db0a-42d0-8cb8-04c16630f2e5" TYPE="ext4" PARTUUID="1549f232-01"
/dev/sdb1: UUID="b6c8b50c-bffe-464c-95b8-f7a34677f123" TYPE="swap" PARTUUID="635a79c3-01"
I also ran a check on the hard disk sdb

Code: Select all

mit@andora:~$ sudo -i dd if=/dev/sdb  bs=128k of=/dev/null
 3815520+1 records in
3815520+1 records out
500107862016 bytes (500 GB, 466 GiB) copied, 9005.03 s, 55.5 MB/s
I also grep-ed the /var/log for any instances of swap or sdb but the result did not give any indication of an "error unmounting swap" sort of thing.

I am going to close both browsers before I go to bed tonight and see what the result is tomorrow morning.

One thing I have noticed is that I don't seem to be using as much swap file as I have previously

Re: Swap File issue

Posted: 30 Nov 2018 17:57
by ilu
fstab and blkid look ok. I checked the UUID - that's a common point of error but you certainly double-checked that already. You could try to format /dev/sda4 as ext4. I don't think that will help but can't hurt ...
xendistar wrote:
30 Nov 2018 17:43
One thing I have noticed is that I don't seem to be using as much swap file as I have previously
Yeah me too. I already startpage'd for ways to log swap activity but without success. I'd really like to know how to do that. I did several stress tests by "overloading" RAM but swap usage (which I check with the xfce panel applet) never reacted until hard freeze (meaning I couldn't even get the F1 console to open). I have 12 gb swap, btw. Syslogs don't show anything except the ordinary until they are cut off by the freeze.

Re: Swap File issue

Posted: 30 Nov 2018 18:13
by xendistar
I normally have 7 tabs across two browser open at all times but during the day and can easily double that amount of open tabs and even edging into the high teens. Then I would start to find I was noticing the programs being offloaded to the swap file and a delay to reopen some tabs. I only moved the swap file as I had the spare disk in my PC think that it may speed things up slightly with the swap file on a different disk than that of the data. Yes the gain would of only been marginal but it was (or should have been) an easy option to try. Currently my PC has been running 5.5hrs and used around 600mb of swap

My PC normally gets rebooted around the 30 days mark or so unless I have a need to reboot but I will log the user off several time in that period to free up memory (I have 8gb and share a bit for graphics). I am looking at upping that to either 12gb or 16gb after new year which will hopefully alleviate swap file issues.

Re: Swap File issue

Posted: 01 Dec 2018 08:16
by kurotsugi
it's a "ghost" issue with several keywords. intel chips - pstate driver- swap - run out memory. the observed symptoms is that kworker suddenly request more resource. swap started to be used. then system freeze or you get a restart.

things to alleviate the issue :
- disable pstate driver
- tweak the kernel parameter
- change/decrease swappiness parameter
- upgrade the ram size
- use tweaked kernel such as liquorix
- regularly clean memory cache

last time the issue on my system was so severe so that I can only open 2 tabs on my browser. the issue gone after I upgraded my system to total 6gb ram. though, a user reported he still have the same issue even with 12gb ram. it seems that the issue related with the latest security patch which potentially decrease intel performance to 50%. I'm afraid I can't help much since the issue is not replicable on my system anymore.

Re: Swap File issue

Posted: 01 Dec 2018 09:00
by xendistar
Thanks for the pointers kurotsugi, I will try grep-ing those phrase and see if it pulls anything through.

Yesterday I reformated the swap file just encase there had been an issue and then re-mounted it with out issue. This morning I come to my PC to find that one browser had closed and the swap was off. Tries to manually start swap and it complained that it could not find the UUID. This turned out to be true as the UUID for sdb1 had changed, but the question is when did it change? Yes I can see that formatting the drive could force the drive to have a new UUID but if that was the case how was I able to turn swap on yesterday after the formatting it again, I did not change the UUID yesterday afternoon?

Maybe it is closer to Kurotugi suggestion, maybe I a ghost playing with my PC at night :shock:

Re: Swap File issue

Posted: 01 Dec 2018 09:36
by Arjen Balfoort
FYI: the live installer sets swappiness in /etc/sysctl.d/sysctl.conf:

Code: Select all


Re: Swap File issue

Posted: 01 Dec 2018 12:03
by xendistar
Hi Arjen

If I look at /etc/sysctl.d/ I only have the following (see attached)

The readme say to put any kernel variable into /etc/sysctl.conf

I checked both the /etc/sysctl.conf & /etc/sysctl.d/@99 - sysctl.conf and the code that you listed is not in either so do I add that to the /etc/sysctl.conf file?

Having said that the swap file seem to be getting a good work out this morning..........

Re: Swap File issue

Posted: 01 Dec 2018 17:03
by kurotsugi
you can put arjen's tweak into 99-sysctl.conf. this tweak is quite extreme (i.e: almost no swap usage. very few cache). it will have an slight impact on your system performance. if you want a mild tweak, you can start with the swappiness and dirty writeback centisecs values. try to use smaller value

Re: Swap File issue

Posted: 01 Dec 2018 17:19
by Arjen Balfoort
I had to look in the source's logic and saw that swapiness is only set for SDD drives or USB pen drives.

I wouldn't just copy the content of my file into yours. You have a different system. You could, however, try different settings for swappiness, starting with 10 (as kurotsugi commented just before me).

I found these helpful: ... management

Re: Swap File issue

Posted: 01 Dec 2018 20:38
by xendistar
Thanks for the updates Arjen and Kurotsugi, I watching how things progress, since restarting swap this morning it seems the system is using the swap file. I will see what happens overnight tonight, then decide on what is next tomorrow.

Re: Swap File issue

Posted: 03 Dec 2018 08:08
by xendistar
Right I have got to the bottom of this issue and it turns out that the issue was a script I had running in the background that was the cause of the issue.

Several month ago I spoke on here about a script that cleared down the memory cache and did a swapoff - swapon to clear the swap file as well. This script ran over night with the idea being was I had a nice fresh start for the morning. The issue was simply I had forgotten all about the script that ran and that script was still pointing to the old swap file location sda4, so it was shutting down the open swapfile and then unable to restart it as it was trying to restart the old swap file location. Updated the script and everything was still running this morning.

Thanks to all those who tried to help me resolve this issue, if anybody has a memory expansion module for the human brain I might be interested :o :shock: :o :shock:

Re: [Solved] Swap File issue

Posted: 03 Dec 2018 11:53
by ilu
@xendistar: lol :roll: and, sorry, I am looking for RAM modules myself. :)
vm.swappiness = 0 # Swap is disabled. In earlier versions, this meant that the kernel would swap only to avoid an out of memory condition, but in later versions this is achieved by setting to 1.
vm.swappiness = 1 # ... Minimum amount of swapping without disabling it entirely.
vm.swappiness = 10 # This value is sometimes recommended to improve performance when sufficient memory exists ...
vm.swappiness = 60 # The default value.
vm.swappiness = 100 # The kernel will swap aggressively.
@arjen and kurotsugi: In my case swappiness =1 doesn't avoid out of memory condition. 12 gb is not really low but my system sometimes needs more and then just hard freezes.
I'll try an increase to 10 and see whether that improves my situation. Should I increase any of the other parameters too?

Re: [Solved] Swap File issue

Posted: 04 Dec 2018 00:43
by kurotsugi
my preference for swappiness is zero. swap is generally slow so the system only use it for certain type of cache. in my experience having a large swap doesn't help much when kworker goes crazy. just as you said, even have 1 swappiness doesn't help much. the _theorically_ better way is actually having large swappiness. with large swappiness, more cache will moved into swap. hence, it will reduce the ram usage. though, with common HDD the performance will drop quite significance. when kworker goes crazy your system might still usable but your system's response is sluggish.

Re: [Solved] Swap File issue

Posted: 04 Dec 2018 06:13
by ilu
I don't think kworker goes crazy on my system. I don't have any Intel stuff either, AMD only. I just sometimes need LOTS of RAM. I tend to go crazy on browser windows and I'm tab hogging and I use some wine stuff that needs lots of RAM.Sluggish is ok but hard freezing is not.

Re: [Solved] Swap File issue

Posted: 04 Dec 2018 09:35
by kurotsugi
perhaps you should try zramswap :3
it works as ordinary swap with two differences.
1. it use ram instead of hdd. less performance cost compared to the old swap technology
2. it's compressed. the virtual space would be lot more compared to the actual size

the disadvantages would be :
1. albeit small, there's still performance cost.
2. you can't use it on small ram. you'll need somewhat decent ram size. though, 12 gb should be quite a lot. with that size I think you can safely allocate 1-4 gb as zramswap