2014-07-09 12:25:14

by Grzegorz Sikorski

[permalink] [raw]
Subject: Question about data integrity on SD cards

Hi,

In our project we use SQLite3 database on EXT4 filesystem partition on
microSD card. On unexpected power failure/system crash or just hardware
reset, we observe occasional database corruption. SQLite3 developers
claim their part is free of risk of database corruption, as long as
fsync call is doing it's job properly. We tried several SD cards,
including industrial grade which should have proper firmware (at least
their manufacturers say there is no risk of data corruption on power
loss). We tried several different mount settings and after some reading
we found, that the safest (and slowest) option (that should never fail,
as far as we understand) would be like:
rw,relatime,barrier=1,journal_checksum,nodelalloc,data=journal,usrquota
In spite of all that, we still observe random database corruption on
power-down/reset. Can you confirm there is no problem in EXT4 filesystem?

Best regards,
Greg

--
ExchangeDefender Message Security: Click below to verify authenticity
https://admin.exchangedefender.com/verify.php?id=s69CHHv3024052&[email protected]




2014-07-09 12:51:11

by Lukas Czerner

[permalink] [raw]
Subject: Re: Question about data integrity on SD cards

On Wed, 9 Jul 2014, Grzegorz Sikorski wrote:

> Date: Wed, 09 Jul 2014 13:17:25 +0100
> From: Grzegorz Sikorski <[email protected]>
> To: [email protected]
> Subject: Question about data integrity on SD cards
>
> Hi,
>
> In our project we use SQLite3 database on EXT4 filesystem partition on microSD
> card. On unexpected power failure/system crash or just hardware reset, we
> observe occasional database corruption. SQLite3 developers claim their part is
> free of risk of database corruption, as long as fsync call is doing it's job
> properly. We tried several SD cards, including industrial grade which should
> have proper firmware (at least their manufacturers say there is no risk of
> data corruption on power loss). We tried several different mount settings and
> after some reading we found, that the safest (and slowest) option (that should
> never fail, as far as we understand) would be like:
> rw,relatime,barrier=1,journal_checksum,nodelalloc,data=journal,usrquota
> In spite of all that, we still observe random database corruption on
> power-down/reset. Can you confirm there is no problem in EXT4 filesystem?

There have been reports on SD cards not working correctly on power
failure, most likely due to flush not working correctly. It was
mentioned several times in this huge thread (concerning different
problem, but maybe related)
http://www.spinics.net/lists/linux-ext4/msg43974.html

At this point we do not know about any problems with ext4 file
system regarding fsync functionality. However you have not said
which kernel you are using.

Also, have you tried reproducing it on a different hardware, let's
say SSD, or spinning disk ? Do you have any SD card which seems to
be working reliably across power failures, or did you see that
behaviour with all SD cards you've tested ?

Thanks!
-Lukas

>
> Best regards,
> Greg
>
> --
> ExchangeDefender Message Security: Click below to verify authenticity
> https://admin.exchangedefender.com/verify.php?id=s69CHHv3024052&[email protected]
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2014-07-09 13:23:27

by Grzegorz Sikorski

[permalink] [raw]
Subject: Re: Question about data integrity on SD cards

We are using 2.6.37 version and we may have some issues with underlying
mmc-host driver. We also tested our setup on newer kernels as well as
different media with similar results, but I was not involved in these
tests, so cannot give any details straight away.

But my main question was partially answered by you. I just need a
confirmation that design of our system should in general be OK, as we
may expect random power downs occasionally. So do you think it is
possible (in general) to build embedded system with SQLite3 database on
EXT4 filesystem on SD card that is not fragile on unexpected power
sequence? Do you know what type of SD card would be recommended in this
case? Are our mounting options fine?

Thanks,
Greg

On 09/07/14 13:51, Luk?? Czerner wrote:
> On Wed, 9 Jul 2014, Grzegorz Sikorski wrote:
>
>> Date: Wed, 09 Jul 2014 13:17:25 +0100
>> From: Grzegorz Sikorski <[email protected]>
>> To: [email protected]
>> Subject: Question about data integrity on SD cards
>>
>> Hi,
>>
>> In our project we use SQLite3 database on EXT4 filesystem partition on microSD
>> card. On unexpected power failure/system crash or just hardware reset, we
>> observe occasional database corruption. SQLite3 developers claim their part is
>> free of risk of database corruption, as long as fsync call is doing it's job
>> properly. We tried several SD cards, including industrial grade which should
>> have proper firmware (at least their manufacturers say there is no risk of
>> data corruption on power loss). We tried several different mount settings and
>> after some reading we found, that the safest (and slowest) option (that should
>> never fail, as far as we understand) would be like:
>> rw,relatime,barrier=1,journal_checksum,nodelalloc,data=journal,usrquota
>> In spite of all that, we still observe random database corruption on
>> power-down/reset. Can you confirm there is no problem in EXT4 filesystem?
> There have been reports on SD cards not working correctly on power
> failure, most likely due to flush not working correctly. It was
> mentioned several times in this huge thread (concerning different
> problem, but maybe related)
> http://www.spinics.net/lists/linux-ext4/msg43974.html
>
> At this point we do not know about any problems with ext4 file
> system regarding fsync functionality. However you have not said
> which kernel you are using.
>
> Also, have you tried reproducing it on a different hardware, let's
> say SSD, or spinning disk ? Do you have any SD card which seems to
> be working reliably across power failures, or did you see that
> behaviour with all SD cards you've tested ?
>
> Thanks!
> -Lukas
>
>> Best regards,
>> Greg
>>
>> --
>> ExchangeDefender Message Security: Click below to verify authenticity
>> https://admin.exchangedefender.com/verify.php?id=s69CHHv3024052&[email protected]
>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>


--
ExchangeDefender Message Security: Click below to verify authenticity
https://admin.exchangedefender.com/verify.php?id=s69DNLGC013653&[email protected]

2014-07-15 07:09:19

by David Jander

[permalink] [raw]
Subject: Re: Question about data integrity on SD cards

On Wed, 09 Jul 2014 14:23:29 +0100
Grzegorz Sikorski <[email protected]> wrote:

> We are using 2.6.37 version and we may have some issues with underlying
> mmc-host driver. We also tested our setup on newer kernels as well as
> different media with similar results, but I was not involved in these
> tests, so cannot give any details straight away.
>
> But my main question was partially answered by you. I just need a
> confirmation that design of our system should in general be OK, as we
> may expect random power downs occasionally. So do you think it is
> possible (in general) to build embedded system with SQLite3 database on
> EXT4 filesystem on SD card that is not fragile on unexpected power
> sequence? Do you know what type of SD card would be recommended in this
> case? Are our mounting options fine?

Sorry for the late reaction. In case you still wonder, no. It is not possible
to do this with common (COTS) SD cards in general. Due to their nature, SD
cards can corrupt even data that is not being written to when power is
interrupted during a write (or read) action. There is no filesystem that can
protect you from that.

And btw, the thread Lukáš mentioned is about a bug in ext4, not really about
problems with SD cards.

If you need robust flash storage, please look at MMC 4.41+ enhanced mode and
"reliable-write" functionality. Without these two functions combined, it is
not possible to do what you want to do. I have not seen (non embedded) MMC
cards (in actual SD/MMC-card format) that support version 4.41 or newer of the
(e)MMC standard, but it may be possible that someone makes them.... that might be
a solution for your problem.

Best regards,

--
David Jander
Protonic Holland.