← Documents Documentation/admin-guide/blockdev/zoned_loop.rst GitHub 원문 ↗

Linux 6.18.37 · Administration / Block devices

Zoned Loop Block Device

Regular file을 zone별 backing storage로 사용하는 zloop device의 state model, 생성 option, 제거·복원과 2-GiB 예제를 설명합니다.

Source pathDocumentation/admin-guide/blockdev/zoned_loop.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

Storage and zone states

zoned_loop.rst:1-45

Zone file 크기로 sequential write pointer를 나타내며 reset과 finish는 truncate로 구현합니다.

Create a device

zoned_loop.rst:46-95

/dev/zloop-control의 add command와 capacity·zone·queue option을 정리합니다.

Remove and restore

zoned_loop.rst:96-115

동일 설정 재추가는 zone state를 복원하고 backing directory 삭제는 device를 완전히 지웁니다.

2-GiB example

zoned_loop.rst:116-169

32개 zone의 file layout과 lsblk·blkzone 출력, 제거 절차를 보여 줍니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 =======================
4 Zoned Loop Block Device
5 =======================
6
7 .. Contents:
8
9 1) Overview
10 2) Creating a Zoned Device
11 3) Deleting a Zoned Device
12 4) Example
13
14
15 1) Overview
16 -----------
17
18 The zoned loop block device driver (zloop) allows a user to create a zoned block
19 device using one regular file per zone as backing storage. This driver does not
20 directly control any hardware and uses read, write and truncate operations to
21 regular files of a file system to emulate a zoned block device.
22
23 Using zloop, zoned block devices with a configurable capacity, zone size and
24 number of conventional zones can be created. The storage for each zone of the
25 device is implemented using a regular file with a maximum size equal to the zone
26 size. The size of a file backing a conventional zone is always equal to the zone
27 size. The size of a file backing a sequential zone indicates the amount of data
28 sequentially written to the file, that is, the size of the file directly
29 indicates the position of the write pointer of the zone.
30
31 When resetting a sequential zone, its backing file size is truncated to zero.
32 Conversely, for a zone finish operation, the backing file is truncated to the
33 zone size. With this, the maximum capacity of a zloop zoned block device created
34 can be larger configured to be larger than the storage space available on the
35 backing file system. Of course, for such configuration, writing more data than
36 the storage space available on the backing file system will result in write
37 errors.
38
39 The zoned loop block device driver implements a complete zone transition state
40 machine. That is, zones can be empty, implicitly opened, explicitly opened,
41 closed or full. The current implementation does not support any limits on the
42 maximum number of open and active zones.
43
44 No user tools are necessary to create and delete zloop devices.
45
46 2) Creating a Zoned Device
47 --------------------------
48
49 Once the zloop module is loaded (or if zloop is compiled in the kernel), the
50 character device file /dev/zloop-control can be used to add a zloop device.
51 This is done by writing an "add" command directly to the /dev/zloop-control
52 device::
53
54 $ modprobe zloop
55 $ ls -l /dev/zloop*
56 crw-------. 1 root root 10, 123 Jan 6 19:18 /dev/zloop-control
57
58 $ mkdir -p <base directory/<device ID>
59 $ echo "add [options]" > /dev/zloop-control
60
61 The options available for the add command can be listed by reading the
62 /dev/zloop-control device::
63
64 $ cat /dev/zloop-control
65 add id=%d,capacity_mb=%u,zone_size_mb=%u,zone_capacity_mb=%u,conv_zones=%u,base_dir=%s,nr_queues=%u,queue_depth=%u,buffered_io
66 remove id=%d
67
68 In more details, the options that can be used with the "add" command are as
69 follows.
70
71 ================ ===========================================================
72 id Device number (the X in /dev/zloopX).
73 Default: automatically assigned.
74 capacity_mb Device total capacity in MiB. This is always rounded up to
75 the nearest higher multiple of the zone size.
76 Default: 16384 MiB (16 GiB).
77 zone_size_mb Device zone size in MiB. Default: 256 MiB.
78 zone_capacity_mb Device zone capacity (must always be equal to or lower than
79 the zone size. Default: zone size.
80 conv_zones Total number of conventioanl zones starting from sector 0.
81 Default: 8.
82 base_dir Path to the base directory where to create the directory
83 containing the zone files of the device.
84 Default=/var/local/zloop.
85 The device directory containing the zone files is always
86 named with the device ID. E.g. the default zone file
87 directory for /dev/zloop0 is /var/local/zloop/0.
88 nr_queues Number of I/O queues of the zoned block device. This value is
89 always capped by the number of online CPUs
90 Default: 1
91 queue_depth Maximum I/O queue depth per I/O queue.
92 Default: 64
93 buffered_io Do buffered IOs instead of direct IOs (default: false)
94 ================ ===========================================================
95
96 3) Deleting a Zoned Device
97 --------------------------
98
99 Deleting an unused zoned loop block device is done by issuing the "remove"
100 command to /dev/zloop-control, specifying the ID of the device to remove::
101
102 $ echo "remove id=X" > /dev/zloop-control
103
104 The remove command does not have any option.
105
106 A zoned device that was removed can be re-added again without any change to the
107 state of the device zones: the device zones are restored to their last state
108 before the device was removed. Adding again a zoned device after it was removed
109 must always be done using the same configuration as when the device was first
110 added. If a zone configuration change is detected, an error will be returned and
111 the zoned device will not be created.
112
113 To fully delete a zoned device, after executing the remove operation, the device
114 base directory containing the backing files of the device zones must be deleted.
115
116 4) Example
117 ----------
118
119 The following sequence of commands creates a 2GB zoned device with zones of 64
120 MB and a zone capacity of 63 MB::
121
122 $ modprobe zloop
123 $ mkdir -p /var/local/zloop/0
124 $ echo "add capacity_mb=2048,zone_size_mb=64,zone_capacity=63MB" > /dev/zloop-control
125
126 For the device created (/dev/zloop0), the zone backing files are all created
127 under the default base directory (/var/local/zloop)::
128
129 $ ls -l /var/local/zloop/0
130 total 0
131 -rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000000
132 -rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000001
133 -rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000002
134 -rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000003
135 -rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000004
136 -rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000005
137 -rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000006
138 -rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000007
139 -rw-------. 1 root root 0 Jan 6 22:23 seq-000008
140 -rw-------. 1 root root 0 Jan 6 22:23 seq-000009
141 ...
142
143 The zoned device created (/dev/zloop0) can then be used normally::
144
145 $ lsblk -z
146 NAME ZONED ZONE-SZ ZONE-NR ZONE-AMAX ZONE-OMAX ZONE-APP ZONE-WGRAN
147 zloop0 host-managed 64M 32 0 0 1M 4K
148 $ blkzone report /dev/zloop0
149 start: 0x000000000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
150 start: 0x000020000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
151 start: 0x000040000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
152 start: 0x000060000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
153 start: 0x000080000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
154 start: 0x0000a0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
155 start: 0x0000c0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
156 start: 0x0000e0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
157 start: 0x000100000, len 0x020000, cap 0x01f800, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em) [type: 2(SEQ_WRITE_REQUIRED)]
158 start: 0x000120000, len 0x020000, cap 0x01f800, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em) [type: 2(SEQ_WRITE_REQUIRED)]
159 ...
160
161 Deleting this device is done using the command::
162
163 $ echo "remove id=0" > /dev/zloop-control
164
165 The removed device can be re-added again using the same "add" command as when
166 the device was first created. To fully delete a zoned device, its backing files
167 should also be deleted after executing the remove command::
168
169 $ rm -r /var/local/zloop/0
170

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Zoned loop block device 개요

