天天看點

Ext4 Fast Commit概述如何使用性能測試Reference

概述

Fast Commit 是 Linux 5.10 引入的一個新的輕量級日志方案,根據 ATC-17 的論文 “iJournaling: Fine-Grained Journaling for Improving the Latency of Fsync System Call” 實作。

在我們常用的 ext4 data=ordered 日志模式下,fsync() 系統調用會因為無關 IO 操作導緻顯著的時延。Fast Commit 根據寫入日志中的中繼資料反推,隻送出與目前 transaction 相關的操作,進而優化 fsync() 的時延。

啟用 Fast Commit 特性後,系統中将會有兩個日志,快速送出日志用于可以優化的操作,正常日志用于标準送出。其中 Fast Commit 日志包含上一次标準送出之後執行的操作。

從作者的 benchmark 測試資料來看,打開 Fast Commit 特性後,本地 ext4 檔案系統有 20% ~ 200% 的性能提升;NFS 場景也有 30% ~ 75% 的性能提升。

Benchmark Config w/o Fast Commit w/ Fast Commit Delta
Fsmark

Local, 8 threads

NFS, 4 threads

1475.1 files/s

299.4 files/s

4309.8 files/s

409.45 files/s

+192.2%

+36.8%

Dbench

Local, 2 procs

NFS, 2 procs

33.32 MB/s

8.84 MB/s

70.87 MB/s

11.88 MB/s

+112.7%

+34.4%

Local, 10 procs

NFS, 10 procs

90.48 MB/s

34.62 MB/s

110.12 MB/s

52.83 MB/s

+21.7%

+52.6%

FileBench

Local, 16 threads

NFS, 16 threads

10442.3 ops/s

1531.3 ops/s

18617.8 ops/s

2681.5 ops/s

+78.3%

+75.1%

如何使用

Alibaba Cloud Linux 3 / Ali5000 已經更新到 Linux 5.10 核心,是以核心預設已經支援 Fast Commit 特性。

但目前預設安裝的 e2fsprogs 版本為 1.45.6,從 e2fsprogs 上遊送出記錄來看,需要 1.46.0 版本才支援 Fast Commit,是以目前在 Alibaba Cloud Linux 3 / Ali5000 中還不能直接使用該特性。

1、下載下傳最新的 e2fsprogs 包并編譯。

wget https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/snapshot/e2fsprogs-1.46.2.tar.gz
tar -xvf e2fsprogs-1.46.2.tar.gz
cd e2fsprogs-1.46.2
./configure
make           

2、格式化打開 fast commit 特性。

./misc/mke2fs -t ext4 -O fast_commit /dev/vdc1           

dumpe2fs 可以看到已經打開 fast commit:

Filesystem features: has_journal ext_attr resize_inode dir_index fast_commit filetype extent 64bit flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize

此外,超級塊中多出 Overhead blocks 字段:

Overhead blocks: 126828

同時,Journal size 也由預設的 128M 變成 130M,應該是預設 fast commit journal size 為 journal size / 64 帶來的增量:

Journal size: 130M

性能測試

在 Alibaba Cloud Linux 3 中使用 fs_mark 對比測試結果顯示,性能有 1 倍以上的提升,表明在頻繁 fsync() 場景的确有很大性能提升,對資料庫 MySQL/PostgreSQL 等場景會有較大的性能優化。

測試指令為 2 線程:

./fs_mark  -d  /mnt/vdc1/testdir1/  -d  /mnt/vdc1/testdir2/  -D  16  -N  256  -n  409600  -L  1  -S  1  -s  4096           

測試結果(data=ordered, barrier):

Test Round
Round 1 5528.5 11448.1 +107.07%
Round 2 5512.3 11499.9 +108.62%

測試結果(data=writeback, nobarrier):

7976.0 18437.4 +131.16%
8005.2 18471.0 +130.74%

Reference

ATC-17 論文:

https://www.usenix.org/system/files/conference/atc17/atc17-park.pdf

LWN 文章:

https://lwn.net/Articles/842385/