LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
LinkBack Search this Thread
Old 01-30-2010, 11:08 AM   #1
aclhkaclhk
Member
 
Registered: Mar 2009
Posts: 54

Rep: Reputation: 15
release swap space


swap space consumed is not released when there is enough main memory.

pls advise how to release used swap space.
 
Old 01-30-2010, 11:15 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Normally, swap usage is completely automatic and transparent to the user---you should never have to do anything.

Please tell us the context of the question---including whatever you are seeing that is evidence of a problem. And please tell us what distro you are using.
 
Old 01-30-2010, 11:17 AM   #3
MS3FGX
Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,850

Rep: Reputation: 350Reputation: 350Reputation: 350Reputation: 350
When another process needs swap space, it will be cleared and the new data will take it's place. There is no need to manually monitor or clear swap.

For that matter, if your system is making regular use of swap it is an indication that your system is overloaded. If anything, you should be looking into what is using swap and why.
 
Old 01-30-2010, 11:28 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
Be aware that your system can also sometimes use swap space for background page caching and swapping, even if there's plenty of memory available. But it's just a convenience/efficiency function. The space will be released if it's ever needed for anything else.

For example, my swap is currently showing at 5% used, even though I still have over half-a-gig of RAM available and I haven't run anything big enough to need it in the normal way since my last reboot.
 
1 members found this post helpful.
Old 02-03-2010, 09:48 PM   #5
aclhkaclhk
Member
 
Registered: Mar 2009
Posts: 54

Original Poster
Rep: Reputation: 15
system monitor showed 100% swap usage (1G), only 16% user memory used.
 
Old 02-03-2010, 10:24 PM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
Well, then, if there really is a problem, then how about giving us the information we need to figure out what's wrong? What were you doing that filled it up? Did you do anything different than usual? What effects has it had on your system (slowdowns, unable to run other programs)? Does it stay constant or change in any way? Does it re-occur after logging out or rebooting? What program(s) are you using to monitor the swap space? What distribution are you using?

Take a minute to follow the big, bolded link in my signature and then come back and give us some details please.
 
0 members found this post helpful.
Old 04-06-2011, 01:18 PM   #7
clkennedy
LQ Newbie
 
Registered: Apr 2009
Location: Monterey, CA
Distribution: suse,debian,centos
Posts: 23

Rep: Reputation: 2
To David The H.

I found this post while looking for an answer to the same question that aclhkaclhk posed. After reading the responses I got the idea. However, I find your final response arrogant and condescending. The fact is aclhkaclhk did give you a direct question. If you need more info, simply ask people instead of slamming them. No wonder this guy didn't respond back.
 
1 members found this post helpful.
Old 10-29-2011, 06:28 AM   #8
hujuice
LQ Newbie
 
Registered: Oct 2006
Distribution: Gentoo
Posts: 3

Rep: Reputation: 1
I think that the argument is not trivial.
Here are some general tips.

Let's start from my desktop 'top' lines, right now.
Code:
Mem:   4063224k total,  2911136k used,  1152088k free,   224128k buffers
Swap:  2008088k total,   247156k used,  1760932k free,   559480k cached
I don't know why my ~240M swap is not released to RAM. I can suppose that no processes requested that pages.
It should be OK, but I perceive some slowdowns when it's so.
Normally I prefer to drive such a situation (some swap minor than free memory) by safely disabling and re-enabling the swap:
Code:
# swapoff -a
# swapon -a
But I'm not completely aware about the risks of this manoeuvre (specially if the free memory is not enough).

Now, 'top' shows:
Code:
Mem:   4063224k total,  2960296k used,  1102928k free,   173752k buffers
Swap:  2008088k total,      844k used,  2007244k free,   487604k cached
Before falling in this situation, there is another possible tuning: the 'swappiness'. You probably have:
Code:
# sysctl -q vm.swappiness
vm.swappiness = 60
This value (from 0 to 100) represents the kernel disposition to swap.

