Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[gentoo-user] To swap or not to swap? Is it really needed?

13 views
Skip to first unread message

Claudio Roberto França Pereira

unread,
Dec 29, 2011, 5:40:02 PM12/29/11
to
I've run my box with 2x2GB of RAM for a while, but a couple weeks ago
one of my chips died, and now I'm stuck with 1x2GB. That's not that
terrible, I'm using Gentoo all day, rarely switching to Windows 7
anyways, who really likes RAM.
Anyway, for the last days, my machine has been really slow, with mouse
lag, input delay, and other things. I imediately associated it to the
lack of free RAM, but I always rushed to check the RAM usage with htop
and it were never really high. So today I decided to turn my swap
partition off. And the system is FLYING. I mean, it's pratically a new
machine, now it's usable and reliable.

I thought of falling back from KDE 4 to awesome (tried it earlier in
an old notebook last year) given the memory footprint of KDE, but it
seems that my hard disk was the culprit here.
I've heard that Linux need a little swap partition, maybe just 512MB,
for some tasks, but I'm not going to turn it on anytime soon. It's a
desktop machine, 24/7, and I couldn't care less about suspend-to-disk.

So, should I ban swap partitions entirely from my life? Is that ok?

Alan McKinnon

unread,
Dec 29, 2011, 6:00:02 PM12/29/11
to
This question comes up about every three months or so, and the end
result is always the same: the same people chip in with the same
answers and we all come to the same conclusion.

You should check the Gentoo archives for the most recent gigantic
thread on this, that one was particularly illuminating.

But to summarize:

You haven't given any real info for people to answer your actual
question. To do that, we need to know what exactly your machine is
doing and why, please what your swap settings are.

Generally, the kernel is happiest with a little bit of swap (512 MB is
a very much more than a little) and you can get by with that if your
apps fit into ram. KDE is reasonably smart with ram usage, if you only
have 2G it will try fit into that. If you have 22G it will try to use
lots.

If your machine was really slow, it was likely thrashing. But no-one
can say for sure - what was your disk doing at the time? What did
vmstat say was going on?

To summarize a summary, the answer to "can I ban swap?" is "maybe"



--
Alan McKinnnon
alan.m...@gmail.com

Dale

unread,
Dec 29, 2011, 6:20:01 PM12/29/11
to
You may want to adjust how swap is being used. I have swap but only
want it used to prevent a lockup or some other bad situation. I have
this in /etc/sysctl.conf:

vm.swappiness = 20

With a setting of 20, it will use swap but only when it is out of ram.
I have 16Gbs of ram in my rig and I wouldn't run it without at least a
little swap. Why? Well not long ago I did a update. One of the KDE
programs got updated and I was still logged in. It wasn't happy and
starting eating ram like a cookie monster. That one program was using
over 14Gbs and growing. I was able to kill it before things got to bad
but even with 16Gbs of ram and swap, it was dog slow. Another minute or
two, it may have locked me out.

I would recommend having swap and just setting it to use it when ram
fills up. I would also replace that stick when I could too. ;-)

Dale

:-) :-)

--
I am only responsible for what I said ... Not for what you understood or how you interpreted my words!

Miss the compile output? Hint:
EMERGE_DEFAULT_OPTS="--quiet-build=n"

Claudio Roberto França Pereira

unread,
Dec 29, 2011, 6:20:01 PM12/29/11
to
Sorry for being so general, for not giving any real info. I'm new to
system monitoring, I just learnt about iostat and swapon -s, now about
vmstat. I mainly tried to catch anything unusual in top/htop.

Trying to be more specifically, my system is a core 2 duo, dual core
3ghz processor, 4gb of ram (now 2gb), ATI radeon HD4850 with 512mb of
vram. I used to play a lot on this box, now a lot less. On Gentoo,
when I play is some browser game or cowsay (it's in games-misc!), not
anything relevant. I'm using radeon open source drivers, by the way.
My main use, currently, is web surfing, firefox with LOTS of tabs,
email, social networks and random browsing. Firefox alone uses lots of
ram, almost always it's using more than a half GB, sometimes it passes
the 1gb mark. I also do Qt develop on this, but nothing heavy. No
virtual machines, no 3d rendering, no heavy processing, no
hibernation.

So, I'm just a basic common web surfer. In this case, can I say it's
at least SAFE to disable swap? I'll look into "last month's" thread on
this.

Paul Hartman

unread,
Dec 29, 2011, 7:10:01 PM12/29/11
to
Safe to disable, sure. "swapoff" your device(s) and see how it goes.
If you start to get out-of-memory errors, you know you've made the
wrong decision. :)

I think general opinion is that swap is slow and kills performance,
you want to avoid it happening if at all possible. If you have enough
RAM to avoid using it entirely, great. Tuning the sysctl settings like
Dale said, while still having swap partition "just in case" is the way
I'd go. If the system is swapping all the time, maybe you just need
more RAM.

While you're looking at recent threads, check the one about ZRAM also.
It is a good alternative to (or complement to) disk-based swap, if
your normal swap usage is less than the amount of ZRAM you've
allocated.

Some things, like suspend-to-disk, might require a swap device
on-disk. I have never used that feature myself, so I'm not familiar
with the details.

Claudio Roberto França Pereira