1-45

이 GPL-2.0 문서는 zoned loop block device의 개요, 생성, 삭제, 예제를 차례로 설명합니다. Zoned loop block device driver(`zloop`)를 사용하면 zone 하나마다 regular file 하나를 backing storage로 두는 zoned block device를 만들 수 있습니다.

`zloop`는 hardware를 직접 제어하지 않습니다. Filesystem의 regular file에 read, write, truncate operation을 수행해 zoned block device를 emulate합니다. Device 전체 capacity, zone size, conventional zone 수를 구성할 수 있으며, 각 zone의 backing file 최대 크기는 zone size와 같습니다.

Conventional zone을 backing하는 file 크기는 언제나 zone size와 같습니다. Sequential zone의 file 크기는 순차적으로 기록된 data 양이며, 그 file 크기가 곧 zone write pointer 위치를 나타냅니다.

Zone backing-file semantics
Zone or operationBacking-file sizeMeaning
Conventional zone항상 zone size전체 random-write 영역을 미리 나타냄
Sequential zone0부터 zone size까지현재 write pointer 위치
Sequential-zone reset0으로 truncateWrite pointer를 처음으로 되돌림
Zone finishzone size로 truncateZone을 full 상태로 마침

Zone 종류와 operation이 backing file 크기에 어떤 의미를 갖는지 정리합니다.

