You are not logged in.

#1 2013-06-23 10:10:49

djipey
Member
Registered: 2011-07-30
Posts: 156

[Swap] I swap too much

Hi,

I have been experimenting swap issues for about one month. I swap for no reason, while I still have free RAM memory, and while the parameter vm.swappiness = 1 in my /etc/sysctl.conf.

Have a look:

free -h                              
             total       used       free     shared    buffers     cached
Mem:          3,8G       3,5G       272M         0B       106M       2,2G
-/+ buffers/cache:       1,2G       2,5G
Swap:         2,7G        93M       2,6G

Do you have an idea about how to solve that ? I had not some months ago.


Sincerely

Last edited by djipey (2013-06-23 11:04:04)

Offline

#2 2013-06-23 10:28:31

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Swap] I swap too much

Do you need swap at all? Are you using hibernation?

Offline

#3 2013-06-23 10:57:25

djipey
Member
Registered: 2011-07-30
Posts: 156

Re: [Swap] I swap too much

Sometimes. Not often, but sometimes. And isn't it useful when you need a lot of memory, for example when you encode a video ?

Offline

#4 2013-06-23 11:01:02

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,621
Website

Re: [Swap] I swap too much

With 4 G of memory, you likely do not need a swap partition at all.  Also, plz edit your first post and use code tags around the output of the free command.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#5 2013-06-23 11:05:48

djipey
Member
Registered: 2011-07-30
Posts: 156

Re: [Swap] I swap too much

Yes, if I don't hibernate. But it's not facing the problem to remove my swap partition. It shouldn't be used like that, moreover it wasn't the case before.

Offline

#6 2013-06-23 11:10:07

cju
Member
Registered: 2013-06-23
Posts: 194

Re: [Swap] I swap too much

You could reduce the so-called swappiness: https://wiki.archlinux.org/index.php/Ma … Swappiness

Offline

#7 2013-06-23 11:17:46

djipey
Member
Registered: 2011-07-30
Posts: 156

Re: [Swap] I swap too much

Yes, as I said in my first post, this parameter is at 1 %.

Offline

#8 2013-06-23 11:59:52

cju
Member
Registered: 2013-06-23
Posts: 194

Re: [Swap] I swap too much

Sorry, kinda missed that. Anyway, does setting this parameter have any effekt on your swapping behavior at all? Any difference w/o?

Offline

#9 2013-06-23 13:32:21

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [Swap] I swap too much

There have been some recent changes with sysctl.conf in relation with systemd's sysctl.d.  Can you check to make sure that swappiness is actually what you want it to be set at? 

$ cat /proc/sys/vm/swappiness 

Offline

#10 2013-06-24 08:40:40

djipey
Member
Registered: 2011-07-30
Posts: 156

Re: [Swap] I swap too much

Yep:

cat /proc/sys/vm/swappiness 
1

Is there a chance the recent grub configuration modification affects my swap ?

I had this:

/etc/default/grub

GRUB_CMDLINE_LINUX="pcie_aspm=force i915.i915_enable_rc6=1 nmi_watchdog=0"

Now the file is saved (pacsave), and there is no options nomore.

And I also had in my /boot/grub/grub.cfg:

   echo   'Chargement de Linux core repo kernel…'
   linux   /boot/vmlinuz-linux root=UUID=2745938a-fdf9-447b-866f-f3de5518aed5 ro pcie_aspm=force i915.i915_enable_rc6=1 nmi_watchdog=0 splash
   echo   'Chargement du disque mémoire initial…'
   initrd   /boot/initramfs-linux-fallback.img

The options have also been removed. Anyway, I'm testing right now with the swapinness parameter set to 80 %. I'll let you know if there is any change.

Last edited by djipey (2013-06-24 09:05:55)

Offline

#11 2013-06-24 11:45:33

fledermann
Member
From: Bielefeld, Germany
Registered: 2013-06-24
Posts: 49

Re: [Swap] I swap too much

