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 = ctrl -> count_pages_variable ;
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
452453static 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/*
0 commit comments