1. 개요
- LVM Cache (lvconvert cache) 기능을 활용하여 저속 디스크(vdb1) 위에 생성한 LV를 고속 디스크(vdc1)기반 Cache Pool로 가속하는 과정을 다룹니다.
2. 버전
- Rocky Linux 9.5
3. 설명
3-1. LVM Cache란?
- LVM Cache는 **저속 디스크(HDD)**에 위치한 Logical Volume(LV)을 **고속 디스크(SSD/NVMe)**를 활용해 캐싱(caching) 하는 기능입니다.
3-2. LVM Cache 동작 방식
- LVM Cache는 기본적으로 **원본 LV(origin)**와 **캐시 풀(cache pool)**을 결합해 동작합니다.
- 구성 요소
- Origin LV: 실제 데이터가 저장되는 저속 디스크(HDD)의 LV
- Cache Pool: 캐시 역할을 하는 고속 디스크(SSD/NVMe)
- Cache Data (실제 캐싱된 데이터 블록 저장)
- Cache Metadata (어떤 블록이 캐싱되었는지 추적)
- Cache 모드
- Writeback 모드 (권장)
- 쓰기 요청이 SSD에 먼저 기록 → 이후 비동기적으로 HDD에 반영(sync).
- 장점: 쓰기 성능이 크게 향상됨.
- 단점: SSD 장애 시 최근 데이터 손실 가능성 존재.
- Writethrough 모드
- 모든 쓰기를 SSD와 HDD에 동시에 기록.
- 장점: 데이터 안정성 ↑
- 단점: 쓰기 성능은 HDD 수준에 머무름.
- Writeback 모드 (권장)
- Cache 정책 (Policy)
smq (Stochastic Multiqueue)
: 기본값, 자주 쓰이는 데이터를 효율적으로 캐싱.mq
: 구 버전 정책, 현재는 잘 쓰이지 않음.
- 동작 흐름
- 읽기(Read):
- SSD(Cache)에 있으면 → 빠른 응답 (Cache Hit).
- SSD에 없으면 → HDD에서 가져오고 SSD에 적재 (Cache Miss + Promotion).
- 쓰기(Write):
- Writeback 모드: SSD → 나중에 HDD 반영.
- Writethrough 모드: SSD와 HDD 동시 기록.
- 읽기(Read):
- 구성 요소
4. Partition
4-1. Partition 생성
# parted -s /dev/vdb mklabel gpt # parted -s /dev/vdb mkpart vdb 1 100% # parted -s /dev/vdb set 1 lvm on
5. PV(Physical Volume)
5-1. PV(Physical Volume) 생성
# pvcreate /dev/vdb1
5-2. PV(Physical Volume) 생성 확인
# pvdisplay -s
출력 예시:
Device "/dev/vdb1" has a capacity of <128.00 GiB
6. VG(Volume Group)
6-1. VG(Volume Group) 생성
# vgcreate vg_test /dev/vdb1
6-2. VG(Volume Group) 생성 확인
# vgdisplay
출력 예시:
--- Volume group --- VG Name vg_test System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size <128.00 GiB PE Size 4.00 MiB Total PE 32767 Alloc PE / Size 0 / 0 Free PE / Size 32767 / <128.00 GiB VG UUID gmjgrB-CGSb-iUmT-qd3I-QThR-Au2V-fihkA1
7. LV(Logical Volume)
7-1. LV(Logical Volume) 생성
# lvcreate -n lv_ext4 -l 32767 vg_test
7-2. LV(Logical Volume) 생성 확인
# lvdisplay
출력 예시:
--- Logical volume --- LV Path /dev/vg_test/lv_ext4 LV Name lv_ext4 VG Name vg_test LV UUID fYd8cT-3u5x-t26c-19Sf-9yxp-llo3-CT54Y9 LV Write Access read/write LV Creation host, time KVM01, 2025-09-06 17:08:09 +0900 LV Status available # open 0 LV Size <128.00 GiB Current LE 32767 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:0
8. 파일 시스템
8-1. 파일 시스템 생성
# mkfs.ext4 /dev/vg_test/lv_ext4
9. 마운트
9-1. 마운트 포인트 생성
# mkdir /mnt/ext4
9-2. 마운트
# mount /dev/vg_test/lv_ext4 /mnt/ext4/
9-3. 마운트 확인
# df -Th /mnt/ext4/
출력 예시:
Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/vg_test-lv_ext4 ext4 126G 24K 120G 1% /mnt/ext4
10. Partition
10-1. Partition 생성
# parted -s /dev/vdc mklabel gpt # parted -s /dev/vdc mkpart vdc 1 100% # parted -s /dev/vdc set 1 lvm on
11. PV(Physical Volume)
11-1. PV(Physical Volume) 생성
# pvcreate /dev/vdc1
출력 예시:
Physical volume "/dev/vdc1" successfully created.
11-2. PV(Physical Volume) 생성 확인
# pvdisplay -s
출력 예시:
Device "/dev/vdb1" has a capacity of 0 Device "/dev/vdc1" has a capacity of <128.00 GiB
12. VG(Volume Group)
12-1. VG(Volume Group) 확인
# vgdisplay -s
출력 예시:
"vg_test" <128.00 GiB [<128.00 GiB used / 0 free]
12-2. VG(Volume Group) 확장
# vgextend vg_test /dev/vdc1
출력 예시:
Volume group "vg_test" successfully extended
12-3. VG(Volume Group) 확장 확인
# vgdisplay -s
출력 예시:
"vg_test" 255.99 GiB [<128.00 GiB used / <128.00 GiB free]
13. LV(Logical Volume)
13-1. Cache Pool 생성
# lvcreate --type cache-pool -n cachepool -L 100G vg_test /dev/vdc1
출력 예시:
Using 128.00 KiB chunk size instead of default 64.00 KiB, so cache pool has less than 1000000 chunks. Logical volume "cachepool" created.
13-2. Cache Pool 생성 확인
# lvdisplay vg_test/cachepool
출력 예시:
--- Logical volume --- LV Path /dev/vg_test/cachepool LV Name cachepool VG Name vg_test LV UUID XU13p3-mOHa-vM0Q-IuQ3-Baon-m9hC-NksTly LV Write Access read/write LV Creation host, time KVM01, 2025-09-06 17:14:06 +0900 LV Pool metadata cachepool_cmeta LV Pool data cachepool_cdata LV Status NOT available LV Size 100.00 GiB Current LE 25600 Segments 1 Allocation inherit Read ahead sectors auto
13-3. LV Cache
13-3-1. LV Cache 적용 전 확인
# lvdisplay -m /dev/vg_test/lv_ext4
출력 예시:
--- Logical volume --- LV Path /dev/vg_test/lv_ext4 LV Name lv_ext4 VG Name vg_test LV UUID UlcPen-hyeP-mDfM-pnd1-jGLE-RtdW-Dp2XnI LV Write Access read/write LV Creation host, time KVM01, 2025-09-07 12:00:36 +0900 LV Status available # open 1 LV Size <128.00 GiB Current LE 32767 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:0 --- Segments --- Logical extents 0 to 32766: Type linear Physical volume /dev/vdb1 Physical extents 0 to 32766
# lvs -a -o lv_name,segtype,cache_mode,cache_policy,metadata_percent,data_percent,devices vg_test
출력 예시:
LV Type CacheMode CachePolicy Meta% Data% Devices cachepool cache-pool cachepool_cdata(0) [cachepool_cdata] linear /dev/vdc1(20) [cachepool_cmeta] linear /dev/vdc1(10) lv_ext4 linear /dev/vdb1(0) [lvol0_pmspare] linear /dev/vdc1(0)
13-3-2. LV Cache 적용
# lvconvert --type cache --cachepool vg_test/cachepool --cachemode writeback vg_test/lv_ext4
출력 예시:
Do you want wipe existing metadata of cache pool vg_test/cachepool? [y/n]: **y** Logical volume vg_test/lv_ext4 is now cached.
13-3-3. LV Cache 적용 확인
# lvdisplay -m /dev/vg_test/lv_ext4
출력 예시:
--- Logical volume --- LV Path /dev/vg_test/lv_ext4 LV Name lv_ext4 VG Name vg_test LV UUID UlcPen-hyeP-mDfM-pnd1-jGLE-RtdW-Dp2XnI LV Write Access read/write LV Creation host, time KVM01, 2025-09-07 12:00:36 +0900 LV Cache pool name cachepool_cpool LV Cache origin name lv_ext4_corig LV Status available # open 1 LV Size <128.00 GiB Cache used blocks 0.01% Cache metadata blocks 16.14% Cache dirty blocks 0.00% Cache read hits/misses 5 / 34 Cache wrt hits/misses 0 / 0 Cache demotions 0 Cache promotions 4 Current LE 32767 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 512 Block device 252:0 --- Segments --- Logical extents 0 to 32766: Type cache Chunk size 128.00 KiB Metadata format 2 Mode writeback Policy smq
# lvs -a -o lv_name,segtype,cache_mode,cache_policy,metadata_percent,data_percent,devices vg_test
출력 예시:
LV Type CacheMode CachePolicy Meta% Data% Devices [cachepool_cpool] cache-pool writeback smq 16.14 0.01 cachepool_cpool_cdata(0) [cachepool_cpool_cdata] linear /dev/vdc1(20) [cachepool_cpool_cmeta] linear /dev/vdc1(10) lv_ext4 cache writeback smq 16.14 0.01 lv_ext4_corig(0) [lv_ext4_corig] linear /dev/vdb1(0) [lvol0_pmspare] linear /dev/vdc1(0)
14. 확인
14-1. 패키지 설치
# dnf -y install sysstat
14-2. iostat 실행
# iostat -x /dev/vdb1 /dev/vdc1 1
14-3. 쓰기 테스트
# dd if=/dev/zero of=/mnt/ext4/test file bs=1024M count=100 oflag=direct
14-4. 확인
- 쓰기 시 캐시 디스크(vdc1)의 w/s 값이 올라가는 것을 확인 하실 수 있습니다.

- 쓰기가 완료 된 다음 캐시 디스크는 r/s 값이 올라가는 것을 확인 하실 수 있고, 원본 LV 디스크는 w/s 값이 올라가는 것을 확인 하실 수 있습니다.