You could also try turning the swap off and on again (swapoff -a && swapon -a). It should be empty after that.
Then you can observe if it starts to fill up again.

Offline

#12 2013-06-24 15:15:02

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [Swap] I swap too much

I think you should try not using swap for a bit and see if your machine freaks out.  I have been running swapless for quite some time.  Now I have 8GB of RAM, but before I had a MacBook 2,1 with 4GB installed and 3GB recognized.  I never needed swap then for my machine to function properly.

[offtopic]
Also, this hasn't anything to do with your issue, but I want to point out some things about your kernel command line.  First of all, we have all this talk about sysctl.conf and sysctl.d, and it is apparent you know hot to use it, yet you instead use "nmi_watchdog=0" in your kernel command line.  In sysctl.conf just put "nmi.watchdog=0". 

Then there is the pcie_aspm=force.   Do you need this?  I see so many users who have just put this on their kernel command line because they don't really know or understand.  So have you checked the state of /sys/module/pcie_aspm/parameters/policy and is it "default [performance] powersave"?  If it is either default or powersave (square brackets not around performance), it parameter is not necessary, and has the potential to cause mild instability.

The one that really bothers me is that I see recommendations everywhere that people use i915.i915_enable_rc6=1.  Haveing the rc6 sleep state is a good thing.  But there are actually three levels of rc6 sleep states.  There is rc6, rc6p, and rc6pp. By using a value of '1', you are effectively ensuring that rc6 is active while deactivating rc6p and rc6pp.  A simple look at the 'modinfo' output of i915 will show you that by default the rc6 and rc6p levels are turned on.  So if you want to potentially save more power, either remove this line, or use a '7' to activate all three sleep states.  Though I have seen reports from some that this can actually end up using slightly more power in older hardware because it takes it that much longer to get from the rc6pp to an active state, but I can neither confirm nor deny this.

Oh and BTW, instead of using the kerel command line for that i915 parameter, I find it much more sane to use /etc/modprobe.d to adjust kernel module options.  But to me this is just person preference, as I don't like to have a kernel command line that is too long.  If you want to use this, see modprobe.d(5).
[/offtopic]

Offline

#13 2013-06-24 16:15:11

djipey
Member
Registered: 2011-07-30
Posts: 156

Re: [Swap] I swap too much

Ok, for my main issue, I still swap, with the swapiness parameter set to 80 %. But it seems it swaps less than before, though I can't really say if it's due to the kernel modifications.

[offtopic]
Ok, I should put nmi_watchdog in the sysctl.conf file, but why not in the grub files ? I have no idea why I put it here a while ago. For instance, how do you know it is preferable to put the i915 parameter in a modprobe file, and not in a grub file or the  sysctl.conf ?

For the pcie_aspm=force parameter, I shouldn't need it, I checked /sys/module/pcie_aspm/parameters/policy.

For the i915 parameter, I will look around more deeply.

The thing is, I use the scripts powerdown  and powerup (in the AUR repository), to handle the power saving, and by looking at the scripts, nmi_watchdog is set to 0 when the laptop in on battery, and to 1 when on AC.

And the parameter pcie_aspm is set to powersave on battery, and to default when on AC.

Last thing, the i915 parameter is set to 1 on battery, and to 0 on AC. So if what you say is right, shall I mail the guy who maintains this script to advise '7' instead of 1 ?
[/offtopic]

Offline

#14 2013-06-24 17:37:15

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [Swap] I swap too much

Still, swapping is usually an indication that you need more RAM, as it is running out.  So in your case in which it is obvious that you are not running out of RAM, I think you should do a "swapoff -a" just to see if your system starts to hang or starts OOM killing things even when the RAM is not full.

