From f68e26ac1268da755815f72d8fca3324ef5736ea Mon Sep 17 00:00:00 2001 From: "S.J.R. van Schaik" Date: Mon, 24 Jul 2017 13:12:54 +0200 Subject: [PATCH] ftl: implement flags to keep track of state --- include/ftl.h | 5 +++++ source/ftl/map.c | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/ftl.h b/include/ftl.h index b1e67ff..8464835 100644 --- a/include/ftl.h +++ b/include/ftl.h @@ -1,5 +1,7 @@ #pragma once +#include + struct ftl_page_group { uint8_t magic[3]; uint8_t epoch; @@ -14,6 +16,7 @@ struct ftl_page_desc { struct ftl_map { struct flash_dev *dev; + unsigned flags; uint32_t last_va; uint32_t last_pa; uint32_t head, tail; @@ -28,6 +31,8 @@ struct ftl_map { uint8_t epoch; }; +#define FTL_CACHED_VA BIT(0) + #define FTL_MAX_ATTEMPTS 8 int ftl_init_map(struct ftl_map *map, struct flash_dev *dev); diff --git a/source/ftl/map.c b/source/ftl/map.c index abce785..10c8f48 100644 --- a/source/ftl/map.c +++ b/source/ftl/map.c @@ -309,6 +309,9 @@ static void reset_map(struct ftl_map *map) map->nblocks = flash_get_size(map->dev) >> map->log2_block_size; + map->flags = 0; + map->last_va = 0; + map->last_pa = 0; map->head = 0; map->tail = 0; map->root = UINT32_MAX; @@ -379,7 +382,7 @@ int trace_path(struct ftl_map *map, struct ftl_page_desc *new_page_desc, uint8_t depth = 0; uint32_t upage = map->root; - if (map->last_va == va) + if ((map->flags & FTL_CACHED_VA) && map->last_va == va) return map->last_pa; if (new_page_desc) @@ -417,6 +420,7 @@ int trace_path(struct ftl_map *map, struct ftl_page_desc *new_page_desc, if (page) *page = upage; + map->flags |= FTL_CACHED_VA; map->last_va = va; map->last_pa = upage;