Changes in uspace/lib/block/block.c [4e00f87:f73b291] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/block.c
r4e00f87 rf73b291 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 { … … 231 233 } 232 234 233 static size_t cache_key_hash(void *key) 234 { 235 aoff64_t *lba = (aoff64_t*)key; 236 return *lba; 237 } 238 239 static size_t cache_hash(const ht_link_t *item) 240 { 241 block_t *b = hash_table_get_inst(item, block_t, hash_link); 242 return b->lba; 243 } 244 245 static bool cache_key_equal(void *key, const ht_link_t *item) 246 { 247 aoff64_t *lba = (aoff64_t*)key; 248 block_t *b = hash_table_get_inst(item, block_t, hash_link); 249 return b->lba == *lba; 250 } 251 252 253 static hash_table_ops_t cache_ops = { 235 static hash_index_t cache_hash(unsigned long *key) 236 { 237 return MERGE_LOUP32(key[0], key[1]) & (CACHE_BUCKETS - 1); 238 } 239 240 static int cache_compare(unsigned long *key, hash_count_t keys, link_t *item) 241 { 242 block_t *b = hash_table_get_instance(item, block_t, hash_link); 243 return b->lba == MERGE_LOUP32(key[0], key[1]); 244 } 245 246 static void cache_remove_callback(link_t *item) 247 { 248 } 249 250 static hash_table_operations_t cache_ops = { 254 251 .hash = cache_hash, 255 .key_hash = cache_key_hash, 256 .key_equal = cache_key_equal, 257 .equal = NULL, 258 .remove_callback = NULL 252 .compare = cache_compare, 253 .remove_callback = cache_remove_callback 259 254 }; 260 255 … … 287 282 cache->blocks_cluster = cache->lblock_size / devcon->pblock_size; 288 283 289 if (!hash_table_create(&cache->block_hash, 0, 0, &cache_ops)) { 284 if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 2, 285 &cache_ops)) { 290 286 free(cache); 291 287 return ENOMEM; … … 325 321 } 326 322 327 hash_table_remove_item(&cache->block_hash, &b->hash_link); 323 unsigned long key[2] = { 324 LOWER32(b->lba), 325 UPPER32(b->lba) 326 }; 327 hash_table_remove(&cache->block_hash, key, 2); 328 328 329 329 free(b->data); … … 357 357 fibril_rwlock_initialize(&b->contents_lock); 358 358 link_initialize(&b->free_link); 359 link_initialize(&b->hash_link); 359 360 } 360 361 … … 376 377 cache_t *cache; 377 378 block_t *b; 378 link_t *link; 379 link_t *l; 380 unsigned long key[2] = { 381 LOWER32(ba), 382 UPPER32(ba) 383 }; 379 384 380 385 int rc; … … 392 397 393 398 fibril_mutex_lock(&cache->lock); 394 ht_link_t *hlink = hash_table_find(&cache->block_hash, &ba);395 if ( hlink) {399 l = hash_table_find(&cache->block_hash, key); 400 if (l) { 396 401 found: 397 402 /* 398 403 * We found the block in the cache. 399 404 */ 400 b = hash_table_get_inst (hlink, block_t, hash_link);405 b = hash_table_get_instance(l, block_t, hash_link); 401 406 fibril_mutex_lock(&b->lock); 402 407 if (b->refcnt++ == 0) … … 436 441 goto out; 437 442 } 438 l ink= list_first(&cache->free_list);439 b = list_get_instance(l ink, block_t, free_link);443 l = list_first(&cache->free_list); 444 b = list_get_instance(l, block_t, free_link); 440 445 441 446 fibril_mutex_lock(&b->lock); … … 474 479 goto retry; 475 480 } 476 hlink = hash_table_find(&cache->block_hash, &ba);477 if ( hlink) {481 l = hash_table_find(&cache->block_hash, key); 482 if (l) { 478 483 /* 479 484 * Someone else must have already … … 497 502 */ 498 503 list_remove(&b->free_link); 499 hash_table_remove_item(&cache->block_hash, &b->hash_link); 504 unsigned long temp_key[2] = { 505 LOWER32(b->lba), 506 UPPER32(b->lba) 507 }; 508 hash_table_remove(&cache->block_hash, temp_key, 2); 500 509 } 501 510 … … 505 514 b->lba = ba; 506 515 b->pba = ba_ltop(devcon, b->lba); 507 hash_table_insert(&cache->block_hash, &b->hash_link);516 hash_table_insert(&cache->block_hash, key, &b->hash_link); 508 517 509 518 /* … … 613 622 * Take the block out of the cache and free it. 614 623 */ 615 hash_table_remove_item(&cache->block_hash, &block->hash_link); 624 unsigned long key[2] = { 625 LOWER32(block->lba), 626 UPPER32(block->lba) 627 }; 628 hash_table_remove(&cache->block_hash, key, 2); 616 629 fibril_mutex_unlock(&block->lock); 617 630 free(block->data);
Note:
See TracChangeset
for help on using the changeset viewer.