# [SOLVED] swap issues

## incubator

Since I run a JBoss application server a lot of memory is used, but also several 100's mb of swap.

What I would like to know is, if there is a way to clean up swap without rebooting after several programs or the JBoss server has been closed because not all swap (actually very little to none) is released.

Current kernel is gentoo-sources-2.6.11-r4, plans to upgrade to 2.6.13 are there but I will wait until more revisions are out.

Ram = 512mb

Swap = 1024mb

at some point when I am working, having KDE, jboss, eclipse, firefox  and amarok open, ram = 170mb free and swap = +- 700 - 800 mb free.

(and I set the JVM parameters for jboss to -Xms64mb -Xmx64mb instead of the usual 128)

----------

## lucabotti

swapon / swapoff cycle?

----------

## incubator

isnt there a risk of data loss then?

----------

## bollucks

No risk. Just do:

```
swapoff -a && swapon -a
```

----------

## incubator

ok, thanks  :Smile: 

----------

## syg00

Mmmm - I've seen such discussions before, and am no closer to accepting the above as valid advice.

No way I'd do it, but it ain't my dog ...

Every time I start to look at the mm/vm code I get a head-ache and give up. Let's assume it might be safe to do a swapoff/swapon if all the slots can be reclaimed, and all active tasks can be swapped back into memory in toto.

*BUT* - if this is possible, there is no reason to do it, because there is obviously (more than) sufficient reclaimable slots.

So why risk it ??? - let the system handle it on demand.

Happy to have some-one point out where my logic is amiss.

incubator, on what do you base the following ????; *Quote:*   

>  after several programs or the JBoss server has been closed because not all swap (actually very little to none) is released. 

 

Edit: - guess it must have worked; just been marked "solved" ....  :Rolling Eyes: 

----------

## incubator

1) I put it to solved as I once did that in the past and did solve the problem back then though I just wanted to know if there was any other way, and apparently not

2) I based that quote on the fact tot all my swap was free before starting all these things, but once I started JBoss and other Java related things, I see swap being eaten.

When I close them, an hour later (idling) the swap was not returned.

----------

## syg00

Presumably from top or meminfo or such ???.

I have seen discussions re the meaning of "free" - and am only a little the wiser.

The interpretation of the page- and swap-cache free lists are "interesting".

Your presumtion of a problem existing is likely to be false. How anyone can ascertain this is questionable.

However, I wouldn't be taking the risk of killing active tasks by pulling swap out.

Your system, your decision.

----------

## incubator

i used gkrellm

and if a killall java does not release the swap it used, then I think there is a reason to do it

----------

## bollucks

Try the swap prefetching patches from the -ck tree that are now in -mm; and slated for mainline inclusion in the near future.

----------

## syg00

Better not - when I looked at Cons notes (when he first released it admittedly), he said you could expect to see up to 50% usage of your swap.

Given the reaction so far, I don't think this is what incubator is looking for.

----------

## bollucks

That's a misunderstanding, it doesn't use any more "real" swap, it's all stuff that has a copy both in ram and in swap to get the maximum benefit - if you need to use the stuff in ram it's already there for you to use, and if you need to push it back out to swap to make room for other stuff, it's already in swap as well.

----------

## syg00

On the contrary - I think I understand quite well what Con has done.

But what do you think gkrellm and its ilk are going to report  ???.

And threads like this are going to pop up everywhere because people will think the sky is falling down.

Happens now with the "why is my memory all used up" threads we see just about every second week - what makes you think this will be any different.

----------

## bollucks

Nothing, it's the same recurring shit that we have to explain to everyone all the time.

----------

## Loci79

I know it's solved but a short comment from my side...

I've done the "swapoff -a && swapon -a"-procedure several times and it's save...

