Discussion:
[linux-lvm] swap on lvm cache
Xen
2016-04-26 22:35:15 UTC
Permalink
Just a weird question here.

Since swap should ordinarily be encrypted if you encrypt any part of
your data at all, I have opted at this point to either put it inside a
volume that might end up getting cached, or to disable that cache and
put the swap in its place.

What I am saying is that in my current scheme there is going to be a
small cache drive and one part of the cache drive is going to serve
unencrypted data and the other part is going to serve encrypted data.

Supposing that, the swap would be in the encrypted part. But using cache
(lvmcache) on swap is completely ludicrous right?

Swap content might change so fast and so often that with regular
parameters (that would need to be identical for the entire encrypted
container) it would never make it to the cache.

More, accessing swap means loading it into RAM and then clearing the
swap part. Therefore, theoretically perhaps unless the promotion values
are 0, there would never be any benefit because swap is always write
once read once.

Then again, that means there is no pain in adding swap to it either,
because it will never get cached.

Maybe it could be considered an innocent or innocuous element. Doesn't
hurt you, doesn't provide any benefit. In Dutch we say "Baat het niet,
dan schaadt het niet."

Alternatively you could put the swap on the SSD (in this case) and not
have any cache for the other part of the drive. What do you think? It
makes no sense and it makes no difference, right.

Regards, Bart.
Zdenek Kabelac
2016-04-27 08:38:44 UTC
Permalink
Post by Xen
Just a weird question here.
Since swap should ordinarily be encrypted if you encrypt any part of your data
at all, I have opted at this point to either put it inside a volume that might
end up getting cached, or to disable that cache and put the swap in its place.
What I am saying is that in my current scheme there is going to be a small
cache drive and one part of the cache drive is going to serve unencrypted data
and the other part is going to serve encrypted data.
Supposing that, the swap would be in the encrypted part. But using cache
(lvmcache) on swap is completely ludicrous right?
Hi

Yes, it would be seriously bad idea to use 'swap' on cached LV...

There are already unsolved issues with plain devices and swapping :)
and you want to put caching logic into this stack.
Post by Xen
Alternatively you could put the swap on the SSD (in this case) and not have
any cache for the other part of the drive. What do you think? It makes no
sense and it makes no difference, right.
Regards

Zdenek
Xen
2016-04-27 10:32:29 UTC
Permalink
Post by Zdenek Kabelac
Yes, it would be seriously bad idea to use 'swap' on cached LV...
There are already unsolved issues with plain devices and swapping :)
and you want to put caching logic into this stack.
I just think it would never promote it to the cache ;-). Unless the same
blocks are written repeatedly with different memory. But typically every
write is followed by a read. I don't think the same regions of swap are
constantly reused. If your system is not heavily swapping, usually it
would be rather stable. On heavy swap though you might find that the
cache might start to promote it, but it also means the values constantly
change.

Question: if a block has been promoted through reading (for example)
(since reading promotion is usually lower (faster)) and is then written
to, does this mean the cache for it is updated and then written through
(or back)? I suppose it would. Let's assume that is the only sensible
thing.

That means you could have swap blocks promoted due to heavy swapping
(and hence reading) and if you have writeback, it would still make a
modicum of sense since then it would actually cause hits to go to the
cache instead of the slower disk.

I mean I could test it. I could just load a few programs heavy on
memory, so that I can fully fill my cache (swap I mean) and then I could
start alt-tabbing through these programs as a test. And then I would
need statistics on lvmcache hits. You say there are issues but I am more
than willing to crash my system for it :p.

For example, swap on thin LVM works fine. Although the swap filesystem
is not cleared with swapoff. This can be changed with the --discard
option, and then it is cleared.

Any discarded swap would instantly discard it from the LVM cache,
likely, but not necessarily. If that happened then the promotion counter
would never rise.

It is hard to find information on LVMcache. I don't know enough about
dmcache to know its relation. I will just ask two short questions in a
new email.

Continue reading on narkive:
Search results for '[linux-lvm] swap on lvm cache' (Questions and Answers)
10
replies
What is AIX Box?
started 2006-05-08 15:58:44 UTC
hardware
Loading...