unread,
Dec 29, 2011, 9:30:02 PM12/29/11
to
ZRAM is a compressed ramdisk for swap, right? I'm really not
interested currently.
My next system will have 16gb of ram, and I'll create an 8gb ramdisk
on it to increase emerge performance. Other than that, I'm pretty
happy with my system performance, disabling swap and compositing
effects (remember, open source radeon drivers, I might try fglrx again
but I really liked KMS) did the trick.

Nikos Chantziaras

unread,
Dec 29, 2011, 10:00:02 PM12/29/11
to
On 12/30/2011 12:34 AM, Claudio Roberto França Pereira wrote:
> Anyway, for the last days, my machine has been really slow, with mouse
> lag, input delay, and other things. I imediately associated it to the
> lack of free RAM, but I always rushed to check the RAM usage with htop
> and it were never really high. So today I decided to turn my swap
> partition off. And the system is FLYING. I mean, it's pratically a new
> machine, now it's usable and reliable.
> [...]

Usable, yes. Reliable, no ;-) Once RAM runs out, random processes get
killed. Possible data loss due to that.


> So, should I ban swap partitions entirely from my life? Is that ok?

No. You simply tweak swappiness. In your /etc/sysctl.conf, add this:

vm.swappiness = 20

The default value is 60. Which makes the system use swap very early on.
With 20, you pretty much will swap only when really needed. I've read
somewhere that values lower than 20 are not recommended, but I don't
remember where or why.

Michael Mol

unread,
Dec 29, 2011, 11:00:01 PM12/29/11
to
8GB isn't enough for some packages. Though putting it on top of zram
might work. I don't know how you'd calculate the free space, though,
and portage would check in advance.

--
:wq

Dale

unread,
Dec 30, 2011, 2:40:01 AM12/30/11
to
I have portages work directory on tmpfs and it works fine. I don't have
it set to a specific amount so it uses whatever it needs. It even works
fine with LOo. I have 16Gbs in all but it rarely uses more than 4Gbs.
Of course, I don't just sit here and watch it either. I start my
updates and usually go to bed.

Michael Mol

unread,
Dec 30, 2011, 8:40:01 AM12/30/11
to
On Fri, Dec 30, 2011 at 2:31 AM, Dale <rdale...@gmail.com> wrote:
> Michael Mol wrote:
>>
>> On Thu, Dec 29, 2011 at 9:23 PM, Claudio Roberto França Pereira
>> <spid...@gmail.com>  wrote:
>>>
>>> ZRAM is a compressed ramdisk for swap, right? I'm really not
>>> interested currently.
>>> My next system will have 16gb of ram, and I'll create an 8gb ramdisk
>>> on it to increase emerge performance. Other than that, I'm pretty
>>> happy with my system performance, disabling swap and compositing
>>> effects (remember, open source radeon drivers, I might try fglrx again
>>> but I really liked KMS) did the trick.
>>
>> 8GB isn't enough for some packages. Though putting it on top of zram
>> might work. I don't know how you'd calculate the free space, though,
>> and portage would check in advance.
>>
>
> I have portages work directory on tmpfs and it works fine.  I don't have it
> set to a specific amount so it uses whatever it needs.  It even works fine
> with LOo.  I have 16Gbs in all but it rarely uses more than 4Gbs.  Of
> course, I don't just sit here and watch it either.  I start my updates and
> usually go to bed.

Hm. tmpfs defaults (at least on my system) to a capacity of about 3GB.
What do you have for mount options in fstab?

I used to put portage's work directory on tmpfs, but I had to stop
when LO ran out of space in a pre-check, IIRC. Now I have it on top of
a RAID5 it shares with /home.

--
:wq

Paul Hartman

unread,
Dec 30, 2011, 9:10:03 AM12/30/11
to
On 12/30/2011 07:32 AM, Michael Mol wrote:
> Hm. tmpfs defaults (at least on my system) to a capacity of about 3GB.
> What do you have for mount options in fstab?

You can set the size with size=XXXX parameter. For example I have mine
set to 10G:

none /dev/shm tmpfs defaults,size=10G 0 0

It is shared memory, so that 10G is not actually used unless it is...
well, actually used. :)

signature.asc

Peter Humphrey

unread,
Dec 30, 2011, 9:20:02 AM12/30/11
to

...and you can set the size to be more than the RAM you have; any used excess gets swapped out.

 

--

Rgds

Peter Linux Counter 5290, 1994-04-23

 

Dale

unread,
Dec 30, 2011, 9:30:01 AM12/30/11
to
This is my fstab line:

tmpfs /var/tmp/portage tmpfs noatime 0 0

According to df it is this size:

tmpfs 8232940 3008 8229932 1% /var/tmp/portage

So it defaults to half the ram you have. I read that somewhere so I set
mine up that way since from what I read, it can grow if needed. So far,
I have had no problems with it set this way. Even LOo compiles with no
problems.

Right now, I'm having a issue with phonon-gstreamer-4.5.1 so the failed
emerge is still there. If it hadn't failed, it would be using 0 space.

Paul Hartman

unread,
Dec 30, 2011, 9:30:02 AM12/30/11
to
Though, if you get to that point, performance would probably be better
if you used disk for tmp in the first place. :)

signature.asc
0 new messages