LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   Swap Partition Ruining PC Performance? (https://www.linuxquestions.org/questions/linux-desktop-74/swap-partition-ruining-pc-performance-917353/)

FredJones 12-06-2011 04:13 AM

Swap Partition Ruining PC Performance?
 
I used my machine normally for 2 days and then I see this:

Code:

$ free -m
            total      used      free    shared    buffers    cached
Mem:          3271      2027      1244          0          1        115
-/+ buffers/cache:      1910      1360
Swap:        5820        503      5316

Then I launched a VBox machine (restore not fresh bootup) and my Xfce desktop becomes virtually unusable for 3 solid minutes (the mouse barely responds a window take 20 seconds to come to forefront if I click on one) while the VBox machine comes up and the disk is audibly grinding away that entire time. Once the machine was up:

Code:

$ free -m
            total      used      free    shared    buffers    cached
Mem:          3271      3097        174          0          0        53
-/+ buffers/cache:      3043        227
Swap:        5820      1115      4705

To get the machine to restore and then close it (save state) straight away took nearly 5 minutes total. I also noticed that once it was up and ready to use (i.e. the 99% thing went away) the disk continued to grind for another 20-30 seconds. Even after I saved it, the noise carried on 10 seconds after it appeared to be finished.

Then I open two news sites in Chromium, each in a fresh tab, and the disk again grinds for 20 seconds straight until both are loaded. Granted, they're heavy pages, but they're just Internet pages. Once they're loaded, it's quiet and the CPU is totally quiet.

So then I hard rebooted my machine, got back into my Xfce desktop, and launched no apps whatsoever except one terminal to get this:

Code:

$ free -m
            total      used      free    shared    buffers    cached
Mem:          3271        388      2882          0        14        198
-/+ buffers/cache:        175      3095
Swap:        5820          0      5820

Tons of free RAM. I launched that same VBox machine (restore) and it came up in 14 seconds and with very little noise. Shut down (save state) in 15 seconds. I launched it again (14 seconds) and then got this:

Code:

$ free -m
            total      used      free    shared    buffers    cached
Mem:          3271      2023      1247          0          1        107
-/+ buffers/cache:      1914      1356
Swap:        5820        12      5807

I closed it and launched Chromium and opened those 2 news sites. They opened in 10 seconds and there was a bit of noise.

My partitions are all mostly empty:

Code:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            10M    0  10M  0% /dev
/run            10M  212K  9.8M  3% /run
/dev/sda2      413G  82G  310G  21% /
shm            1.6G  68K  1.6G  1% /dev/shm
/dev/sda1        92M  34M  53M  40% /boot
/dev/sda3      499G  124G  350G  27% /home

My fstab is OK I think:

Code:

$ more /etc/fstab
#
# /etc/fstab: static file system information
#
# <file system>        <dir>        <type>    <options>          <dump> <pass>
devpts                /dev/pts      devpts    defaults            0      0
shm                    /dev/shm      tmpfs    nodev,nosuid        0      0
#/dev/sda1 /boot ext3 defaults 0 1
#/dev/sda2 / ext3 defaults 0 1
#/dev/sda3 /home ext3 defaults 0 1
#/dev/sda4 swap swap defaults 0 0
#UUID=121b8ba5-48b2-4083-ac6b-ae1386ebd600 /boot ext3 defaults 0 1
#UUID=923771e6-7ea1-4bc5-815c-a8c78bcfa1f6 /    ext3 defaults 0 1
#UUID=e0f83332-f764-400b-9052-58a3ea83aafd /home ext3 defaults 0 1
#UUID=dafb368a-0c80-40ca-aca8-208ca48a941b swap  swap defaults 0 0
/dev/sda1 /boot ext3 defaults 0 1
/dev/sda2 / ext3 defaults 0 1
/dev/sda3 /home ext3 defaults 0 1
/dev/sda4 swap swap defaults 0 0

I wonder if all this points to a problem with my swap partition maybe? The VBox performance with and without a lot of unused RAM is strikingly different...

zordrak 12-06-2011 05:18 AM

I'm not quite sure what you're asking.

You have 3 GiB of RAM.
You are using VirtualBox to virtualise a guest Operating System.
VirtualBox assigns a large section of RAM to the virtual machine by reserving the configured amount all at once.
Your host OS runs out of RAM and starts using swap.
Your hard disk read/write performance is awful when compared to RAM read/write performance.
All Operating System tasks and applications that are loaded into swap, or are accessing data in swap take a lot longer to process.
Also since your swap space and your root partition are both on the same disk, the same read/write heads are coping with not just the excess RAM load, but also with reading and writing to the root filesystem.

This is all normal. Get more RAM, or assign less RAM to VirtualBox.

syg00 12-06-2011 05:26 AM

Or to state it another way ...
Swap partition(s) don't affect performance, using the swap partition(s) is what hurts. If you don't swap, it don't matter.

Every performance/tuning problem I've ever seen can be fixed by more memory - somewhere; central, {L1/2/3/4} cache, disk controller cache, GPU, whatever.

H_TeXMeX_H 12-06-2011 05:50 AM

Also see:
http://linuxpoison.blogspot.com/2009...linux-for.html

johnsfine 12-06-2011 07:56 AM

Quote:

Originally Posted by FredJones (Post 4543266)
I used my machine normally for 2 days and then I see this:

What was running at that point? That looks like quite a lot of memory use with very little buffer and cache use.

You should use top (or similar tool) and sort on the RES column to get a first estimate of which processes are using a lot of memory (ignore VIRT and SWAP columns in top, they are less meaningful than you might think).

Many application program problems can cause X to leak, and some versions of X leak due to their own bugs (rather than due to flaws in applications using them). You haven't given enough info to support a real diagnosis, so I am just making a guess based on experience, but everything you have reported seems to fit the behavior one would expect from a memory leak in X.

The big memory stress of launching VBOX is OK when everything else is using no significant amount of memory, but when your memory is already heavily used, launching VBOX is a performance disaster.

FredJones 12-06-2011 12:44 PM

Thank you everyone for your comments. To explain, I have sort of jumped into the middle of a saga here. I posted my VBox test to clearly illustrate my problem, which is that my disk makes crazy noise a LOT and this PC does not perform as well as I think it should. It runs Arch Linux and Xfce and has "Intel(R) Core(TM) i5 CPU 650 @ 3.20GHz" and "Hitachi 1 TB sata 7200 RPM" and should be blazing fast, I would think.

I have a tool called ps_mem from http://www.pixelbeat.org/scripts/ which shows which processes use the most RAM. Two weeks ago, I open a 100MB file in mousepad and got this:

Code:

107.3 MiB + -84036.5 KiB =  25.3 MiB        java
 22.0 MiB +  4.1 MiB =  26.1 MiB        Xorg
117.3 MiB + -23853.5 KiB =  94.0 MiB        chromium [updated] (10)
210.6 MiB + -60663.0 KiB = 151.3 MiB        thunderbird-bin
498.0 MiB + -27615.0 KiB = 471.0 MiB        firefox-bin
  1.0 GiB + -216764.0 KiB = 837.4 MiB        mousepad
---------------------------------
                          1.8 GiB
=================================

 Private  +  Shared  =  RAM used        Program

$ free -m
            total      used      free    shared    buffers    cached
Mem:          3271      2905        365          0          1        216
-/+ buffers/cache:      2688        582
Swap:        5820        295      5525

Which is crazy I think. 800 M for a 100 M file?

I tried opening the same file in gedit and I got a message at the top of gedit (after 20 or 30 seconds of it being blank) that it's "LOADING file.sql..." with a progress bar. I let it go 3.5 minutes, it got to less than half finished, and then I closed it.
Before I closed it, I got this:

Code:

...
536.7 MiB + -520010.0 KiB =  28.9 MiB        xfce4-cpugraph-plugin
127.6 MiB + -98245.0 KiB =  31.7 MiB        mysqld
 44.2 MiB + -12172.0 KiB =  32.3 MiB        skype
107.8 MiB + -75847.0 KiB =  33.8 MiB        java
 41.3 MiB + -2816.0 KiB =  38.5 MiB        plugin-container
221.1 MiB + -60744.0 KiB = 161.8 MiB        thunderbird-bin
220.3 MiB + -34389.0 KiB = 186.7 MiB        chromium [updated] (12)
647.2 MiB + -98126.0 KiB = 551.4 MiB        gedit
606.6 MiB + -7155.0 KiB = 599.6 MiB        firefox-bin
---------------------------------
                          1.8 GiB
=================================

 Private  +  Shared  =  RAM used        Program
$ free -m
            total      used      free    shared    buffers    cached
Mem:          3271      3085        185          0          0        57
-/+ buffers/cache:      3027        244
Swap:        5820        545      5274

To be 100% clear, this is the file I am talking about, as viewed by "ls -l" :

Code:

-rw-r--r-- 1 kirk kirk 104989658 Nov 14 16:01 file.sql
It's a 100 M file!

Before I closed gedit, my PC was almost unusable--it was responding very slowly to clicks and apps were very slow to render.

I'm a bit confused by all this. Something is wrong here and so I came up with my VBox test to demonstrate the problem.

zordak, your point

Quote:

Also since your swap space and your root partition are both on the same disk, the same read/write heads are coping with not just the excess RAM load, but also with reading and writing to the root filesystem.
makes good sense. However, I installed zramswap and so now I see 9 G Swap. Anyhow right now I see:

Code:

$ free -m
            total      used      free    shared    buffers    cached
Mem:          3271      2324        946          0        716        548
-/+ buffers/cache:      1059      2211
Swap:        9091          0      9091

no swap used and tons of free RAM. I open those two news sites in new tabs in Chromium and I hear the disk grinding.

I have an Antec Three Hundred Mini-Tower which is supposed to be a silent case. That means, I think, that my disk is super loud. I even replaced it right after I bought this machine a few months ago b/c I thought it was so loud. Same make/model. This one, the replacement, is better--it's quieter and the performance is better, but it still has these problems.

I realize that Firefox is a RAM hog and I do often restart it just to get more RAM back, but still, it shouldn't make my system SO slow.

Overall, anyhow, I have no explanation for why 800 M are needed for a 100 M file, nor why the disk should grind for a news site in Chromium, when there is plenty of free RAM for such.

However, the idea from zordak is the only one I have yet heard (I have posted about this issue on another forum) that really makes sense. I suppose I could put in a spare drive I have and use that for swap and see. But the issues in my previous paragraph I don't think will be fixed by that.

johnsfine 12-06-2011 03:37 PM

Quote:

Originally Posted by FredJones (Post 4543619)
I posted my VBox test to clearly illustrate my problem, which is that my disk makes crazy noise a LOT and this PC does not perform as well as I think it should.

If the disks heads must go back and forth between the swap partition and the regular partition, the PC will make a lot of noise and run slow.

You could get more memory, or use less memory, or get a different disk for swap.

Quote:

I have a tool called ps_mem from http://www.pixelbeat.org/scripts/ which shows which processes use the most RAM.
Code:

  1.0 GiB + -216764.0 KiB = 837.4 MiB        mousepad
So where would I get any hint what those numbers mean? I know what the various memory numbers in top mean (numbers most Linux users don't actually understand). But that just makes me more aware of the wide range of possibilities for memory use measurements.
Quote:

I open a 100MB file in mousepad
Does it have a lot of short lines?
I never used mousepad, but a typical text editor locates all the line boundaries in a text file. If the lines are short, the data needed to remember where all the line boundaries are might be much larger than the total data in the file.

Quote:

Before I closed gedit, my PC was almost unusable--it was responding very slowly to clicks and apps were very slow to render.
Something else is seriously wrong with this system. Looking at everything you have posted so far gives me a new guess at that. You made some earlier attempt to adjust Linux settings to improve performance, misunderstood what you were changing, and wrecked the performance.

My more specific guess is swappiness. Your system seems to act as if swappiness is set way too low. I'm guessing you set it to zero. That does decrease the use of swap space, but by greatly increasing the number of reads needed from executable files. Even while it managed to suppress use of swap space, it was already slowing the system. But once it isn't enough to suppress use of swap space, it may be a disaster as every read or write with swap must be alternated with reading executable files at the other end of the same disk.

BTW, you might be able to get more ram simply by enabling it. You seem to have more than 3GB but far less than 4GB, which almost always means you have 4GB of ram physically installed but only have 32bit physical addressing, which only supports 3 and a fraction GB of ram.
If the BIOS has enabled more ram, then you can switch to a PAE kernel to use that additional ram in 32 bit Linux. If the BIOS hasn't enabled the extra ram, that may be harder to solve, but still worth the effort. If the motherboard is limited to 32bit physical addressing then the problem can't be fixed. I don't know how to get a PAE kernel in Arch Linux. If that is a problem for you, search that question or start a new thread to ask it.

FredJones 12-07-2011 05:21 AM

Quote:

Originally Posted by johnsfine (Post 4543747)
So where would I get any hint what those numbers mean? I know what the various memory numbers in top mean (numbers most Linux users don't actually understand). But that just makes me more aware of the wide range of possibilities for memory use measurements.

All I know is what it shows as the last line:

Code:

Private  +  Shared  =  RAM used        Program
That is also the first line of the output of this Python script. The URL I posted above has the source code.

Quote:

Originally Posted by johnsfine (Post 4543747)
Something else is seriously wrong with this system. Looking at everything you have posted so far gives me a new guess at that. You made some earlier attempt to adjust Linux settings to improve performance, misunderstood what you were changing, and wrecked the performance.

Finally, someone commiserates and agrees with me that something is wrong here! :)

Quote:

Originally Posted by johnsfine (Post 4543747)
My more specific guess is swappiness. Your system seems to act as if swappiness is set way too low. I'm guessing you set it to zero. That does decrease the use of swap space, but by greatly increasing the number of reads needed from executable files. Even while it managed to suppress use of swap space, it was already slowing the system. But once it isn't enough to suppress use of swap space, it may be a disaster as every read or write with swap must be alternated with reading executable files at the other end of the same disk.

I was suggested to play with this setting but I never did. I see now:

Code:

$ sysctl vm.swappiness
vm.swappiness = 60

which I don't think could be too low. Let me know if you disagree.

Quote:

Originally Posted by johnsfine (Post 4543747)
BTW, you might be able to get more ram simply by enabling it. You seem to have more than 3GB but far less than 4GB, which almost always means you have 4GB of ram physically installed but only have 32bit physical addressing, which only supports 3 and a fraction GB of ram.

You are a genius. I noticed that I posted elsewhere once that I have 4 GB of RAM. I forgot about that--I think I do! I am working now on getting PAE running--I do the hardware for it. Hopefully this will help.

The only other suggestion that makes sense thus far, as far as I can tell, is to use a separate disk for swap. I will also work on that.

Thank you!

H_TeXMeX_H 12-08-2011 07:10 AM

Quote:

Originally Posted by FredJones (Post 4543619)
Thank you everyone for your comments. To explain, I have sort of jumped into the middle of a saga here. I posted my VBox test to clearly illustrate my problem, which is that my disk makes crazy noise a LOT and this PC does not perform as well as I think it should. It runs Arch Linux and Xfce and has "Intel(R) Core(TM) i5 CPU 650 @ 3.20GHz" and "Hitachi 1 TB sata 7200 RPM" and should be blazing fast, I would think.

I am assuming this is a desktop and not a laptop or netbook.

Besides "swappiness" possible causing this, I would also check to make sure the drive is not failing or it isn't some type of firmware bug where the drive spins itself down.

So, post the output of:

Code:

smartctl -A /dev/sda

FredJones 12-08-2011 07:14 AM

I have checked the Smart tests many times. They always come back good:

Code:


$ sudo smartctl -A /dev/sda
smartctl 5.42 2011-10-20 r3458 [i686-linux-3.1.4-1-ARCH] (local build)
Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net

=== START OF READ SMART DATA SECTION ===
SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG    VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate    0x000b  100  100  016    Pre-fail  Always      -      0
  2 Throughput_Performance  0x0005  137  137  054    Pre-fail  Offline      -      89
  3 Spin_Up_Time            0x0007  122  122  024    Pre-fail  Always      -      304 (Average 315)
  4 Start_Stop_Count        0x0012  100  100  000    Old_age  Always      -      55
  5 Reallocated_Sector_Ct  0x0033  100  100  005    Pre-fail  Always      -      0
  7 Seek_Error_Rate        0x000b  100  100  067    Pre-fail  Always      -      0
  8 Seek_Time_Performance  0x0005  140  140  020    Pre-fail  Offline      -      30
  9 Power_On_Hours          0x0012  100  100  000    Old_age  Always      -      3587
 10 Spin_Retry_Count        0x0013  100  100  060    Pre-fail  Always      -      0
 12 Power_Cycle_Count      0x0032  100  100  000    Old_age  Always      -      55
192 Power-Off_Retract_Count 0x0032  100  100  000    Old_age  Always      -      59
193 Load_Cycle_Count        0x0012  100  100  000    Old_age  Always      -      59
194 Temperature_Celsius    0x0002  206  206  000    Old_age  Always      -      29 (Min/Max 18/40)
196 Reallocated_Event_Count 0x0032  100  100  000    Old_age  Always      -      0
197 Current_Pending_Sector  0x0022  100  100  000    Old_age  Always      -      0
198 Offline_Uncorrectable  0x0008  100  100  000    Old_age  Offline      -      0
199 UDMA_CRC_Error_Count    0x000a  200  200  000    Old_age  Always      -      0

It's also not an inherently slow disk:

Code:

$ sudo hdparm -Tt /dev/sda2

/dev/sda2:
 Timing cached reads:  10814 MB in  2.00 seconds = 5410.86 MB/sec
 Timing buffered disk reads: 426 MB in  3.00 seconds = 141.84 MB/sec


H_TeXMeX_H 12-08-2011 07:18 AM

Yeah, the drive seems normal in term of performance, and it is not failing.

FredJones 12-08-2011 07:24 AM

Yes, this is a desktop machine, with excellent specs.

So the only two suggestions which seem usable thus far are:

1. Get PAE kernel. This, however, should only provide another .5 G RAM and so will only help the problem, not fix it.

2. Put swap partition on a separate physical drive. I am going to try this as soon as my new USB disk arrives. I realize USB 2.0 is slower than a SATA disk, but it's an easy way to test this hypothesis--the hard drive shouldn't grind anymore anyhow. If it's better, I will put in a real drive from another machine and put swap there and see if it gets even better.

Are there are any other ideas? I feel that something is still not right here, because many if not most desktop users (and probably virtually all laptop users) indeed only have one physical drive and so their swap is on that drive.

I think I have clearly configured something wrong on this machine. But I have no idea what.

H_TeXMeX_H 12-08-2011 08:12 AM

I don't have a swap partition, because when it kicks in, it does ruin performance.

However, there is this experimental option:
http://www.webupd8.org/2011/10/incre...inux-with.html

FredJones 12-08-2011 08:21 AM

Oh I have zswapram. My physical swap space is 6 G. Yet free shows 9 G:

Code:

$ free -m
            total      used      free    shared    buffers    cached
Mem:          3271      2913        357          0        14        369
-/+ buffers/cache:      2530        741
Swap:        9091        111      8980

I haven't noticed that it helps yet.

Perhaps the bottom line is that my work habits require more than 3.5 G RAM and that's it.

johnsfine 12-08-2011 08:33 AM

Quote:

Originally Posted by FredJones (Post 4544139)
I was suggested to play with this setting but I never did. I see now:

Code:

$ sysctl vm.swappiness
vm.swappiness = 60

which I don't think could be too low. Let me know if you disagree.

My guess about swappiness was wrong. You didn't (and shouldn't) mess with it.

In the info you posted, the amount in cache is very low, relative to fully free memory, and even more so relative to really used memory. I have been guessing that is a connective detail (between cause and effect) of some serious performance problem. But other than swappiness, I can't think of a plausible cause.

When cache use is low and there is significant memory pressure, one would expect the system to constantly page in code from the original main executables and .so files. That seems to fit the overall performance symptoms. But I don't see any explanation for cache being so low. If almost all the memory use were anonymous (programs using very little code but a lot of heap and/or stack) the memory stats could look as they do without the low cache being a major performance factor. But that isn't as good a fit for the described performance symptoms.

Quote:

Originally Posted by FredJones (Post 4543619)
I realize that Firefox is a RAM hog and I do often restart it just to get more RAM back, but still, it shouldn't make my system SO slow.

That seems to be a big part of the problem, maybe a very big part. So why is Firefox a RAM hog and why does restarting it make a big difference? Two theorys seem obvious: 1) Firefox might have a memory leak, so you really need to restart it often to keep it from dominating your ram. 2) Firefox has user settable parameters for how much ram and how much hard drive space is used for its caching of web content and you have the ram parameter set way too high. Your hard drive should be much faster than your internet connection and generally fast enough for your display, so web content should be mostly cached on disk and not in ram.


All times are GMT -5. The time now is 08:16 PM.