You can drive this value actually
Code:
# sysctl -w vm.swappiness=40
or definitely (i.e. after a reboot)
Code:
# echo "vm.swappiness=40" >> /etc/sysctl.conf
(Naturally '40' is my choice, make some tests to fit yours.)

All that tricks are a good management for my experience.

Regards,
HUjuice

Last edited by hujuice; 10-29-2011 at 06:30 AM.
 
1 members found this post helpful.
Old 10-29-2011, 08:29 AM   #9
johnsfine
Senior Member
 
Registered: Dec 2007
Distribution: Centos
Posts: 4,968

Rep: Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073
Quote:
Originally Posted by hujuice View Post
I don't know why my ~240M swap is not released to RAM.
Why should it be "released" to RAM?

Quote:
I can suppose that no processes requested that pages.
If I understand you correctly, I agree. A likely reason for pages staying in swap is that the process(es) owning those pages aren't actually using them.

Quote:
It should be OK, but I perceive some slowdowns when it's so.
That would be nearly impossible to measure, so I'm pretty sure what you "perceive" is entirely imaginary.

Quote:
Normally I prefer to drive such a situation (some swap minor than free memory) by safely disabling and re-enabling the swap:
Code:
# swapoff -a
# swapon -a
At best a waste of effort.

Quote:
Before falling in this situation, there is another possible tuning: the 'swappiness'.
...
All that tricks are a good management for my experience.
Since you don't understand what you're tuning, the value you choose is likely worse than the default. You are likely making your system slightly slower rather than slightly faster.

Lowering swappiness primarily increases the priority of anonymous memory vs. non anonymous. A low enough swappiness makes Linux drop code pages from active processes in preference to dropping data pages from inactive processes. Those code pages are more likely to be needed again soon, and when needed again they must be read back in and some other code pages dropped.

(Ignoring more obscure case): When dropping a code page, Linux does not write it to swap, because it remembers where it originally got that page. If the page is needed again, it can be reread from the original source.
When dropping an anonymous page, Linux normally must write it to swap. If the page is needed later, it is read back from swap. So assuming each page is needed again equally soon, swapping data is twice as costly as dropping code, so Linux should prefer to drop code (swappiness should not be 100). But recently accessed pages are more likely to be accessed again soon. The probable time before the page will be needed again must be balanced against the double cost for use of swap (so swappiness should not be less than 50 in typical systems).

With swap space on solid state media or RAID1 or in a variety of other conditions in which a write/read of swap takes significantly longer than two reads from ordinary files, swappiness should be below 50 to maximize performance.

If you have low priority tasks that do a lot of file I/O while interactive tasks are stalled waiting for user (or network) activity, lowering swappiness can be used as a crude way to increase the responsiveness of the system (how quickly interactive tasks recover the resources they lost while stalled) at the cost of overall throughput. That won't fix responsiveness as much as true memory prioritization would and it hurts throughput more than true memory prioritization would. But so far as I understand, Linux can't effectively prioritize memory. So in specific cases where your low priority tasks do a lot of file I/O without a lot of anonymous memory and your interactive tasks have a lot of anonymous memory, low swappiness serves as a crude substitute for memory prioritization.

Last edited by johnsfine; 10-29-2011 at 08:49 AM.
 
Old 10-29-2011, 01:56 PM   #10
hujuice
LQ Newbie
 
Registered: Oct 2006
Distribution: Gentoo
Posts: 3

Rep: Reputation: 1
First of all, thanks johnsfine.
I felt your exposition useful and clarifying.

I think anyway that a definitive verdict cannot be written when talking about desktops.

The centre of my argument is this sentence:
Quote:
Originally Posted by hujuice View Post
I perceive some slowdowns when it's so
And your centre is:
Quote:
Originally Posted by johnsfine View Post
recently accessed pages are more likely to be accessed again soon
When you manage a web server with millions of requests per day, your sentence is surely valid. But this happens because the law of large numbers.

