Skip to content

Commit c3b2f48

Browse files
committed
Revert "[nrf noup] settings: nvs: use dedicated lookup cache hash function"
This reverts commit 98ba1b4. Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent 1830a84 commit c3b2f48

File tree

2 files changed

+0
-55
lines changed

2 files changed

+0
-55
lines changed

subsys/fs/nvs/Kconfig

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@ config NVS_LOOKUP_CACHE_SIZE
2929
Number of entries in Non-volatile Storage lookup cache.
3030
It is recommended that it be a power of 2.
3131

32-
config NVS_LOOKUP_CACHE_FOR_SETTINGS
33-
bool "Non-volatile Storage lookup cache optimized for settings"
34-
depends on NVS_LOOKUP_CACHE
35-
help
36-
Use the lookup cache hash function that results in the least number of
37-
collissions and, in turn, the best NVS performance provided that the NVS
38-
is used as the settings backend only. This option should NOT be enabled
39-
if the NVS is also written to directly, outside the settings layer.
40-
4132
module = NVS
4233
module-str = nvs
4334
source "subsys/logging/Kconfig.template.log_config"

subsys/fs/nvs/nvs.c

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
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>
2217
LOG_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-
6824
static 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-
8539
static int nvs_lookup_cache_rebuild(struct nvs_fs *fs)
8640
{
8741
int rc;

0 commit comments

Comments
 (0)