Changeset 0ca7286 in mainline for uspace/srv/vfs/vfs_node.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/vfs/vfs_node.c

    r1c1da4b r0ca7286  
    5858#define KEY_INDEX       2
    5959
    60 static hash_index_t nodes_hash(unsigned long []);
    61 static int nodes_compare(unsigned long [], hash_count_t, link_t *);
    62 static void nodes_remove_callback(link_t *);
     60static size_t nodes_key_hash(unsigned long []);
     61static size_t nodes_hash(const link_t *);
     62static bool nodes_match(unsigned long [], size_t, const link_t *);
    6363
    6464/** VFS node hash table operations. */
    65 hash_table_operations_t nodes_ops = {
     65hash_table_ops_t nodes_ops = {
    6666        .hash = nodes_hash,
    67         .compare = nodes_compare,
    68         .remove_callback = nodes_remove_callback
     67        .key_hash = nodes_key_hash,
     68        .match = nodes_match,
     69        .equal = 0,
     70        .remove_callback = 0,
    6971};
    7072
     
    7577bool vfs_nodes_init(void)
    7678{
    77         return hash_table_create(&nodes, NODES_BUCKETS, 3, &nodes_ops);
     79        return hash_table_create(&nodes, 0, 3, &nodes_ops);
    7880}
    7981
     
    207209                link_initialize(&node->nh_link);
    208210                fibril_rwlock_initialize(&node->contents_rwlock);
    209                 hash_table_insert(&nodes, key, &node->nh_link);
     211                hash_table_insert(&nodes, &node->nh_link);
    210212        } else {
    211213                node = hash_table_get_instance(tmp, vfs_node_t, nh_link);
     
    240242}
    241243
    242 hash_index_t nodes_hash(unsigned long key[])
    243 {
    244         hash_index_t a = key[KEY_FS_HANDLE] << (NODES_BUCKETS_LOG / 4);
    245         hash_index_t b = (a | key[KEY_DEV_HANDLE]) << (NODES_BUCKETS_LOG / 2);
    246        
    247         return (b | key[KEY_INDEX]) & (NODES_BUCKETS - 1);
    248 }
    249 
    250 int nodes_compare(unsigned long key[], hash_count_t keys, link_t *item)
     244size_t nodes_key_hash(unsigned long key[])
     245{
     246        /* Combine into a hash like they do in Effective Java, 2nd edition. */
     247        size_t hash = 17;
     248        hash = 37 * hash + key[KEY_FS_HANDLE];
     249        hash = 37 * hash + key[KEY_DEV_HANDLE];
     250        hash = 37 * hash + key[KEY_INDEX];
     251        return hash;
     252}
     253
     254size_t nodes_hash(const link_t *item)
     255{
     256        vfs_node_t *node = hash_table_get_instance(item, vfs_node_t, nh_link);
     257       
     258        unsigned long key[] = {
     259                [KEY_FS_HANDLE] = node->fs_handle,
     260                [KEY_DEV_HANDLE] = node->service_id,
     261                [KEY_INDEX] = node->index
     262        };
     263       
     264        return nodes_key_hash(key);
     265}
     266
     267
     268bool nodes_match(unsigned long key[], size_t keys, const link_t *item)
    251269{
    252270        vfs_node_t *node = hash_table_get_instance(item, vfs_node_t, nh_link);
     
    256274}
    257275
    258 void nodes_remove_callback(link_t *item)
    259 {
    260 }
    261276
    262277struct refcnt_data {
     
    267282};
    268283
    269 static void refcnt_visitor(link_t *item, void *arg)
     284static bool refcnt_visitor(link_t *item, void *arg)
    270285{
    271286        vfs_node_t *node = hash_table_get_instance(item, vfs_node_t, nh_link);
     
    275290            (node->service_id == rd->service_id))
    276291                rd->refcnt += node->refcnt;
     292       
     293        return true;
    277294}
    278295
Note: See TracChangeset for help on using the changeset viewer.