Since a desktop system interact with one single human, a desktop system has unpredictable behaviour.
Swap caused latency occurs when switching between heavy applications. This happens when humans responds to external events: a phone call, a bad music in our favourite player, the urgency of an email.

That's why swap appears as an annoyance to people wanting a quick interactivity.
Simply, recently accessed pages are NOT always to be accessed again, because the discontinuous single human behaviour.

I can explain better myself: what I perceive on my desktop is the most important thing. Linux is a very good system to run servers and serve very large numbers of requests, but if I use it as a desktop perhaps it doesn't matter.
Unlike servers' needs, overall throughput could be my very last problem, while latency could be my first one.

What mostly matter is the nature of my activities (and of my character, too!).
So, perhaps I don't want that unused pages stay in swap so much.

That's why, IMO, testing different swappiness values can fit your needs in a preferred way.
And that's why such a tuning option is there.

Finally, while disagreeing a bit with johnsfine, I find very interesting this wide range conversation: http://kerneltrap.org/node/3000
Here Andrew Morton, lead kernel developer, stays "against" me and with johnsfine: I run my desktop machines at
swappiness=100
.

Long live to the difference.

Regards,
HUjuice

Last edited by hujuice; 10-29-2011 at 02:41 PM.
 
Old 05-30-2012, 08:19 AM   #11
ferdinand
LQ Newbie
 
Registered: May 2012
Posts: 2

Rep: Reputation: Disabled
someone asked why to release swap:

one possible answer

hibernate needs as much swap as possible

Example
8 GB ram, 1.5 used
2 swap partitions with each 2 mb
some 800k used - which is not really necessary as enough ram seems to be available.

system fails to hibernate - "not enough swap"
 
Old 05-30-2012, 09:07 AM   #12
johnsfine
Senior Member
 
Registered: Dec 2007
Distribution: Centos
Posts: 4,968

Rep: Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073
Quote:
Originally Posted by ferdinand View Post
why to release swap ...
hibernate needs as much swap as possible

Example
8 GB ram, 1.5 used
2 swap partitions with each 2 mb
some 800k used - which is not really necessary as enough ram seems to be available.

system fails to hibernate - "not enough swap"
Did you test any of that?

I don't use hibernate nor know details of its internal implementation, so I'm not certain you are wrong. But it wouldn't make sense for hibernate to be implemented in a way that fits the implications of your post.

When the system hibernates, it needs to write out anything that could be swapped plus some other stuff. Anything that is swapped is already written out and should be consuming the same space it would consume if written out by hibernate.
 
Old 05-30-2012, 04:10 PM   #13
ferdinand
LQ Newbie
 
Registered: May 2012
Posts: 2

Rep: Reputation: Disabled
I tested

the hibernate process reports the free swap space

Example
2 GB swap
memory usage 1 GB
swap usage 0,6GB
total 1,6 mem usage = which should be written to swap as you said
swap usage = 0,6 GB + 1,6 GB 2,2 - not enough space

after
swapoff -a
swapon -a
whatever is needed is pushed to ram (IMHO) and swap is freed
the swap usage is 0 and 1,6 (or less?) can be written to swap

BTW interesting enough - I have 8GB memory, never used more then3 GB but some swap is always used.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to reduce swap space and reclaim the space grantm Linux - Newbie 7 08-16-2012 07:05 AM
swap file or swap space? simonb1975uk Linux - General 11 08-15-2008 02:39 PM
swap space (or) swap file yusufs Linux - Newbie 8 07-17-2008 02:02 AM
how much swap space is needed; how to increase swap space? johnpaulodonnell Linux - Newbie 5 03-23-2007 03:20 AM
How to unmount actual swap and mount a new(bigger) swap space? isaac Linux - Newbie 1 06-06-2004 01:23 AM


All times are GMT -5. The time now is 09:05 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration