Skip to content

Commit 30feff8

Browse files
committed
Add BLAKE3 support to OpenZFS
Add another checksum to OpenZFS that has similar performance to Edon-R, but without the caveats around the latter. Add micro benchmarking for all advanced hashing functions like it's done for fletcher-4. Linux statistics are here: '/proc/spl/kstat/zfs/chksum_bench' ''' 20 0 0x01 -1 0 865606240142 1529555928674 implementation 1k 4k 16k 64k 256k 1m 4m fletcher-4 4772 13872 25625 32300 34418 33477 20507 edonr-generic 1240 1600 1750 1749 1741 1751 1750 skein-generic 548 600 612 618 618 611 615 sha256-generic 284 309 318 319 320 294 320 sha512-generic 404 461 481 485 484 484 485 blake3-generic 295 302 302 302 298 298 298 blake3-sse2 356 1272 1434 1470 1469 1471 1436 blake3-sse41 425 1368 1626 1694 1703 1676 1651 blake3-avx2 423 1895 3112 3346 3391 3372 3189 blake3-avx512 457 2668 5029 5833 6013 5891 5504 ''' FreeBSD statistics via 'sysctl -n kstat.zfs.misc.chksum_bench' ''' implementation 1k 4k 16k 64k 256k 1m 4m fletcher-4 2995 8686 18052 25044 27950 28649 17091 edonr-generic 1273 1609 1693 1704 1738 1714 1729 skein-generic 219 233 235 236 236 235 236 sha256-generic 259 275 283 281 283 283 282 sha512-generic 380 419 437 445 445 445 444 blake3-generic 518 514 509 516 519 515 508 blake3-sse2 272 1203 1298 1320 1345 1329 1311 ... ''' The units are MiB/s for each method. TODO Split up the patch into into patchset with multiple parts. Signed-off-by: Rich Ercolani <[email protected]> Signed-off-by: Tino Reichardt <[email protected]>
1 parent 1135d0a commit 30feff8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+12034
-15
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ CONTRIBUTORS:
285285
Tim Connors <[email protected]>
286286
Tim Crawford <[email protected]>
287287
Tim Haley <[email protected]>
288+
Tino Reichardt <[email protected]>
288289
Tobin Harding <[email protected]>
289290
Tom Caputi <[email protected]>
290291
Tom Matthews <[email protected]>

include/os/freebsd/spl/sys/ccompile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ extern "C" {
7777

7878
#ifndef LOCORE
7979
#ifndef HAVE_RPC_TYPES
80+
#ifndef _KERNEL
8081
typedef int bool_t;
8182
typedef int enum_t;
8283
#endif
8384
#endif
85+
#endif
8486

8587
#ifndef __cplusplus
8688
#define __init

include/sys/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ COMMON_H = \
99
avl.h \
1010
avl_impl.h \
1111
bitops.h \
12+
blake3.h \
1213
blkptr.h \
1314
bplist.h \
1415
bpobj.h \
@@ -104,6 +105,7 @@ COMMON_H = \
104105
zfs_acl.h \
105106
zfs_bootenv.h \
106107
zfs_context.h \
108+
zfs_chksum.h \
107109
zfs_debug.h \
108110
zfs_delay.h \
109111
zfs_file.h \

include/sys/blake3.h

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
2+
/*
3+
* CDDL HEADER START
4+
*
5+
* The contents of this file are subject to the terms of the
6+
* Common Development and Distribution License, Version 1.0 only
7+
* (the "License"). You may not use this file except in compliance
8+
* with the License.
9+
*
10+
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11+
* or http://www.opensolaris.org/os/licensing.
12+
* See the License for the specific language governing permissions
13+
* and limitations under the License.
14+
*
15+
* When distributing Covered Code, include this CDDL HEADER in each
16+
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17+
* If applicable, add the following below this CDDL HEADER, with the
18+
* fields enclosed by brackets "[]" replaced with your own identifying
19+
* information: Portions Copyright [yyyy] [name of copyright owner]
20+
*
21+
* CDDL HEADER END
22+
*/
23+
24+
/*
25+
* Based on BLAKE3 v1.2.0, https://github.com/BLAKE3-team/BLAKE3
26+
* Copyright (c) 2019-2020 Samuel Neves and Jack O'Connor
27+
* Copyright (c) 2021 Tino Reichardt <[email protected]>
28+
*/
29+
30+
#ifndef BLAKE3_H
31+
#define BLAKE3_H
32+
33+
#ifdef _KERNEL
34+
#include <sys/types.h>
35+
#else
36+
#include <stdint.h>
37+
#include <stdlib.h>
38+
#endif
39+
40+
#ifdef __cplusplus
41+
extern "C" {
42+
#endif
43+
44+
#define BLAKE3_KEY_LEN 32
45+
#define BLAKE3_OUT_LEN 32
46+
#define BLAKE3_MAX_DEPTH 54
47+
#define BLAKE3_BLOCK_LEN 64
48+
#define BLAKE3_CHUNK_LEN 1024
49+
50+
/*
51+
* This struct is a private implementation detail.
52+
* It has to be here because it's part of BLAKE3_CTX below.
53+
*/
54+
typedef struct {
55+
uint32_t cv[8];
56+
uint64_t chunk_counter;
57+
uint8_t buf[BLAKE3_BLOCK_LEN];
58+
uint8_t buf_len;
59+
uint8_t blocks_compressed;
60+
uint8_t flags;
61+
} blake3_chunk_state_t;
62+
63+
typedef struct {
64+
uint32_t key[8];
65+
blake3_chunk_state_t chunk;
66+
uint8_t cv_stack_len;
67+
68+
/*
69+
* The stack size is MAX_DEPTH + 1 because we do lazy merging. For
70+
* example, with 7 chunks, we have 3 entries in the stack. Adding an
71+
* 8th chunk requires a 4th entry, rather than merging everything down
72+
* to 1, because we don't know whether more input is coming. This is
73+
* different from how the reference implementation does things.
74+
*/
75+
uint8_t cv_stack[(BLAKE3_MAX_DEPTH + 1) * BLAKE3_OUT_LEN];
76+
} BLAKE3_CTX;
77+
78+
/* init the context for hash operation */
79+
void Blake3_Init(BLAKE3_CTX *ctx);
80+
81+
/* init the context for a MAC and/or tree hash operation */
82+
void Blake3_InitKeyed(BLAKE3_CTX *ctx, const uint8_t key[BLAKE3_KEY_LEN]);
83+
84+
/* process the input bytes */
85+
void Blake3_Update(BLAKE3_CTX *ctx, const void *input, size_t input_len);
86+
87+
/* finalize the hash computation and output the result */
88+
void Blake3_Final(const BLAKE3_CTX *ctx, uint8_t *out);
89+
90+
/* finalize the hash computation and output the result */
91+
void Blake3_FinalSeek(const BLAKE3_CTX *ctx, uint64_t seek, uint8_t *out,
92+
size_t out_len);
93+
94+
/*
95+
* Returns the number of supported BLAKE3 implementations
96+
*/
97+
extern int blake3_get_impl_count(void);
98+
99+
/*
100+
* Returns the name of selected BLAKE3 implementation
101+
*/
102+
extern const char *blake3_get_impl_name(void);
103+
104+
/*
105+
* Set BLAKE3 implementation via id or name
106+
*/
107+
extern void blake3_set_impl_id(int id);
108+
extern void blake3_set_impl_name(char *name);
109+
110+
#ifdef __cplusplus
111+
}
112+
#endif
113+
114+
#endif /* BLAKE3_H */

include/sys/zfs_chksum.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
/*
3+
* CDDL HEADER START
4+
*
5+
* The contents of this file are subject to the terms of the
6+
* Common Development and Distribution License (the "License").
7+
* You may not use this file except in compliance with the License.
8+
*
9+
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10+
* or http://www.opensolaris.org/os/licensing.
11+
* See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*
14+
* When distributing Covered Code, include this CDDL HEADER in each
15+
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16+
* If applicable, add the following below this CDDL HEADER, with the
17+
* fields enclosed by brackets "[]" replaced with your own identifying
18+
* information: Portions Copyright [yyyy] [name of copyright owner]
19+
*
20+
* CDDL HEADER END
21+
*/
22+
23+
/*
24+
* Copyright (c) 2021 Tino Reichardt <[email protected]>
25+
*/
26+
27+
#ifndef _ZFS_CHKSUM_H
28+
#define _ZFS_CHKSUM_H
29+
30+
#ifdef _KERNEL
31+
#include <sys/types.h>
32+
#else
33+
#include <stdint.h>
34+
#include <stdlib.h>
35+
#endif
36+
37+
#ifdef __cplusplus
38+
extern "C" {
39+
#endif
40+
41+
/* Benchmark the chksums of ZFS when the module is loading */
42+
void chksum_init(void);
43+
void chksum_fini(void);
44+
45+
#ifdef __cplusplus
46+
}
47+
#endif
48+
49+
#endif /* _ZFS_CHKSUM_H */

include/sys/zfs_ioctl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ typedef enum drr_headertype {
124124
* default use of "zfs send" won't encounter the bug mentioned above.
125125
*/
126126
#define DMU_BACKUP_FEATURE_SWITCH_TO_LARGE_BLOCKS (1 << 27)
127+
#define DMU_BACKUP_FEATURE_BLAKE3 (1 << 28)
127128

128129
/*
129130
* Mask of all supported backup features
@@ -134,7 +135,7 @@ typedef enum drr_headertype {
134135
DMU_BACKUP_FEATURE_COMPRESSED | DMU_BACKUP_FEATURE_LARGE_DNODE | \
135136
DMU_BACKUP_FEATURE_RAW | DMU_BACKUP_FEATURE_HOLDS | \
136137
DMU_BACKUP_FEATURE_REDACTED | DMU_BACKUP_FEATURE_SWITCH_TO_LARGE_BLOCKS | \
137-
DMU_BACKUP_FEATURE_ZSTD)
138+
DMU_BACKUP_FEATURE_ZSTD | DMU_BACKUP_FEATURE_BLAKE3)
138139

139140
/* Are all features in the given flag word currently supported? */
140141
#define DMU_STREAM_SUPPORTED(x) (!((x) & ~DMU_BACKUP_FEATURE_MASK))

include/sys/zio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ enum zio_checksum {
8989
ZIO_CHECKSUM_SHA512,
9090
ZIO_CHECKSUM_SKEIN,
9191
ZIO_CHECKSUM_EDONR,
92+
ZIO_CHECKSUM_BLAKE3,
9293
ZIO_CHECKSUM_FUNCTIONS
9394
};
9495

include/sys/zio_checksum.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
/*
2222
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2323
* Copyright (c) 2014, 2016 by Delphix. All rights reserved.
24-
* Copyright Saso Kiselkov 2013, All rights reserved.
24+
* Copyright (c) 2013 Saso Kiselkov, All rights reserved.
25+
* Copyright (c) 2021 Tino Reichardt <[email protected]>
2526
*/
2627

2728
#ifndef _SYS_ZIO_CHECKSUM_H
@@ -107,6 +108,13 @@ _SYS_ZIO_CHECKSUM_H zio_checksum_info_t
107108
/*
108109
* Checksum routines.
109110
*/
111+
112+
/* Fletcher 4 */
113+
extern zio_abd_checksum_func_t fletcher_4_abd_ops;
114+
extern zio_checksum_t abd_fletcher_4_native;
115+
extern zio_checksum_t abd_fletcher_4_byteswap;
116+
117+
/* SHA2 */
110118
extern zio_checksum_t abd_checksum_SHA256;
111119
extern zio_checksum_t abd_checksum_SHA512_native;
112120
extern zio_checksum_t abd_checksum_SHA512_byteswap;
@@ -123,6 +131,12 @@ extern zio_checksum_t abd_checksum_edonr_byteswap;
123131
extern zio_checksum_tmpl_init_t abd_checksum_edonr_tmpl_init;
124132
extern zio_checksum_tmpl_free_t abd_checksum_edonr_tmpl_free;
125133

134+
/* BLAKE3 */
135+
extern zio_checksum_t abd_checksum_blake3_native;
136+
extern zio_checksum_t abd_checksum_blake3_byteswap;
137+
extern zio_checksum_tmpl_init_t abd_checksum_blake3_tmpl_init;
138+
extern zio_checksum_tmpl_free_t abd_checksum_blake3_tmpl_free;
139+
126140
_SYS_ZIO_CHECKSUM_H zio_abd_checksum_func_t fletcher_4_abd_ops;
127141
extern zio_checksum_t abd_fletcher_4_native;
128142
extern zio_checksum_t abd_fletcher_4_byteswap;

include/zfeature_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ typedef enum spa_feature {
7575
SPA_FEATURE_DEVICE_REBUILD,
7676
SPA_FEATURE_ZSTD_COMPRESS,
7777
SPA_FEATURE_DRAID,
78+
SPA_FEATURE_BLAKE3,
7879
SPA_FEATURES
7980
} spa_feature_t;
8081

lib/libicp/Makefile.am

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,26 @@ ASM_SOURCES_C = asm-x86_64/aes/aeskey.c
1414
ASM_SOURCES_AS = \
1515
asm-x86_64/aes/aes_amd64.S \
1616
asm-x86_64/aes/aes_aesni.S \
17+
asm-x86_64/blake3/blake3_avx2.S \
18+
asm-x86_64/blake3/blake3_avx512.S \
19+
asm-x86_64/blake3/blake3_sse2.S \
20+
asm-x86_64/blake3/blake3_sse41.S \
1721
asm-x86_64/modes/gcm_pclmulqdq.S \
1822
asm-x86_64/modes/aesni-gcm-x86_64.S \
1923
asm-x86_64/modes/ghash-x86_64.S \
2024
asm-x86_64/sha1/sha1-x86_64.S \
2125
asm-x86_64/sha2/sha256_impl.S \
2226
asm-x86_64/sha2/sha512_impl.S
27+
else
28+
if TARGET_CPU_AARCH64
29+
ASM_SOURCES_C =
30+
ASM_SOURCES_AS = \
31+
asm-aarch64/blake3/blake3_neon.S
2332
else
2433
ASM_SOURCES_C =
2534
ASM_SOURCES_AS =
2635
endif
36+
endif
2737

2838
KERNEL_C = \
2939
spi/kcf_spi.c \
@@ -37,6 +47,11 @@ KERNEL_C = \
3747
algs/aes/aes_impl_x86-64.c \
3848
algs/aes/aes_impl.c \
3949
algs/aes/aes_modes.c \
50+
algs/blake3/blake3.c \
51+
algs/blake3/blake3_generic.c \
52+
algs/blake3/blake3_impl.c \
53+
algs/blake3/blake3_neon.c \
54+
algs/blake3/blake3_x86-64.c \
4055
algs/edonr/edonr.c \
4156
algs/modes/modes.c \
4257
algs/modes/cbc.c \

lib/libzfs/libzfs.abi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@
599599
<elf-symbol name='fletcher_4_superscalar_ops' size='64' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
600600
<elf-symbol name='libspl_assert_ok' size='4' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
601601
<elf-symbol name='libzfs_config_ops' size='16' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
602-
<elf-symbol name='spa_feature_table' size='1904' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
602+
<elf-symbol name='spa_feature_table' size='1960' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
603603
<elf-symbol name='zfeature_checks_disable' size='4' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
604604
<elf-symbol name='zfs_deleg_perm_tab' size='512' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
605605
<elf-symbol name='zfs_history_event_names' size='328' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
@@ -1862,8 +1862,8 @@
18621862
</function-decl>
18631863
</abi-instr>
18641864
<abi-instr address-size='64' path='../../module/zcommon/zfeature_common.c' language='LANG_C99'>
1865-
<array-type-def dimensions='1' type-id='83f29ca2' size-in-bits='15232' id='d96379d0'>
1866-
<subrange length='34' type-id='7359adad' id='6a6a7e00'/>
1865+
<array-type-def dimensions='1' type-id='83f29ca2' size-in-bits='15680' id='d96379d0'>
1866+
<subrange length='35' type-id='7359adad' id='6a6a7e00'/>
18671867
</array-type-def>
18681868
<enum-decl name='spa_feature' id='33ecb627'>
18691869
<underlying-type type-id='9cac1fee'/>
@@ -1902,7 +1902,8 @@
19021902
<enumerator name='SPA_FEATURE_DEVICE_REBUILD' value='31'/>
19031903
<enumerator name='SPA_FEATURE_ZSTD_COMPRESS' value='32'/>
19041904
<enumerator name='SPA_FEATURE_DRAID' value='33'/>
1905-
<enumerator name='SPA_FEATURES' value='34'/>
1905+
<enumerator name='SPA_FEATURE_BLAKE3' value='34'/>
1906+
<enumerator name='SPA_FEATURES' value='35'/>
19061907
</enum-decl>
19071908
<typedef-decl name='spa_feature_t' type-id='33ecb627' id='d6618c78'/>
19081909
<enum-decl name='zfeature_flags' id='6db816a4'>

lib/libzpool/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ KERNEL_C = \
5454
aggsum.c \
5555
arc.c \
5656
arc_os.c \
57+
blake3_zfs.c \
5758
blkptr.c \
5859
bplist.c \
5960
bpobj.c \
@@ -160,6 +161,7 @@ KERNEL_C = \
160161
zcp_synctask.c \
161162
zfeature.c \
162163
zfs_byteswap.c \
164+
zfs_chksum.c \
163165
zfs_debug.c \
164166
zfs_fm.c \
165167
zfs_fuid.c \

man/man7/zfsprops.7

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ This property is not inherited.
743743
.It Xo
744744
.Sy checksum Ns = Ns Sy on Ns | Ns Sy off Ns | Ns Sy fletcher2 Ns | Ns
745745
.Sy fletcher4 Ns | Ns Sy sha256 Ns | Ns Sy noparity Ns | Ns
746-
.Sy sha512 Ns | Ns Sy skein Ns | Ns Sy edonr
746+
.Sy sha512 Ns | Ns Sy skein Ns | Ns Sy edonr Ns | Ns Sy blake3
747747
.Xc
748748
Controls the checksum used to verify data integrity.
749749
The default value is
@@ -768,6 +768,7 @@ a recommended practice.
768768
The
769769
.Sy sha512 ,
770770
.Sy skein ,
771+
.Sy blake3 ,
771772
and
772773
.Sy edonr
773774
checksum algorithms require enabling the appropriate features on the pool.
@@ -981,7 +982,7 @@ mount options.
981982
.It Xo
982983
.Sy dedup Ns = Ns Sy off Ns | Ns Sy on Ns | Ns Sy verify Ns | Ns
983984
.Sy sha256 Ns Oo , Ns Sy verify Oc Ns | Ns Sy sha512 Ns Oo , Ns Sy verify Oc Ns | Ns Sy skein Ns Oo , Ns Sy verify Oc Ns | Ns
984-
.Sy edonr , Ns Sy verify
985+
.Sy edonr , Ns Sy verify Ns | Ns Sy blake3 Ns Oo , Ns Sy verify Oc Ns
985986
.Xc
986987
Configures deduplication for a dataset.
987988
The default value is

0 commit comments

Comments
 (0)