Skip to content

Commit

Permalink
dmu_objset: replace dnode_hash impl with cityhash4
Browse files Browse the repository at this point in the history
As mentioned in PR #16131, replacing CRC-based hash with cityhash4
could slightly improve the performance by eliminating memory access.
Replacing algorightm is safe since the hash result is not persisted.

Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de>
Signed-off-by: Shengqi Chen <harry-chen@outlook.com>
Closes #16131
Closes #16483
  • Loading branch information
Harry-Chen authored and behlendorf committed Sep 19, 2024
1 parent 4d469ac commit 1c35206
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions module/zfs/dmu_objset.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "zfs_namecheck.h"
#include <sys/vdev_impl.h>
#include <sys/arc.h>
#include <cityhash.h>

/*
* Needed to close a window in dnode_move() that allows the objset to be freed
Expand Down Expand Up @@ -404,27 +405,13 @@ dmu_objset_byteswap(void *buf, size_t size)
}

/*
* The hash is a CRC-based hash of the objset_t pointer and the object number.
* Runs cityhash4 on the objset_t pointer and the object number.
*/
static uint64_t
dnode_hash(const objset_t *os, uint64_t obj)
{
uintptr_t osv = (uintptr_t)os;
uint64_t crc = -1ULL;

ASSERT(zfs_crc64_table[128] == ZFS_CRC64_POLY);
/*
* The lower 11 bits of the pointer don't have much entropy, because
* the objset_t is more than 1KB long and so likely aligned to 2KB.
*/
crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ (osv >> 11)) & 0xFF];
crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ (obj >> 0)) & 0xFF];
crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ (obj >> 8)) & 0xFF];
crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ (obj >> 16)) & 0xFF];

crc ^= (osv>>14) ^ (obj>>24);

return (crc);
return (cityhash4((uint64_t)osv, obj, 0, 0));
}

static unsigned int
Expand Down

0 comments on commit 1c35206

Please sign in to comment.