Sequential zone을 reset하면 backing file을 0으로 truncate합니다. 반대로 zone finish operation은 file을 zone size까지 truncate합니다. 이 sparse한 표현 덕분에 zloop device의 configured maximum capacity를 backing filesystem의 실제 여유 공간보다 크게 잡을 수 있지만, 실제 여유 공간을 넘겨 쓰면 write error가 발생합니다.

Driver는 완전한 zone transition state machine을 구현합니다. Zone은 empty, implicitly opened, explicitly opened, closed, full 상태를 가질 수 있습니다. 현재 구현은 open zone과 active zone의 최대 개수 제한을 지원하지 않습니다.

Zone state transitions
EmptyImplicitly openedClosedFull
EmptyExplicitly openedClosedFull
Sequential-zone resetEmpty
Zone finishFull

구현되는 주요 zone 상태와 완료 경로입니다.

Zloop storage model
/dev/zloopX block deviceZone state machineOne regular file per zoneFilesystem read/write/truncate

Hardware 없이 filesystem operation으로 zoned device를 구성합니다.

Zloop device를 만들거나 삭제하는 데 별도의 user tool은 필요하지 않습니다.

Zoned device 생성

46-95

`zloop` module을 load했거나 kernel에 built-in한 뒤 character device `/dev/zloop-control`에 `add` command를 직접 쓰면 zloop device를 추가할 수 있습니다. 먼저 device ID에 대응하는 base directory를 준비합니다.

	$ modprobe zloop
        $ ls -l /dev/zloop*
        crw-------. 1 root root 10, 123 Jan  6 19:18 /dev/zloop-control

        $ mkdir -p <base directory/<device ID>
        $ echo "add [options]" > /dev/zloop-control

`/dev/zloop-control`을 읽으면 지원하는 `add` option 형식과 `remove` command 형식을 확인할 수 있습니다.

	$ cat /dev/zloop-control
        add id=%d,capacity_mb=%u,zone_size_mb=%u,zone_capacity_mb=%u,conv_zones=%u,base_dir=%s,nr_queues=%u,queue_depth=%u,buffered_io
        remove id=%d
Zloop add options
OptionMeaning and constraintDefault
id`/dev/zloopX`의 X인 device number자동 할당
capacity_mbDevice total capacity(MiB), zone size의 다음 배수로 올림16384 MiB (16 GiB)
zone_size_mbDevice zone size(MiB)256 MiB
zone_capacity_mbZone capacity, zone size보다 작거나 같아야 함zone size
conv_zonesSector 0부터 시작하는 conventional zone 총수8
base_dirDevice zone file directory를 만들 base path/var/local/zloop
nr_queuesI/O queue 수, online CPU 수 이하로 제한1
queue_depthI/O queue 하나당 최대 depth64
buffered_ioDirect I/O 대신 buffered I/O를 사용false
undefinedundefined
undefinedundefined

`add` command의 값, 제약과 default입니다.

`id`를 생략하면 번호를 자동 할당합니다. `capacity_mb`는 zone size의 정수 배수가 되도록 위쪽으로 반올림됩니다. `zone_capacity_mb`는 zone size를 넘을 수 없습니다. `conv_zones`는 sector 0에서 시작하는 conventional zone 수입니다.

`base_dir` 아래에는 device ID 이름의 directory를 만들고 그 안에 zone file을 둡니다. `nr_queues`는 online CPU 수를 상한으로 하며, `queue_depth`는 queue별 최대 I/O 깊이입니다. `buffered_io`를 지정하지 않으면 direct I/O를 사용합니다.

Create a zloop device
Load or build in zloopCreate <base_dir>/<device ID>Write add [options] to /dev/zloop-controlOpen /dev/zloopX

Control device에 add command를 보내기까지의 최소 절차입니다.

Zoned device 제거와 복원

96-115

사용하지 않는 zoned loop block device를 제거하려면 `/dev/zloop-control`에 제거할 device ID를 지정한 `remove` command를 씁니다.

        $ echo "remove id=X" > /dev/zloop-control

