Skip to content

feat(kvdb): add a transient sector read cache for the loading phases - #433

Open
xidongxu-xfaith-tech wants to merge 1 commit into
armink:masterfrom
xidongxu-xfaith-tech:read_cache
Open

xidongxu-xfaith-tech wants to merge 1 commit into
armink:masterfrom
xidongxu-xfaith-tech:read_cache

Conversation

@xidongxu-xfaith-tech

Copy link
Copy Markdown
Contributor

A KV search reads the sector chunk by chunk: walking the KV chain, and searching the used area end. For a 64 KB sector which holds a few KB of data that is thousands of storage reads, and it dominates the time a small database takes to load.

This adds an optional read cache above the storage layer: while a scan is running, the sector it reads is copied into RAM once and every later read of that sector is served from there. It is invalidated before any write or erase of the sector, so it never returns stale data.

The cache is borrowed, not owned. It is allocated by the first read which needs it and given back when the phase which opened it ends:

  • fdb_kvdb_init() opens a phase, released when the initialization ends;
  • fdb_kv_iterate() opens a phase, released when the iteration completes. A single key read or write at run time never allocates it, so a running database keeps no sector sized buffer in RAM.

Opt-in, zero behaviour change when FDB_USING_READ_CACHE is 0.

A KV search reads the sector chunk by chunk: walking the KV chain, and
searching the used area end. For a 64 KB sector which holds a few KB of
data that is thousands of storage reads, and it dominates the time a small
database takes to load.

This adds an optional read cache above the storage layer: while a scan is
running, the sector it reads is copied into RAM once and every later read
of that sector is served from there. It is invalidated before any write or
erase of the sector, so it never returns stale data.

The cache is borrowed, not owned. It is allocated by the first read which
needs it and given back when the phase which opened it ends:
- fdb_kvdb_init() opens a phase, released when the initialization ends;
- fdb_kv_iterate() opens a phase, released when the iteration completes.
A single key read or write at run time never allocates it, so a running
database keeps no sector sized buffer in RAM.

Opt-in, zero behaviour change when FDB_USING_READ_CACHE is 0.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant