LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Possible "swap " concern ? (https://www.linuxquestions.org/questions/linux-newbie-8/possible-swap-concern-796705/)

uncle-c 03-20-2010 12:27 PM

Possible "swap " concern ?
 
G'day.
I wanted to find out how much swap memory I was using, if any. The results of "free" and "top" showed zero swap usage.
Code:

unclec-$ free -m
            total      used      free    shared    buffers    cached
Mem:          493        484          9          0          7        152
-/+ buffers/cache:        323        169
Swap:            0          0          0

Swap usage is ZERO.

Code:

unclec~$ top

top - 17:19:50 up 20 min,  2 users,  load average: 0.03, 0.17, 0.23
Tasks: 108 total,  3 running, 105 sleeping,  0 stopped,  0 zombie
Cpu(s):  6.6%us,  1.3%sy,  0.0%ni, 92.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    505592k total,  495368k used,    10224k free,    8068k buffers
Swap:        0k total,        0k used,        0k free,  155104k cached

Again swap usage is ZERO. Is this the norm in Linux. i.e. is swap only used when RAM is low and extra memory is required ?

Thanks.

troop 03-20-2010 12:49 PM

Quote:

Swap: 0k total
You have no swap at all...

Quakeboy02 03-20-2010 12:54 PM

Quote:

Originally Posted by uncle-c (Post 3905675)
Again swap usage is ZERO. Is this the norm in Linux. i.e. is swap only used when RAM is low and extra memory is required ?

Thanks.

The use of swap almost always slows a system down, so it should be no surprise that swap is not used unless absolutely necessary.

troop 03-20-2010 01:01 PM

Quote:

The use of swap almost always slows a system down, so it should be no surprise that swap is not used unless absolutely necessary.
It's not quite true.
http://kerneltrap.org/node/3000
Quote:

You really don't want hundreds of megabytes of BloatyApp's untouched memory floating about in the machine. Get it out on the disk, use the memory for something useful.
swappiness is 60 by default.

Quakeboy02 03-20-2010 01:05 PM

I'm not gonna bite. The kerneltrap.org link has more than enough discussion.

uncle-c 03-20-2010 01:20 PM

Thanks for the info gents. There was an incorrect UUID entry in my /etc/fstab file hence the ZERO entries in top and free -m outputs.

Quakeboy02 03-20-2010 01:51 PM

I see that I totally misapprehended your post and am very red-faced. Congrats for fixing it, anyway!

uncle-c 03-20-2010 02:43 PM

Quote:

Originally Posted by Quakeboy02 (Post 3905738)
I see that I totally misapprehended your post and am very red-faced. Congrats for fixing it, anyway!

No need to apologise. On the contrary, I had been using the system for so long without any swap I am now begining to wonder if it would be any use at all ! :) Reading your link has made some things clearer so thanks are in order.

brucehinrichs 03-20-2010 02:54 PM

The amount of swap needed depends (among other things) how much RAM you have. The rule of thumb that I've seen most often is to create a swap partition that is twice your installed RAM. In a machine with 8GB of RAM, creating a swap of 16GB would be ridiculous imho because you most likely won't use up all of your RAM, and therefore won't use any swap. If your machine has 512k of RAM installed, you might mant to consider allocating more than 1GB of swap. How big of a swap partition you need depends mainly on how much RAM is installed, and how you use your machine.

Quakeboy02 03-20-2010 03:42 PM

Quote:

Originally Posted by uncle-c (Post 3905773)
No need to apologise. On the contrary, I had been using the system for so long without any swap I am now begining to wonder if it would be any use at all ! :) Reading your link has made some things clearer so thanks are in order.

Yeah, troop's link is quite a good one; written by the guys who actually write the kernel code. As you've kinda figured out, swap serves no real purpose until you need it. I've just settled into recommending 1GB or so of swap for everyone. Those who need more will eventually understand that what they really need is more RAM. :)

johnsfine 03-20-2010 04:11 PM

Quote:

Originally Posted by uncle-c (Post 3905773)
I had been using the system for so long without any swap I am now begining to wonder if it would be any use at all

It is very possible for use of swap space to make the system run faster in cases where you don't "need" swap space, meaning the things you are running won't flat out fail for lack of swap space.

The important fact is that most "swapping" is not from the swap space. I expect some argument about the word "swapping" there. But there is no better word for the practical meaning.

Most "swapping" is from read only mappings.

Swapping to/from swap space is inherently twice as expensive because it is to/from, while read only mappings are only from. So the Kernel is biased against the activity described by the narrower meaning of "swapping" (to/from swap space).

But actual access patterns vary by far more than two to one. So many disk accessed might be saved by each pair of disk accesses to swap something stale to/from swap space.

Quote:

Originally Posted by Quakeboy02 (Post 3905842)
As you've kinda figured out, swap serves no real purpose until you need it.

Based on previous threads, I won't try to convince you otherwise. But I want to make sure the OP and others reading this thread know there is an opposing viewpoint on that.

Quote:

I've just settled into recommending 1GB or so of swap for everyone.
On one hand, that is as invalid as every other rule of thumb for swap size. If you don't know what will be run on the system you have no basis for estimating the appropriate amount of swap space. On the other hand, virtually no one knows enough about what they will run on their Linux system and how memory will be used to make an informed decision about swap space size. Your unsupported guess of 1GB is probably better than most guesses. (Small enough to usually not waste important disk space when it is too large; Big enough to give a decent chance of at least understanding the problem when it is too small and big enough to rarely be too small for ordinary home users of Linux).

Quote:

Those who need more will eventually understand that what they really need is more RAM.
Hopefully those who just need more swap space will figure that out too.

There really are cases where more swap space allows massive problems to be solved and only slightly slower than they could be solved with absurd and expensive amounts of ram. Swap space is a lot less expensive than ram. Most people don't need enough of either for the cost to be significant. But if you do need a lot it's worth figuring out which you need.

Quakeboy02 03-20-2010 04:47 PM

Quote:

There really are cases where more swap space allows massive problems to be solved and only slightly slower than they could be solved with absurd and expensive amounts of ram.
I won't argue that, John, because I'm in absolute agreement with you. However, it's the .001% solution, and I just don't spend time on it. By this, I mean that only .001% (random number) of the people who ask about swap will be asking because they have one of these situations. Generally, there is some sort of hint in the question/post about this, and I will either change my response or leave it to you or one of the other, few, people here on LQ that has shown a more than casual understanding of swap in exceptional circumstances. Most people, in my personal observation, just want a checkbox number and a semi-basic understanding of what swap is and how much to use. Giving them a 5000 word dissertation serves no real purpose and probably confuses more than it educates.

But, that's my opinion.

Quote:

But if you do need a lot it's worth figuring out which you need.
Yes it is, but there is no simple metric of "X" amount of memory times some random value "Y" that will give you that. In such a case, you generally need to understand the problem before you can attempt a solution; i.e. deciding on the size of swap.

Cheers, John. I enjoy your posts and your help.

chrism01 03-22-2010 06:32 AM

Redhat's take on this: http://kbase.redhat.com/faq/docs/DOC-15252

uncle-c 03-22-2010 12:27 PM

Gents,
The system involved only has 512 MB RAM and uses the lightweight Fluxbox as WM. To be honest since I added the swap I haven't noticed an iota of difference in speed or performance.

chrism01 03-22-2010 07:29 PM

For a relatively low amt of RAM like that, swap would be handy if you start using the machine relatively heavily; you could run out of RAM. Its not a performance issue (speed/throughput) for you, its a capacity issue.


All times are GMT -5. The time now is 02:34 PM.