1

Not sure this is the right place for this question but here goes...

I have some application that writes a log file. Now I have to run it on a system which has only flash storage: embedded MMC and micro SD. And this machine has high probability of unexpected power offs (this was not planned when the application was created). So at best, the log file can be truncated, at worst the whole volume may be corrupted. The log records are produced at variable rate, sometimes several in a second.

The question is, if I simply call a file flush (and a sync) after writing every log record - will it cause excessive wear of the flash drive? Does the SD/MMC internal controller optimize writes when small pieces of data are appended, so that it uses the existing space in the current sector (?) or it will allocate a new block for every write? If the latter is true, then SD/MMC is not suitable for log files at all?

Related question (or same, re-phrased): If you append lines to the file one by one (open the file in append mode, write, close) will the last physical block be reused if not full? or the last block will be reallocated and previous data copied into it?

ddbug
  • 111
  • 6
  • I *think* that writing a new file with thousand lines of log data at once to an micro SD card causes the same amount of wear as creating a new file and (slowly) one at a time appending a thousand lines to that same new file, as that is essence the same contiguous operation. – HBruijn Jul 11 '19 at 11:12
  • @HBruijn but what if between writing lines you flush often (discarding effect of the cache)? – ddbug Jul 11 '19 at 11:34
  • 1
    Can't you log to a log server? – Sven Jul 11 '19 at 11:35
  • @Sven no, I cannot. Must be stored locally. – ddbug Jul 11 '19 at 11:41
  • So I'm thinking towards EEPROM or low level (non-disk) flash memory writable by byte instead of the SD/MMC... – ddbug Jul 11 '19 at 13:39
  • Which operating system? On Linux there is a choice of several file systems including f2fs. – John Mahowald Jul 12 '19 at 03:13
  • Yes, Linux. How f2fs would help with SD media (with internal controller)? – ddbug Jul 13 '19 at 12:20

0 Answers0