In this article there is a nice recipe for how to use a RAM-disk as cache-device for a classical LVM volume.
Assumed you have an elder disk, lots of RAM and no SSD, you can boost disk performance to native RAM-throughput using this technique.
So I did this on an LVM which is used for my virtual VM running Windows 10. Voila: Disk-throughput was 4 times faster within the VM (average throughput, best used while patching Windows).
All was well - until I shutdown my linux-system (CentOS 7).
Data Loss!
The shutdown will not disassemble that cache. The same would be true in a power-failure-situation (yes - there will be data loss).
However - there has to be a way to recover what is left. But LVM will not let you operate on a VG with missing disks.
So - is there a receipe for this case out there?
Like
- recover missing LVM cache disk with a new disk
- force clean state
- access cached LV again
In the last step one would make filesystem repairs and would recover missing/corrupted files from backup (using rsync).
No, not quite. Once the cache is full of writes, write throughput degrades to what the underlying disk can do. And the first reads from the backing disk are still slow. I/O to the cache, yes is faster.
This method is very risky because it is very much a not persistent disk. I'm skeptical of the utility when you can just get a fast solid state disk or hardware write cache, but failure modes are fun to test.
THIS WILL CAUSE DATA LOSS. ONLY PROCEED IF YOU HAVE A BACKUP OF YOUR DATA.
First, without cache.
Add cache.
When it comes back, LVM is very unhappy, the volume is unaccessible.
You can't even force uncache it because the metadata has an I/O error.
But you can force the data loss by creating a new PV with the same UUID. Uncache it to remove the ramdisk PV that LVM thinks still has data in it, but was lost. You could re-add the new cache with
lvconvert
, but I am not going to after the results of this experiment.Finally, check for any file system damage. Restore from backup is required to get your data back into a good state.
Edit: adding an empty PV in with the same UUID back in seems super hacky. lvconvert refused to uncache it, after all. If instead you put the metadata LV on permanent disk, then it can be cleaned up a little easier.
It can be forced to uncache. Don't let the "Flushing 0 blocks" output reassure you, in-flight writes were already lost. The missing ramdisk can then be removed, making the VG consistent again.