* Best strategy for use of swap?
@ 2010-01-24 10:21 Kenni Lund
2010-01-24 10:42 ` Michael Tokarev
0 siblings, 1 reply; 2+ messages in thread
From: Kenni Lund @ 2010-01-24 10:21 UTC (permalink / raw)
To: kvm
Hi
I was wondering; Does it make any sense to use swap inside guests?
Wouldn't it give better performance to just skip swap entirely in the
guest, assign it more memory and then increase the swap size on the
host?
Writing to swap on the host side doesn't have the overhead of the
virtio layer, Qcow2 filesystem or an underlying host filesystem. And
at the same time, KSM can decrease the overall memory usage on the
host, which I suppose will lower the risk of the host using swap at
all.
Are there any disadvantages to this or would this be the prefered way
of using swap on a KVM-based system?
Thanks
Best Regards
Kenni Lund
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Best strategy for use of swap?
2010-01-24 10:21 Best strategy for use of swap? Kenni Lund
@ 2010-01-24 10:42 ` Michael Tokarev
0 siblings, 0 replies; 2+ messages in thread
From: Michael Tokarev @ 2010-01-24 10:42 UTC (permalink / raw)
To: Kenni Lund; +Cc: kvm
Kenni Lund wrote:
> Hi
>
> I was wondering; Does it make any sense to use swap inside guests?
> Wouldn't it give better performance to just skip swap entirely in the
> guest, assign it more memory and then increase the swap size on the
> host?
The Gold Rule: do not swap guests.
If a guest does not know it is swapped, and an interrupt comes which
requires memory which is swapped on host but guest thinks it's right
here, all bad things happens. Guest is not ready to face a situation
when access to system RAM takes several _seconds_, usually it's in
range of nanoseconds.
For another thing, guest knows better what to swap.
Generally, swap serves as a safety measure in case we run into a
situation when the amount of RAM isn't sufficient. Amount of memory
should be enough for "typical" workload of a system, and swap serves
for situation where it requires a bit more during peaks etc. For that,
let the particular guest handle the (light) swap load, instead of
slowing down _all_ guests by swapping in host.
(And a side note to stop possible flame war here: there are different
views as of what swap is and is not. Another "version" is that it
is used to free system memory from tasks which are not used right
now, and so on. The main rule stands still: there should be very
few swapping. And for light swapping it does not really matter if
we do swapping a bit faster in host than a bit slower in guest
(due to virtual i/o overhead): the difference isn't that high and
for _small_ amount of swapping it does not really matter speed-
wise. But swapping in guest makes things more predictable and
smooth due to all the above).
/mjt
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-01-24 10:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-24 10:21 Best strategy for use of swap? Kenni Lund
2010-01-24 10:42 ` Michael Tokarev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox