Skip to content

Commit

Permalink
Use Multi-buffer sha256 support from SPL
Browse files Browse the repository at this point in the history
If SPL is configured with multi-buffer hash, it will export a C
predefine marco HAVE_HASH_MB and C api mulbuf_sha256 to ZFS. Using
this api, performance of sha256 will be increased 2~7 times.

Signed-off-by: Xiaodong Liu <[email protected]>
Requires-spl: refs/pull/646/head
  • Loading branch information
dong-liuliu committed Aug 23, 2017
1 parent db4c1ad commit 8b83a54
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
24 changes: 24 additions & 0 deletions module/zfs/sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@
#include <sys/sha2.h>
#include <sys/abd.h>


#if defined(__x86_64) && defined(_KERNEL) && defined(HAVE_HASH_MB)

extern int mulbuf_sha256(void *buffer, size_t size, unsigned char *digest);

int zfs_hash_mb_disable = B_FALSE;
module_param(zfs_hash_mb_disable, int, 0644);
MODULE_PARM_DESC(zfs_hash_mb_disable, "Disable multi-buffer sha256");

#endif

static int
sha_incremental(void *buf, size_t size, void *arg)
{
Expand All @@ -47,6 +58,19 @@ abd_checksum_SHA256(abd_t *abd, uint64_t size,
SHA2_CTX ctx;
zio_cksum_t tmp;

#if defined(__x86_64) && defined(_KERNEL) && defined(HAVE_HASH_MB)

void *buffer;

if (abd_is_linear(abd) && size > 8 * 1024 && !zfs_hash_mb_disable) {
buffer = abd->abd_u.abd_linear.abd_buf;
mulbuf_sha256(buffer, size, (unsigned char *)zcp);

return;
}

#endif /* _KERNEL && __x86_64 && HAVE_HASH_MB */

SHA2Init(SHA256, &ctx);
(void) abd_iterate_func(abd, 0, size, sha_incremental, &ctx);
SHA2Final(&tmp, &ctx);
Expand Down
8 changes: 8 additions & 0 deletions module/zfs/spa.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ static inline int spa_load_impl(spa_t *spa, uint64_t, nvlist_t *config,
char **ereport);
static void spa_vdev_resilver_done(spa_t *spa);

extern int zfs_hash_mb_disable;
uint_t zio_taskq_batch_pct = 75; /* 1 thread per cpu in pset */
id_t zio_taskq_psrset_bind = PS_NONE;
boolean_t zio_taskq_sysdc = B_TRUE; /* use SDC scheduling class */
Expand Down Expand Up @@ -899,6 +900,13 @@ spa_taskqs_init(spa_t *spa, zio_type_t t, zio_taskq_type_t q)
case ZTI_MODE_BATCH:
batch = B_TRUE;
flags |= TASKQ_THREADS_CPU_PCT;

#if defined(__x86_64) && defined(_KERNEL) && defined(HAVE_HASH_MB)
/* Eightfold threads cpu percentage */
if (!zfs_hash_mb_disable)
value = zio_taskq_batch_pct * 8;
else
#endif
value = MIN(zio_taskq_batch_pct, 100);
break;

Expand Down

0 comments on commit 8b83a54

Please sign in to comment.