← Documents Documentation/block/writeback_cache_control.rst GitHub 원문 ↗

Linux 6.18.37 · Block

Explicit volatile write back cache control

volatile writeback cache의 durability를 보장하는 REQ_PREFLUSH·REQ_FUA와 block driver별 구현 규칙을 설명합니다.

Source pathDocumentation/block/writeback_cache_control.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약과 해설

writeback_cache_control.rst:1-95

volatile writeback cache는 completion latency를 줄이지만 전원 손실에 취약합니다. filesystem은 `REQ_PREFLUSH`로 이전 write를 먼저 안정 저장하고 `REQ_FUA`로 현재 write가 non-volatile media에 도달한 뒤 완료되게 합니다.

driver는 `BLK_FEAT_WRITE_CACHE`와 선택적인 `BLK_FEAT_FUA`로 capability를 알립니다. block layer는 native FUA가 없을 때 flush를 합성해 filesystem이 device별 차이를 직접 처리하지 않도록 합니다.

bio-based driver는 `BLK_FEAT_FUA` 설정 여부와 관계없이 전달될 수 있는 `REQ_FUA`를 처리해야 하고, remapping driver는 FUA 전파와 global preflush를 구현해야 합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 ==========================================
2 Explicit volatile write back cache control
3 ==========================================
4
5 Introduction
6 ------------
7
8 Many storage devices, especially in the consumer market, come with volatile
9 write back caches. That means the devices signal I/O completion to the
10 operating system before data actually has hit the non-volatile storage. This
11 behavior obviously speeds up various workloads, but it means the operating
12 system needs to force data out to the non-volatile storage when it performs
13 a data integrity operation like fsync, sync or an unmount.
14
15 The Linux block layer provides two simple mechanisms that let filesystems
16 control the caching behavior of the storage device. These mechanisms are
17 a forced cache flush, and the Force Unit Access (FUA) flag for requests.
18
19
20 Explicit cache flushes
21 ----------------------
22
23 The REQ_PREFLUSH flag can be OR ed into the r/w flags of a bio submitted from
24 the filesystem and will make sure the volatile cache of the storage device
25 has been flushed before the actual I/O operation is started. This explicitly
26 guarantees that previously completed write requests are on non-volatile
27 storage before the flagged bio starts. In addition the REQ_PREFLUSH flag can be
28 set on an otherwise empty bio structure, which causes only an explicit cache
29 flush without any dependent I/O. It is recommend to use
30 the blkdev_issue_flush() helper for a pure cache flush.
31
32
33 Forced Unit Access
34 ------------------
35
36 The REQ_FUA flag can be OR ed into the r/w flags of a bio submitted from the
37 filesystem and will make sure that I/O completion for this request is only
38 signaled after the data has been committed to non-volatile storage.
39
40
41 Implementation details for filesystems
42 --------------------------------------
43
44 Filesystems can simply set the REQ_PREFLUSH and REQ_FUA bits and do not have to
45 worry if the underlying devices need any explicit cache flushing and how
46 the Forced Unit Access is implemented. The REQ_PREFLUSH and REQ_FUA flags
47 may both be set on a single bio.
48
49 Feature settings for block drivers
50 ----------------------------------
51
52 For devices that do not support volatile write caches there is no driver
53 support required, the block layer completes empty REQ_PREFLUSH requests before
54 entering the driver and strips off the REQ_PREFLUSH and REQ_FUA bits from
55 requests that have a payload.
56
57 For devices with volatile write caches the driver needs to tell the block layer
58 that it supports flushing caches by setting the
59
60 BLK_FEAT_WRITE_CACHE
61
62 flag in the queue_limits feature field. For devices that also support the FUA
63 bit the block layer needs to be told to pass on the REQ_FUA bit by also setting
64 the
65
66 BLK_FEAT_FUA
67
68 flag in the features field of the queue_limits structure.
69
70 Implementation details for bio based block drivers
71 --------------------------------------------------
72
73 For bio based drivers the REQ_PREFLUSH and REQ_FUA bit are simply passed on to
74 the driver if the driver sets the BLK_FEAT_WRITE_CACHE flag and the driver
75 needs to handle them.
76
77 *NOTE*: The REQ_FUA bit also gets passed on when the BLK_FEAT_FUA flags is
78 _not_ set. Any bio based driver that sets BLK_FEAT_WRITE_CACHE also needs to
79 handle REQ_FUA.
80
81 For remapping drivers the REQ_FUA bits need to be propagated to underlying
82 devices, and a global flush needs to be implemented for bios with the
83 REQ_PREFLUSH bit set.
84
85 Implementation details for blk-mq drivers
86 -----------------------------------------
87
88 When the BLK_FEAT_WRITE_CACHE flag is set, REQ_OP_WRITE | REQ_PREFLUSH requests
89 with a payload are automatically turned into a sequence of a REQ_OP_FLUSH
90 request followed by the actual write by the block layer.
91
92 When the BLK_FEAT_FUA flags is set, the REQ_FUA bit is simply passed on for the
93 REQ_OP_WRITE request, else a REQ_OP_FLUSH request is sent by the block layer
94 after the completion of the write request for bio submissions with the REQ_FUA
95 bit set.
96

