An LVM cache1 for the SSD as a caching scheme. Objective
Recently, due to the need for work, some SSD cache-related knowledge was contacted. The so-called SSD cache is the use of fast device (such as SSD), to slow device (such as mechanical hard disk) cache, to improve the overall computer I/O storage performance.
Currently in personal computers, the use of more is mechanical hard disk and solid state Drive (SSD). Mechanical hard disk with large capacity, low price, good fault tolerance, long life and other advantages; The disadvantage is that the reading and writing performance relative to the mechanical hard disk has a relatively large gap. The advantage of SSD is that the reading and writing performance is good, especially the random reading and writing performance, the disadvantage is the price is more expensive, the capacity is small, the writing life is limited, once the damaged data is difficult to recover.
Therefore, in some cases we want to combine the advantages of both, so the SSD cache technology solution emerged.
2. Requirements
Assume:
- There is a fast device with a smaller capacity (e.g. SSD);
- There is one and more large capacity mechanical hard drives;
- There are larger data needs to be stored;
- The data read and write performance has certain requirements.
So at this point, we can consider using SSDs as caches.
3. Common Scenarios
From the caching scheme, the common Dm-cache, Bcache, LVM cache, Flashcache, Enhanceio, etc., this article mainly introduces the LVM cache.
4. LVM Cache
After RHEL6.7, LVM provides support for LVM cache logical volumes, which are small logical volumes that are based on DM-CACHE,LVM cache logical volumes using fast devices, such as SSD drives, to improve the performance of larger, but slower, logical volumes. The following shows how to create and use the virtual machine.
Note: Because it is demonstrated on a virtual machine installed on a personal host, it does not reflect performance, just demonstrates the creation process, and if you need to test its performance, use a real storage device test on the physical machine
4.1 Create
, because it is a test, the/dev/sdb and/DEV/SDD on the virtual machine are used as fast device and slow device to demonstrate the creation process, respectively.
4.1.1 Partition
(Take the Create SDB partition as an example)
fdisk /dev/sdb
Enter the partition operation, type N to create the partition, then enter to select the default option, when the option is complete, enter W to save the exit.
The common parameters for the options after Fdisk are:
- M: Help information
- P: Show partition Table
- D: Delete a partition table
- L: List the known partition types
- N: Create a new partition table
- Q: Exit does not save
- W: Save and exit
- T: Modify partition Table System ID
The partitioning results are as follows:
4.1.2 Creating a physical volume
pvcreate /dev/sdb1 /dev/sdd1
4.1.3 Creating a volume group VG
vgcreate vg /dev/sdb1 /dev/sdd1
4.1.4 Creating a logical volume
- Create a data Logical volume
lvcreate -n data -L 6G vg /dev/sdd1
Create a logical volume that stores data, dividing the space of/dev/sdd1 physical volumes.
- Create a cache logical volume
lvcreate -n cache -L 6G vg /dev/sdb1
Create a logical volume cache of cached data, dividing the space of/dev/sdb1 physical volumes.
- Create a meta logical volume
lvcreate -n meta -L 64M vg /dev/sdb1
Create a logical volume meta that caches data, dividing the space of/dev/sdb1 physical volumes.
The results are as follows:
The LVM cache includes a total of three parts: data, cache, meta, where meta size needs to be greater than 1 per thousand Cache;data is the memory, cache and meta together constitute the buffer
4.1.5 Creating a cache pool
(Note that the order of the cache and meta cannot be reversed)
lvconvert --type cache-pool --poolmetadata vg/meta vg/cache
4.1.6 Adding a storage volume to a cache pool
lvconvert --type cache --cachepool vg/cache --cachemode writeback vg/data
Note: The Cachemode has two modes of writeback and Writethrough, the default is Writethrough, where the test is set to writeback. Writeback is better at reading and writing, but loses data in some extreme cases
4.1.7 Formatting and mounting
mkfs.ext3 /dev/vg/datamkdir datamount /dev/vg/data ./data/
Finally, you can store the data in the./data/directory. When the directory reads and writes data, there is actually a cache effect of fast device, which accelerates the read and write performance of the disk.
The LVM cache for SSD caching scenarios