Skip to content

Commit

Permalink
Introduce optimistic fast path for engine_rd
Browse files Browse the repository at this point in the history
Signed-off-by: Avi Halaf <[email protected]>
Signed-off-by: Robert Baldyga <[email protected]>
Signed-off-by: Michal Mielewczyk <[email protected]>
  • Loading branch information
mmichal10 committed Sep 12, 2024
1 parent bd06b1c commit 9dc5ed4
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/concurrency/ocf_cache_line_concurrency.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static ocf_cache_line_t ocf_cl_lock_line_get_entry(
return req->map[index].coll_idx;
}

static int ocf_cl_lock_line_fast(struct ocf_alock *alock,
int ocf_cl_lock_line_fast(struct ocf_alock *alock,
struct ocf_request *req, int rw)
{
int32_t i;
Expand Down
43 changes: 43 additions & 0 deletions src/engine/engine_rd.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,46 @@ int ocf_read_generic(struct ocf_request *req)

return 0;
}

int ocf_read_generic_try_fast(struct ocf_request *req)
{
struct ocf_alock *c = ocf_cache_line_concurrency(req->cache);

/* Calculate hashes for hash-bucket locking */
ocf_req_hash(req);

/* Read-lock hash buckets associated with request target core & LBAs
* (core lines) to assure that cache mapping for these core lines does
* not change during traversation */
ocf_hb_req_prot_lock_rd(req);

/* check CL status */
ocf_engine_lookup(req);

if (ocf_engine_is_mapped(req) && ocf_engine_is_hit(req) &&
ocf_cl_lock_line_fast(c, req, OCF_READ) == OCF_LOCK_ACQUIRED) {

OCF_DEBUG_RQ(req, "Submit read generic fast");

ocf_req_get(req);
ocf_engine_set_hot(req);
ocf_hb_req_prot_unlock_rd(req);

if (ocf_engine_needs_repart(req)) {
ocf_hb_req_prot_lock_wr(req);
ocf_user_part_move(req);
ocf_hb_req_prot_unlock_wr(req);
}

ocf_read_generic_submit_hit(req);

/* Update statistics */
ocf_engine_update_request_stats(req);
ocf_engine_update_block_stats(req);
return OCF_FAST_PATH_YES;
} else {
ocf_hb_req_prot_unlock_rd(req);
OCF_DEBUG_RQ(req, "Failed to read generic fast");
return OCF_FAST_PATH_NO;
}
}
2 changes: 2 additions & 0 deletions src/engine/engine_rd.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand All @@ -9,5 +10,6 @@
int ocf_read_generic(struct ocf_request *req);

void ocf_read_generic_submit_hit(struct ocf_request *req);
int ocf_read_generic_try_fast(struct ocf_request *req);

#endif /* ENGINE_RD_H_ */
34 changes: 34 additions & 0 deletions src/ocf_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
#include "ocf_io_priv.h"
#include "metadata/metadata.h"
#include "engine/cache_engine.h"
#include "engine/engine_rd.h"
#include "utils/utils_user_part.h"
#include "ocf_request.h"

#define MAX_FAST_PATH_CACHE_LINES (64)

struct ocf_core_volume {
ocf_core_t core;
};
Expand Down Expand Up @@ -218,6 +221,29 @@ static void ocf_req_complete(struct ocf_request *req, int error)
ocf_io_put(&req->ioi.io);
}

static inline int _ocf_core_submit_io_fast_rd_generic(struct ocf_io *io,
struct ocf_request *req)
{
int res;

switch (req->cache_mode) {
case ocf_req_cache_mode_wt:
case ocf_req_cache_mode_wa:
case ocf_req_cache_mode_wi:
case ocf_req_cache_mode_wb:
case ocf_req_cache_mode_wo:
res = ocf_read_generic_try_fast(req);
break;
default:
break;
}

if (res == OCF_FAST_PATH_NO)
ocf_req_clear_map(req);

return res;
}

static inline ocf_req_cache_mode_t _ocf_core_req_resolve_fast_mode(
ocf_cache_t cache, struct ocf_request *req)
{
Expand Down Expand Up @@ -248,6 +274,14 @@ static int ocf_core_submit_io_fast(struct ocf_io *io, struct ocf_request *req,
if (req->cache_mode == ocf_req_cache_mode_pt)
return OCF_FAST_PATH_NO;

/* If a read request isn't too big for a lookup in submission context,
check it is a read-hit and if cache line lock could be acquired
without waiting. If so, submit immediately */
if (req->rw == OCF_READ) {
if (req->core_line_count <= MAX_FAST_PATH_CACHE_LINES)
return _ocf_core_submit_io_fast_rd_generic(io, req);
}

resolved_mode = _ocf_core_req_resolve_fast_mode(cache, req);
if (resolved_mode == ocf_req_cache_mode_max)
return OCF_FAST_PATH_NO;
Expand Down

0 comments on commit 9dc5ed4

Please sign in to comment.