swapoff tries to move all data in swap (as far it's still used) to RAM... if this fails due to limited ressources it aborts and does not deactivate swapspace...

Unfortunately this also means unused data which still remains in swap is still there and won't be removed... in this case it's not a valid solution... I'll investigate further...

My system is a notebook with Athlon XP mobile, 768MB RAM, 512MB swap. Both are nearly full after only 6 days uptime... I already stopped running MySQL and Apache... but still the same problem...

Loci

----------

## incubator

I removed the solved status as this problem is still reoccurring.

I switched to ck-sources  2.6.15-ck1-r1 and tested with both sun-jdk 1.4.2.10 and 1.5.0_06 (the latter not in portage)

When I run JBoss and Eclipse, compile my program during development several times for testing, both my ram and swap are low by the end of the day. ANd i'm not talking about this virtual visual dillusion, but my system is constantly writing data to swap and my system becomes very slow near the end.

Closing JBoss, Eclipse and any other application I had running freed up some of the ram + swap (about half of it)  but not all.

I waited 12 hours and still not a single change.

so I dont know what I'm doing wrong here, either its a misconfiguration in the kernel or something in the JVM's settings, but its definitly not my code as I ran several testcases with JProfiler and the garbage collector cleaned up things at runtime as it should, my main concern is more the bigger applications like JBoss and eclipse, I think they're the ones causing it.

----------

## bollucks

 *incubator wrote:*   

> Closing JBoss, Eclipse and any other application I had running freed up some of the ram + swap (about half of it)  but not all.
> 
> I waited 12 hours and still not a single change.

 

Do you have swap prefetching enabled? That stabilises the fake swap at 50% which sounds suspiciously like yours. The easy way to tell if it is prefetched copied swap is how much ram in /proc/meminfo is SwapCached. The swap prefetch patches copy the ram into SwapCached. Also if it is prefetched then a swapoff will be virtually instant instead of taking a while to swap everything back in, but a swapon again will not fill up the swap again.

As for your swap usage problem it just looks like you don't have enough ram for that workload?

----------

## incubator

that may very well be the problem as you say, a swapoff doesnt take long, in fact it ends instantly.

And a swapon show back the ful 981 mb swap (in gkrellm) but as you said in one of the previous posts, this could be wrong information.

When I get home I will post the info you need from /proc/meminfo before and after using all those large java applications.

As for not having enough ram for this workload, that might also be true, eclipse uses about 100 mb ram, jboss has been set to 64mb (-Xms64m -Xmx64m ) but since I use kde I already lose a bit more memory for that.

(total ram: 512mb)

At work, our development workstations each have 1GB of ram, they run windows however (not my decision) but in there jboss and eclipse both use about 400 mb of ram in total. (but for jboss the jvm heap settings there are different: -Xms128m -Xmx512m )

I also took the liberty of looking in /proc/sys/vm/swap_token_timeout

it had a number 300 seconds.

I changed that to 30 just to see if it would do anything (even maybe breaking my system?) but I noticed nothing really, except that for some reason my JBoss server is now a bit faster

----------

## sundialsvc4

Why is this not just a memory-leak in a particular app?  What happens when you log-off (and check for and remove any "nohup" processes that may linger in your name, if any)?

----------

## incubator

meminfo at clean startup:

```

MemTotal:       514416 kB

MemFree:         44940 kB

Buffers:         12816 kB

Cached:          88844 kB

SwapCached:          0 kB

Active:         334132 kB

Inactive:        44932 kB

HighTotal:           0 kB

HighFree:            0 kB

LowTotal:       514416 kB

LowFree:         44940 kB

SwapTotal:     1004052 kB

SwapFree:      1003716 kB

Dirty:              12 kB

Writeback:           0 kB

Mapped:         337880 kB

Slab:            78996 kB

CommitLimit:   1261260 kB

Committed_AS:   508068 kB

PageTables:       2164 kB

VmallocTotal:   515796 kB

VmallocUsed:     23700 kB

VmallocChunk:   489168 kB

```

meminfo after doing lots of Java stuff (note that more ram stays free now and swap gets returned a bit more frequently since that token_timeout setting.

```

MemTotal:       514416 kB

MemFree:        221536 kB

Buffers:          9924 kB

Cached:         142804 kB

SwapCached:      40936 kB

Active:         197216 kB

Inactive:        62520 kB

HighTotal:           0 kB

HighFree:            0 kB

LowTotal:       514416 kB

LowFree:        221536 kB

SwapTotal:     1004052 kB

SwapFree:       868216 kB

Dirty:               4 kB

Writeback:           0 kB

Mapped:         150196 kB

Slab:            21524 kB

CommitLimit:   1261260 kB

Committed_AS:   534584 kB

PageTables:       2232 kB

VmallocTotal:   515796 kB

VmallocUsed:     23700 kB

VmallocChunk:   489168 kB

```

----------

## frenkel

Everybody keeps on complaining about memory and swap usage in Linux. It won't remove most of the stuff until it needs more space/till the memory is completely full. What's the problem? When processes get killed because the memory is full, THEN there is a problem.

----------

## bollucks

 *incubator wrote:*   

> that may very well be the problem as you say, a swapoff doesnt take long, in fact it ends instantly.
> 
> And a swapon show back the ful 981 mb swap (in gkrellm) but as you said in one of the previous posts, this could be wrong information.

 

It sounds to me like your memory is swapping back in fine then (and I've seen your later post with meminfo). This is exactly what swap prefetching was designed to do. It is not "wrong information" as that swap is indeed in use, but in an efficient way (ie it is a copy of something that is both in ram and on swap).  I see no problem here.

The only issue is that your workload actually swaps in the first place, meaning you just don't have enough ram for the workload you're doing.

----------

