-
Notifications
You must be signed in to change notification settings - Fork 82
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
Backfill optimization #834
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,15 +68,91 @@ static void _ocf_backfill_complete(struct ocf_request *req, int error) | |
} | ||
} | ||
|
||
#define __entries_not_adjacent(__req, __i, __j) \ | ||
__req->map[__i].coll_idx + 1 != __req->map[__j].coll_idx | ||
|
||
#define __is_the_last_chunk(__req, __i) (__i == (__req->core_line_count - 1)) | ||
|
||
#define __skip_on_the_last_entry(__skip, __req, __i) \ | ||
__skip * (int)__is_the_last_chunk(__req, __i) | ||
|
||
static int _ocf_backfill_do(struct ocf_request *req) | ||
{ | ||
ocf_cache_t cache = req->cache; | ||
uint64_t metadata_offset = cache->device->metadata_offset; | ||
ocf_cache_line_size_t cache_line_size = ocf_line_size(cache); | ||
uint64_t addr, bytes, total_bytes = 0; | ||
uint64_t seek, skip, last_chunk_size; | ||
uint32_t i; | ||
|
||
req->data = req->cp_data; | ||
if (unlikely(req->data == NULL)) { | ||
_ocf_backfill_complete(req, -OCF_ERR_NO_MEM); | ||
return 0; | ||
} | ||
|
||
ocf_engine_forward_cache_io_req(req, OCF_WRITE, _ocf_backfill_complete); | ||
req->cache_forward_end = _ocf_backfill_complete; | ||
|
||
if (ocf_engine_is_sequential(req)) { | ||
addr = metadata_offset; | ||
addr += req->map[0].coll_idx * cache_line_size; | ||
addr += req->addr % cache_line_size; | ||
|
||
ocf_core_stats_cache_block_update(req->core, req->part_id, | ||
OCF_WRITE, req->bytes); | ||
|
||
ocf_req_forward_cache_io(req, OCF_WRITE, addr, req->bytes, | ||
req->offset); | ||
return 0; | ||
} | ||
|
||
seek = req->addr % cache_line_size; | ||
last_chunk_size = (req->addr + req->bytes) % cache_line_size; | ||
skip = (cache_line_size - last_chunk_size) % cache_line_size; | ||
Comment on lines
+110
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This math is very confusing. The |
||
|
||
ocf_req_forward_cache_get(req); | ||
for (i = 0; i < req->core_line_count; i++) { | ||
if (req->map[i].status == LOOKUP_HIT) { | ||
/* This is the 1st cache line in the interval, and it's | ||
a hit. Don't write it to the cache */ | ||
total_bytes += cache_line_size; | ||
total_bytes -= seek; | ||
/* Seek should be taken into account for the first chunk | ||
only */ | ||
seek = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer |
||
continue; | ||
} | ||
|
||
addr = metadata_offset; | ||
addr += req->map[i].coll_idx * cache_line_size; | ||
|
||
bytes = cache_line_size; | ||
for (; i < (req->core_line_count - 1); i++) { | ||
if (__entries_not_adjacent(req, i, i + 1)) | ||
break; | ||
|
||
bytes += cache_line_size; | ||
} | ||
|
||
/* Seek should be taken into account for the first chunk only */ | ||
addr += seek; | ||
bytes -= seek; | ||
Comment on lines
+138
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here we completely unnecessarily add/subtract 0 on every loop iteration. |
||
seek = 0; | ||
|
||
bytes -= __skip_on_the_last_entry(skip, req, i); | ||
|
||
bytes = OCF_MIN(bytes, req->bytes - total_bytes); | ||
|
||
ocf_core_stats_cache_block_update(req->core, req->part_id, | ||
OCF_WRITE, bytes); | ||
|
||
ocf_req_forward_cache_io(req, OCF_WRITE, addr, bytes, | ||
req->offset + total_bytes); | ||
|
||
total_bytes += bytes; | ||
} | ||
|
||
ocf_req_forward_cache_put(req); | ||
|
||
return 0; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's no longer 90's,
unlikely()
should do.