why is my machine swapping?

Story: Kernel Log: Linux 3.3 goes into testingTotal Replies: 21
Author Content
mbaehrlxer

Jan 22, 2012
1:42 PM EDT
"linux ate my ram" is curious. i was never bothered by that. instead i am troubled by something else:

occasionally a machine goes into a frenzy of disk activity bringing the machine almost to a halt and i can never figure out what is going on. it can't just be swapping because i don't have any active swap space. so what is it then? does chromium do its own swapping internally? does the linux kernel "swap" out libraries and executables? (since the programs and libs live on disk, presumably the pages they occupy in memory could just be removed if the programs in question are not active)

so where can i find that "linuxswapstomuch.org" website? :-)

greetings, eMBee.
cr

Jan 22, 2012
3:14 PM EDT
Dunno about your setup, but some of mine (the old RedHats) do makewhatis nightly a little after 4am. There's other stuff in the various cron areas, but that one causes a flurry of disk activity. On one Mepis box, that happens after 6am; on another, it's 10am. Check /etc/crontab to see when housekeeping is scheduled on your machine; does the frenzy of disk activity happen right about then?
Koriel

Jan 22, 2012
3:46 PM EDT
As CR says a lot of stuff is run by cron on a daily basis by most distros such as mlocate, makewhatis their is a reasonable chance it might be those causing the disk to go like the clappers.
gus3

Jan 22, 2012
7:24 PM EDT
It may or may not be "swapping" as we understand the term. It may also be over-buffering disk writes. This was a known problem in a recent 2.6.something kernel, supposedly fixed by 3.0.

My first suggestion would be to remount everything with the "sync" option, so that no writes get buffered. It will slow the machine down, but if over-buffering is the issue, you should see no more total system stalls.

If you do see more total stalling, then over-buffering isn't the problem.
cr

Jan 22, 2012
8:41 PM EDT
One other thing to check, if you've got a LAN, is network activity. Etherape is my tool of choice for this: I leave it up on one virtual-desktop 24/7 on a machine that's on the same hubbed segment as the gateway, so I can see who in my house is hogging DSL bandwidth and for what. In your case, it could reveal something as innocuous as apt pulling in fresh package lists from the repos, or as pernicious as somebody getting into your WAP and nosing around where they shouldn't. Or something you set up and then forgot; my nightly rsync sure lights up the network here when it starts backing up machines outside the office switch, and that causes a lot of disk activity too.
mbaehrlxer

Jan 23, 2012
8:16 AM EDT
gus3: that is interesting. i did not hear about over-buffering before, it's worth checking out.

i don't think it is any background stuff as it does happen mostly when i do overload the machine by having to many tabs open in the browser or running to many programs. when that happens i expect the kernel to start killing processes or i wish the browser would just tell me: "sorry, not enough memory to open more tabs" or something like that.

one may argue that killing processes is not nice, but locking up the machine usually costs me more time than having to restart a program.

greetings, eMBee.
cr

Jan 23, 2012
9:00 AM EDT
Is it too late to suggest that you throw some swap in there? That way you get a gradual slowdown as your warning that you're pushing the machine's resources. If not a swap partition, then a swap file.

https://help.ubuntu.com/community/SwapFaq has instructions if you need it. Slightly more in depth: http://www.xenotime.net/linux/doc/swap-mini-howto.txt
mbaehrlxer

Jan 23, 2012
11:41 AM EDT
well, if the answer is that swap prevents this problem then yes,, but i was actually hoping to prevent it by not having swap. the machines have plenty of ram. except for the OLPC XO, but that one also doesn't have enough diskspace to add swap. sofor that one i'd need another solution.

greetings, eMBee.
JaseP

Jan 23, 2012
12:10 PM EDT
You are aware that you can adjust the swappiness setting, correct?!?! Most distros set it to between 60 and 100, which is fine for a server,... But you can set it to 10 or even as low as 5, with little ill effect. Setting it lower with a small swap partition is preferable to not having swap at all. Some programs will crash if there is no swap available. Just Google for Linux and swappiness.

Or, look here: http://en.wikipedia.org/wiki/Swappiness
mbaehrlxer

Jan 23, 2012
2:09 PM EDT
oh if they only would crash, that at least i'd understand :-)

i remember having read about swappiness,but as i have swap off i didn't keep it in mind. so thanks, i'll try that too.

greetings, eMBee.
Steven_Rosenber

Jan 23, 2012
5:19 PM EDT
I dramatically lowered swappiness on my machine when I had this problem. That solved it.
Khamul

Jan 23, 2012
8:45 PM EDT
Why on Earth does Ubuntu set the default to 60 anyway? It's not like it's normally used for servers.
gus3

Jan 23, 2012
9:46 PM EDT
60 is (or was) the default in the kernel. Ubuntu didn't change anything.
Khamul

Jan 23, 2012
10:16 PM EDT
Still doesn't quite answer the question. The kernel sets a default because the kernel can be used for all kinds of things: servers, workstations, etc. Distros are supposed to change defaults when they can get better performance or functionality for specific uses where they specialize. Ubuntu is a desktop distro, not a server distro (they also have a server distro, but I believe that's a separate download). So are they just too dumb or lazy to set a single parameter that makes this big a difference in interactive applications? They sure don't have any trouble wasting tons of resources on a dumbed-down UI for tablets.
gus3

Jan 23, 2012
11:38 PM EDT
First, you criticize them for changing it, then you criticize them for not changing it?
Khamul

Jan 24, 2012
12:28 AM EDT
@gus3: When did I criticize Ubuntu for changing the swappiness setting?
visionofarun

Jan 24, 2012
1:01 AM EDT
Have a look at http://pthreads.blogspot.com/2011/12/swappiness-and-dropcach...
gus3

Jan 24, 2012
9:33 AM EDT
Khamul, at 12:45 AM UTC.

"Why on Earth does Ubuntu set the default..."
Steven_Rosenber

Jan 24, 2012
12:16 PM EDT
When I decreased my swappiness, I don't think it was in response to an actual performance issue. I had just arrived back in Linux from a long time running OpenBSD on the same hardware. OpenBSD never swapped on this configuration, and Linux did.

But it was all a bunch of numbers -- me looking at the output of top and htop.

I bet the machine performed the same on my Linux desktop tasks no matter what the swappiness was set at.
JaseP

Jan 24, 2012
1:33 PM EDT
Optimal swappiness settings are highly dependent on what you are running. If you run services that do better with a lot if free RAM, sometimes pegging it to 100 is actually better. If you run a desktop with a bunch of smaller apps, then a low setting is better. If you run off an SSD instead of an HD, you are better with a lower setting (as well as limiting the more unnecessary writes to the "disk"). SSDs have limited write/rewrite cycles, although modern ones are better. So, a little experimentation is sometimes in order.
gus3

Jan 24, 2012
1:35 PM EDT
Running off an SSD?

Disable swap, and spread out the pain over time. Better to suffer with slow, weak programs than to lose data to a failing SSD.
JaseP

Jan 24, 2012
1:44 PM EDT
@gus3:

No need to totally disable swap. Most modern SSD have plenty of write/rewrite cycles for a nice long life with a low swappiness swap partition or file, provided that you're not otherwise abusing the drive. But it's the things like excessive logging that'll hurt it. The average life cycle of a modern SSD is about equal to the life cycle of the average hard drive these days,... again, provided you make adjustments...

Posting in this forum is limited to members of the group: [ForumMods, SITEADMINS, MEMBERS.]

Becoming a member of LXer is easy and free. Join Us!