3. 한국어 전문 번역

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

Volatile writeback cache 제어

1-18

많은 storage device, 특히 consumer market의 device는 volatile writeback cache를 사용합니다. 실제 data가 non-volatile storage에 도달하기 전에 operating system에 I/O completion을 알리므로 여러 workload가 빨라집니다.

하지만 operating system은 `fsync`, `sync`, unmount 같은 data integrity operation을 수행할 때 cache의 data를 non-volatile storage로 강제로 내보내야 합니다.

Linux block layer는 filesystem이 storage device의 caching behavior를 제어하는 두 가지 간단한 mechanism을 제공합니다. 하나는 forced cache flush이고 다른 하나는 request의 Force Unit Access(FUA) flag입니다.

Explicit cache flush와 REQ_PREFLUSH

19-30

`REQ_PREFLUSH` flag는 filesystem이 제출하는 bio의 r/w flag에 OR할 수 있습니다. 실제 I/O operation을 시작하기 전에 storage device의 volatile cache를 flush하도록 보장합니다.

따라서 flag가 붙은 bio를 시작하기 전에 이전에 완료된 write request가 non-volatile storage에 존재함을 명시적으로 보장합니다.

`REQ_PREFLUSH`는 다른 내용이 없는 empty bio structure에도 설정할 수 있습니다. 그러면 dependent I/O 없이 explicit cache flush만 수행합니다. pure cache flush에는 `blkdev_issue_flush()` helper 사용을 권장합니다.

Forced Unit Access와 REQ_FUA

31-39

`REQ_FUA` flag는 filesystem이 제출하는 bio의 r/w flag에 OR할 수 있습니다. 해당 request의 data가 non-volatile storage에 commit된 뒤에만 I/O completion을 알리도록 보장합니다.

Filesystem 구현 규칙

40-47

filesystem은 `REQ_PREFLUSH`와 `REQ_FUA` bit를 설정하기만 하면 됩니다. underlying device가 explicit cache flush를 필요로 하는지, Forced Unit Access를 어떻게 구현하는지는 신경 쓰지 않아도 됩니다.

`REQ_PREFLUSH`와 `REQ_FUA` flag는 하나의 bio에 함께 설정할 수 있습니다.

Block driver feature 설정

48-68

volatile write cache를 지원하지 않는 device에는 driver 지원이 필요하지 않습니다. block layer는 empty `REQ_PREFLUSH` request를 driver에 들어가기 전에 완료하고, payload가 있는 request에서는 `REQ_PREFLUSH`와 `REQ_FUA` bit를 제거합니다.

volatile write cache가 있는 device의 driver는 cache flush를 지원한다고 block layer에 알리기 위해 queue_limits feature field에 다음 flag를 설정해야 합니다.

BLK_FEAT_WRITE_CACHE

FUA bit도 지원하는 device라면 block layer가 `REQ_FUA` bit를 전달하도록 queue_limits structure의 features field에 다음 flag도 설정해야 합니다.

BLK_FEAT_FUA

Bio-based·remapping driver 구현

69-83

bio-based driver가 `BLK_FEAT_WRITE_CACHE` flag를 설정하면 `REQ_PREFLUSH`와 `REQ_FUA` bit를 driver에 그대로 전달하며 driver가 이를 처리해야 합니다.

`BLK_FEAT_FUA` flag를 설정하지 않은 경우에도 `REQ_FUA` bit가 전달됩니다. `BLK_FEAT_WRITE_CACHE`를 설정하는 모든 bio-based driver는 `REQ_FUA`도 처리해야 합니다.

remapping driver는 `REQ_FUA` bit를 underlying device로 전파해야 하며, `REQ_PREFLUSH` bit가 설정된 bio에는 global flush를 구현해야 합니다.

blk-mq driver 구현

84-95

`BLK_FEAT_WRITE_CACHE` flag가 설정돼 있으면 payload가 있는 `REQ_OP_WRITE | REQ_PREFLUSH` request를 block layer가 자동으로 `REQ_OP_FLUSH` request 다음 실제 write가 오는 sequence로 바꿉니다.

`BLK_FEAT_FUA` flag가 설정돼 있으면 `REQ_OP_WRITE` request에 `REQ_FUA` bit를 그대로 전달합니다. 설정돼 있지 않으면 `REQ_FUA` bit가 붙은 bio submission의 write request가 완료된 뒤 block layer가 `REQ_OP_FLUSH` request를 보냅니다.