f2fs 파일시스템 fsync mode : posix, strict, nobarrier

2023. 8. 21. 16:52파일시스템

fsync 연산은 데이터와 데이터를 가리키는 direct node만을 쓴다. 따라서 fsync만으로는 데이터의 consistency를 보장할 수 없다. 

 

fsync consistency

NAND 상에서 node write가 먼저 일어나고 data write이 일어나는 도중에 crash가 일어나는 상황을 가정해보자. 이 때 데이터의 consistency는 무너지게 된다.

 

 

이를 해결하기 위한 방법은 두가지가 있다.

 

1. roll forward recovery

2. fsync with strict mode

 

 

먼저 roll forward recovery를 보자.

 

 

f2fs 파일 시스템은 시스템 크래쉬가 일어났을 때 roll-back recovery를 진행한 후에 roll-forward recovery를 진행한다.

 

롤백 리커버리는 체크포인트 팩을 보고 가장 최근 저장된 시점으로 돌리는 것이고, 롤 포워드 리커버리는 그 이후에 진행된 fsync연산에 대해서 노드 블락의 값을 변경해주는 것이다.

 

roll forward 방식의 구체적인 내용은 아래를 보면 이해가 쉽다.

F2FS performs roll-forward recovery as follows. If we denote the log position of the last stable checkpoint as N, (1) F2FS collects the direct node blocks having the special flag located in N+n, while constructing a list of their node information. n refers to the number of blocks updated since the last checkpoint. (2) By using the node information in the list, it loads the most recently written node blocks, named N-n, into the page cache. (3) Then, it compares the data indices in between N-n and N+n. (4) If it detects different data indices, then it refreshes the cached node blocks with the new indices stored in N+n, and finally marks them as dirty. Once completing the roll-forward recovery, F2FS performs checkpointing to store the whole in-memory changes to the disk.

 

 

두번째는 fsync strict mode를 사용해서 노드가 데이터가 쓰인 이후로 쓰이게 해서 노드가 가리키는 데이터는 항상 valid하게 만들어주는 방식이다.

 

 

물론 이 방식은 fsync하는데 걸리는 시간을 크게 증가 시킨다.

 

f2fs 파일시스템의 fsync 모드에는 posix, strict, nobarrier 모드가 있다.

 

각각에 대해서 f2fs man 페이지를 보자.

 

fsync_mode=%s
: Control the policy of fsync. Currently supports "posix", "strict", and "nobarrier". In "posix" mode, which is default, fsync will follow POSIX semantics and does a light operation to improve the filesystem performance. In "strict" mode, fsync will be heavy and behaves in line with xfs, ext4 and btrfs, where xfstest generic/342 will pass, but the performance will regress. "nobarrier" is based on "posix", but doesn't issue flush command for non-atomic files likewise "nobarrier" mount option.

 

라고 기술되어 있다.

 

fsync - posix, nobarrier

 

fsync를 수행하면 먼저 data block이 dma를 통해 보내지고 dma가 완료되고 나면 node가 보내지게 된다.

 

 

dma 완료에 대한 리턴이 오면 POSIX 모드는 flush 명령어를 사용해서 durability를 보장한다. 이 때 flush는 NAND에 적히는 것을 보장하는 것이다.

 

 

PLP(power loss protection)을 지원하는 디바이스의 경우 DMA transfer이 끝나게 되면 데이터에 대한 persistence가 보장된다고 한다.  따라서 PLP 기능이 지원되는 디바이스의 경우 nobarrier 옵션을 많이 사용한다고 한다.

 

 

f2fs strict mode

 

 

f2fs strict mode는 마지막 노드 블락 이전에 flush 명령어를 두어서 노드 블락이 그 이전에 있는 모든 블락이 적히기 이전에 적히지 않게 하는 것을 보장하는 것이다.

 

 

 

 

'파일시스템' 카테고리의 다른 글

stackless coroutine 스택리스 코루틴  (0) 2023.10.15