Skip to content

Commit a25218d

Browse files
committed
lru: Improve part max size accounting
Signed-off-by: Robert Baldyga <robert.baldyga@unvertical.com>
1 parent 7c622ca commit a25218d

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/ocf_lru.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "ocf_cache_priv.h"
2020
#include "ocf_request.h"
2121
#include "engine/engine_common.h"
22+
#include "utils/utils_user_part.h"
2223

2324
#define OCF_LRU_MAX_LRU_ELEMENT_IDX 256
2425

@@ -792,9 +793,14 @@ uint32_t ocf_lru_req_clines(struct ocf_request *req,
792793
struct ocf_part *dst_part;
793794
ocf_part_id_t actual_src_part_id;
794795

796+
uint32_t dst_max_size;
797+
795798
if (cline_no == 0)
796799
return 0;
797800

801+
dst_max_size = ocf_user_part_get_max_size(cache,
802+
&cache->user_parts[req->part_id]);
803+
798804
if (unlikely(ocf_engine_unmapped_count(req) < cline_no)) {
799805
ocf_cache_log(req->cache, log_err, "Not enough space in"
800806
"request: unmapped %u, requested %u",
@@ -868,6 +874,18 @@ uint32_t ocf_lru_req_clines(struct ocf_request *req,
868874

869875
++req_idx;
870876
++i;
877+
878+
/* When allocating from freelist or another partition (not
879+
* self-eviction), curr_size was incremented. Stop if the
880+
* destination partition has reached its occupancy limit.
881+
* This bounds the TOCTOU race in ocf_user_part_has_space()
882+
* to at most OCF_NUM_LRU_LISTS cache lines of overshoot. */
883+
if (actual_src_part_id != dst_part->id &&
884+
(uint32_t)env_atomic_read(
885+
&dst_part->runtime->curr_size) >=
886+
dst_max_size)
887+
break;
888+
871889
/* Number of cachelines to evict have to match space in the
872890
* request */
873891
ENV_BUG_ON(req_idx == req->core_line_count && i != cline_no);

0 commit comments

Comments
 (0)