Archived:How does write cache work on the Nokia N91
How does write cache work on the Nokia N91
The write cache is cluster based (i.e., it has no concept of whether it is writing to files or FAT or directories, etc). As such it is a fifo queue, in other words, the first thing to be written is first to be flushed. Write-through may be more important from a data preservation point of view, but consider cases such as downloading a file from the Internet over a slow connection. Assume the file takes 5 minutes to download. As the file is being downloaded, the file contents get written to write cache. However, as the file size increases, the FAT must also be updated and if those entries were write-through, the disk would be spinning the whole time and the battery life would drop remarkably. All the cases where data could be lost should be accounted for, except for crashes that cause device reset (which there hopefully won't be any of). In the case of device reset, there is no way to guarantee data preservation as even with write-through the HDD has an internal cache and if not powered down correctly, it can cause random data loss that we have no control over. Other cases should be handled properly:
- Before the battery dies, a low power warning will flush the cache and change it to write-through.
- If the battery cover is removed, the cache is flushed and the HDD is unavailable in case the user pulls the battery.
- If the device is dropped, the accelerometer flushes the cache and disables the drive in case the impact causes the back cover to open and battery to pop out.
- If the device is powered down, the cache is flushed and the HDD is shut down.
- Also handle any other cases you can think of.
The write cache is ~1.5MB and the read cache is ~11MB. If the user writes less than 1.5 MB to disk and then stops all disk activity (doesn't write any more and doesn't read anything that isn't previously cached, doesn't power down, doesn't drop the device or remove the battery cover or start the mass storage mode, etc.) and a device crash occurs, then data could be lost. The combination of these situations should be very rare or non-existent if there aren't any device crashes).