I have a persistent dictionary (string -> string map) that I write to a NAND filesystem as a log file. My binary format is:
1 byte - key size
<key size> bytes - key without the terminating nul-character
2 bytes - value size and flags
<value size> bytes - value without terminating nul-character
Usually, I write between 20 to 100 bytes with each change in the dictionary. But since this is been persisted on NAND this design causes a new page to be allocated each time, reducing my available NAND space by 2k on each iteration.
I can’t cache the writes because I can’t lose this data. It’s running point of sales terminals, saving transaction data. My algorithm effectively writes and call flush, so this doesn’t happen.
Now, is there a de-facto or standard algorithm to solve this problem? I’ve looked at power-down triggers on the target platform, but the SDK suggests using the NAND as the persistent layer.
Since the NAND FLASH is limited to page-granularity on writes, I’m out of luck.
I could rely on some external persistent device, or on-shutdown routines, but I don’t have access to any other secondary memory and old point of sale terminals even have capacitors for last resort routines, but they aren’t reliable enough for transaction data.
I’ll have to live with the FLASH limitation.