# Solved: How to troubleshoot swap memory issues?



## StalkerB (May 27, 2004)

Recently the server I use has been falling over because the swap memory has been filling up. Where normally it's at 0.00 - 2.00 (usually around 0.10) or so, sometimes it starts to just increase exponentially until I have to force a restart. The problem is I don't know what's causing it and have no idea how to troubleshoot it.

There used to be a single site hosted on the server, built entirely in php and created from a database. The database powers several other functions on other sites and it is queried often, sometimes with rather large queries.

Recently I added 4 new IPs to the server and installed a Wordpress site. That went okay and I installed a vBulletin forum. That was also okay but I then attempted to bridge WP and vB and every time I activated the bridge (whether the bridge had any mySQL details in or not) the swap memory would start to fill and I'd have to deactivate it.

I figured the bridge was outdated and decided not to bother with it.

Next I installed another WP site on another IP. Eventually having about a dozen installs running off a couple of databases. At some point the swap memory began filling up and I deleted the config files to stop it connecting to the database which seemed to prevent that problem.

So trying again yesterday I reactivated one of the sites, which went fine. I then reactivated a second site which went fine as well. I was transferring files via FTP for a third site, without having connected it to the database and there was also a reasonable sized query being run, when the swap memory filled up again and we had to restart the server.

Since then it's been fine, with the 2 sites I did manage to set up working correctly without problem; swap memory still between 0.00 - 2.00 or so.

What's not clear though is what causes the problem, running a query, connecting WP or being in via FTP or any combination of these. I can't repeat it when I try and although it looks like it only happens when people are doing something, the something is always different and anyway correlation &#8800; causation.

Throwing more memory at it wouldn't seem to be a solution as it just eats up whatever is there, it doesn't top out, so what can I do to start troubleshooting what's causing the problem? 

All help appreciated.


----------



## lotuseclat79 (Sep 12, 2003)

Hi StalkerB,

When swap reaches its limit, cache should fill the gap. On that basis, it might not be too far fetched to add more memory, or to reallocate the partition size for swap. Do you know what you have, i.e. processor, size of L1 and L2, or even L3 cache (if you have it), and the size of your RAM vs Swap size? What Linux distribution are you running? Does it offer PAE capability to recognize 4GB of RAM? What Linux kernel are you running?

There may be standard swap size vs RAM allocations. What are your ratios of swap to RAM size? For example, I have 4GB of RAM w/o PAE and so, only 3GB is recognized by my Live CD Ubuntu 9.10 (Karmic Koala) OS. However, I have 1490 MB=1.49GB in terms of 190 cylinders of 16065 * 512 = 8225280 bytes for swap space vs the 3GB recognized, i.e. 1/2 of RAM. Use the sudo fdisk -l command to figure out your ratio. What is it? Do you have a 1/2 ratio of swap size/RAM size?

-- Tom


----------



## StalkerB (May 27, 2004)

Dunno what you need so heres a bunch of stats 

*swapon -s*
Filename Type Size Used Priority
/dev/sda3 partition 1052248 140824 -1
/var/swap/swap.img file 1023992 0 -2

*Free*
total used free shared buffers cached
Mem: 1025712 1015244 10468 0 2680 291132
-/+ buffers/cache: 721432 304280
Swap: 2076240 140820 1935420

*cat version*
Linux version 2.6.18-92.1.22.el5 ([email protected]) (gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)) #1 SMP Tue Dec 16 11:57:43 EST 2008

*cat cpuinfo*
model name : Intel(R) Pentium(R) Dual CPU E2200 @ 2.20GHz
stepping : 13
cpu MHz : 1200.000
cache size : 1024 KB

Version: Intel(R) Pentium(R) Dual CPU E2200 @ 2.20GHz
Voltage: 1.4 V
External Clock: 800 MHz
Max Speed: 3000 MHz
Current Speed: 2200 MHz

*vmstat*
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 5 367904 156304 2328 227656 2 4 624 38 84 11 5 1 86 8 0

*vmstat -S M*
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 12 526 7 1 184 0 0 624 38 84 11 5 1 86 8 0

*fdisk -l*
Disk /dev/sda: 160.0 GB, 160000000000 bytes
255 heads, 63 sectors/track, 19452 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2624 20972857+ 83 Linux
/dev/sda3 2625 2755 1052257+ 82 Linux swap / Solaris
/dev/sda4 2756 19452 134118652+ 5 Extended
/dev/sda5 2756 19452 134118621 83 Linux

Think that answers what you wanted to know, except maybe the L1/2/3 cache. System claims it can take up to 8Gb RAM, so assume PAE is enabled.

Let me know if there's anything else you need.

Thanks for looking at it for me; I can't make head nor tail of it. Buying more RAM isn't a problem if you think that'll help.


----------



## lotuseclat79 (Sep 12, 2003)

Ok, so you are using RH 4.1.2-42 build. Never assume max system board RAM means PAE is enabled - you claim 3GB, so likely you don't. PAE is dependent on the OS installed, and whether or not you have the PAE and NX bits.

It appears you only have 130 cylinders ( allocated for swap w/3GB RAM detected, i.e. a little over 1GB swap, so your swap/RAM ratio is 1/3). You should at least increase swap so it would be in a 1/2 ratio with RAM detected - i.e. give it a boost of another 500 MB (1/2 GB). In other words, make it 190 cylinders (add 60 cylinders in /dev/sda3) and decrease your Linux partitions on /dev/sda4 and /dev/sda5 by a like amount to accomodate the change.

Note: Backup each partition you plan to change before doing it with the dd command so you don't lose anything that may be stored there already.

-- Tom


----------