[offtopic]
I don't necessarily think that there is a "correct" way between the kernel command line and sysctl.{conf,d}.  I just try to configure things with the native tools of my system, since they are going to be running anyway.  I think for me, it just serves as a way of learning about those tools.  Using the kernel command line will actually produce the same end result, I just like to keep in under control.  As an example, it is possible to actually fully disable udev and specify every module to be loaded on the kernel command line, but that just seems silly since there are other ways to go about it.  Udev has become pretty central to our systems in terms of harware initialization, and it works pretty well, so why not use it?  And even if you have a reason not to use it, it would just make more sense to create a list of necessary modules and put them in /etc/modules-load.d wouldn't it?  Thats just my two cents.

If you are using a script to change power parameters between AC and battery power, then none of those parameters are going to do anything anyway since the script is just going to handle things itself anyway.  I used to use a script to change parameters on my system, but honestly, with the power of today's machines, I really see no reason to enforce inefficient policies when using AC.  I think of it in terms of the usability of the hardware between the two options.  Can you really tell a difference between the perfrmance of the computer when you have it plugged in vs. not plugged in?  I couldn't, and I would imagine that most people won't be able to apart from the possibility of benchmarks and certain special cases (like real-time audio uses).

So what I have done is I just used powertop (and various things I found about the interwebs) to configure my laptop to be more power friendly.  They are set to those parameters by a combination of tmpfiles.d, udev/rules.d, and sysctl.d, and they do not change.  Alternatively, you could just redirect values into the /sys and /proc files, and these parameters can be found by using powertop's ability to generate an html report (see the powertop man page).  But again, by doing it with the tools that were on my system, I was able to learn how to use sysctl, tmpfiles, and how to write basic udev rules.

