Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs, jbd: use a more generic hash function

While the hash function used by the revoke hashtable is good somewhere else,
it's not really good here.

The default hash shift (8) means that one third of the hashing function
gets lost (and is undefined anyways (8 - 12 = negative shift)):

"(block << (hash_shift - 12))) & (table->hash_size - 1)"

Instead, just use the kernel's generic hash function that gets used everywhere
else.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Jan Kara <jack@suse.cz>

authored by

Sasha Levin and committed by
Jan Kara
3c9cafe0 474d2605

+2 -5
+2 -5
fs/jbd/revoke.c
··· 93 93 #include <linux/bio.h> 94 94 #endif 95 95 #include <linux/log2.h> 96 + #include <linux/hash.h> 96 97 97 98 static struct kmem_cache *revoke_record_cache; 98 99 static struct kmem_cache *revoke_table_cache; ··· 130 129 131 130 /* Utility functions to maintain the revoke table */ 132 131 133 - /* Borrowed from buffer.c: this is a tried and tested block hash function */ 134 132 static inline int hash(journal_t *journal, unsigned int block) 135 133 { 136 134 struct jbd_revoke_table_s *table = journal->j_revoke; 137 - int hash_shift = table->hash_shift; 138 135 139 - return ((block << (hash_shift - 6)) ^ 140 - (block >> 13) ^ 141 - (block << (hash_shift - 12))) & (table->hash_size - 1); 136 + return hash_32(block, table->hash_shift); 142 137 } 143 138 144 139 static int insert_revoke_hash(journal_t *journal, unsigned int blocknr,