LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-07-2013, 03:12 AM   #1
werner291
Member
 
Registered: Feb 2012
Distribution: Debian (Ans soon Ubuntu and Android)
Posts: 48

Rep: Reputation: Disabled
Swap used even when ram is available after memory usage spike


Hello,

now, I don't have much experience when it comes to swap, so please forgive me if this post doesn't make sense.

Basically, after a memory usage spike and closing down some apps, I noticed that my system still uses swap space even if there's now ram available, even with actively used processes.
(Currently using around 1/3rd of ram available, while still using around 180 MiB swap.)

Sometimes this makes things in my system extremely slow (really old machine, slow hard drives...).

When there is ram available, shouldn't the system put what is in the swap back in the ram?
If that's not default behavior, can it be enabled?

(Currently using Debian Wheezy as a desktop OS)
 
Old 08-07-2013, 03:18 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,533

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
It's expensive to continually run the allocated/free memory chains - so it isn't done unless necessary.
What you can try to force the swap back into memory - the swapoff will simply fail if it won't fit in memory, no damage done.
Code:
swapoff /dev/sda?
swapon /dev/sda?
Substitute the appropriate partition - "swapon -s" will show that.
 
1 members found this post helpful.
Old 08-07-2013, 03:19 AM   #3
thelinuxist
Member
 
Registered: Nov 2012
Location: Munich, Germany
Distribution: CentOS, Debian, Fedora, Ubuntu, DSL (Whatever neccessary)
Posts: 61

Rep: Reputation: Disabled
Some swap is always in use - at least the way it usually works. Even with my "working" machine (Fedora 18, 6 Gigs of RAM) there is some data stored in the swap.
Changing this behavior is called "changing swappiness". I found something on the internet, but it's for Ubuntu:
https://help.ubuntu.com/community/SwapFaq
I think it will work for Debian the same way, as Ubuntu is based on Debian (And let's be honest, it IS Debian with a few simplifications in configuration and day to day usage).
Hope I could help.
 
Old 08-07-2013, 03:27 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,185

Rep: Reputation: 2673Reputation: 2673Reputation: 2673Reputation: 2673Reputation: 2673Reputation: 2673Reputation: 2673Reputation: 2673Reputation: 2673Reputation: 2673Reputation: 2673
I do not think swap is used by active processes, swap is only used in case of "out of memory". Pages in use are always located in the main memory. Unused pages will not be copied back to the memory (as long as it was not requested by the system).
 
Old 08-07-2013, 05:26 AM   #5
werner291
Member
 
Registered: Feb 2012
Distribution: Debian (Ans soon Ubuntu and Android)
Posts: 48

Original Poster
Rep: Reputation: Disabled
Thanks for the replies, I'll have a look if anything works.
 
Old 08-07-2013, 07:31 AM   #6
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
Quote:
Originally Posted by werner291 View Post
Basically, after a memory usage spike and closing down some apps, I noticed that my system still uses swap space even if there's now ram available,
That is perfectly normal. There is no reason to try to "fix" it.

Quote:
even with actively used processes.
Even if every process is active (which I doubt), not every memory page of every process is active. Any page in swap that gets accessed won't be in swap any more.

Quote:
Sometimes this makes things in my system extremely slow (really old machine, slow hard drives...).
WRONG!

Maybe the swap use makes you imagine the system is slow. Maybe the system is slow for some other reason at the same time swap is in use. But the swap use does not make your system slow.

Quote:
When there is ram available, shouldn't the system put what is in the swap back in the ram?
It doesn't and it shouldn't. Pages are read back from swap when those pages are used. No matter how much free memory you have, there is no point reading back a page that isn't being used.

Without that extra free memory, when it reads one page from swap, it must write another to swap. With the excess free memory, it can read pages from swap if/when they are used, and not write anything back to swap.
 
1 members found this post helpful.
Old 08-07-2013, 08:57 AM   #7
werner291
Member
 
Registered: Feb 2012
Distribution: Debian (Ans soon Ubuntu and Android)
Posts: 48

Original Poster
Rep: Reputation: Disabled
@johnsfine Thanks for preventing me from trying stupid things.

Then there must be something wrong with the stuff I'm running on my system then... Some day I will find it.
 
Old 08-07-2013, 09:20 AM   #8
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 841

Rep: Reputation: 165Reputation: 165
Quote:
Originally Posted by johnsfine View Post
WRONG!

Maybe the swap use makes you imagine the system is slow. Maybe the system is slow for some other reason at the same time swap is in use. But the swap use does not make your system slow.
I'd like to understand your line of reasoning about this, John. Since access time for a page on disk is several orders of magnitude slower than for a page in resident memory (milliseconds vs nanoseconds), use of swap definitely elongates response times for affected programs. If thrashing is occurring, the effect on overall performance is usually very noticeable.
 
Old 08-07-2013, 10:26 AM   #9
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
Quote:
Originally Posted by Z038 View Post
I'd like to understand your line of reasoning about this, John. Since access time for a page on disk is several orders of magnitude slower than for a page in resident memory (milliseconds vs nanoseconds), use of swap definitely elongates response times for affected programs. If thrashing is occurring, the effect on overall performance is usually very noticeable.
I was assuming the pages in question were still in swap AFTER the slowness of the system was observed, despite sufficient free ram.

That would mean those pages were not accessed. If they aren't accessed, then the time it would have taken to access them doesn't matter.

The important thing to distinguish here is between space being occupied in swap (no ongoing performance cost and no indication of a problem) vs. continuing swap-in/swap-out activity, which would be a significant performance hit.

The OP did not quote the right stats to directly see the level of swap in/out activity. But Linux is pretty reliable about reasonable behavior regarding swap. So we can infer a low swap in/out rate from the free memory.
 
Old 08-08-2013, 07:46 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,356

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
I know what Z038 meant; Johnsfine's one-liner comment just there would have been better with some context.
As he pointed out, if the use of swap (mem spike) has passed, then the kernel will only swap pages back into RAM IF it wants them.
No affect on system performance by leaving them on swap if not reqd.
OTOH, if swap is being actively used, then yes, that will be magnitudes slower than a RAM read/write.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
memory metric to monitor memory usage or swap? karlochacon Linux - Newbie 5 08-13-2011 03:49 PM
Excessive RAM/swap usage Jinouchi Linux - Software 10 03-09-2009 09:59 AM
ram and swap usage? FredericV Linux - General 6 03-25-2007 04:56 PM
Odd swap usage even though there is free RAM Artanicus Linux - Hardware 5 09-28-2005 02:25 AM
RAM/SWAP usage ganja_guru Linux - Software 13 12-29-2004 03:17 AM


All times are GMT -5. The time now is 01:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration