qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Vincenzo Maffione <v.maffione@gmail.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	qemu-devel <qemu-devel@nongnu.org>,
	Giuseppe Lettieri <g.lettieri@iet.unipi.it>,
	Luigi Rizzo <rizzo@iet.unipi.it>
Subject: Re: [Qemu-devel] [PATCH v2 0/3] virtio: proposal to optimize accesses to VQs
Date: Wed, 16 Dec 2015 12:37:50 +0100	[thread overview]
Message-ID: <56714D0E.1030209@redhat.com> (raw)
In-Reply-To: <CA+_eA9i8K7BCzm6Cw109T_D1wozCcXAU=612z2ZXRGcovSRbDg@mail.gmail.com>



On 16/12/2015 11:39, Vincenzo Maffione wrote:
> No problems.
> 
> I have some additional (orthogonal) curiosities:
> 
>   1) Assuming "hw/virtio/dataplane/vring.c" is what I think it is (VQ
> data structures directly accessible in the host virtual memory, with
> guest-phyisical-to-host-virtual mapping done statically at setup time)
> why isn't QEMU using this approach also for virtio-net? I see it is
> used by virtio-blk only.

Yes, it's a good idea.  vring.c's roots are in the old "virtio-blk
dataplane" code, which bypassed all of QEMU.  It had a separate event
loop, a separate I/O queue, a separate implementation of the memory map,
and a separate implementation of virtio.  virtio-blk dataplane is plenty
fast, which is why there isn't a vhost-blk.

Right now the only part that survives is the last one, which is vring.c.
 The event loop has been reconciled with AioContext, the I/O queue uses
BlockDriverState, and the memory map uses memory_region_find.

virtio-net dataplane also existed, as a possible competitor of
vhost-net.  However, vhost-net actually had better performance, so
virtio-net dataplane was never committed.  As Michael mentioned, in
practice on Linux you use vhost, and non-Linux hypervisors you do not
use QEMU. :)

Indeed the implementation in virtio.c does kind of suck.  On the other
hand, vring.c doesn't support migration because it doesn't know how to
mark guest memory as dirty.  And virtio.c is used by plenty of
devices---including virtio-blk and virtio-scsi unless you enable usage
of a separate I/O thread---and converting them to vring.c is bug-prone.
This is why I would like to drop vring.c and improve virtio.c, rather
than use vring.c even more.

The main optimization that vring.c has is to cache the translation of
the rings.  Using address_space_map/unmap for rings in virtio.c would be
a noticeable improvement, as your numbers for patch 3 show.  However, by
caching translations you also conveniently "forget" to promptly mark the
pages as dirty.  As you pointed out this is obviously an issue for
migration.  You can then add a notifier for runstate changes.  When
entering RUN_STATE_FINISH_MIGRATE or RUN_STATE_SAVE_VM the rings would
be unmapped, and then remapped the next time the VM starts running again.

You also guessed right that there are consistency issues; for these you
can add a MemoryListener that invalidates all mappings.

That said, I'm wondering where the cost of address translation lies---is
it cache-unfriendly data structures, locked operations, or simply too
much code to execute?  It was quite surprising to me that on virtio-blk
benchmarks we were spending 5% of the time doing memcpy! (I have just
extracted from my branch the patches to remove that, and sent them to
qemu-devel).

Examples of missing optimizations in exec.c include:

* caching enough information in RAM MemoryRegions to avoid the calls to
qemu_get_ram_block (e.g. replace mr->ram_addr with a RAMBlock pointer);

* adding a MRU cache to address_space_lookup_region.

In particular, the former should be easy if you want to give it a
try---easier than caching ring translations in virtio.c.

Paolo

  parent reply	other threads:[~2015-12-16 11:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-15 22:33 [Qemu-devel] [PATCH v2 0/3] virtio: proposal to optimize accesses to VQs Vincenzo Maffione
2015-12-15 22:33 ` [Qemu-devel] [PATCH v2 1/3] virtio: cache used_idx in a VirtQueue field Vincenzo Maffione
2015-12-15 22:33 ` [Qemu-devel] [PATCH v2 2/3] virtio: read avail_idx from VQ only when necessary Vincenzo Maffione
2015-12-15 22:33 ` [Qemu-devel] [PATCH v2 3/3] virtio: combine write of an entry into used ring Vincenzo Maffione
2015-12-16  8:38 ` [Qemu-devel] [PATCH v2 0/3] virtio: proposal to optimize accesses to VQs Paolo Bonzini
2015-12-16  9:28   ` Vincenzo Maffione
2015-12-16  9:34     ` Paolo Bonzini
2015-12-16 10:39       ` Vincenzo Maffione
2015-12-16 11:02         ` Michael S. Tsirkin
2015-12-16 11:23           ` Vincenzo Maffione
2015-12-16 11:37         ` Paolo Bonzini [this message]
2015-12-16 14:25           ` Vincenzo Maffione
2015-12-16 15:46             ` Paolo Bonzini
2015-12-30 16:45               ` Vincenzo Maffione

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=56714D0E.1030209@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=armbru@redhat.com \
    --cc=g.lettieri@iet.unipi.it \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rizzo@iet.unipi.it \
    --cc=v.maffione@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;
as well as URLs for NNTP newsgroup(s).