From d7c1404f8246e594f2bf1444d53ef701b0314c22 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Tue, 7 Sep 2021 22:48:43 +0200 Subject: [PATCH 1/4] Simplify metadata bit function declarations Signed-off-by: Robert Baldyga --- src/metadata/metadata_bit.h | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/metadata/metadata_bit.h b/src/metadata/metadata_bit.h index 5e1ccb6..d825726 100644 --- a/src/metadata/metadata_bit.h +++ b/src/metadata/metadata_bit.h @@ -221,20 +221,13 @@ static bool _ocf_metadata_test_and_clear_##what##_##type( \ return test; \ } \ -ocf_metadata_bit_struct(u8); -ocf_metadata_bit_struct(u16); -ocf_metadata_bit_struct(u32); -ocf_metadata_bit_struct(u64); -ocf_metadata_bit_struct(u128); +#define ocf_metadata_bit_funcs(type) \ +ocf_metadata_bit_struct(type); \ +ocf_metadata_bit_func(dirty, type); \ +ocf_metadata_bit_func(valid, type); \ -ocf_metadata_bit_func(dirty, u8); -ocf_metadata_bit_func(dirty, u16); -ocf_metadata_bit_func(dirty, u32); -ocf_metadata_bit_func(dirty, u64); -ocf_metadata_bit_func(dirty, u128); - -ocf_metadata_bit_func(valid, u8); -ocf_metadata_bit_func(valid, u16); -ocf_metadata_bit_func(valid, u32); -ocf_metadata_bit_func(valid, u64); -ocf_metadata_bit_func(valid, u128); +ocf_metadata_bit_funcs(u8); +ocf_metadata_bit_funcs(u16); +ocf_metadata_bit_funcs(u32); +ocf_metadata_bit_funcs(u64); +ocf_metadata_bit_funcs(u128); From 65d3e7a41a7a885e78ff1bff03078c9de1580b28 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Tue, 7 Sep 2021 22:49:33 +0200 Subject: [PATCH 2/4] Introduce ocf_metadata_clear_valid_if_clean() Signed-off-by: Robert Baldyga --- src/metadata/metadata.c | 26 ++++++++++++++++++++++++++ src/metadata/metadata_bit.h | 26 ++++++++++++++++++++++++++ src/metadata/metadata_status.h | 9 +++++++++ 3 files changed, 61 insertions(+) diff --git a/src/metadata/metadata.c b/src/metadata/metadata.c index 1d3f44e..d1c0397 100644 --- a/src/metadata/metadata.c +++ b/src/metadata/metadata.c @@ -1540,6 +1540,32 @@ bool ocf_metadata_##what(struct ocf_cache *cache, \ _ocf_metadata_funcs(dirty) _ocf_metadata_funcs(valid) +bool ocf_metadata_clear_valid_if_clean(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop) +{ + switch (cache->metadata.line_size) { + case ocf_cache_line_size_4: + return _ocf_metadata_clear_valid_if_clean_u8(cache, + line, start, stop); + case ocf_cache_line_size_8: + return _ocf_metadata_clear_valid_if_clean_u16(cache, + line, start, stop); + case ocf_cache_line_size_16: + return _ocf_metadata_clear_valid_if_clean_u32(cache, + line, start, stop); + case ocf_cache_line_size_32: + return _ocf_metadata_clear_valid_if_clean_u64(cache, + line, start, stop); + case ocf_cache_line_size_64: + return _ocf_metadata_clear_valid_if_clean_u128(cache, + line, start, stop); + case ocf_cache_line_size_none: + default: + ENV_BUG_ON(1); + return false; + } +} + int ocf_metadata_init(struct ocf_cache *cache, ocf_cache_line_size_t cache_line_size) { diff --git a/src/metadata/metadata_bit.h b/src/metadata/metadata_bit.h index d825726..2a2a586 100644 --- a/src/metadata/metadata_bit.h +++ b/src/metadata/metadata_bit.h @@ -221,10 +221,36 @@ static bool _ocf_metadata_test_and_clear_##what##_##type( \ return test; \ } \ +#define ocf_metadata_bit_func_basic(type) \ +static bool _ocf_metadata_clear_valid_if_clean_##type(struct ocf_cache *cache, \ + ocf_cache_line_t line, uint8_t start, uint8_t stop) \ +{ \ + type mask = _get_mask_##type(start, stop); \ +\ + struct ocf_metadata_ctrl *ctrl = \ + (struct ocf_metadata_ctrl *) cache->metadata.priv; \ +\ + struct ocf_metadata_raw *raw = \ + &ctrl->raw_desc[metadata_segment_collision]; \ +\ + struct ocf_metadata_map_##type *map = raw->mem_pool; \ +\ + _raw_bug_on(raw, line); \ +\ + map[line].valid &= ~mask & map[line].dirty; \ +\ + if (map[line].valid) { \ + return true; \ + } else { \ + return false; \ + } \ +} \ + #define ocf_metadata_bit_funcs(type) \ ocf_metadata_bit_struct(type); \ ocf_metadata_bit_func(dirty, type); \ ocf_metadata_bit_func(valid, type); \ +ocf_metadata_bit_func_basic(type); \ ocf_metadata_bit_funcs(u8); ocf_metadata_bit_funcs(u16); diff --git a/src/metadata/metadata_status.h b/src/metadata/metadata_status.h index bacf980..be34eb3 100644 --- a/src/metadata/metadata_status.h +++ b/src/metadata/metadata_status.h @@ -26,6 +26,8 @@ bool ocf_metadata_clear_valid(struct ocf_cache *cache, ocf_cache_line_t line, ui bool ocf_metadata_set_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); bool ocf_metadata_test_and_set_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); bool ocf_metadata_test_and_clear_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); +bool ocf_metadata_clear_valid_if_clean(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop); static inline void metadata_init_status_bits(struct ocf_cache *cache, ocf_cache_line_t line) @@ -214,6 +216,13 @@ static inline void metadata_clear_valid(struct ocf_cache *cache, ocf_metadata_clear_valid(cache, line, 0, ocf_line_end_sector(cache)); } +static inline void metadata_clear_valid_if_clean(struct ocf_cache *cache, + ocf_cache_line_t line) +{ + ocf_metadata_clear_valid_if_clean(cache, line, 0, + ocf_line_end_sector(cache)); +} + static inline bool metadata_test_and_clear_valid( struct ocf_cache *cache, ocf_cache_line_t line) { From 1892f58aba76237a476e9f464f97fe8abb9620ba Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Tue, 7 Sep 2021 22:50:56 +0200 Subject: [PATCH 3/4] Optimize out looping over cache line sectors in recovery Signed-off-by: Robert Baldyga --- src/mngt/ocf_mngt_cache.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index fab9132..a22feef 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -509,19 +509,6 @@ static void _recovery_rebuild_cline_metadata(ocf_cache_t cache, } } -static void _recovery_invalidate_clean_sec(struct ocf_cache *cache, - ocf_cache_line_t cline) -{ - uint8_t i; - - for (i = 0; i <= ocf_line_sectors(cache); i++) { - if (!metadata_test_dirty_one(cache, cline, i)) { - /* Invalidate clear sectors */ - metadata_clear_valid_sec_one(cache, cline, i); - } - } -} - static void _recovery_reset_cline_metadata(struct ocf_cache *cache, ocf_cache_line_t cline) { @@ -553,7 +540,7 @@ static void _ocf_mngt_recovery_rebuild_metadata(ocf_cache_t cache) _recovery_rebuild_cline_metadata(cache, core_id, core_line, cline); if (dirty_only) - _recovery_invalidate_clean_sec(cache, cline); + metadata_clear_valid_if_clean(cache, cline); } else { /* Reset metadata for not mapped or clean cache line */ _recovery_reset_cline_metadata(cache, cline); From 1a3843ba12e4dad6c0e8ad4a445b71280f9812f1 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Tue, 7 Sep 2021 22:53:05 +0200 Subject: [PATCH 4/4] Little coding style fix Signed-off-by: Robert Baldyga --- src/metadata/metadata_status.h | 36 ++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/metadata/metadata_status.h b/src/metadata/metadata_status.h index be34eb3..661591c 100644 --- a/src/metadata/metadata_status.h +++ b/src/metadata/metadata_status.h @@ -13,19 +13,31 @@ * Dirty ******************************************************************************/ -bool ocf_metadata_test_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); -bool ocf_metadata_test_out_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); -bool ocf_metadata_clear_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); -bool ocf_metadata_set_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); -bool ocf_metadata_test_and_set_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); -bool ocf_metadata_test_and_clear_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); +bool ocf_metadata_test_dirty(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); +bool ocf_metadata_test_out_dirty(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop); +bool ocf_metadata_clear_dirty(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop); +bool ocf_metadata_set_dirty(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop); +bool ocf_metadata_test_and_set_dirty(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); +bool ocf_metadata_test_and_clear_dirty(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); -bool ocf_metadata_test_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); -bool ocf_metadata_test_out_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); -bool ocf_metadata_clear_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); -bool ocf_metadata_set_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); -bool ocf_metadata_test_and_set_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); -bool ocf_metadata_test_and_clear_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); +bool ocf_metadata_test_valid(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); +bool ocf_metadata_test_out_valid(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop); +bool ocf_metadata_clear_valid(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop); +bool ocf_metadata_set_valid(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop); +bool ocf_metadata_test_and_set_valid(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); +bool ocf_metadata_test_and_clear_valid(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); bool ocf_metadata_clear_valid_if_clean(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop);