Changeset 0ca7286 in mainline for uspace/srv/fs/tmpfs/tmpfs_ops.c


Ignore:
Timestamp:
2012-07-21T11:19:27Z (12 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/tmpfs/tmpfs_ops.c

    r1c1da4b r0ca7286  
    5656#define max(a, b)               ((a) > (b) ? (a) : (b))
    5757
    58 #define NODES_BUCKETS   256
    59 
    6058/** All root nodes have index 0. */
    6159#define TMPFS_SOME_ROOT         0
     
    146144
    147145/* Implementation of hash table interface for the nodes hash table. */
    148 static hash_index_t nodes_hash(unsigned long key[])
    149 {
    150         return key[NODES_KEY_INDEX] % NODES_BUCKETS;
    151 }
    152 
    153 static int nodes_compare(unsigned long key[], hash_count_t keys, link_t *item)
     146static size_t nodes_key_hash(unsigned long key[])
     147{
     148        /* Based on Effective Java, 2nd Edition. */
     149        size_t hash = 17;
     150        hash = 37 * hash + key[NODES_KEY_DEV];
     151        hash = 37 * hash + key[NODES_KEY_INDEX];
     152        return hash;
     153}
     154
     155static size_t nodes_hash(const link_t *item)
     156{
     157        tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t, nh_link);
     158       
     159        unsigned long key[] = {
     160                [NODES_KEY_DEV] = nodep->service_id,
     161                [NODES_KEY_INDEX] = nodep->index
     162        };
     163       
     164        return nodes_key_hash(key);
     165}
     166
     167static bool nodes_match(unsigned long key[], size_t keys, const link_t *item)
    154168{
    155169        tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t,
     
    192206
    193207/** TMPFS nodes hash table operations. */
    194 hash_table_operations_t nodes_ops = {
     208hash_table_ops_t nodes_ops = {
    195209        .hash = nodes_hash,
    196         .compare = nodes_compare,
     210        .key_hash = nodes_key_hash,
     211        .match = nodes_match,
     212        .equal = 0,
    197213        .remove_callback = nodes_remove_callback
    198214};
     
    220236bool tmpfs_init(void)
    221237{
    222         if (!hash_table_create(&nodes, NODES_BUCKETS, 2, &nodes_ops))
     238        if (!hash_table_create(&nodes, 0, 2, &nodes_ops))
    223239                return false;
    224240       
     
    331347
    332348        /* Insert the new node into the nodes hash table. */
    333         unsigned long key[] = {
    334                 [NODES_KEY_DEV] = nodep->service_id,
    335                 [NODES_KEY_INDEX] = nodep->index
    336         };
    337         hash_table_insert(&nodes, key, &nodep->nh_link);
     349        hash_table_insert(&nodes, &nodep->nh_link);
    338350        *rfn = FS_NODE(nodep);
    339351        return EOK;
Note: See TracChangeset for help on using the changeset viewer.