Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimistic fastpath #821

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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