blog.stackframe.dev

라즈베리파이4 cryptsetup 벤치마크

지금까지 라즈베리파이를 사용하면서 더 빠른 처리 속도를 뽑아내는걸 추구해왔다. 그래서 매 번 새로운 버전이 출시 될 때마다 사고 MicroSD 대신 샌디스크의 Extreme Pro USB를 사용하고 쿨링팬도 장착하는 등 최대한 성능을 뽑아먹을 수 있게 투자했다. 이것으로 꽤 괜찮은 퍼포먼스를 보여주었지만 IO 액세스 대역폭이 Extreme Pro가 광고하는 400MB/s도 나오지 않는 문제가 있었다.

사실 나의 모든 시스템들은 LUKS로 암호화가 되어있다. 그래서 디스크 IO가 발생한다면 암,복호화가 이루어지는데 라즈베리파이는 이게 느려서 결국 USB 성능을 제대로 활용하지 못하는 것이었다. 아래는 cryptsetup의 벤치마크를 돌린 결과이다:

$ cryptsetup benchmark
# Tests are approximate using memory only (no storage IO).
PBKDF2-sha1       403298 iterations per second for 256-bit key
PBKDF2-sha256     649675 iterations per second for 256-bit key
PBKDF2-sha512     516031 iterations per second for 256-bit key
PBKDF2-ripemd160  335651 iterations per second for 256-bit key
PBKDF2-whirlpool  125307 iterations per second for 256-bit key
argon2i       4 iterations, 321549 memory, 4 parallel threads (CPUs) for 256-bit key (requested 2000 ms time)
argon2id      4 iterations, 320139 memory, 4 parallel threads (CPUs) for 256-bit key (requested 2000 ms time)
#     Algorithm |       Key |      Encryption |      Decryption
        aes-cbc        128b        78.0 MiB/s        80.9 MiB/s
    serpent-cbc        128b        35.3 MiB/s        37.0 MiB/s
    twofish-cbc        128b        56.0 MiB/s        57.9 MiB/s
        aes-cbc        256b        62.2 MiB/s        64.1 MiB/s
    serpent-cbc        256b        35.2 MiB/s        37.0 MiB/s
    twofish-cbc        256b        56.0 MiB/s        57.8 MiB/s
        aes-xts        256b        88.2 MiB/s        89.7 MiB/s
    serpent-xts        256b        38.0 MiB/s        38.6 MiB/s
    twofish-xts        256b        63.5 MiB/s        62.1 MiB/s
        aes-xts        512b        68.6 MiB/s        69.4 MiB/s
    serpent-xts        512b        38.0 MiB/s        38.6 MiB/s
    twofish-xts        512b        63.5 MiB/s        62.1 MiB/s

현재 내가 사용하는 알고리즘은 AES-XTS 512비트인데 벤치마크 결과에서 약 70MB/s 정도의 대역폭을 낸다고 한다. 참고로 아래는 내 노트북에서 실행한 결과이다:

$ cryptsetup benchmark
# Tests are approximate using memory only (no storage IO).
PBKDF2-sha1      3134756 iterations per second for 256-bit key
PBKDF2-sha256    5077849 iterations per second for 256-bit key
PBKDF2-sha512    1989707 iterations per second for 256-bit key
PBKDF2-ripemd160 1149754 iterations per second for 256-bit key
PBKDF2-whirlpool  810336 iterations per second for 256-bit key
argon2i       9 iterations, 1048576 memory, 4 parallel threads (CPUs) for 256-bit key (requested 2000 ms time)
argon2id      9 iterations, 1048576 memory, 4 parallel threads (CPUs) for 256-bit key (requested 2000 ms time)
#     Algorithm |       Key |      Encryption |      Decryption
        aes-cbc        128b      1745.6 MiB/s      6648.3 MiB/s
    serpent-cbc        128b       116.5 MiB/s       771.5 MiB/s
    twofish-cbc        128b       277.0 MiB/s       497.2 MiB/s
        aes-cbc        256b      1339.6 MiB/s      5334.6 MiB/s
    serpent-cbc        256b       117.6 MiB/s       773.2 MiB/s
    twofish-cbc        256b       281.3 MiB/s       500.8 MiB/s
        aes-xts        256b      5387.1 MiB/s      5382.1 MiB/s
    serpent-xts        256b       737.5 MiB/s       700.7 MiB/s
    twofish-xts        256b       466.4 MiB/s       470.4 MiB/s
        aes-xts        512b      4774.2 MiB/s      4733.9 MiB/s
    serpent-xts        512b       742.9 MiB/s       701.0 MiB/s
    twofish-xts        512b       468.3 MiB/s       469.8 MiB/s

노트북의 결과를 보면 AES 알고리즘인 경우 같은 키 크기의 다른 알고리즘보다 매우 빠르게 처리되는 것을 볼 수 있다. 이것은 CPU에서 AES 가속을 지원하기 때문이다. x86 CPU의 /proc/cpuinfo를 보면 flagsaes가 들어 있다.

넷째 줄 중간에 aes가 들어있다.

그런데 라즈베리파이는 해당 기능이 빠져있어 하드웨어 가속 없이 오직 CPU만으로 연산하고 이마저도 CPU 성능이 낮기 때문에 다같이 느리다. ARM CPU에도 ARMv8-A부터 Cryptographic Extension이라고 하드웨어 가속을 지원하는 기능을 넣을 수 있지만 라즈베리파이는 가격 절감을 위해 해당 기능이 빠진 칩셋을 사용중이다.

라즈베리파이 재단의 비전을 생각하면 앞으로 나올 버전에도 AES 가속이 추가될 것 같진 않으니 셀러론 CPU를 탑재한 mini PC나 다른 SBC 중에서 AES 가속 기능을 가진 것을 사야 확실하게 성능을 개선할 수 있을 것 같다.

댓글