Skip to content

Commit 5d8da33

Browse files
committed
Split count_pages and update on metadata deinit
This resets count_pages_variable on cache-detach, so during the following cache-attach metadata size is calculated properly. Signed-off-by: Daniel Madej <daniel.madej@huawei.com>
1 parent c200c24 commit 5d8da33

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

src/metadata/metadata.c

Lines changed: 13 additions & 10 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+
+ ctrl->count_pages_fixed + ctrl->count_pages_variable);
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+
(ctrl->count_pages_fixed + ctrl->count_pages_variable) * PAGE_SIZE;
791794

792795
cache->conf_meta->cachelines = ctrl->cachelines;
793796
cache->conf_meta->line_size = line_size;
@@ -954,7 +957,7 @@ ocf_cache_line_t ocf_metadata_get_pages_count(struct ocf_cache *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_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+
ocf_cache_line_t count_pages_fixed;
25+
ocf_cache_line_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 & 2 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

@@ -87,7 +87,7 @@ int ocf_metadata_passive_update(struct ocf_request *master)
8787
return 0;
8888
}
8989

90-
if (io_start_page >= ctrl->count_pages) {
90+
if (io_start_page >= ctrl->count_pages_fixed + ctrl->count_pages_variable) {
9191
master->complete(master, 0);
9292
return 0;
9393
}

0 commit comments

Comments
 (0)