1313#include <zephyr/sys/crc.h>
1414#include "nvs_priv.h"
1515
16- #ifdef CONFIG_NVS_LOOKUP_CACHE_FOR_SETTINGS
17- #include <zephyr/sys/util.h>
18- #include <settings/settings_nvs.h>
19- #endif
20-
2116#include <zephyr/logging/log.h>
2217LOG_MODULE_REGISTER (fs_nvs , CONFIG_NVS_LOG_LEVEL );
2318
@@ -26,45 +21,6 @@ static int nvs_ate_valid(struct nvs_fs *fs, const struct nvs_ate *entry);
2621
2722#ifdef CONFIG_NVS_LOOKUP_CACHE
2823
29- #ifdef CONFIG_NVS_LOOKUP_CACHE_FOR_SETTINGS
30-
31- static inline size_t nvs_lookup_cache_pos (uint16_t id )
32- {
33- /*
34- * 1. The NVS settings backend uses up to (NVS_NAME_ID_OFFSET - 1) NVS IDs to
35- store keys and equal number of NVS IDs to store values.
36- * 2. For each key-value pair, the value is stored at NVS ID greater by exactly
37- * NVS_NAME_ID_OFFSET than NVS ID that holds the key.
38- * 3. The backend tries to minimize the range of NVS IDs used to store keys.
39- * That is, NVS IDs are allocated sequentially, and freed NVS IDs are reused
40- * before allocating new ones.
41- *
42- * Therefore, to assure the least number of collisions in the lookup cache,
43- * the least significant bit of the hash indicates whether the given NVS ID
44- * represents a key or a value, and remaining bits of the hash are set to
45- * the ordinal number of the key-value pair. Consequently, the hash function
46- * provides the following mapping:
47- *
48- * 1st settings key => hash 0
49- * 1st settings value => hash 1
50- * 2nd settings key => hash 2
51- * 2nd settings value => hash 3
52- * ...
53- */
54- BUILD_ASSERT (IS_POWER_OF_TWO (NVS_NAMECNT_ID ), "NVS_NAMECNT_ID is not power of 2" );
55- BUILD_ASSERT (IS_POWER_OF_TWO (NVS_NAME_ID_OFFSET ), "NVS_NAME_ID_OFFSET is not power of 2" );
56-
57- uint16_t key_value_bit ;
58- uint16_t key_value_ord ;
59-
60- key_value_bit = (id >> LOG2 (NVS_NAME_ID_OFFSET )) & 1 ;
61- key_value_ord = id & (NVS_NAME_ID_OFFSET - 1 );
62-
63- return ((key_value_ord << 1 ) | key_value_bit ) % CONFIG_NVS_LOOKUP_CACHE_SIZE ;
64- }
65-
66- #else /* CONFIG_NVS_LOOKUP_CACHE_FOR_SETTINGS */
67-
6824static inline size_t nvs_lookup_cache_pos (uint16_t id )
6925{
7026 uint16_t hash ;
@@ -80,8 +36,6 @@ static inline size_t nvs_lookup_cache_pos(uint16_t id)
8036 return hash % CONFIG_NVS_LOOKUP_CACHE_SIZE ;
8137}
8238
83- #endif /* CONFIG_NVS_LOOKUP_CACHE_FOR_SETTINGS */
84-
8539static int nvs_lookup_cache_rebuild (struct nvs_fs * fs )
8640{
8741 int rc ;
0 commit comments