Changes in uspace/lib/block/libblock.c [bc216a0:9d58539] in mainline
- File:
-
- 1 edited
-
uspace/lib/block/libblock.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/libblock.c
rbc216a0 r9d58539 62 62 static LIST_INITIALIZE(dcl); 63 63 64 #define CACHE_BUCKETS_LOG2 10 65 #define CACHE_BUCKETS (1 << CACHE_BUCKETS_LOG2) 64 66 65 67 typedef struct { … … 254 256 } 255 257 256 static size_t cache_key_hash(void *key) 257 { 258 aoff64_t *lba = (aoff64_t*)key; 259 return *lba; 260 } 261 262 static size_t cache_hash(const ht_link_t *item) 263 { 264 block_t *b = hash_table_get_inst(item, block_t, hash_link); 265 return b->lba; 266 } 267 268 static bool cache_key_equal(void *key, const ht_link_t *item) 269 { 270 aoff64_t *lba = (aoff64_t*)key; 271 block_t *b = hash_table_get_inst(item, block_t, hash_link); 272 return b->lba == *lba; 273 } 274 275 276 static hash_table_ops_t cache_ops = { 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) 264 { 265 block_t *b = hash_table_get_instance(item, block_t, hash_link); 266 return b->lba == MERGE_LOUP32(key[0], key[1]); 267 } 268 269 static void cache_remove_callback(link_t *item) 270 { 271 } 272 273 static hash_table_operations_t cache_ops = { 277 274 .hash = cache_hash, 278 .key_hash = cache_key_hash, 279 .key_equal = cache_key_equal, 280 .equal = 0, 281 .remove_callback = 0 275 .compare = cache_compare, 276 .remove_callback = cache_remove_callback 282 277 }; 283 278 … … 310 305 cache->blocks_cluster = cache->lblock_size / devcon->pblock_size; 311 306 312 if (!hash_table_create(&cache->block_hash, 0, 0, &cache_ops)) { 307 if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 2, 308 &cache_ops)) { 313 309 free(cache); 314 310 return ENOMEM; … … 348 344 } 349 345 350 hash_table_remove_item(&cache->block_hash, &b->hash_link); 346 unsigned long key[2] = { 347 LOWER32(b->lba), 348 UPPER32(b->lba) 349 }; 350 hash_table_remove(&cache->block_hash, key, 2); 351 351 352 352 free(b->data); … … 380 380 fibril_rwlock_initialize(&b->contents_lock); 381 381 link_initialize(&b->free_link); 382 link_initialize(&b->hash_link); 382 383 } 383 384 … … 399 400 cache_t *cache; 400 401 block_t *b; 401 link_t *link; 402 link_t *l; 403 unsigned long key[2] = { 404 LOWER32(ba), 405 UPPER32(ba) 406 }; 402 407 403 408 int rc; … … 415 420 416 421 fibril_mutex_lock(&cache->lock); 417 ht_link_t *hlink = hash_table_find(&cache->block_hash, &ba);418 if ( hlink) {422 l = hash_table_find(&cache->block_hash, key); 423 if (l) { 419 424 found: 420 425 /* 421 426 * We found the block in the cache. 422 427 */ 423 b = hash_table_get_inst (hlink, block_t, hash_link);428 b = hash_table_get_instance(l, block_t, hash_link); 424 429 fibril_mutex_lock(&b->lock); 425 430 if (b->refcnt++ == 0) … … 459 464 goto out; 460 465 } 461 l ink= list_first(&cache->free_list);462 b = list_get_instance(l ink, block_t, free_link);466 l = list_first(&cache->free_list); 467 b = list_get_instance(l, block_t, free_link); 463 468 464 469 fibril_mutex_lock(&b->lock); … … 500 505 goto retry; 501 506 } 502 hlink = hash_table_find(&cache->block_hash, &ba);503 if ( hlink) {507 l = hash_table_find(&cache->block_hash, key); 508 if (l) { 504 509 /* 505 510 * Someone else must have already … … 523 528 */ 524 529 list_remove(&b->free_link); 525 hash_table_remove_item(&cache->block_hash, &b->hash_link); 530 unsigned long temp_key[2] = { 531 LOWER32(b->lba), 532 UPPER32(b->lba) 533 }; 534 hash_table_remove(&cache->block_hash, temp_key, 2); 526 535 } 527 536 … … 531 540 b->lba = ba; 532 541 b->pba = ba_ltop(devcon, b->lba); 533 hash_table_insert(&cache->block_hash, &b->hash_link);542 hash_table_insert(&cache->block_hash, key, &b->hash_link); 534 543 535 544 /* … … 643 652 * Take the block out of the cache and free it. 644 653 */ 645 hash_table_remove_item(&cache->block_hash, &block->hash_link); 654 unsigned long key[2] = { 655 LOWER32(block->lba), 656 UPPER32(block->lba) 657 }; 658 hash_table_remove(&cache->block_hash, key, 2); 646 659 fibril_mutex_unlock(&block->lock); 647 660 free(block->data);
Note:
See TracChangeset
for help on using the changeset viewer.
