All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Richard W.M. Jones" <rjones@redhat.com>
To: richard -rw- weinberger <richard.weinberger@gmail.com>
Cc: "user-mode-linux-devel@lists.sourceforge.net"
	<user-mode-linux-devel@lists.sourceforge.net>
Subject: Re: [uml-devel] Performance tests (was: Using UML in libguestfs)
Date: Fri, 16 Aug 2013 08:54:47 +0100	[thread overview]
Message-ID: <20130816075447.GR5918@redhat.com> (raw)
In-Reply-To: <CAFLxGvyJ1EEjBVwXee=175YFBB=WOQg6VcCOBq5qHTG2nKg6Bw@mail.gmail.com>

On Thu, Aug 15, 2013 at 10:31:54PM +0200, richard -rw- weinberger wrote:
> On Thu, Aug 15, 2013 at 8:59 PM, Richard W.M. Jones <rjones@redhat.com> wrote:
> > On Thu, Aug 15, 2013 at 08:41:53PM +0200, richard -rw- weinberger wrote:
> >> Meant regarding fsync()...
> >
> > Ah right, see what you mean :-)
> >
> > It calls sync(2).  Then it opens each /dev/ubdX device and calls fsync
> > on the file descriptor:
> >
> > https://github.com/libguestfs/libguestfs/blob/master/daemon/sync.c#L54
> >
> > The reason for this is a bit complicated, but has to do with write
> > barriers.  I believe this has been fixed since then.
> >
> > https://github.com/libguestfs/libguestfs/commit/c0a3c9ce70b98171e737e49e6dccc4457963f2ec
> >
> > In any case, we're calling sync & fsync in the guest, and that ain't
> > causing the host cache to be flushed.
> 
> Hmm, AFAIK a fsync() after sync() is pointless.

That's definitely what you'd expect, but Linux was buggy until last
year: it only synched mounted filesystems, not devices in general.

This was fixed:

  commit a8c7176b6ded413d5044a00f1d05477b95a6d7ad
  Author: Jan Kara <jack@suse.cz>
  Date:   Tue Jul 3 16:45:32 2012 +0200

    vfs: Make sys_sync writeout also block device inodes

but in libguestfs we can't rely on people using a new enough kernel so
we do the safe thing.

> > It's pretty easy to show this with libguestfs:
> >
> > LIBGUESTFS_BACKEND=uml LIBGUESTFS_HV=~/d/linux-um/linux \
> > time ./run ./fish/guestfish -N fs:ext2:1G -m /dev/sda1 fallocate64 /data 800M
> > time sync
> >
> > The first command finishes in 8 seconds, with barely any disk
> > activity.  The sync afterwards takes 9 seconds with the disk light on
> > the whole time, while it actually writes the whole 800 MB of data.
> 
> I think you don't see the desired effect because UML does not open
> the backing file with O_SYNC.
> But you can tell UML to do so.
> e.g. write ubdas=/foo instead of ubda=/foo.

I didn't know about these flags.

I modified libguestfs to use the 's' flag, and reran the test above:

  UML (with O_SYNC):           598 seconds
  UML (unsafe):                  9 seconds
  UML + explicit host sync:     20 seconds
  KVM:                          20 seconds

However using O_SYNC is not the same as properly handling write
barriers.  UML is buggy in this respect because a user in the guest
who does 'sync' (and the sync returns to the prompt) wouldn't expect
that if the power failed immediately afterwards they would lose all
their data.  If they are using a journaled filesystem they'd also risk
unrecoverable data corruption during general usage.

KVM and LVM have both been here a few years ago and have fixed these
issues (mind you, KVM only does the right thing if you use the right
cache=... option).

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming blog: http://rwmj.wordpress.com
Fedora now supports 80 OCaml packages (the OPEN alternative to F#)

------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


      reply	other threads:[~2013-08-16  7:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-09 20:43 [uml-devel] Using UML in libguestfs Richard W.M. Jones
2013-08-09 20:57 ` richard -rw- weinberger
2013-08-09 21:31   ` Richard W.M. Jones
2013-08-10  4:16   ` Mattia Dongili
2013-08-09 21:15 ` Richard W.M. Jones
2013-08-09 21:18   ` Richard Weinberger
2013-08-09 21:24     ` Richard W.M. Jones
2013-08-11 19:05 ` Geert Uytterhoeven
2013-08-11 19:27   ` Richard W.M. Jones
2013-08-13 11:16     ` Geert Uytterhoeven
2013-08-14 17:59 ` [uml-devel] Performance tests (was: Using UML in libguestfs) Richard W.M. Jones
2013-08-15 17:37   ` richard -rw- weinberger
2013-08-15 17:59     ` Richard W.M. Jones
2013-08-15 18:41       ` richard -rw- weinberger
2013-08-15 18:59         ` Richard W.M. Jones
2013-08-15 20:31           ` richard -rw- weinberger
2013-08-16  7:54             ` Richard W.M. Jones [this message]

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=20130816075447.GR5918@redhat.com \
    --to=rjones@redhat.com \
    --cc=richard.weinberger@gmail.com \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /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.