Skip to contentSkip to conversation

swap on lvm cache

linux-lvm Xen 2 participants 3 messages Apr 26, 2016 – Apr 27, 2016

lore
Share & tools
lore

Xen

author
#0 lore raw

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.

#1 lore raw
Quoted 6 lines · 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.

Quoted 6 lines

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.

Quoted 3 lines

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

author
#2 lore raw

Zdenek Kabelac schreef op 27-04-2016 8:38:

Quoted 4 lines

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.