Skip to content
Merged
27 changes: 15 additions & 12 deletions src/cleaning/acp.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ static int ocf_acp_populate_handle(ocf_parallelize_t parallelize,
{
struct ocf_acp_populate_context *context = priv;
ocf_cache_t cache = context->cache;
ocf_cache_line_t entries = cache->device->collision_table_entries;
ocf_cache_line_t entries = ocf_metadata_line_count(&cache->metadata);
ocf_cache_line_t cline, portion;
uint64_t begin, end;
struct acp_cleaning_policy_meta *acp_meta;
Expand Down Expand Up @@ -479,7 +479,7 @@ void cleaning_policy_acp_populate(ocf_cache_t cache, bool reconstruct,
void cleaning_policy_acp_prepopulate(ocf_cache_t cache,
ocf_cleaning_op_end_t cmpl, void *priv)
{
ocf_cache_line_t entries = cache->device->collision_table_entries;
ocf_cache_line_t entries = ocf_metadata_line_count(&cache->metadata);
ocf_cache_line_t cline;
uint32_t step = 0;

Expand All @@ -503,8 +503,9 @@ static int ocf_acp_update_handle(ocf_parallelize_t parallelize,
{
struct ocf_acp_update_context *context = priv;
ocf_cache_t cache = context->cache;
ocf_cache_line_t entries = cache->device->hash_table_entries;
ocf_cache_line_t terminator = cache->device->collision_table_entries;
ocf_cache_line_t entries = ocf_metadata_hash_entries(&cache->metadata);
ocf_cache_line_t terminator =
ocf_metadata_terminator_line(&cache->metadata);
ocf_cache_line_t hash, cline, portion;
uint64_t begin, end;
unsigned lock_idx = shard_id % OCF_NUM_GLOBAL_META_LOCKS;
Expand All @@ -514,11 +515,11 @@ static int ocf_acp_update_handle(ocf_parallelize_t parallelize,
begin = portion*shard_id;
end = OCF_MIN(portion*(shard_id + 1), entries);

ocf_metadata_start_shared_access(&cache->metadata.lock, lock_idx);
ocf_metadata_start_shared_access(&cache->metadata_lock, lock_idx);
for (hash = begin; hash < end; hash++) {
OCF_COND_RESCHED_DEFAULT(step);

ocf_hb_id_naked_lock_rd(&cache->metadata.lock, hash);
ocf_hb_id_naked_lock_rd(&cache->metadata_lock, hash);
cline = ocf_metadata_get_hash(cache, hash);

while (cline != terminator) {
Expand All @@ -529,9 +530,9 @@ static int ocf_acp_update_handle(ocf_parallelize_t parallelize,

cline = ocf_metadata_get_collision_next(cache, cline);
}
ocf_hb_id_naked_unlock_rd(&cache->metadata.lock, hash);
ocf_hb_id_naked_unlock_rd(&cache->metadata_lock, hash);
}
ocf_metadata_end_shared_access(&cache->metadata.lock, lock_idx);
ocf_metadata_end_shared_access(&cache->metadata_lock, lock_idx);

return 0;
}
Expand Down Expand Up @@ -637,7 +638,7 @@ static ocf_cache_line_t _acp_trylock_dirty(struct ocf_cache *cache,
unsigned lock_idx = ocf_metadata_concurrency_next_idx(
cache->cleaner.io_queue);

ocf_hb_cline_prot_lock_rd(&cache->metadata.lock, lock_idx, core_id,
ocf_hb_cline_prot_lock_rd(&cache->metadata_lock, lock_idx, core_id,
core_line);

ocf_engine_lookup_map_entry(cache, &info, core_id,
Expand All @@ -650,10 +651,11 @@ static ocf_cache_line_t _acp_trylock_dirty(struct ocf_cache *cache,
info.coll_idx);
}

ocf_hb_cline_prot_unlock_rd(&cache->metadata.lock, lock_idx, core_id,
ocf_hb_cline_prot_unlock_rd(&cache->metadata_lock, lock_idx, core_id,
core_line);

return locked ? info.coll_idx : cache->device->collision_table_entries;
return locked ? info.coll_idx :
ocf_metadata_terminator_line(&cache->metadata);
}

static void _acp_handle_flush_error(struct ocf_cache *cache,
Expand Down Expand Up @@ -774,7 +776,8 @@ static bool _acp_prepare_flush_data(struct acp_context *acp,
ocf_cache_line_t cache_line;

cache_line = _acp_trylock_dirty(cache, chunk->core_id, core_line);
if (cache_line == cache->device->collision_table_entries)
if (cache_line ==
ocf_metadata_terminator_line(&cache->metadata))
continue;

ACP_DEBUG_BEGIN(acp, cache_line);
Expand Down
78 changes: 47 additions & 31 deletions src/cleaning/alru.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "../utils/utils_parallelize.h"
#include "../utils/utils_realloc.h"
#include "../concurrency/ocf_cache_line_concurrency.h"
#include "../concurrency/ocf_metadata_concurrency.h"
#include "../ocf_def_priv.h"
#include "cleaning_priv.h"

Expand Down Expand Up @@ -71,7 +72,8 @@ struct alru_context {
static void append_alru_head(ocf_cache_t cache, ocf_part_id_t part_id,
ocf_cache_line_t head, ocf_cache_line_t tail)
{
ocf_cache_line_t terminator = cache->device->collision_table_entries;
ocf_cache_line_t terminator =
ocf_metadata_terminator_line(&cache->metadata);
struct alru_cleaning_policy *part_alru;
struct cleaning_policy_meta *meta;
struct alru_cleaning_policy_meta *old_head;
Expand Down Expand Up @@ -105,7 +107,8 @@ static void append_alru_head(ocf_cache_t cache, ocf_part_id_t part_id,
static void add_alru_head(ocf_cache_t cache, ocf_part_id_t part_id,
ocf_cache_line_t cline)
{
ocf_cache_line_t terminator = cache->device->collision_table_entries;
ocf_cache_line_t terminator =
ocf_metadata_terminator_line(&cache->metadata);
struct alru_cleaning_policy *part_alru;
struct cleaning_policy_meta *meta;
struct alru_cleaning_policy_meta *entry;
Expand Down Expand Up @@ -133,7 +136,8 @@ static void remove_alru_list(struct ocf_cache *cache, int partition_id,
unsigned int collision_index)
{
uint32_t prev_lru_node, next_lru_node;
uint32_t collision_table_entries = cache->device->collision_table_entries;
uint32_t collision_table_entries =
ocf_metadata_line_count(&cache->metadata);
struct alru_cleaning_policy *part_alru = &cache->user_parts[partition_id]
.clean_pol->policy.alru;
struct alru_cleaning_policy_meta *alru;
Expand Down Expand Up @@ -235,7 +239,8 @@ static bool is_on_alru_list(struct ocf_cache *cache, int partition_id,
unsigned int collision_index)
{
uint32_t prev_lru_node, next_lru_node;
uint32_t collision_table_entries = cache->device->collision_table_entries;
uint32_t collision_table_entries =
ocf_metadata_line_count(&cache->metadata);
struct alru_cleaning_policy *part_alru = &cache->user_parts[partition_id]
.clean_pol->policy.alru;
struct alru_cleaning_policy_meta *alru;
Expand Down Expand Up @@ -265,8 +270,8 @@ void cleaning_policy_alru_init_cache_block(struct ocf_cache *cache,
alru = &ocf_metadata_get_cleaning_policy(cache,
cache_line)->meta.alru;
alru->timestamp = 0;
alru->lru_prev = cache->device->collision_table_entries;
alru->lru_next = cache->device->collision_table_entries;
alru->lru_prev = ocf_metadata_terminator_line(&cache->metadata);
alru->lru_next = ocf_metadata_terminator_line(&cache->metadata);
}

void cleaning_policy_alru_purge_cache_block(struct ocf_cache *cache,
Expand Down Expand Up @@ -324,7 +329,8 @@ void cleaning_policy_alru_set_hot_cache_line(struct ocf_cache *cache,
struct alru_cleaning_policy *part_alru = &cache->user_parts[part_id]
.clean_pol->policy.alru;
uint32_t prev_lru_node, next_lru_node;
uint32_t collision_table_entries = cache->device->collision_table_entries;
uint32_t collision_table_entries =
ocf_metadata_line_count(&cache->metadata);
struct alru_cleaning_policy_meta *alru;

ENV_WARN_ON(!metadata_test_dirty(cache, cache_line));
Expand Down Expand Up @@ -419,7 +425,7 @@ static void add_alru_head_populate(struct ocf_alru_fill_context *context,
struct alru_cleaning_policy_meta *entry;
struct alru_cleaning_policy_meta *next;

terminator = ocf_metadata_collision_table_entries(cache);
terminator = ocf_metadata_terminator_line(&cache->metadata);
curr_head = context->shard[shard_id].part[part_id].head;

meta = ocf_metadata_get_cleaning_policy(cache, cline);
Expand Down Expand Up @@ -453,8 +459,9 @@ static int ocf_alru_populate_handle(ocf_parallelize_t parallelize,
{
struct ocf_alru_fill_context *context = priv;
ocf_cache_t cache = context->cache;
ocf_cache_line_t entries = cache->device->collision_table_entries;
ocf_cache_line_t terminator = cache->device->collision_table_entries;
ocf_cache_line_t entries = ocf_metadata_line_count(&cache->metadata);
ocf_cache_line_t terminator =
ocf_metadata_terminator_line(&cache->metadata);
unsigned part_size[OCF_USER_IO_CLASS_MAX] = {};
struct ocf_user_part *user_part;
struct alru_cleaning_policy *part_alru;
Expand Down Expand Up @@ -505,8 +512,9 @@ static int ocf_alru_prepopulate_handle(ocf_parallelize_t parallelize,
{
struct ocf_alru_fill_context *context = priv;
ocf_cache_t cache = context->cache;
ocf_cache_line_t entries = cache->device->collision_table_entries;
ocf_cache_line_t terminator = cache->device->collision_table_entries;
ocf_cache_line_t entries = ocf_metadata_line_count(&cache->metadata);
ocf_cache_line_t terminator =
ocf_metadata_terminator_line(&cache->metadata);
unsigned part_size[OCF_USER_IO_CLASS_MAX] = {};
struct ocf_user_part *user_part;
struct alru_cleaning_policy *part_alru;
Expand Down Expand Up @@ -592,8 +600,10 @@ static void cleaning_policy_alru_fill(ocf_cache_t cache,
/* ALRU initialization */
part_alru = &user_part->clean_pol->policy.alru;
env_atomic_set(&part_alru->size, 0);
part_alru->lru_head = cache->device->collision_table_entries;
part_alru->lru_tail = cache->device->collision_table_entries;
part_alru->lru_head =
ocf_metadata_terminator_line(&cache->metadata);
part_alru->lru_tail =
ocf_metadata_terminator_line(&cache->metadata);
cache->device->runtime_meta->cleaning_thread_access = 0;
}

Expand Down Expand Up @@ -635,8 +645,9 @@ static int ocf_alru_update_handle(ocf_parallelize_t parallelize,
{
struct ocf_alru_update_context *context = priv;
ocf_cache_t cache = context->cache;
ocf_cache_line_t entries = cache->device->hash_table_entries;
ocf_cache_line_t terminator = cache->device->collision_table_entries;
ocf_cache_line_t entries = ocf_metadata_hash_entries(&cache->metadata);
ocf_cache_line_t terminator =
ocf_metadata_terminator_line(&cache->metadata);
ocf_cache_line_t hash, cline, portion;
uint32_t begin, end;
unsigned lock_idx = shard_id % OCF_NUM_GLOBAL_META_LOCKS;
Expand All @@ -646,11 +657,11 @@ static int ocf_alru_update_handle(ocf_parallelize_t parallelize,
begin = portion*shard_id;
end = OCF_MIN((uint64_t)portion*(shard_id + 1), entries);

ocf_metadata_start_shared_access(&cache->metadata.lock, lock_idx);
ocf_metadata_start_shared_access(&cache->metadata_lock, lock_idx);
for (hash = begin; hash < end; hash++) {
OCF_COND_RESCHED_DEFAULT(step);

ocf_hb_id_naked_lock_rd(&cache->metadata.lock, hash);
ocf_hb_id_naked_lock_rd(&cache->metadata_lock, hash);
cline = ocf_metadata_get_hash(cache, hash);

while (cline != terminator) {
Expand All @@ -661,9 +672,9 @@ static int ocf_alru_update_handle(ocf_parallelize_t parallelize,

cline = ocf_metadata_get_collision_next(cache, cline);
}
ocf_hb_id_naked_unlock_rd(&cache->metadata.lock, hash);
ocf_hb_id_naked_unlock_rd(&cache->metadata_lock, hash);
}
ocf_metadata_end_shared_access(&cache->metadata.lock, lock_idx);
ocf_metadata_end_shared_access(&cache->metadata_lock, lock_idx);

return 0;
}
Expand Down Expand Up @@ -947,7 +958,7 @@ static bool more_blocks_to_flush(struct ocf_cache *cache,
{
struct alru_cleaning_policy_meta *alru;

if (cache_line >= cache->device->collision_table_entries)
if (cache_line >= ocf_metadata_line_count(&cache->metadata))
return false;

alru = &ocf_metadata_get_cleaning_policy(cache,
Expand Down Expand Up @@ -1000,13 +1011,18 @@ static int get_data_to_flush(struct alru_context *ctx)
last_access = fctx->dirty_ratio_exceeded ? (uint32_t)(~0UL) : compute_timestamp(config);

#if OCF_CLEANING_DEBUG == 1
if (cache_line != cache->device->collision_table_entries) {
alru = &ocf_metadata_get_cleaning_policy(
cache, cache_line)->meta.alru;
OCF_DEBUG_PARAM(cache, "Last access=%u, "
"timestamp=%u rel=%d",
last_access, alru->timestamp,
alru->timestamp < last_access);
{
ocf_cache_line_t terminator =
ocf_metadata_terminator_line(&cache->metadata);

if (cache_line != terminator) {
alru = &ocf_metadata_get_cleaning_policy(
cache, cache_line)->meta.alru;
OCF_DEBUG_PARAM(cache, "Last access=%u, "
"timestamp=%u rel=%d",
last_access, alru->timestamp,
alru->timestamp < last_access);
}
}
#endif

Expand Down Expand Up @@ -1063,7 +1079,7 @@ static void alru_clean(struct alru_context *ctx)
return;
}

if (ocf_metadata_try_start_exclusive_access(&cache->metadata.lock)) {
if (ocf_metadata_try_start_exclusive_access(&cache->metadata_lock)) {
alru_clean_complete(fctx, 0);
return;
}
Expand All @@ -1082,7 +1098,7 @@ static void alru_clean(struct alru_context *ctx)
ocf_cleaner_sort_flush_data(fctx->flush_data, to_clean);
ocf_cleaner_do_flush_data_async(cache, fctx->flush_data,
to_clean, &fctx->attribs);
ocf_metadata_end_exclusive_access(&cache->metadata.lock);
ocf_metadata_end_exclusive_access(&cache->metadata_lock);
return;
}

Expand All @@ -1091,7 +1107,7 @@ static void alru_clean(struct alru_context *ctx)
env_ticks_to_secs(env_get_tick_count());

end:
ocf_metadata_end_exclusive_access(&cache->metadata.lock);
ocf_metadata_end_exclusive_access(&cache->metadata_lock);
alru_clean_complete(fctx, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/cleaning/cleaning_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "nop.h"
#include "acp.h"
#include "../metadata/metadata_superblock.h"
#include "../metadata/metadata_structs.h"
#include "../metadata/metadata_priv.h"
#include "../ocf_cache_priv.h"
#include "ocf_env_refcnt.h"

Expand Down
3 changes: 2 additions & 1 deletion src/concurrency/ocf_cache_line_concurrency.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2022-2024 Huawei Technologies
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -273,5 +274,5 @@ void ocf_cache_line_concurrency_deinit(struct ocf_alock **self)

size_t ocf_cache_line_concurrency_size_of(ocf_cache_t cache)
{
return ocf_alock_size(cache->device->collision_table_entries);
return ocf_alock_size(ocf_metadata_line_count(&cache->metadata));
}
7 changes: 6 additions & 1 deletion src/concurrency/ocf_concurrency.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

#include "ocf_concurrency.h"
#include "ocf_metadata_concurrency.h"
#include "../metadata/metadata.h"

int ocf_concurrency_init(struct ocf_cache *cache)
{
int result = 0;

ocf_metadata_concurrency_attached_init(&cache->metadata_lock, cache,
ocf_metadata_hash_entries(&cache->metadata));

result = ocf_cache_line_concurrency_init(
&cache->device->concurrency.cache_line,
ocf_metadata_collision_table_entries(cache),
ocf_metadata_line_count(&cache->metadata),
cache);

if (result)
Expand Down
Loading
Loading