From c123bfb946088f43475a2d7f6c78d3f97806610a Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Fri, 16 Oct 2026 14:33:14 +0200 Subject: [PATCH] Fix cached_clines accounting when moving invalid cache line Only valid cache lines are accounted in cached_clines, and a line gets accounted to its current partition once it becomes valid. However ocf_user_part_move() moved the counter for every cache line, so moving a line that is mapped, but not valid (e.g. left mapped by a failed read miss for a request of another IO class waiting for it), underflowed the counter of the source partition and accounted the line twice in the destination one. Signed-off-by: Robert Baldyga --- src/utils/utils_user_part.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/utils/utils_user_part.c b/src/utils/utils_user_part.c index 4ac35513d..26fea1825 100644 --- a/src/utils/utils_user_part.c +++ b/src/utils/utils_user_part.c @@ -1,6 +1,7 @@ /* * Copyright(c) 2012-2021 Intel Corporation * Copyright(c) 2024 Huawei Technologies + * Copyright(c) 2026 Unvertical * SPDX-License-Identifier: BSD-3-Clause */ @@ -156,10 +157,16 @@ void ocf_user_part_move(struct ocf_request *req) part_counters[id_old].dirty_clines); } - env_atomic_inc(&req->core->runtime_meta-> - part_counters[id_new].cached_clines); - env_atomic_dec(&req->core->runtime_meta-> - part_counters[id_old].cached_clines); + /* Only valid cache lines are accounted. A line that is mapped, + * but not valid yet, gets accounted to its current partition + * once it becomes valid. + */ + if (metadata_test_valid_any(cache, line)) { + env_atomic_inc(&req->core->runtime_meta-> + part_counters[id_new].cached_clines); + env_atomic_dec(&req->core->runtime_meta-> + part_counters[id_old].cached_clines); + } /* DONE */ }