Skip to content

Commit 9dc5ed4

Browse files
committed
Introduce optimistic fast path for engine_rd
Signed-off-by: Avi Halaf <[email protected]> Signed-off-by: Robert Baldyga <[email protected]> Signed-off-by: Michal Mielewczyk <[email protected]>
1 parent bd06b1c commit 9dc5ed4

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

src/concurrency/ocf_cache_line_concurrency.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static ocf_cache_line_t ocf_cl_lock_line_get_entry(
3333
return req->map[index].coll_idx;
3434
}
3535

36-
static int ocf_cl_lock_line_fast(struct ocf_alock *alock,
36+
int ocf_cl_lock_line_fast(struct ocf_alock *alock,
3737
struct ocf_request *req, int rw)
3838
{
3939
int32_t i;

src/engine/engine_rd.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,46 @@ int ocf_read_generic(struct ocf_request *req)
258258

259259
return 0;
260260
}
261+
262+
int ocf_read_generic_try_fast(struct ocf_request *req)
263+
{
264+
struct ocf_alock *c = ocf_cache_line_concurrency(req->cache);
265+
266+
/* Calculate hashes for hash-bucket locking */
267+
ocf_req_hash(req);
268+
269+
/* Read-lock hash buckets associated with request target core & LBAs
270+
* (core lines) to assure that cache mapping for these core lines does
271+
* not change during traversation */
272+
ocf_hb_req_prot_lock_rd(req);
273+
274+
/* check CL status */
275+
ocf_engine_lookup(req);
276+
277+
if (ocf_engine_is_mapped(req) && ocf_engine_is_hit(req) &&
278+
ocf_cl_lock_line_fast(c, req, OCF_READ) == OCF_LOCK_ACQUIRED) {
279+
280+
OCF_DEBUG_RQ(req, "Submit read generic fast");
281+
282+
ocf_req_get(req);
283+
ocf_engine_set_hot(req);
284+
ocf_hb_req_prot_unlock_rd(req);
285+
286+
if (ocf_engine_needs_repart(req)) {
287+
ocf_hb_req_prot_lock_wr(req);
288+
ocf_user_part_move(req);
289+
ocf_hb_req_prot_unlock_wr(req);
290+
}
291+
292+
ocf_read_generic_submit_hit(req);
293+
294+
/* Update statistics */
295+
ocf_engine_update_request_stats(req);
296+
ocf_engine_update_block_stats(req);
297+
return OCF_FAST_PATH_YES;
298+
} else {
299+
ocf_hb_req_prot_unlock_rd(req);
300+
OCF_DEBUG_RQ(req, "Failed to read generic fast");
301+
return OCF_FAST_PATH_NO;
302+
}
303+
}

src/engine/engine_rd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright(c) 2012-2021 Intel Corporation
3+
* Copyright(c) 2024 Huawei Technologies
34
* SPDX-License-Identifier: BSD-3-Clause
45
*/
56

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

1112
void ocf_read_generic_submit_hit(struct ocf_request *req);
13+
int ocf_read_generic_try_fast(struct ocf_request *req);
1214

1315
#endif /* ENGINE_RD_H_ */

src/ocf_core.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
#include "ocf_io_priv.h"
1111
#include "metadata/metadata.h"
1212
#include "engine/cache_engine.h"
13+
#include "engine/engine_rd.h"
1314
#include "utils/utils_user_part.h"
1415
#include "ocf_request.h"
1516

17+
#define MAX_FAST_PATH_CACHE_LINES (64)
18+
1619
struct ocf_core_volume {
1720
ocf_core_t core;
1821
};
@@ -218,6 +221,29 @@ static void ocf_req_complete(struct ocf_request *req, int error)
218221
ocf_io_put(&req->ioi.io);
219222
}
220223

224+
static inline int _ocf_core_submit_io_fast_rd_generic(struct ocf_io *io,
225+
struct ocf_request *req)
226+
{
227+
int res;
228+
229+
switch (req->cache_mode) {
230+
case ocf_req_cache_mode_wt:
231+
case ocf_req_cache_mode_wa:
232+
case ocf_req_cache_mode_wi:
233+
case ocf_req_cache_mode_wb:
234+
case ocf_req_cache_mode_wo:
235+
res = ocf_read_generic_try_fast(req);
236+
break;
237+
default:
238+
break;
239+
}
240+
241+
if (res == OCF_FAST_PATH_NO)
242+
ocf_req_clear_map(req);
243+
244+
return res;
245+
}
246+
221247
static inline ocf_req_cache_mode_t _ocf_core_req_resolve_fast_mode(
222248
ocf_cache_t cache, struct ocf_request *req)
223249
{
@@ -248,6 +274,14 @@ static int ocf_core_submit_io_fast(struct ocf_io *io, struct ocf_request *req,
248274
if (req->cache_mode == ocf_req_cache_mode_pt)
249275
return OCF_FAST_PATH_NO;
250276

277+
/* If a read request isn't too big for a lookup in submission context,
278+
check it is a read-hit and if cache line lock could be acquired
279+
without waiting. If so, submit immediately */
280+
if (req->rw == OCF_READ) {
281+
if (req->core_line_count <= MAX_FAST_PATH_CACHE_LINES)
282+
return _ocf_core_submit_io_fast_rd_generic(io, req);
283+
}
284+
251285
resolved_mode = _ocf_core_req_resolve_fast_mode(cache, req);
252286
if (resolved_mode == ocf_req_cache_mode_max)
253287
return OCF_FAST_PATH_NO;

0 commit comments

Comments
 (0)