Changeset 0ca7286 in mainline for uspace/lib/block/libblock.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/lib/block/libblock.c

    r1c1da4b r0ca7286  
    6262static LIST_INITIALIZE(dcl);
    6363
    64 #define CACHE_BUCKETS_LOG2  10
    65 #define CACHE_BUCKETS       (1 << CACHE_BUCKETS_LOG2)
    6664
    6765typedef struct {
     
    256254}
    257255
    258 static hash_index_t cache_hash(unsigned long *key)
    259 {
    260         return MERGE_LOUP32(key[0], key[1]) & (CACHE_BUCKETS - 1);
    261 }
    262 
    263 static int cache_compare(unsigned long *key, hash_count_t keys, link_t *item)
     256static size_t cache_key_hash(unsigned long *key)
     257{
     258        /* As recommended by Effective Java, 2nd Edition. */
     259        size_t hash = 17;
     260        hash = 31 * hash + key[1];
     261        hash = 31 * hash + key[0];
     262        return hash;
     263}
     264
     265static size_t cache_hash(const link_t *item)
     266{
     267        block_t *b = hash_table_get_instance(item, block_t, hash_link);
     268        unsigned long key[] = {
     269                LOWER32(b->lba),
     270                UPPER32(b->lba)
     271        };
     272       
     273        return cache_key_hash(key);
     274}
     275
     276static bool cache_match(unsigned long *key, size_t keys, const link_t *item)
    264277{
    265278        block_t *b = hash_table_get_instance(item, block_t, hash_link);
     
    267280}
    268281
    269 static void cache_remove_callback(link_t *item)
    270 {
    271 }
    272 
    273 static hash_table_operations_t cache_ops = {
     282
     283static hash_table_ops_t cache_ops = {
    274284        .hash = cache_hash,
    275         .compare = cache_compare,
    276         .remove_callback = cache_remove_callback
     285        .key_hash = cache_key_hash,
     286        .match = cache_match,
     287        .equal = 0,
     288        .remove_callback = 0
    277289};
    278290
     
    305317        cache->blocks_cluster = cache->lblock_size / devcon->pblock_size;
    306318
    307         if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 2,
    308             &cache_ops)) {
     319        if (!hash_table_create(&cache->block_hash, 0, 2, &cache_ops)) {
    309320                free(cache);
    310321                return ENOMEM;
     
    540551                b->lba = ba;
    541552                b->pba = ba_ltop(devcon, b->lba);
    542                 hash_table_insert(&cache->block_hash, key, &b->hash_link);
     553                hash_table_insert(&cache->block_hash, &b->hash_link);
    543554
    544555                /*
Note: See TracChangeset for help on using the changeset viewer.