Switch from global metadata locks to hash-bucket locks in engines

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski
2019-07-31 16:31:28 -04:00
parent b39bcf86d4
commit 3a70d68d38
12 changed files with 124 additions and 129 deletions

View File

@@ -137,8 +137,6 @@ err_alloc:
static int _ocf_read_generic_do(struct ocf_request *req)
{
struct ocf_cache *cache = req->cache;
if (ocf_engine_is_miss(req) && req->map->rd_locked) {
/* Miss can be handled only on write locks.
* Need to switch to PT
@@ -153,12 +151,12 @@ static int _ocf_read_generic_do(struct ocf_request *req)
if (ocf_engine_is_miss(req)) {
if (req->info.dirty_any) {
OCF_METADATA_LOCK_RD();
ocf_req_hash_lock_rd(req);
/* Request is dirty need to clean request */
ocf_engine_clean(req);
OCF_METADATA_UNLOCK_RD();
ocf_req_hash_unlock_rd(req);
/* We need to clean request before processing, return */
ocf_req_put(req);
@@ -166,25 +164,25 @@ static int _ocf_read_generic_do(struct ocf_request *req)
return 0;
}
OCF_METADATA_LOCK_RD();
ocf_req_hash_lock_rd(req);
/* Set valid status bits map */
ocf_set_valid_map_info(req);
OCF_METADATA_UNLOCK_RD();
ocf_req_hash_unlock_rd(req);
}
if (req->info.re_part) {
OCF_DEBUG_RQ(req, "Re-Part");
OCF_METADATA_LOCK_WR();
ocf_req_hash_lock_wr(req);
/* Probably some cache lines are assigned into wrong
* partition. Need to move it to new one
*/
ocf_part_move(req);
OCF_METADATA_UNLOCK_WR();
ocf_req_hash_unlock_wr(req);
}
OCF_DEBUG_RQ(req, "Submit");
@@ -216,6 +214,7 @@ int ocf_read_generic(struct ocf_request *req)
int lock = OCF_LOCK_NOT_ACQUIRED;
struct ocf_cache *cache = req->cache;
bool promote = true;
struct ocf_metadata_lock *metadata_lock = &cache->metadata.lock;
ocf_io_start(&req->ioi.io);
@@ -231,10 +230,11 @@ int ocf_read_generic(struct ocf_request *req)
/* Set resume call backs */
req->io_if = &_io_if_read_generic_resume;
/* calculate hashes for hash-bucket locking */
ocf_req_hash(req);
/*- Metadata RD access -----------------------------------------------*/
OCF_METADATA_LOCK_RD();
ocf_req_hash_lock_rd(req);
/* Traverse request to cache if there is hit */
ocf_engine_traverse(req);
@@ -251,27 +251,27 @@ int ocf_read_generic(struct ocf_request *req)
*/
lock = ocf_req_async_lock_wr(req, ocf_engine_on_resume);
}
}
if (!mapped) {
} else {
promote = ocf_promotion_req_should_promote(
cache->promotion_policy, req);
}
OCF_METADATA_UNLOCK_RD();
if (mapped || !promote) {
ocf_req_hash_unlock_rd(req);
} else {
/*- Metadata RD access ---------------------------------------*/
ocf_req_hash_lock_upgrade(req);
ocf_engine_map(req);
ocf_req_hash_unlock_wr(req);
/*- END Metadata RD access -------------------------------------------*/
if (!mapped && promote) {
/*- Metadata WR access ---------------------------------------*/
OCF_METADATA_LOCK_WR();
/* Now there is exclusive access for metadata. May traverse once
* again. If there are misses need to call eviction. This
* process is called 'mapping'.
*/
if (ocf_engine_evict(req) == LOOKUP_MAPPED)
ocf_engine_map(req);
if (req->info.mapping_error) {
/* Still not mapped - evict cachelines under global
* metadata write lock */
ocf_metadata_start_exclusive_access(metadata_lock);
if (ocf_engine_evict(req) == LOOKUP_MAPPED)
ocf_engine_map(req);
ocf_metadata_end_exclusive_access(metadata_lock);
}
if (!req->info.mapping_error) {
if (ocf_engine_is_hit(req)) {
@@ -288,9 +288,6 @@ int ocf_read_generic(struct ocf_request *req)
ocf_engine_on_resume);
}
}
OCF_METADATA_UNLOCK_WR();
/*- END Metadata WR access -----------------------------------*/
}
if (promote && !req->info.mapping_error) {