Skip to content

Commit bb4d673

Browse files
Merge pull request #861 from Deixx/deinit-variable-metadata
Split count_pages and update on metadata deinit
2 parents ba4b81a + d8feef3 commit bb4d673

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

src/metadata/metadata.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright(c) 2012-2022 Intel Corporation
3-
* Copyright(c) 2024 Huawei Technologies
3+
* Copyright(c) 2024-2025 Huawei Technologies
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
66

@@ -271,7 +271,7 @@ static int ocf_metadata_calculate_metadata_size(
271271
lowest_diff = cache_lines;
272272

273273
do {
274-
count_pages = ctrl->count_pages;
274+
count_pages = 0;
275275
for (i = metadata_segment_variable_size_start;
276276
i < metadata_segment_max; i++) {
277277
struct ocf_metadata_raw *raw = &ctrl->raw_desc[i];
@@ -286,7 +286,7 @@ static int ocf_metadata_calculate_metadata_size(
286286
/*
287287
* Setup SSD location and size
288288
*/
289-
raw->ssd_pages_offset = count_pages;
289+
raw->ssd_pages_offset = ctrl->count_pages_fixed + count_pages;
290290
raw->ssd_pages = OCF_DIV_ROUND_UP(raw->entries,
291291
raw->entries_in_page);
292292

@@ -321,7 +321,7 @@ static int ocf_metadata_calculate_metadata_size(
321321
/* Cache size in bytes */
322322
diff_lines = ctrl->device_lines * line_size;
323323
/* Sub metadata size which is in 4 kiB unit */
324-
diff_lines -= (int64_t)count_pages * PAGE_SIZE;
324+
diff_lines -= (int64_t)(ctrl->count_pages_fixed + count_pages) * PAGE_SIZE;
325325
/* Convert back to cache lines */
326326
diff_lines /= line_size;
327327
/* Calculate difference */
@@ -344,7 +344,7 @@ static int ocf_metadata_calculate_metadata_size(
344344

345345
} while (diff_lines);
346346

347-
ctrl->count_pages = count_pages;
347+
ctrl->count_pages_variable = count_pages;
348348
ctrl->cachelines = cache_lines;
349349
OCF_DEBUG_PARAM(cache, "Cache lines = %u", ctrl->cachelines);
350350

@@ -447,6 +447,7 @@ void ocf_metadata_deinit_variable_size(struct ocf_cache *cache)
447447
i < metadata_segment_max; i++) {
448448
ocf_metadata_segment_destroy(cache, ctrl->segment[i]);
449449
}
450+
ctrl->count_pages_variable = 0;
450451
}
451452

452453
static inline void ocf_metadata_config_init(ocf_cache_t cache, size_t size)
@@ -530,7 +531,7 @@ static struct ocf_metadata_ctrl *ocf_metadata_ctrl_init(
530531
page += ocf_metadata_raw_size_on_ssd(raw);
531532
}
532533

533-
ctrl->count_pages = page;
534+
ctrl->count_pages_fixed = page;
534535

535536
return ctrl;
536537
}
@@ -711,9 +712,10 @@ int ocf_metadata_init_variable_size(struct ocf_cache *cache,
711712
}
712713

713714
OCF_DEBUG_PARAM(cache, "Metadata begin pages = %u", ctrl->start_page);
714-
OCF_DEBUG_PARAM(cache, "Metadata count pages = %u", ctrl->count_pages);
715+
OCF_DEBUG_PARAM(cache, "Metadata count pages fixed = %u", ctrl->count_pages_fixed);
716+
OCF_DEBUG_PARAM(cache, "Metadata count pages variable = %u", ctrl->count_pages_variable);
715717
OCF_DEBUG_PARAM(cache, "Metadata end pages = %u", ctrl->start_page
716-
+ ctrl->count_pages);
718+
+ ocf_metadata_get_pages_count(cache));
717719

718720
superblock = ctrl->segment[metadata_segment_sb_config];
719721

@@ -787,7 +789,8 @@ int ocf_metadata_init_variable_size(struct ocf_cache *cache,
787789
cache->device->hash_table_entries =
788790
ctrl->raw_desc[metadata_segment_hash].entries;
789791

790-
cache->device->metadata_offset = ctrl->count_pages * PAGE_SIZE;
792+
cache->device->metadata_offset =
793+
ocf_metadata_get_pages_count(cache) * PAGE_SIZE;
791794

792795
cache->conf_meta->cachelines = ctrl->cachelines;
793796
cache->conf_meta->line_size = line_size;
@@ -946,15 +949,15 @@ void ocf_metadata_init_hash_table(ocf_pipeline_t pipeline, void *priv,
946949
/*
947950
* Get count of pages that is dedicated for metadata
948951
*/
949-
ocf_cache_line_t ocf_metadata_get_pages_count(struct ocf_cache *cache)
952+
uint32_t ocf_metadata_get_pages_count(struct ocf_cache *cache)
950953
{
951954
struct ocf_metadata_ctrl *ctrl = NULL;
952955

953956
OCF_DEBUG_TRACE(cache);
954957

955958
ctrl = (struct ocf_metadata_ctrl *) cache->metadata.priv;
956959

957-
return ctrl->count_pages;
960+
return ctrl->count_pages_fixed + ctrl->count_pages_variable;
958961
}
959962

960963
/*

src/metadata/metadata.h

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

@@ -125,7 +126,7 @@ ocf_metadata_get_cachelines_count(struct ocf_cache *cache);
125126
* @param cache - Cache instance
126127
* @return Pages required for store metadata on cache device
127128
*/
128-
ocf_cache_line_t ocf_metadata_get_pages_count(struct ocf_cache *cache);
129+
uint32_t ocf_metadata_get_pages_count(struct ocf_cache *cache);
129130

130131
/**
131132
* @brief Flush metadata

src/metadata/metadata_internal.h

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

@@ -20,7 +21,8 @@
2021
struct ocf_metadata_ctrl {
2122
ocf_cache_line_t cachelines;
2223
ocf_cache_line_t start_page;
23-
ocf_cache_line_t count_pages;
24+
uint32_t count_pages_fixed;
25+
uint32_t count_pages_variable;
2426
uint32_t device_lines;
2527
size_t mapping_size;
2628
struct ocf_metadata_raw raw_desc[metadata_segment_max];

src/metadata/metadata_passive_update.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright(c) 2012-2022 Intel Corporation
3-
* Copyright(c) 2024 Huawei Technologies
3+
* Copyright(c) 2024-2025 Huawei Technologies
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
66

@@ -76,7 +76,6 @@ static void passive_io_page_lock_acquired(struct ocf_request *req)
7676
int ocf_metadata_passive_update(struct ocf_request *master)
7777
{
7878
ocf_cache_t cache = master->cache;
79-
struct ocf_metadata_ctrl *ctrl = cache->metadata.priv;
8079
uint64_t io_start_page = BYTES_TO_PAGES(master->addr);
8180
uint64_t io_end_page = io_start_page + BYTES_TO_PAGES(master->bytes);
8281
struct ocf_request *req;
@@ -87,7 +86,7 @@ int ocf_metadata_passive_update(struct ocf_request *master)
8786
return 0;
8887
}
8988

90-
if (io_start_page >= ctrl->count_pages) {
89+
if (io_start_page >= ocf_metadata_get_pages_count(cache)) {
9190
master->complete(master, 0);
9291
return 0;
9392
}

0 commit comments

Comments
 (0)