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.

See: #16131

Signed-off-by: Shengqi Chen <[email protected]>
  • Loading branch information
Harry-Chen committed Aug 27, 2024
1 parent 50b32cb commit a74282e
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 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 @@ -390,27 +391,12 @@ 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)os, obj, 0, 0);

Check failure on line 399 in module/zfs/dmu_objset.c

View workflow job for this annotation

GitHub Actions / checkstyle

unparenthesized return expression
}

static unsigned int
Expand Down

0 comments on commit a74282e

Please sign in to comment.