Changeset 0ca7286 in mainline for uspace/srv/fs/ext2fs/ext2fs_ops.c


Ignore:
Timestamp:
2012-07-21T11:19:27Z (13 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2732c94
Parents:
1c1da4b
Message:

Added resizing to user space (single-threaded) hash_table. Resizes in a way to mitigate effects of bad hash functions. Change of interface affected many files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/ext2fs/ext2fs_ops.c

    r1c1da4b r0ca7286  
    6565#define OPEN_NODES_DEV_HANDLE_KEY 0
    6666#define OPEN_NODES_INODE_KEY 1
    67 #define OPEN_NODES_BUCKETS 256
    6867
    6968typedef struct ext2fs_instance {
     
    123122
    124123/* Hash table interface for open nodes hash table */
    125 static hash_index_t open_nodes_hash(unsigned long key[])
    126 {
    127         /* TODO: This is very simple and probably can be improved */
    128         return key[OPEN_NODES_INODE_KEY] % OPEN_NODES_BUCKETS;
    129 }
    130 
    131 static int open_nodes_compare(unsigned long key[], hash_count_t keys,
    132     link_t *item)
     124static size_t open_nodes_key_hash(unsigned long key[])
     125{
     126        /* Hash construction recommended in Effective Java, 2nd Edition. */
     127        size_t hash = 17;
     128        hash = 31 * hash + key[OPEN_NODES_DEV_HANDLE_KEY];
     129        hash = 31 * hash + key[OPEN_NODES_INODE_KEY];
     130        return hash;
     131}
     132
     133static size_t open_nodes_hash(const link_t *item)
     134{
     135        ext2fs_node_t *enode = hash_table_get_instance(item, ext2fs_node_t, link);
     136
     137        assert(enode->instance);
     138        assert(enode->inode_ref);
     139       
     140        unsigned long key[] = {
     141                [OPEN_NODES_DEV_HANDLE_KEY] = enode->instance->service_id,
     142                [OPEN_NODES_INODE_KEY] = enode->inode_ref->index,
     143        };
     144       
     145        return open_nodes_key_hash(key);
     146}
     147
     148static bool open_nodes_match(unsigned long key[], size_t keys,
     149    const link_t *item)
    133150{
    134151        ext2fs_node_t *enode = hash_table_get_instance(item, ext2fs_node_t, link);
     
    145162}
    146163
    147 static void open_nodes_remove_cb(link_t *link)
    148 {
    149         /* We don't use remove callback for this hash table */
    150 }
    151 
    152 static hash_table_operations_t open_nodes_ops = {
     164static hash_table_ops_t open_nodes_ops = {
    153165        .hash = open_nodes_hash,
    154         .compare = open_nodes_compare,
    155         .remove_callback = open_nodes_remove_cb,
     166        .key_hash = open_nodes_key_hash,
     167        .match = open_nodes_match,
     168        .equal = 0,
     169        .remove_callback = 0,
    156170};
    157171
     
    161175int ext2fs_global_init(void)
    162176{
    163         if (!hash_table_create(&open_nodes, OPEN_NODES_BUCKETS,
    164             OPEN_NODES_KEYS, &open_nodes_ops)) {
     177        if (!hash_table_create(&open_nodes, 0, OPEN_NODES_KEYS, &open_nodes_ops)) {
    165178                return ENOMEM;
    166179        }
     
    362375        *rfn = node;
    363376       
    364         hash_table_insert(&open_nodes, key, &enode->link);
     377        hash_table_insert(&open_nodes, &enode->link);
    365378        inst->open_nodes_count++;
    366379       
Note: See TracChangeset for help on using the changeset viewer.