All of lore.kernel.org
 help / color / mirror / Atom feed
From: Theodore Ts'o <tytso@mit.edu>
To: Eric Sandeen <sandeen@redhat.com>
Cc: "Clemens Gruber" <clemens.gruber@pqgruber.com>,
	"Lukáš Czerner" <lczerner@redhat.com>,
	linux-ext4@vger.kernel.org
Subject: Re: Fast ext4 cleanup to avoid data loss after power failure
Date: Fri, 3 Oct 2014 23:47:07 -0400	[thread overview]
Message-ID: <20141004034707.GA4581@thunk.org> (raw)
In-Reply-To: <542EC445.5030503@redhat.com>

So long as you aren't dilly-dallying, 1.5 seconds is an huge amount of
time so long as the application doesn't have to write a huge amount of
state.  What I would do is to give the application a second time
budget to shutdown, then use the FIFREEZE ioctl to lock the file
system into a consistent state, and then wait for the end to come.

More generally, it's a good idea to seriously control how much stuff
you are writing to the eMMC, and to question whether any of it is
necessary, and if it isn't to ruthless cut it out.

In addition to the write everything to a temporary file, and the fsync
the changes, and then use an atomic rename to replace the original
file, an additional design pattern you can use is an application level
journal.  Just append each thing that needs to be saved to an
application journal file: "dispensed one shot of whisky"; "entering
light pour mode for happy hour", etc, with an fsync() after each write
to the application.  This minimizes the amount of writes you need for
each application update, and then periodically, you can dump all of
the state out to the temp file, rename it, and then truncate the
application journal.

If you crash, then it's simply a matter of replaying the application
journal log into your application state when you start up again.

One important thing to remember is that most eMMC are not protected
against power failure.  So if you are writing to the eMMC flash when
the power finally fails, the flash translation metadata can get
corrupted, and you can lose all of your data, or some of your data,
but it will not be under your control at all.

Hence my recommendation to give your application a one second time
budget to quiesce itself, and then to use FIFREEZE --- that way you
don't have to optimize your system daemons from having a fast shutdown
sequence.  Or you can have your emergency shutdown program send a kill
-9 to all processes except itself and init, and then unmount the file
system --- but FIFREEZE might be easier.  :-)

Cheers,

						- Ted

P.S.  And keeping a read-only root and only having writable state in
small writable partition is also a good idea.  For bonus points, keep
*two* copies of the read-only root, so you can update one of the
roots, reboot into it, and if you can successfuly reboot into it, only
then do you update the other read-only root.

  reply	other threads:[~2014-10-04  3:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-03 13:09 Fast ext4 cleanup to avoid data loss after power failure Clemens Gruber
2014-10-03 14:08 ` Lukáš Czerner
2014-10-03 15:39   ` Clemens Gruber
2014-10-03 15:44     ` Eric Sandeen
2014-10-04  3:47       ` Theodore Ts'o [this message]
2014-10-06 22:04         ` Clemens Gruber

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=20141004034707.GA4581@thunk.org \
    --to=tytso@mit.edu \
    --cc=clemens.gruber@pqgruber.com \
    --cc=lczerner@redhat.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sandeen@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.