요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
Reclaim과 metadata 보호
dm-zoned.rst:104-140LRU reclaim, 이중 metadata set과 flush commit 절차를 정리합니다.
Format, status와 message
dm-zoned.rst:141-194`dmzadm` 준비 명령, zone usage status와 수동 reclaim을 설명합니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
========
dm-zoned
========
The dm-zoned device mapper target exposes a zoned block device (ZBC and
ZAC compliant devices) as a regular block device without any write
pattern constraints. In effect, it implements a drive-managed zoned
block device which hides from the user (a file system or an application
doing raw block device accesses) the sequential write constraints of
host-managed zoned block devices and can mitigate the potential
device-side performance degradation due to excessive random writes on
host-aware zoned block devices.
For a more detailed description of the zoned block device models and
their constraints see (for SCSI devices):
https://www.t10.org/drafts.htm#ZBC_Family
and (for ATA devices):
http://www.t13.org/Documents/UploadedDocuments/docs2015/di537r05-Zoned_Device_ATA_Command_Set_ZAC.pdf
The dm-zoned implementation is simple and minimizes system overhead (CPU
and memory usage as well as storage capacity loss). For a 10TB
host-managed disk with 256 MB zones, dm-zoned memory usage per disk
instance is at most 4.5 MB and as little as 5 zones will be used
internally for storing metadata and performing reclaim operations.
dm-zoned target devices are formatted and checked using the dmzadm
utility available at:
https://github.com/hgst/dm-zoned-tools
Algorithm
=========
dm-zoned implements an on-disk buffering scheme to handle non-sequential
write accesses to the sequential zones of a zoned block device.
Conventional zones are used for caching as well as for storing internal
metadata. It can also use a regular block device together with the zoned
block device; in that case the regular block device will be split logically
in zones with the same size as the zoned block device. These zones will be
placed in front of the zones from the zoned block device and will be handled
just like conventional zones.
The zones of the device(s) are separated into 2 types:
1) Metadata zones: these are conventional zones used to store metadata.
Metadata zones are not reported as usable capacity to the user.
2) Data zones: all remaining zones, the vast majority of which will be
sequential zones used exclusively to store user data. The conventional
zones of the device may be used also for buffering user random writes.
Data in these zones may be directly mapped to the conventional zone, but
later moved to a sequential zone so that the conventional zone can be
reused for buffering incoming random writes.
dm-zoned exposes a logical device with a sector size of 4096 bytes,
irrespective of the physical sector size of the backend zoned block
device being used. This allows reducing the amount of metadata needed to
manage valid blocks (blocks written).
The on-disk metadata format is as follows:
1) The first block of the first conventional zone found contains the
super block which describes the on disk amount and position of metadata
blocks.
2) Following the super block, a set of blocks is used to describe the
mapping of the logical device blocks. The mapping is done per chunk of
blocks, with the chunk size equal to the zoned block device size. The
mapping table is indexed by chunk number and each mapping entry
indicates the zone number of the device storing the chunk of data. Each
mapping entry may also indicate if the zone number of a conventional
zone used to buffer random modification to the data zone.
3) A set of blocks used to store bitmaps indicating the validity of
blocks in the data zones follows the mapping table. A valid block is
defined as a block that was written and not discarded. For a buffered
data chunk, a block is always valid only in the data zone mapping the
chunk or in the buffer zone of the chunk.
For a logical chunk mapped to a conventional zone, all write operations
are processed by directly writing to the zone. If the mapping zone is a
sequential zone, the write operation is processed directly only if the
write offset within the logical chunk is equal to the write pointer
offset within of the sequential data zone (i.e. the write operation is
aligned on the zone write pointer). Otherwise, write operations are
processed indirectly using a buffer zone. In that case, an unused
conventional zone is allocated and assigned to the chunk being
accessed. Writing a block to the buffer zone of a chunk will
automatically invalidate the same block in the sequential zone mapping
the chunk. If all blocks of the sequential zone become invalid, the zone
is freed and the chunk buffer zone becomes the primary zone mapping the
chunk, resulting in native random write performance similar to a regular
block device.
Read operations are processed according to the block validity
information provided by the bitmaps. Valid blocks are read either from
the sequential zone mapping a chunk, or if the chunk is buffered, from
the buffer zone assigned. If the accessed chunk has no mapping, or the
accessed blocks are invalid, the read buffer is zeroed and the read
operation terminated.
After some time, the limited number of conventional zones available may
be exhausted (all used to map chunks or buffer sequential zones) and
unaligned writes to unbuffered chunks become impossible. To avoid this
situation, a reclaim process regularly scans used conventional zones and
tries to reclaim the least recently used zones by copying the valid
blocks of the buffer zone to a free sequential zone. Once the copy
completes, the chunk mapping is updated to point to the sequential zone
and the buffer zone freed for reuse.
Metadata Protection
===================
To protect metadata against corruption in case of sudden power loss or
system crash, 2 sets of metadata zones are used. One set, the primary
set, is used as the main metadata region, while the secondary set is
used as a staging area. Modified metadata is first written to the
secondary set and validated by updating the super block in the secondary
set, a generation counter is used to indicate that this set contains the
newest metadata. Once this operation completes, in place of metadata
block updates can be done in the primary metadata set. This ensures that
one of the set is always consistent (all modifications committed or none
at all). Flush operations are used as a commit point. Upon reception of
a flush request, metadata modification activity is temporarily blocked
(for both incoming BIO processing and reclaim process) and all dirty
metadata blocks are staged and updated. Normal operation is then
resumed. Flushing metadata thus only temporarily delays write and
discard requests. Read requests can be processed concurrently while
metadata flush is being executed.
If a regular device is used in conjunction with the zoned block device,
a third set of metadata (without the zone bitmaps) is written to the
start of the zoned block device. This metadata has a generation counter of
'0' and will never be updated during normal operation; it just serves for
identification purposes. The first and second copy of the metadata
are located at the start of the regular block device.
Usage
=====
A zoned block device must first be formatted using the dmzadm tool. This
will analyze the device zone configuration, determine where to place the
metadata sets on the device and initialize the metadata sets.
Ex::
dmzadm --format /dev/sdxx
If two drives are to be used, both devices must be specified, with the
regular block device as the first device.
Ex::
dmzadm --format /dev/sdxx /dev/sdyy
Formatted device(s) can be started with the dmzadm utility, too.:
Ex::
dmzadm --start /dev/sdxx /dev/sdyy
Information about the internal layout and current usage of the zones can
be obtained with the 'status' callback from dmsetup:
Ex::
dmsetup status /dev/dm-X
will return a line
0 <size> zoned <nr_zones> zones <nr_unmap_rnd>/<nr_rnd> random <nr_unmap_seq>/<nr_seq> sequential
where <nr_zones> is the total number of zones, <nr_unmap_rnd> is the number
of unmapped (ie free) random zones, <nr_rnd> the total number of zones,
<nr_unmap_seq> the number of unmapped sequential zones, and <nr_seq> the
total number of sequential zones.
Normally the reclaim process will be started once there are less than 50
percent free random zones. In order to start the reclaim process manually
even before reaching this threshold the 'dmsetup message' function can be
used:
Ex::
dmsetup message /dev/dm-X 0 reclaim
will start the reclaim process and random zones will be moved to sequential
zones.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Zoned device 제약을 숨기는 regular block interface
1-33`dm-zoned` target은 ZBC·ZAC 준수 zoned block device를 write pattern 제약이 없는 일반 block device로 노출합니다. 사실상 drive-managed zoned device를 구현해 filesystem이나 raw application에 host-managed device의 sequential-write 제약을 숨기고, host-aware device에서 과도한 random write가 일으키는 성능 저하를 완화합니다.
사용자 random I/O를 zone 규칙에 맞는 sequential write와 conventional-zone buffering으로 변환합니다.
SCSI ZBC 모델은 `https://www.t10.org/drafts.htm#ZBC_Family`, ATA ZAC 모델은 `http://www.t13.org/Documents/UploadedDocuments/docs2015/di537r05-Zoned_Device_ATA_Command_Set_ZAC.pdf`를 참고할 수 있습니다.
구현은 CPU·memory 사용과 storage 용량 손실을 최소화합니다. 256 MB zone을 가진 10 TB host-managed disk 한 개당 memory는 최대 4.5 MB이며 metadata와 reclaim에 내부적으로 필요한 zone은 최소 5개입니다.
10 TB host-managed disk와 256 MB zone 구성의 상한입니다.
Target 장치는 `dmzadm`으로 format하고 검사합니다. 도구는 `https://github.com/hgst/dm-zoned-tools`에서 제공합니다.
Conventional buffer와 sequential data zone
34-62`dm-zoned`는 sequential zone에 대한 non-sequential write를 처리하기 위해 on-disk buffering을 구현합니다. Conventional zone은 cache와 내부 metadata에 사용합니다.
Zoned device와 일반 block device를 함께 쓸 수도 있습니다. 일반 장치를 zoned device와 같은 크기의 논리 zone으로 나누고 zoned-device zone 앞에 배치해 conventional zone처럼 다룹니다.
내부 metadata와 user data·random-write buffer의 역할을 분리합니다.
Conventional data zone의 data는 직접 mapping할 수 있지만 나중에 sequential zone으로 이동해 conventional zone을 새 random write buffer로 재사용할 수 있습니다.
Backend physical sector 크기와 무관하게 logical device는 4096-byte sector를 노출합니다. 이는 write된 valid block을 관리하는 metadata 양을 줄입니다.
Superblock, chunk mapping과 validity bitmap
63-82첫 conventional zone에서 superblock, logical chunk mapping, block-validity bitmap 순으로 배치됩니다.
첫 conventional zone의 첫 block은 on-disk metadata block의 양과 위치를 설명하는 superblock입니다.
그 뒤 mapping block 집합이 logical device block을 chunk 단위로 mapping합니다. Chunk 크기는 zoned block device의 zone 크기와 같습니다. Table은 chunk 번호로 index하고 각 entry는 data chunk를 저장하는 zone 번호와, random modification을 buffer하는 conventional zone 번호를 선택적으로 기록합니다.
Mapping table 다음에는 data-zone block validity bitmap이 옵니다. Valid block은 write됐고 discard되지 않은 block입니다. Buffered chunk의 한 block은 primary data zone 또는 chunk buffer zone 중 정확히 한 곳에서만 valid합니다.
Mapping별 write와 bitmap 기반 read
83-103Primary zone 종류와 sequential write pointer 정렬 여부에 따라 direct 또는 buffered write를 선택합니다.
Conventional zone에 mapping된 chunk의 write는 직접 처리합니다. Sequential zone에서는 logical chunk offset이 zone write-pointer offset과 같을 때만 direct write합니다. 정렬되지 않으면 사용하지 않은 conventional zone을 buffer로 할당합니다.
Buffer block을 쓰면 sequential primary의 같은 block이 자동 invalidate됩니다. Primary의 모든 block이 invalid가 되면 해당 zone을 해제하고 buffer zone을 chunk의 primary mapping으로 바꿉니다.
Validity bitmap이 실제 data 위치 또는 zero-fill을 결정합니다.
LRU conventional zone reclaim
104-113Conventional zone 수는 제한되어 있어 모두 chunk mapping이나 sequential-zone buffer로 사용하면 unbuffered chunk의 unaligned write가 불가능해집니다.
이를 막기 위해 reclaim process가 사용 중인 conventional zone을 주기적으로 scan하고 least-recently-used zone을 회수합니다. Buffer의 valid block을 free sequential zone으로 복사한 뒤 chunk mapping을 새 sequential zone으로 바꾸고 buffer zone을 해제합니다.
오래된 buffer data를 sequential zone으로 compact해 random-write 공간을 되찾습니다.
이중 metadata set과 flush commit
114-140갑작스러운 power loss나 crash의 metadata corruption을 막기 위해 metadata zone set을 두 벌 사용합니다. Primary는 main metadata이고 secondary는 staging 영역입니다.
Secondary staging을 먼저 완성하고 generation counter로 유효화한 뒤 primary를 갱신합니다.
Flush가 commit point입니다. Flush request를 받으면 incoming BIO와 reclaim의 metadata 수정 활동을 잠시 막고 모든 dirty metadata block을 stage·update한 뒤 정상 동작을 재개합니다. Write와 discard만 잠시 지연되며 read는 metadata flush와 동시에 처리할 수 있습니다.
정상 갱신용 두 copy는 regular device에, 식별용 copy는 zoned device에 둡니다.
dmzadm format과 start
141-167Zoned block device는 먼저 `dmzadm`으로 format해야 합니다. 도구가 zone 구성을 분석해 metadata set 위치를 정하고 초기화합니다.
dmzadm --format /dev/sdxx
장치 두 개를 사용할 때는 일반 block device를 첫 번째로 두고 두 장치를 모두 지정합니다.
dmzadm --format /dev/sdxx /dev/sdyy
Format된 장치는 `dmzadm --start`로 시작할 수 있습니다.
dmzadm --start /dev/sdxx /dev/sdyy
단일 zoned 장치 또는 regular+zoned 조합을 format한 뒤 target을 시작합니다.
Zone 사용률 status와 수동 reclaim
168-194`dmsetup status /dev/dm-X`로 내부 layout과 현재 zone 사용량을 확인합니다.
dmsetup status /dev/dm-X
0 <size> zoned <nr_zones> zones <nr_unmap_rnd>/<nr_rnd> random <nr_unmap_seq>/<nr_seq> sequential
전체 zone 수와 random·sequential zone의 free/total 수를 반환합니다.
보통 free random zone이 50% 미만이 되면 reclaim이 시작합니다. 임계값 이전에 수동으로 시작하려면 다음 message를 보냅니다.
dmsetup message /dev/dm-X 0 reclaim
Message가 random-zone data 이동을 즉시 시작합니다.
Zone 추상화와 mapping
dm-zoned.rst:1-103Zone 종류, metadata layout과 direct·buffered read/write 경로를 설명합니다.