Separate engine map/evict (refactoring)

This temporarily increases amount of boiler-plate code, but
this is going to be mitigated in the following commits.

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski 2019-07-30 16:03:16 -04:00
parent d91012f4b4
commit b39bcf86d4
5 changed files with 58 additions and 25 deletions

View File

@ -16,7 +16,6 @@
#include "../utils/utils_cleaner.h" #include "../utils/utils_cleaner.h"
#include "../metadata/metadata.h" #include "../metadata/metadata.h"
#include "../eviction/eviction.h" #include "../eviction/eviction.h"
#include "../promotion/promotion.h"
void ocf_engine_error(struct ocf_request *req, void ocf_engine_error(struct ocf_request *req,
bool stop_cache, const char *msg) bool stop_cache, const char *msg)
@ -315,18 +314,15 @@ void ocf_engine_map(struct ocf_request *req)
int status = LOOKUP_MAPPED; int status = LOOKUP_MAPPED;
ocf_core_id_t core_id = ocf_core_get_id(req->core); ocf_core_id_t core_id = ocf_core_get_id(req->core);
if (!ocf_promotion_req_should_promote(cache->promotion_policy, req)) { if (!ocf_engine_unmapped_count(req))
return;
if (ocf_engine_unmapped_count(req) >
ocf_freelist_num_free(cache->freelist)) {
req->info.mapping_error = 1; req->info.mapping_error = 1;
return; return;
} }
if (ocf_engine_unmapped_count(req))
status = space_managment_evict_do(cache, req,
ocf_engine_unmapped_count(req));
if (req->info.mapping_error)
return;
ocf_req_clear_info(req); ocf_req_clear_info(req);
req->info.seq_req = true; req->info.seq_req = true;
@ -397,6 +393,15 @@ static void _ocf_engine_clean_end(void *private_data, int error)
} }
} }
int ocf_engine_evict(struct ocf_request *req)
{
if (!ocf_engine_unmapped_count(req))
return 0;
return space_managment_evict_do(req->cache, req,
ocf_engine_unmapped_count(req));
}
static int _ocf_engine_clean_getter(struct ocf_cache *cache, static int _ocf_engine_clean_getter(struct ocf_cache *cache,
void *getter_context, uint32_t item, ocf_cache_line_t *line) void *getter_context, uint32_t item, ocf_cache_line_t *line)
{ {

View File

@ -162,19 +162,28 @@ void ocf_engine_lookup_map_entry(struct ocf_cache *cache,
uint64_t core_line); uint64_t core_line);
/** /**
* @brief Traverse request in order to lookup cache lines If there are misses * @brief Traverse request in order to lookup cache lines. If there are misses,
* need to call eviction. This process is called 'mapping'. * attempt to map free cache lines.
*
* @note This function CALL EVICTION
* *
* @param req OCF request * @param req OCF request
*/ */
void ocf_engine_map(struct ocf_request *req); void ocf_engine_map(struct ocf_request *req);
/**
* @brief Evict cachelines to populate freelist.
*
* @param req OCF request
*
* @returns eviction status
* @retval LOOKUP_MAPPED successfully evicted required number of cachelines
* @retval LOOKUP_MISS eviction failure
*/
int ocf_engine_evict(struct ocf_request *req);
/** /**
* @brief Traverse OCF request (lookup cache) * @brief Traverse OCF request (lookup cache)
* *
* @note This function DO NOT CALL EVICTION. Only lookup in metadata is * @note This function does not evict cachelines. Only lookup in metadata is
* performed. Main purpose of this function is to check if there is a HIT. * performed. Main purpose of this function is to check if there is a HIT.
* *
* @param req OCF request * @param req OCF request

View File

@ -215,6 +215,7 @@ int ocf_read_generic(struct ocf_request *req)
bool mapped; bool mapped;
int lock = OCF_LOCK_NOT_ACQUIRED; int lock = OCF_LOCK_NOT_ACQUIRED;
struct ocf_cache *cache = req->cache; struct ocf_cache *cache = req->cache;
bool promote = true;
ocf_io_start(&req->ioi.io); ocf_io_start(&req->ioi.io);
@ -252,20 +253,24 @@ int ocf_read_generic(struct ocf_request *req)
} }
} }
if (!mapped) {
promote = ocf_promotion_req_should_promote(
cache->promotion_policy, req);
}
OCF_METADATA_UNLOCK_RD(); OCF_METADATA_UNLOCK_RD();
/*- END Metadata RD access -------------------------------------------*/ /*- END Metadata RD access -------------------------------------------*/
if (!mapped) { if (!mapped && promote) {
/*- Metadata WR access ---------------------------------------*/ /*- Metadata WR access ---------------------------------------*/
OCF_METADATA_LOCK_WR(); OCF_METADATA_LOCK_WR();
/* Now there is exclusive access for metadata. May traverse once /* Now there is exclusive access for metadata. May traverse once
* again. If there are misses need to call eviction. This * again. If there are misses need to call eviction. This
* process is called 'mapping'. * process is called 'mapping'.
*/ */
if (ocf_engine_evict(req) == LOOKUP_MAPPED)
ocf_engine_map(req); ocf_engine_map(req);
if (!req->info.mapping_error) { if (!req->info.mapping_error) {
@ -288,7 +293,7 @@ int ocf_read_generic(struct ocf_request *req)
/*- END Metadata WR access -----------------------------------*/ /*- END Metadata WR access -----------------------------------*/
} }
if (!req->info.mapping_error) { if (promote && !req->info.mapping_error) {
if (lock >= 0) { if (lock >= 0) {
if (lock != OCF_LOCK_ACQUIRED) { if (lock != OCF_LOCK_ACQUIRED) {
/* Lock was not acquired, need to wait for resume */ /* Lock was not acquired, need to wait for resume */

View File

@ -170,6 +170,7 @@ int ocf_write_wb(struct ocf_request *req)
bool mapped; bool mapped;
int lock = OCF_LOCK_NOT_ACQUIRED; int lock = OCF_LOCK_NOT_ACQUIRED;
struct ocf_cache *cache = req->cache; struct ocf_cache *cache = req->cache;
bool promote = true;
ocf_io_start(&req->ioi.io); ocf_io_start(&req->ioi.io);
@ -192,15 +193,21 @@ int ocf_write_wb(struct ocf_request *req)
lock = ocf_req_async_lock_wr(req, ocf_engine_on_resume); lock = ocf_req_async_lock_wr(req, ocf_engine_on_resume);
} }
if (!mapped) {
promote = ocf_promotion_req_should_promote(
cache->promotion_policy, req);
}
OCF_METADATA_UNLOCK_RD(); /*- END Metadata READ access----------------*/ OCF_METADATA_UNLOCK_RD(); /*- END Metadata READ access----------------*/
if (!mapped) { if (!mapped && promote) {
OCF_METADATA_LOCK_WR(); /*- Metadata WR access, eviction -----*/ OCF_METADATA_LOCK_WR(); /*- Metadata WR access, eviction -----*/
/* Now there is exclusive access for metadata. May traverse once /* Now there is exclusive access for metadata. May traverse once
* again. If there are misses need to call eviction. This * again. If there are misses need to call eviction. This
* process is called 'mapping'. * process is called 'mapping'.
*/ */
if (ocf_engine_evict(req) == LOOKUP_MAPPED)
ocf_engine_map(req); ocf_engine_map(req);
if (!req->info.mapping_error) { if (!req->info.mapping_error) {
@ -211,7 +218,7 @@ int ocf_write_wb(struct ocf_request *req)
OCF_METADATA_UNLOCK_WR(); /*- END Metadata WR access ---------*/ OCF_METADATA_UNLOCK_WR(); /*- END Metadata WR access ---------*/
} }
if (!req->info.mapping_error) { if (promote && !req->info.mapping_error) {
if (lock >= 0) { if (lock >= 0) {
if (lock != OCF_LOCK_ACQUIRED) { if (lock != OCF_LOCK_ACQUIRED) {
/* WR lock was not acquired, need to wait for resume */ /* WR lock was not acquired, need to wait for resume */

View File

@ -165,6 +165,7 @@ int ocf_write_wt(struct ocf_request *req)
bool mapped; bool mapped;
int lock = OCF_LOCK_NOT_ACQUIRED; int lock = OCF_LOCK_NOT_ACQUIRED;
struct ocf_cache *cache = req->cache; struct ocf_cache *cache = req->cache;
bool promote = true;
ocf_io_start(&req->ioi.io); ocf_io_start(&req->ioi.io);
@ -185,15 +186,21 @@ int ocf_write_wt(struct ocf_request *req)
lock = ocf_req_async_lock_wr(req, ocf_engine_on_resume); lock = ocf_req_async_lock_wr(req, ocf_engine_on_resume);
} }
if (!mapped) {
promote = ocf_promotion_req_should_promote(
cache->promotion_policy, req);
}
OCF_METADATA_UNLOCK_RD(); /*- END Metadata READ access----------------*/ OCF_METADATA_UNLOCK_RD(); /*- END Metadata READ access----------------*/
if (!mapped) { if (!mapped && promote) {
OCF_METADATA_LOCK_WR(); /*- Metadata WR access, eviction -----*/ OCF_METADATA_LOCK_WR(); /*- Metadata WR access, eviction -----*/
/* Now there is exclusive access for metadata. May traverse once /* Now there is exclusive access for metadata. May traverse once
* again. If there are misses need to call eviction. This * again. If there are misses need to call eviction. This
* process is called 'mapping'. * process is called 'mapping'.
*/ */
if (ocf_engine_evict(req) == LOOKUP_MAPPED)
ocf_engine_map(req); ocf_engine_map(req);
if (!req->info.mapping_error) { if (!req->info.mapping_error) {
@ -204,7 +211,7 @@ int ocf_write_wt(struct ocf_request *req)
OCF_METADATA_UNLOCK_WR(); /*- END Metadata WR access ---------*/ OCF_METADATA_UNLOCK_WR(); /*- END Metadata WR access ---------*/
} }
if (!req->info.mapping_error) { if (promote && !req->info.mapping_error) {
if (lock >= 0) { if (lock >= 0) {
if (lock != OCF_LOCK_ACQUIRED) { if (lock != OCF_LOCK_ACQUIRED) {
/* WR lock was not acquired, need to wait for resume */ /* WR lock was not acquired, need to wait for resume */