mirror of https://github.com/schoebel/mars
infra: better dent hash function
This commit is contained in:
parent
5d1484fc26
commit
423ff91956
|
@ -77,6 +77,15 @@ extern char *my_id(void);
|
||||||
struct mars_dent;
|
struct mars_dent;
|
||||||
typedef void (*dent_skip_fn)(struct mars_dent *);
|
typedef void (*dent_skip_fn)(struct mars_dent *);
|
||||||
|
|
||||||
|
unsigned int dent_hash(const char *str, int len);
|
||||||
|
|
||||||
|
#define DENT_HASH_ANCHOR(global,index) \
|
||||||
|
({ \
|
||||||
|
struct list_head *table = (global)->dent_hash_table[(index) / MARS_GLOBAL_HASH_TABLE]; \
|
||||||
|
\
|
||||||
|
table + ((index) % MARS_GLOBAL_HASH_TABLE); \
|
||||||
|
})
|
||||||
|
|
||||||
#define MARS_DENT(TYPE) \
|
#define MARS_DENT(TYPE) \
|
||||||
struct list_head dent_link; \
|
struct list_head dent_link; \
|
||||||
struct list_head dent_hash_link; \
|
struct list_head dent_hash_link; \
|
||||||
|
@ -99,7 +108,7 @@ typedef void (*dent_skip_fn)(struct mars_dent *);
|
||||||
int d_serial; /* for pre-grouping order */ \
|
int d_serial; /* for pre-grouping order */ \
|
||||||
int d_version; /* dynamic programming per call of mars_ent_work() */ \
|
int d_version; /* dynamic programming per call of mars_ent_work() */ \
|
||||||
int d_child_count; \
|
int d_child_count; \
|
||||||
int d_hash; \
|
unsigned int d_hash; \
|
||||||
int d_proto; \
|
int d_proto; \
|
||||||
char d_once_error; \
|
char d_once_error; \
|
||||||
bool d_no_scan; \
|
bool d_no_scan; \
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include <linux/namei.h>
|
#include <linux/namei.h>
|
||||||
#include <linux/mount.h>
|
#include <linux/mount.h>
|
||||||
#include <linux/utsname.h>
|
#include <linux/utsname.h>
|
||||||
|
#include <linux/crc32c.h>
|
||||||
|
|
||||||
#include "strategy.h"
|
#include "strategy.h"
|
||||||
|
|
||||||
|
@ -1436,6 +1437,23 @@ int get_inode(char *newpath, struct mars_dent *dent, bool get_deleted)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int dent_hash(const char *str, int len)
|
||||||
|
{
|
||||||
|
u32 raw_hash = crc32c(0, str, len);
|
||||||
|
u32 mask = (u32)-1;
|
||||||
|
unsigned int hash = 0;
|
||||||
|
|
||||||
|
/* catch all possible bits */
|
||||||
|
while (mask) {
|
||||||
|
hash ^= raw_hash;
|
||||||
|
raw_hash /= MARS_GLOBAL_HASH;
|
||||||
|
mask /= MARS_GLOBAL_HASH;
|
||||||
|
}
|
||||||
|
hash %= MARS_GLOBAL_HASH;
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int dent_compare(struct mars_dent *a, struct mars_dent *b)
|
int dent_compare(struct mars_dent *a, struct mars_dent *b)
|
||||||
{
|
{
|
||||||
|
@ -1492,8 +1510,7 @@ int mars_filler(void *__buf, const char *name, int namlen, loff_t offset,
|
||||||
// end_remove_this
|
// end_remove_this
|
||||||
struct mars_dent *dent;
|
struct mars_dent *dent;
|
||||||
char *newpath;
|
char *newpath;
|
||||||
unsigned char digest[MARS_DIGEST_SIZE];
|
unsigned int hash;
|
||||||
int hash;
|
|
||||||
int prefix = 0;
|
int prefix = 0;
|
||||||
int pathlen;
|
int pathlen;
|
||||||
int class;
|
int class;
|
||||||
|
@ -1526,10 +1543,7 @@ int mars_filler(void *__buf, const char *name, int namlen, loff_t offset,
|
||||||
pathlen += namlen;
|
pathlen += namlen;
|
||||||
newpath[pathlen] = '\0';
|
newpath[pathlen] = '\0';
|
||||||
|
|
||||||
mars_digest(MREF_CHKSUM_CRC32C,
|
hash = dent_hash(newpath, pathlen);
|
||||||
NULL,
|
|
||||||
digest,
|
|
||||||
newpath, pathlen);
|
|
||||||
|
|
||||||
dent = brick_zmem_alloc(cookie->allocsize);
|
dent = brick_zmem_alloc(cookie->allocsize);
|
||||||
|
|
||||||
|
@ -1538,7 +1552,6 @@ int mars_filler(void *__buf, const char *name, int namlen, loff_t offset,
|
||||||
dent->d_path = newpath;
|
dent->d_path = newpath;
|
||||||
newpath = NULL;
|
newpath = NULL;
|
||||||
|
|
||||||
hash = *(unsigned long *)&digest % MARS_GLOBAL_HASH;
|
|
||||||
dent->d_hash = hash;
|
dent->d_hash = hash;
|
||||||
dent->d_name = brick_string_alloc(namlen + 1);
|
dent->d_name = brick_string_alloc(namlen + 1);
|
||||||
memcpy(dent->d_name, name, namlen);
|
memcpy(dent->d_name, name, namlen);
|
||||||
|
@ -1581,13 +1594,6 @@ void _reconnect_dent(struct mars_cookie *cookie, struct mars_dent *dent)
|
||||||
fatal: ;
|
fatal: ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define _HASH_ANCHOR(global,index) \
|
|
||||||
({ \
|
|
||||||
struct list_head *table = (global)->dent_hash_table[(index) / MARS_GLOBAL_HASH_TABLE]; \
|
|
||||||
\
|
|
||||||
table + ((index) % MARS_GLOBAL_HASH_TABLE); \
|
|
||||||
})
|
|
||||||
|
|
||||||
static
|
static
|
||||||
void _mars_order(struct mars_cookie *cookie, struct mars_dent *dent)
|
void _mars_order(struct mars_cookie *cookie, struct mars_dent *dent)
|
||||||
{
|
{
|
||||||
|
@ -1609,7 +1615,7 @@ void _mars_order(struct mars_cookie *cookie, struct mars_dent *dent)
|
||||||
*/
|
*/
|
||||||
sorted_anchor = &global->dent_anchor;
|
sorted_anchor = &global->dent_anchor;
|
||||||
CHECK_PTR(sorted_anchor, fatal);
|
CHECK_PTR(sorted_anchor, fatal);
|
||||||
hash_anchor = _HASH_ANCHOR(global, dent->d_hash);
|
hash_anchor = DENT_HASH_ANCHOR(global, dent->d_hash);
|
||||||
CHECK_PTR(hash_anchor, fatal);
|
CHECK_PTR(hash_anchor, fatal);
|
||||||
|
|
||||||
sorted_prev = sorted_anchor;
|
sorted_prev = sorted_anchor;
|
||||||
|
@ -1675,7 +1681,7 @@ void _mars_order(struct mars_cookie *cookie, struct mars_dent *dent)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
hash_try_anchor = _HASH_ANCHOR(global, hash_try_index);
|
hash_try_anchor = DENT_HASH_ANCHOR(global, hash_try_index);
|
||||||
CHECK_PTR(hash_try_anchor, fatal);
|
CHECK_PTR(hash_try_anchor, fatal);
|
||||||
hash_try = test->dent_hash_link.next;
|
hash_try = test->dent_hash_link.next;
|
||||||
CHECK_PTR(hash_try, fatal);
|
CHECK_PTR(hash_try, fatal);
|
||||||
|
|
Loading…
Reference in New Issue