I believe I have told taylorchu before about the incorrect rc6 setting in his 3x battery life thread (powerdown is taylorchu's script, right?), but apparently it was never changed.  Just take a look at the modinfo of i915.  rc6 has a 1 value, rc6p has a 2 value, and rc6pp has a value of 4.  So if you want all three, you add those up and get 7.  It is not imperative that you make this change, but if it were me and I was trying to implement power saving, I would want the potential for the greatest level of power saving that I could.  I think that it is just a common misconception that rc6 should be a 1, because that is what ubuntu does.  Though I feel like this is just a rememant of when rc6 was in its infancy and both didn't have the deeper sleep states and didn't necessarily turn it on by default on all hardware.
[/offtopic]

Offline

#15 2013-06-24 19:38:26

djipey
Member
Registered: 2011-07-30
Posts: 156

Re: [Swap] I swap too much

I'll do it, but I have no clue about my swap usage.

[offtopic]
I tried to put nmi.watchdog=0 in my sysctl.conf file, and it had no effect. It worked only in my grub.cfg conf ! And I really need to set this parameter to 0, for another reason, because it crashes virtualBox if it is set to 1. Is it normal it does not work in sysctl ?

For the rest, I removed the 2 previous options of my grub.conf, as I don't need it by default. They will be activated anyway when I will be on battery. And I think you're right about i915, I set it to 7 in the powerdown script.
[/offtopic]

Well, I still have my swap problem.

Offline

#16 2013-06-24 20:53:52

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [Swap] I swap too much

When you say you still have your swap problem, did you try turning it off and seeing if the system starts OOM killing things?  You mention that you use VirtualBox, what kind of memory allotment do you allow the virtualmachine(s) to have?  This could be a very good reason why it might be swapping so much.  I'm not sure if virtualbox has the ability to share pages like other virtualization solutions can.  I have seen that virtualbox has memory ballooning capabilities though.  Here is the docs on how to set it up: http://www.virtualbox.org/manual/ch09.html#vboxwatchdog .

But then again, this is going off of just a brief mention of the use of vitualbox.  If you are running a non-linux VM, then the shared memory pages is something that is not going to help you anyway.  But the ballooning might.

[offtopic]
Yeah, sorry abou that.  It was a typo.  The correct parameter is "kernel.watchdog=0".  You say though that the powerdown script turns this functionality on and off with the power source, so how do you handle that?  Do you simply make the changes to the powerdown scripts?

I also see that you commented in taylorchu's powerdown thread.  We'll see what he says about that.  He typically seems to be pretty open to suggestions and contructive criticism... unless you tell him that he is abusing udev rules.  But the powerdown script is a pretty legit use case I think.
[/offtopic]

Offline

#17 2013-06-24 21:08:12

djipey
Member
Registered: 2011-07-30
Posts: 156

Re: [Swap] I swap too much

Nonono, I use sometimes virtualBox, not always. The swap problem does not come from it. It's just that a few months ago, when I bought my laptop, I experimented crashes with virtualBox. It turned out that the parameter nmi_watchdog HAD to be set to 0, otherwise VB crashes. It's still the case today.

[offtopic]
Yes, the scripts turn the functionality on and off. But they are bash scripts, so you can basically comment/uncomment as you want. I don't use all the parameters. For instance, if I use the powersave mode of my wireless card, I encounter too  many problems with my connection. Same thing for the webcam module, I want it always loaded.
[/offtopic]

Offline

#18 2013-06-24 21:22:40

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [Swap] I swap too much

Hmmm... kidna out of ideas.  I would still recommend seeing running with your swap off leads to OOM killings (out of memory).  If so, then there is something that is definitely agressively using your memory, and you would need to figure out what it is.  If there are no adverse effects, then I really have no idea why it is not respecting your swappiness.  Can you set it to zero and see if it still swaps?  I'm not saying that you need to change these configurations permanently or run without swap forever, but just do it as a (hopefully) diagnostic procedure.

Offline

#19 2013-06-30 00:23:16

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,144

Re: [Swap] I swap too much

Just out of interest, is the use of swap causing any issues? I ask because I have 8G of ram but I occasionally find the system uses a small amount of swap. However, I only know this because I have seen it with free. It isn't because I have noticed any performance issues. (Sometimes things slow down for one reason or another but it does not seem related to the use of swap.) So I just let the system get on with it. Also, Linux seems to handle swap differently than I am used to and the amount of swap in use actually can decrease without rebooting. This is kind of neat - I'm used to swap only increasing unless the system is rebooted. (On my previous laptop, I used swap quite heavily because ram was maxed out and the system really wanted more.)

This will be no surprise to WonderWoofy (hi, WonderWoofy smile) but I quite like using the command line parameters although I suspect that WonderWoofy is correct and that I should just not use some of them. The thing about the command line parameters is that they are dead easy to adjust at boot and that you can create different boot entries using different parameters. So I don't use them for recovery entries, for example, just in case they cause issues.

The point I find most worrying about this thread, though, is that you are apparently ignoring .pacsave files. This may not be a problem on this occasion but it is very bad practice and it will break stuff sooner or later (probably sooner). If you do not know how to deal with .pacsave and .pacnew files, see the wiki.

Last edited by cfr (2013-06-30 00:25:05)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#20 2013-06-30 08:04:30

djipey
Member
Registered: 2011-07-30
Posts: 156

Re: [Swap] I swap too much

I think I know how to deal with them. But I'm very careful when I move to a pacnew file, because it can break a system which was working. That's also the occasion to check if old parameters are still up to date.

But I don't encounter any performances issues, it's just that my laptop swaps when it should not. I'm going to try to unmount my swap partition as suggested to see if it kills something in memory, and I'll let you know.

Offline

#21 2013-06-30 08:09:42

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [Swap] I swap too much

I think that not merging pacnew files is probably more hazardous than being so careful about moving pacnew files that you don't do it.  Improperly configured software can definitely make software behave erratically.  Though I am not sure that they would cause this odd swapping.

Offline

#22 2013-06-30 08:53:20

djipey
Member
Registered: 2011-07-30
Posts: 156

Re: [Swap] I swap too much

Indeed, I had a lot of pacnew files on my system, unmerged. I fixed that, I hope I won't break anything. Thanks for that, I learnt something new today smile

Offline

#23 2013-06-30 09:24:12

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [Swap] I swap too much

Maybe useful, to see who uses swap:

sed -n '/^Name:/{s/Name:\s*//;h};/^Pid:/{s/Pid:\s*/(/;s/$/)/;H};/^VmSwap:/{s/VmSwap:\s*//;G;s/\n/\t/;s/\n/ /;p}' /proc/[0-9]*/status | sort -h

Offline

#24 2013-06-30 13:56:27

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,144

Re: [Swap] I swap too much

Note that in this case pacsave files were the issue rather than pacnew files.

Not dealing with these files is guaranteed to break your system sooner or later. Ignoring them is really not an option if you want stuff to work.


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#25 2013-07-13 08:48:27

djipey
Member
Registered: 2011-07-30
Posts: 156

Re: [Swap] I swap too much

I tried to wait a bit after I made the changes with the pacsave files, but I stil swap !! When I unmount the swap partition, it seems nothing happens. I tried the command line you recommended @Procyon:

sed -n '/^Name:/{s/Name:\s*//;h};/^Pid:/{s/Pid:\s*/(/;s/$/)/;H};/^VmSwap:/{s/VmSwap:\s*//;G;s/\n/\t/;s/\n/ /;p}' /proc/[0-9]*/status | sort -h
0 kB	anacron (11021)
0 kB	conky (25323)
0 kB	firefox (28113)
0 kB	gconfd-2 (30044)
0 kB	gnome-pty-helpe (28014)
0 kB	gnome-terminal- (28011)
0 kB	gvfsd-http (28325)
0 kB	sed (28454)
0 kB	sort (28455)
0 kB	zsh (28015)
12 kB	gvfsd-trash (30208)
36 kB	uptimed (328)
48 kB	vnstatd (314)
72 kB	dbus-daemon (1995)
88 kB	deluge-gtk (25861)
108 kB	agetty (329)
120 kB	atd (319)
140 kB	dhcpcd (2537)
156 kB	dbus-daemon (316)
168 kB	dbus-daemon (1772)
168 kB	dconf-service (3225)
180 kB	xcompmgr (1853)
220 kB	systemd-journal (122)
228 kB	bumblebeed (322)
228 kB	dbus-daemon (1769)
248 kB	dbus-launch (1757)
272 kB	systemd-logind (318)
288 kB	gvfsd (2023)
396 kB	at-spi-bus-laun (1985)
396 kB	sh (1861)
396 kB	stickynotes (1854)
408 kB	gnome-keyring-d (3076)
420 kB	hddtemp (305)
440 kB	wpa_supplicant (1340)
444 kB	ntpd (483)
472 kB	crond (311)
488 kB	gvfsd-fuse (2038)
504 kB	udisksd (7344)
544 kB	at-spi2-registr (2002)
544 kB	deluged (25882)
548 kB	preload (307)
576 kB	gnome-keyring-d (1692)
612 kB	conky (6609)
712 kB	gvfsd-metadata (3234)
712 kB	gvfs-udisks2-vo (7342)
712 kB	systemd-udevd (137)
832 kB	conky (6607)
840 kB	conky (6611)
852 kB	ModemManager (1410)
856 kB	tint2 (1852)
880 kB	evolution-alarm (3245)
912 kB	gnome-keyring-d (1725)
976 kB	geoclue-master (2055)
996 kB	synapse (7338)
1084 kB	NetworkManager (308)
1120 kB	openbox (1694)
1124 kB	upowerd (2039)
1188 kB	syslog-ng (312)
1332 kB	systemd (1)
1416 kB	polkit-gnome-au (1951)
1760 kB	nm-applet (1950)
1812 kB	redshiftgui (1856)
2380 kB	slim (330)
2668 kB	X (407)
3072 kB	evolution-calen (3251)
3288 kB	evolution-sourc (3229)
4024 kB	python2 (1874)
4108 kB	goa-daemon (3238)
4484 kB	notify-osd (2107)
7012 kB	conky (6605)
7320 kB	batti (1855)
8136 kB	polkitd (370)
12864 kB	evolution (3201)

Offline

Board footer

Powered by FluxBB