This commit is contained in:
Shengqi Chen 2024-09-11 05:49:06 +08:00 committed by GitHub
commit 616332846e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 65 additions and 24 deletions

View File

@ -132,7 +132,7 @@ static void
rdt_insert(redup_table_t *rdt, rdt_insert(redup_table_t *rdt,
uint64_t guid, uint64_t object, uint64_t offset, uint64_t stream_offset) uint64_t guid, uint64_t object, uint64_t offset, uint64_t stream_offset)
{ {
uint64_t ch = cityhash4(guid, object, offset, 0); uint64_t ch = cityhash3(guid, object, offset);
uint64_t hashcode = BF64_GET(ch, 0, rdt->numhashbits); uint64_t hashcode = BF64_GET(ch, 0, rdt->numhashbits);
redup_entry_t **rdepp; redup_entry_t **rdepp;
@ -152,7 +152,7 @@ rdt_lookup(redup_table_t *rdt,
uint64_t guid, uint64_t object, uint64_t offset, uint64_t guid, uint64_t object, uint64_t offset,
uint64_t *stream_offsetp) uint64_t *stream_offsetp)
{ {
uint64_t ch = cityhash4(guid, object, offset, 0); uint64_t ch = cityhash3(guid, object, offset);
uint64_t hashcode = BF64_GET(ch, 0, rdt->numhashbits); uint64_t hashcode = BF64_GET(ch, 0, rdt->numhashbits);
for (redup_entry_t *rde = rdt->redup_hash_array[hashcode]; for (redup_entry_t *rde = rdt->redup_hash_array[hashcode];

View File

@ -32,6 +32,13 @@
extern "C" { extern "C" {
#endif #endif
/*
* Define 1/2/3-argument specialized versions of cityhash4, which can reduce
* instruction count (especially multiplication) on some 32-bit arches.
*/
_SYS_CITYHASH_H uint64_t cityhash1(uint64_t);
_SYS_CITYHASH_H uint64_t cityhash2(uint64_t, uint64_t);
_SYS_CITYHASH_H uint64_t cityhash3(uint64_t, uint64_t, uint64_t);
_SYS_CITYHASH_H uint64_t cityhash4(uint64_t, uint64_t, uint64_t, uint64_t); _SYS_CITYHASH_H uint64_t cityhash4(uint64_t, uint64_t, uint64_t, uint64_t);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -153,6 +153,9 @@
<elf-symbol name='avl_update_lt' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/> <elf-symbol name='avl_update_lt' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='avl_walk' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/> <elf-symbol name='avl_walk' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='bookmark_namecheck' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/> <elf-symbol name='bookmark_namecheck' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='cityhash1' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='cityhash2' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='cityhash3' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='cityhash4' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/> <elf-symbol name='cityhash4' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='color_end' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/> <elf-symbol name='color_end' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='color_start' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/> <elf-symbol name='color_start' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
@ -9179,6 +9182,21 @@
</function-decl> </function-decl>
</abi-instr> </abi-instr>
<abi-instr address-size='64' path='module/zcommon/cityhash.c' language='LANG_C99'> <abi-instr address-size='64' path='module/zcommon/cityhash.c' language='LANG_C99'>
<function-decl name='cityhash1' mangled-name='cityhash1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='cityhash1'>
<parameter type-id='9c313c2d' name='w'/>
<return type-id='9c313c2d'/>
</function-decl>
<function-decl name='cityhash2' mangled-name='cityhash2' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='cityhash2'>
<parameter type-id='9c313c2d' name='w1'/>
<parameter type-id='9c313c2d' name='w2'/>
<return type-id='9c313c2d'/>
</function-decl>
<function-decl name='cityhash3' mangled-name='cityhash3' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='cityhash3'>
<parameter type-id='9c313c2d' name='w1'/>
<parameter type-id='9c313c2d' name='w2'/>
<parameter type-id='9c313c2d' name='w3'/>
<return type-id='9c313c2d'/>
</function-decl>
<function-decl name='cityhash4' mangled-name='cityhash4' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='cityhash4'> <function-decl name='cityhash4' mangled-name='cityhash4' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='cityhash4'>
<parameter type-id='9c313c2d' name='w1'/> <parameter type-id='9c313c2d' name='w1'/>
<parameter type-id='9c313c2d' name='w2'/> <parameter type-id='9c313c2d' name='w2'/>

View File

@ -566,8 +566,8 @@ zvol_request_impl(zvol_state_t *zv, struct bio *bio, struct request *rq,
rq->q->queue_hw_ctx[rq->q->mq_map[rq->cpu]]->queue_num; rq->q->queue_hw_ctx[rq->q->mq_map[rq->cpu]]->queue_num;
#endif #endif
#endif #endif
taskq_hash = cityhash4((uintptr_t)zv, offset >> ZVOL_TASKQ_OFFSET_SHIFT, taskq_hash = cityhash3((uintptr_t)zv, offset >> ZVOL_TASKQ_OFFSET_SHIFT,
blk_mq_hw_queue, 0); blk_mq_hw_queue);
tq_idx = taskq_hash % ztqs->tqs_cnt; tq_idx = taskq_hash % ztqs->tqs_cnt;
if (rw == WRITE) { if (rw == WRITE) {

View File

@ -49,8 +49,8 @@ cityhash_helper(uint64_t u, uint64_t v, uint64_t mul)
return (b); return (b);
} }
uint64_t static inline uint64_t
cityhash4(uint64_t w1, uint64_t w2, uint64_t w3, uint64_t w4) cityhash_impl(uint64_t w1, uint64_t w2, uint64_t w3, uint64_t w4)
{ {
uint64_t mul = HASH_K2 + 64; uint64_t mul = HASH_K2 + 64;
uint64_t a = w1 * HASH_K1; uint64_t a = w1 * HASH_K1;
@ -59,9 +59,38 @@ cityhash4(uint64_t w1, uint64_t w2, uint64_t w3, uint64_t w4)
uint64_t d = w3 * HASH_K2; uint64_t d = w3 * HASH_K2;
return (cityhash_helper(rotate(a + b, 43) + rotate(c, 30) + d, return (cityhash_helper(rotate(a + b, 43) + rotate(c, 30) + d,
a + rotate(b + HASH_K2, 18) + c, mul)); a + rotate(b + HASH_K2, 18) + c, mul));
}
/*
* Passing w as the 2nd argument could save one 64-bit multiplication.
*/
uint64_t
cityhash1(uint64_t w)
{
return (cityhash_impl(0, w, 0, 0));
}
uint64_t
cityhash2(uint64_t w1, uint64_t w2)
{
return (cityhash_impl(w1, w2, 0, 0));
}
uint64_t
cityhash3(uint64_t w1, uint64_t w2, uint64_t w3)
{
return (cityhash_impl(w1, w2, w3, 0));
}
uint64_t
cityhash4(uint64_t w1, uint64_t w2, uint64_t w3, uint64_t w4)
{
return (cityhash_impl(w1, w2, w3, w4));
} }
#if defined(_KERNEL) #if defined(_KERNEL)
EXPORT_SYMBOL(cityhash1);
EXPORT_SYMBOL(cityhash2);
EXPORT_SYMBOL(cityhash3);
EXPORT_SYMBOL(cityhash4); EXPORT_SYMBOL(cityhash4);
#endif #endif

View File

@ -66,6 +66,7 @@
#include "zfs_namecheck.h" #include "zfs_namecheck.h"
#include <sys/vdev_impl.h> #include <sys/vdev_impl.h>
#include <sys/arc.h> #include <sys/arc.h>
#include <cityhash.h>
/* /*
* Needed to close a window in dnode_move() that allows the objset to be freed * Needed to close a window in dnode_move() that allows the objset to be freed
@ -390,27 +391,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 cityhash on the objset_t pointer and the object number.
*/ */
static uint64_t static uint64_t
dnode_hash(const objset_t *os, uint64_t obj) dnode_hash(const objset_t *os, uint64_t obj)
{ {
uintptr_t osv = (uintptr_t)os; uintptr_t osv = (uintptr_t)os;
uint64_t crc = -1ULL; return (cityhash2((uint64_t)osv, obj));
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);
} }
static unsigned int static unsigned int

View File

@ -4161,8 +4161,8 @@ zio_alloc_zil(spa_t *spa, objset_t *os, uint64_t txg, blkptr_t *new_bp,
* some parallelism. * some parallelism.
*/ */
int flags = METASLAB_ZIL; int flags = METASLAB_ZIL;
int allocator = (uint_t)cityhash4(0, 0, 0, int allocator = (uint_t)cityhash1(os->os_dsl_dataset->ds_object)
os->os_dsl_dataset->ds_object) % spa->spa_alloc_count; % spa->spa_alloc_count;
error = metaslab_alloc(spa, spa_log_class(spa), size, new_bp, 1, error = metaslab_alloc(spa, spa_log_class(spa), size, new_bp, 1,
txg, NULL, flags, &io_alloc_list, NULL, allocator); txg, NULL, flags, &io_alloc_list, NULL, allocator);
*slog = (error == 0); *slog = (error == 0);