Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Artem Bityutskiy <dedekind1@gmail.com>
To: "Mats Kärrman" <Mats.Karrman@tritech.se>
Cc: "linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>,
	rcrb rcrb <rcrbsw@gmail.com>
Subject: Re: UBIFS data integrity
Date: Thu, 16 Jan 2014 11:26:22 +0200	[thread overview]
Message-ID: <1389864382.26808.97.camel@sauron.fi.intel.com> (raw)
In-Reply-To: <ED3E0BCACD909541BA94A34C4A164D4C4FDD5418@post.tritech.se>

On Thu, 2014-01-16 at 09:12 +0000, Mats Kärrman wrote:
> On Thursday, January 16, 2014 9:16 AM, Artem Bityutskiy wrote:
> > > UBIFS writes in 4KiB units.
> > 
> > I guess this is a bit confusing. The low-level flash write operations
> > can be bigger or smaller. However, the file data "buffers" that UBIFS
> > writes contain 4KiB of file data (aligned, e.g., regions of the file
> > would be 0-4K, 4K-8K, etc). Every such "buffer" is protected with CRC32,
> > and if a power cut results in the buffer not being fully written, the
> > CRC32 mismatches and UBIFS discards the entire buffer. And the old
> > contents of this file region is stays on the flash. The old contents
> > does not go away before the new contents reaches the flash media. So the
> > read operation for any aligned 4KiB region always returns the old
> > contents, or the new contents, nothing else.
> > 
> > >  So any aligned 4KiB piece of your file is
> > > guaranteed to either be fully written, then the read will return new
> > > data, or not be written at all, then the read will return old data.
> 
> Sorry if I mislead you, I guess the final statement of my original mail is
> still valid then:
> "In general this requires that your database also is implemented
> in a fault tolerant way."
> I.e. it must itself make sure it's entire write is completed before
> switching to a new "state". Unless the DB implements some kind of
> journaling this may be a problem.

Sure. The ordering or the 4K writes is not guaranteed, but I think the
memory management subsystem uses LRU lists so older writes go first. Any
write that crosses the 4096 byte-aligned boundary is not atomic. So the
only thing UBIFS guarantees is something like:

fsync
write(4k-5k)
fsync

will guarantee that the 1K piece of data either gets fully written or
not at all.

-- 
Best Regards,
Artem Bityutskiy

  reply	other threads:[~2014-01-16  9:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-14  2:51 UBIFS data integrity rcrb rcrb
2014-01-14  9:32 ` Mats Kärrman
2014-01-15 18:31   ` rcrb rcrb
2014-01-16  8:00     ` Artem Bityutskiy
2014-01-16  8:16       ` Artem Bityutskiy
2014-01-16  9:12         ` Mats Kärrman
2014-01-16  9:26           ` Artem Bityutskiy [this message]
2014-01-17  9:21             ` Gupta, Pekon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1389864382.26808.97.camel@sauron.fi.intel.com \
    --to=dedekind1@gmail.com \
    --cc=Mats.Karrman@tritech.se \
    --cc=linux-mtd@lists.infradead.org \
    --cc=rcrbsw@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox