LUKS加密分割區的資料存取速度

LUKS加密分割區的資料存取速度

在Linux (Fedora 28) 中,我的主目錄LUKS 已加密,當使用Gnome Disk(螢幕截圖)時,我可以分別對底層LUKS 分割區(上方藍色矩形)和解密的主分割區(下方白色矩形)進行基準測試。

LUKS 分割區的存取時間為 500MB/s,但解密後的存取速度為 350MB/s。需要明確的是,這是 500GB SSD 的相同分割區。

得出這樣的結論是否公平加密資料存取速度是否減慢了 30% (= 150/500)?

這種類型的數字是否有記錄,或者我做錯了什麼。這比我預期的要慢得多。

截圖磁碟


編輯:這是我的輸出

$ cryptsetup benchmark
# Tests are approximate using memory only (no storage IO).
PBKDF2-sha1       384375 iterations per second for 256-bit key
PBKDF2-sha256     494611 iterations per second for 256-bit key
PBKDF2-sha512     323634 iterations per second for 256-bit key
PBKDF2-ripemd160  293225 iterations per second for 256-bit key
PBKDF2-whirlpool  185917 iterations per second for 256-bit key
argon2i       4 iterations, 748334 memory, 4 parallel threads (CPUs) for 256-bit key (requested 2000 ms time)
argon2id      4 iterations, 745443 memory, 4 parallel threads (CPUs) for 256-bit key (requested 2000 ms time)
#     Algorithm |       Key |      Encryption |      Decryption
        aes-cbc        128b       195.0 MiB/s       664.0 MiB/s
    serpent-cbc        128b        28.8 MiB/s        94.7 MiB/s
    twofish-cbc        128b        58.8 MiB/s       111.6 MiB/s
        aes-cbc        256b       146.5 MiB/s       507.3 MiB/s
    serpent-cbc        256b        33.3 MiB/s       110.2 MiB/s
    twofish-cbc        256b        59.3 MiB/s       123.6 MiB/s
        aes-xts        256b       433.7 MiB/s       416.8 MiB/s
    serpent-xts        256b       101.0 MiB/s        94.7 MiB/s
    twofish-xts        256b       111.8 MiB/s       110.3 MiB/s
        aes-xts        512b       349.5 MiB/s       356.6 MiB/s
    serpent-xts        512b       101.6 MiB/s        96.0 MiB/s
    twofish-xts        512b       111.2 MiB/s       108.1 MiB/s

$ lscpu | grep aes
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge 
mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall
 nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology
 nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est 
tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer
 aes xsave avx f16c rdrand lahf_lm cpuid_fault epb pti ssbd ibrs ibpb stibp
 tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm 
ida arat pln pts flush_l1d

2020 年編輯:我更換了計算機,並得到了完全不同的 crypto 基準測試結果,遠遠超出了更快的處理器所能解釋的範圍。所以,我認為我的舊硬體沒有專用的加密晶片:

$ cryptsetup benchmark
# Tests are approximate using memory only (no storage IO).
PBKDF2-sha1      1756408 iterations per second for 256-bit key
PBKDF2-sha256    2264742 iterations per second for 256-bit key
PBKDF2-sha512    1653905 iterations per second for 256-bit key
PBKDF2-ripemd160  949797 iterations per second for 256-bit key
PBKDF2-whirlpool  711381 iterations per second for 256-bit key
argon2i       8 iterations, 1048576 memory, 4 parallel threads (CPUs) for 256-bit key (requested 2000 ms time)
argon2id      8 iterations, 1048576 memory, 4 parallel threads (CPUs) for 256-bit key (requested 2000 ms time)
#     Algorithm |       Key |      Encryption |      Decryption
        aes-cbc        128b      1256.4 MiB/s      3669.2 MiB/s
    serpent-cbc        128b       101.6 MiB/s       771.8 MiB/s
    twofish-cbc        128b       230.0 MiB/s       418.4 MiB/s
        aes-cbc        256b       947.9 MiB/s      2961.6 MiB/s
    serpent-cbc        256b       105.1 MiB/s       785.0 MiB/s
    twofish-cbc        256b       235.7 MiB/s       424.5 MiB/s
        aes-xts        256b      2209.9 MiB/s      2218.9 MiB/s
    serpent-xts        256b       762.0 MiB/s       776.6 MiB/s
    twofish-xts        256b       415.7 MiB/s       384.0 MiB/s
        aes-xts        512b      1701.8 MiB/s      1677.2 MiB/s
    serpent-xts        512b       713.7 MiB/s       769.6 MiB/s
    twofish-xts        512b       407.9 MiB/s       414.2 MiB/s

答案1

加密會增加額外的 CPU 負載,因為每個磁碟區塊在存取時都需要由作業系統解密。對於 i7 上的通用 AES 處理,您的測試結果(~600 MB/s 解密)相當平均。

為了避免這個問題,現代 CPU 通常內建基於硬體的 AES 支援lscpu。 。

首先運行lscpu並檢查它是否在功能標誌中提到“aes”。這英特爾方舟顯示它存在於您的 CPU 型號中,但它可能會被韌體 (BIOS) 設定停用。 (方舟有一個註腳:“某些產品可以透過處理器配置更新支援 AES 新指令…請聯絡 OEM 以取得包含最新處理器配置更新的 BIOS。”

Linux 使用「aesni_intel」模組來啟用硬體加速。透過運行來檢查它是否在您的核心中啟用zgrep AES_NI_INTEL /proc/config.gz。如果它顯示“ =y”,則它是主核心映像的一部分並且應該可用。

如果輸出顯示“ =m”,則它已被編譯為模組 - 嘗試透過執行手動載入模組sudo modprobe -v aesni_intel。如果該命令無法找到該模組,您可能必須重新啟動。 (重新啟動後,請確保uname -r顯示與中相同的核心版本ls /lib/modules。)

相關內容