QNX & SQLite (On NAND flash drive)

  • Thread starter Thread starter cpscdave
  • Start date Start date
  • Tags Tags
    Drive Flash
Click For Summary

Discussion Overview

The discussion revolves around the interaction between QNX operating system, SQLite database management, and NAND flash drive storage, particularly focusing on file writing behavior and its implications for data integrity and drive longevity. Participants explore how appending data to files may lead to complete rewrites and the potential risks of corruption over time.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant raises a concern that appending to a file on QNX with an ETFS file system may result in the entire file being rewritten to a new location, potentially leading to excessive NAND flash writes and subsequent corruption.
  • Another participant argues that as long as file allocation information is properly managed, there should not be any corruption issues, emphasizing the finite number of write cycles of flash drives.
  • It is noted that the wear on flash drives is related to the number of writes, and rewriting entire files increases the frequency of writes compared to appending.
  • Some participants discuss the possibility that the operating system may copy entire files to maintain performance and avoid fragmentation, which could explain the observed behavior of file handling.
  • One participant explains that due to NAND flash architecture, writes occur in pages or blocks, and to optimize access speeds, entire files may be rewritten even for small updates.
  • A later reply mentions that SQLite can be configured to work with NAND drives by setting a specific compile option to keep temporary files in memory, potentially reducing writes to the disk.

Areas of Agreement / Disagreement

Participants express differing views on the implications of appending versus rewriting files on NAND flash drives. While some believe that proper file management can prevent corruption, others highlight the risks associated with excessive writes. The discussion remains unresolved regarding the exact behavior of file handling in this context.

Contextual Notes

Limitations include assumptions about file allocation management and the specific behaviors of the QNX operating system and SQLite in relation to NAND flash storage. The discussion does not resolve the technical details of how appending versus rewriting affects drive longevity and data integrity.

cpscdave
Messages
402
Reaction score
120
Wondering if anyone knows anything about this.

It was mentioned to me in passing. That on QNX, with an ETFS file system when you append to a file, that it completely rewrites that entire file to another location on the Drive. This presenting an issue with extra NAND flash writes ultimately causing corruption. (if anyone has more info on this that would be great as well)

So my question is, when you do an insert into a SQLite DB, and SQLite writes that insert to the disk, is that going to do an append and a complete rewrite?
We want to ensure that we arent' going to corrupt drives 6 months down the road here :)

Thanks for your help!
 
Technology news on Phys.org
I don't see why it would cause any corruption as long as the file allocation information is properly handled (which it certainly should be).
 
phinds said:
I don't see why it would cause any corruption as long as the file allocation information is properly handled (which it certainly should be).
Because of the finite number of write cycles to a flash drive before it wears out. On the order of 104 - 105 writes to a location.
 
Tom.G said:
Because of the finite number of write cycles to a flash drive before it wears out. On the order of 104 - 105 writes to a location.
Well, sure but that's a function of just WRITING (which obviously IS done more if you re-write entire files) not something that is caused directly by rewriting rather than appending. That is, writing lots of new files and then "erasing" them does the same thing. I put "erasing" in quotes because files are not actually erased, they just get their disk space taken out of the file allocation pointers and the space is used in rotation with other unused space so as to minimize writing to any given cell.
 
Why this was raised was the thought that appending to these files would cause the OS to copy the entire file to a new physical location and then add the little extra bit it.

Only reason I could think of why the OS would do this is to keep the drive non-fragmented to maintain performance.
 
cpscdave said:
Why this was raised was the thought that appending to these files would cause the OS to copy the entire file to a new physical location and then add the little extra bit it.

Only reason I could think of why the OS would do this is to keep the drive non-fragmented to maintain performance.
With NAND flash device architecture, individual bytes are not addressable. Writes are for at least a page/block at a time. The number of writes is limited, so in order to avoid uneven wear, writes are preferentially targeted to areas in inverse order of of how many times the area has previously been written. As you surmised, in order to keep access speeds optimal, files are preferentially written to contiguous areas. To maintain contiguity, systems will, at least for a file composed of a small number of pages/blocks, write the entire file for an update, even if the update was to content within only one block of a multi-block file.
 
  • Like
Likes   Reactions: Tom.G
I looked into this a bit more and it looks as if you can compile SQLite to work with NAND drives
by setting -DSQLITE_TEMP_STORE=3

More info can be found here: https://www.sqlite.org/compile.html

But basically setting it to 3 SQLite will keep all temp files in memory as opposed to writing the temp files out to the disk.
 
  • Like
Likes   Reactions: Tom.G

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
11K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 19 ·
Replies
19
Views
14K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 19 ·
Replies
19
Views
9K
Replies
30
Views
4K
Replies
1
Views
4K