13.10 上的 Luks/dm-crypt 性能非常糟糕(华硕 Zenbook、SSD、支持 AES-NI)

13.10 上的 Luks/dm-crypt 性能非常糟糕(华硕 Zenbook、SSD、支持 AES-NI)

我有一台配备 124GB SSD 的笔记本电脑(华硕 Zenbook UX31A)。我在加密分区上安装了 Ubuntu,然后开始遇到暂时或永久无响应的情况。我怀疑是 I/O 的问题,并做了一些基准测试。

磁盘写入似乎非常慢:

➜  ~  dd if=/dev/zero of=tempfile bs=1M count=200 conv=fdatasync,notrunc
200+0 records in
200+0 records out
209715200 bytes (210 MB) copied, 8.2222 s, 25.5 MB/s

读起来还不错

➜  ~  echo 3 > /proc/sys/vm/drop_caches
➜  ~  dd if=tempfile of=/dev/null bs=1M count=200
200+0 records in
200+0 records out
209715200 bytes (210 MB) copied, 0.9317 s, 225 MB/s

我正在检查顶部iotop在执行写入时,注意到 CPU 负载没有明显增加。iotop 的“实际磁盘写入”在短时间内显示约为 200MB/s,然后立即降回 0(此后写入 dd 又运行了几秒钟)。

我有 Intel i7-3517U CPU,它支持 AES-NI,它也在 BIOS 中启用。AES-NI 内核模块似乎已启用:

➜  ~  lsmod | grep aes
aesni_intel            55624  376 
aes_x86_64             17131  1 aesni_intel
lrw                    13286  5 serpent_sse2_x86_64,aesni_intel,serpent_avx_x86_64,twofish_avx_x86_64,twofish_x86_64_3way
glue_helper            13990  5 serpent_sse2_x86_64,aesni_intel,serpent_avx_x86_64,twofish_avx_x86_64,twofish_x86_64_3way
ablk_helper            13597  4 serpent_sse2_x86_64,aesni_intel,serpent_avx_x86_64,twofish_avx_x86_64
cryptd                 20359  190 ghash_clmulni_intel,aesni_intel,ablk_helper

cryptsetup 基准测试看起来也不错:

➜  ~  ./workspace/cryptsetup-1.6.1/src/cryptsetup benchmark
# Tests are approximate using memory only (no storage IO).
PBKDF2-sha1       433295 iterations per second
PBKDF2-sha256     254508 iterations per second
PBKDF2-sha512     154021 iterations per second
PBKDF2-ripemd160  347671 iterations per second
PBKDF2-whirlpool  184608 iterations per second
#  Algorithm | Key |  Encryption |  Decryption
     aes-cbc   128b   516.9 MiB/s  1894.4 MiB/s
 serpent-cbc   128b    72.8 MiB/s   251.0 MiB/s
 twofish-cbc   128b   156.1 MiB/s   284.7 MiB/s
     aes-cbc   256b   368.2 MiB/s  1379.8 MiB/s
 serpent-cbc   256b    75.3 MiB/s   243.3 MiB/s
 twofish-cbc   256b   157.7 MiB/s   292.7 MiB/s
     aes-xts   256b  2376.0 MiB/s  3503.0 MiB/s
 serpent-xts   256b   307.7 MiB/s   264.2 MiB/s
 twofish-xts   256b   340.7 MiB/s   345.7 MiB/s
     aes-xts   512b  4548.0 MiB/s  4527.0 MiB/s
 serpent-xts   512b   315.1 MiB/s   265.0 MiB/s
 twofish-xts   512b   327.7 MiB/s   328.7 MiB/s

Cryptsetup 状态:

➜  ~  sudo cryptsetup status sda3_crypt
/dev/mapper/sda3_crypt is active and is in use.
  type:    LUKS1
  cipher:  aes-xts-plain64
  keysize: 512 bits
  device:  /dev/sda3
  offset:  4096 sectors
  size:    241291264 sectors
  mode:    read/write

SSD是SanDisk U100:

➜  ~  sudo lshw
...
 *-scsi:0
      physical id: 1
      logical name: scsi0
      capabilities: emulated
    *-disk
         description: ATA Disk
         product: SanDisk SSD U100
         physical id: 0.0.0
         bus info: scsi@0:0.0.0
         logical name: /dev/sda
         version: 10.5
         serial: 122300414449
         size: 115GiB (124GB)
         capabilities: gpt-1.00 partitioned partitioned:gpt
         configuration: ansiversion=5 guid=462c7bc0-c895-4486-a0de-9911664bdbf8 sectorsize=512
       *-volume:0
            description: Windows FAT volume
            vendor: mkdosfs
            physical id: 1
            bus info: scsi@0:0.0.0,1
            logical name: /dev/sda1
            logical name: /boot/efi
            version: FAT32
            serial: f767-aca8
            size: 189MiB
            capacity: 189MiB
            capabilities: boot fat initialized
            configuration: FATs=2 filesystem=fat mount.fstype=vfat mount.options=rw,noatime,nodiratime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro state=mounted
       *-volume:1
            description: data partition
            vendor: Linux
            physical id: 2
            bus info: scsi@0:0.0.0,2
            logical name: /dev/sda2
            logical name: /boot
            version: 1.0
            serial: 196c3925-113a-465a-b73e-b3506bf86401
            size: 244MiB
            capabilities: ext2 initialized
            configuration: filesystem=ext2 modified=2014-01-28 00:30:04 mount.fstype=ext2 mount.options=rw,noatime,nodiratime,errors=continue state=mounted
       *-volume:2
            description: data partition
            vendor: Windows
            physical id: 3
            bus info: scsi@0:0.0.0,3
            logical name: /dev/sda3
            serial: 4e2be2b7-d729-4e1f-912a-319533fa4e4b
            size: 115GiB
            capacity: 115GiB
            width: 512 bits
            capabilities: encrypted luks initialized
            configuration: bits=512 cipher=aes filesystem=luks hash=sha1 mode=xts-plain64 version=1

谢谢你!

答案1

事实证明,问题与加密完全无关。我需要fstrim在我的 SSD 分区上使用命令,discard并向我的 SSD 分区挂载添加选项。现在它可以按预期工作了。

相关内容