`remove` command에는 다른 option이 없습니다. 제거한 device를 다시 추가하면 각 zone은 제거 직전 상태로 복원됩니다. 단, 최초 추가 때와 완전히 같은 configuration을 사용해야 합니다. Zone configuration 변경을 감지하면 error를 반환하고 device를 만들지 않습니다.

Device를 완전히 삭제하려면 `remove` operation 뒤에 zone backing file이 들어 있는 device base directory도 삭제해야 합니다.

Remove, restore, or fully delete
remove id=XBlock device disappearsKeep backing filesRe-add with identical configurationRestore prior zone states
remove id=XDelete device base directoryDevice fully deleted
Re-add with changed zone configurationConfiguration errorDevice not created

Control-plane 제거와 backing-file 삭제는 서로 다른 단계입니다.

2 GiB zoned device 예제

116-169

다음 명령은 전체 capacity 2 GiB, zone size 64 MiB, zone capacity 63 MiB인 zoned device를 만듭니다. 원문의 `add` 명령은 `zone_capacity=63MB`라고 적혀 있으며 이 표기를 그대로 보존합니다.

        $ modprobe zloop
        $ mkdir -p /var/local/zloop/0
        $ echo "add capacity_mb=2048,zone_size_mb=64,zone_capacity=63MB" > /dev/zloop-control

생성된 `/dev/zloop0`의 zone backing file은 모두 기본 base directory `/var/local/zloop/0` 아래에 생깁니다. `cnv-000000`부터 `cnv-000007`까지 conventional-zone file은 각각 67,108,864 byte(64 MiB)이고, 아직 비어 있는 `seq-000008` 이후 sequential-zone file은 크기가 0입니다.

        $ ls -l /var/local/zloop/0
        total 0
        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000000
        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000001
        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000002
        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000003
        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000004
        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000005
        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000006
        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000007
        -rw-------. 1 root root        0 Jan  6 22:23 seq-000008
        -rw-------. 1 root root        0 Jan  6 22:23 seq-000009
        ...
Example device and backing files
ItemValueInterpretation
Device/dev/zloop0Host-managed zoned block device
Total capacity2048 MiB32 zones at 64 MiB each
Zone size64 MiBZONE-SZ 64M
Zone capacity63 MiBSequential-zone cap 0x01f800
Conventional zones8cnv-000000 through cnv-000007
Sequential zones24seq-000008 onward

예제 설정과 생성 직후 file 상태입니다.

이 device는 일반 zoned block device처럼 사용할 수 있습니다. `lsblk -z`는 host-managed device, zone 32개, active/open 최대값 0, append granularity 1 MiB, write granularity 4 KiB를 보여 줍니다. `blkzone report`에서 앞 8개 zone은 `CONVENTIONAL`이고, 다음 zone은 capacity가 `0x01f800`인 `SEQ_WRITE_REQUIRED` empty zone입니다.

        $ lsblk -z
        NAME   ZONED        ZONE-SZ ZONE-NR ZONE-AMAX ZONE-OMAX ZONE-APP ZONE-WGRAN
        zloop0 host-managed     64M      32         0         0       1M         4K
        $ blkzone report /dev/zloop0
          start: 0x000000000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
          start: 0x000020000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
          start: 0x000040000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
          start: 0x000060000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
          start: 0x000080000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
          start: 0x0000a0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
          start: 0x0000c0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
          start: 0x0000e0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
          start: 0x000100000, len 0x020000, cap 0x01f800, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em) [type: 2(SEQ_WRITE_REQUIRED)]
          start: 0x000120000, len 0x020000, cap 0x01f800, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em) [type: 2(SEQ_WRITE_REQUIRED)]
          ...

Device를 제거할 때는 ID 0으로 `remove` command를 보냅니다.

        $ echo "remove id=0" > /dev/zloop-control

제거한 device는 처음과 같은 `add` command로 다시 추가할 수 있습니다. 완전히 삭제하려면 `remove` 뒤 backing file directory도 삭제합니다.

        $ rm -r /var/local/zloop/0
Example lifecycle
modprobe zloopmkdir /var/local/zloop/0add 2 GiB deviceInspect with lsblk -z and blkzoneremove id=0
Keep /var/local/zloop/0Re-add same configuration
rm -r /var/local/zloop/0Delete backing storage

생성·검사·제거·완전 삭제 명령의 관계입니다.