qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Xu <peterx@redhat.com>
Subject: [PULL 17/26] KVM: Add dirty-ring-size property
Date: Thu, 20 May 2021 10:22:48 +0200	[thread overview]
Message-ID: <20210520082257.187061-18-pbonzini@redhat.com> (raw)
In-Reply-To: <20210520082257.187061-1-pbonzini@redhat.com>

From: Peter Xu <peterx@redhat.com>

Add a parameter for dirty gfn count for dirty rings.  If zero, dirty ring is
disabled.  Otherwise dirty ring will be enabled with the per-vcpu gfn count as
specified.  If dirty ring cannot be enabled due to unsupported kernel or
illegal parameter, it'll fallback to dirty logging.

By default, dirty ring is not enabled (dirty-gfn-count default to 0).

Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20210506160549.130416-9-peterx@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 accel/kvm/kvm-all.c | 46 +++++++++++++++++++++++++++++++++++++++++++++
 qemu-options.hx     | 12 ++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index df9fbf59a6..5afe15ae66 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -126,6 +126,8 @@ struct KVMState
         KVMMemoryListener *ml;
         AddressSpace *as;
     } *as;
+    uint64_t kvm_dirty_ring_bytes;  /* Size of the per-vcpu dirty ring */
+    uint32_t kvm_dirty_ring_size;   /* Number of dirty GFNs per ring */
 };
 
 KVMState *kvm_state;
@@ -3182,6 +3184,42 @@ bool kvm_kernel_irqchip_split(void)
     return kvm_state->kernel_irqchip_split == ON_OFF_AUTO_ON;
 }
 
+static void kvm_get_dirty_ring_size(Object *obj, Visitor *v,
+                                    const char *name, void *opaque,
+                                    Error **errp)
+{
+    KVMState *s = KVM_STATE(obj);
+    uint32_t value = s->kvm_dirty_ring_size;
+
+    visit_type_uint32(v, name, &value, errp);
+}
+
+static void kvm_set_dirty_ring_size(Object *obj, Visitor *v,
+                                    const char *name, void *opaque,
+                                    Error **errp)
+{
+    KVMState *s = KVM_STATE(obj);
+    Error *error = NULL;
+    uint32_t value;
+
+    if (s->fd != -1) {
+        error_setg(errp, "Cannot set properties after the accelerator has been initialized");
+        return;
+    }
+
+    visit_type_uint32(v, name, &value, &error);
+    if (error) {
+        error_propagate(errp, error);
+        return;
+    }
+    if (value & (value - 1)) {
+        error_setg(errp, "dirty-ring-size must be a power of two.");
+        return;
+    }
+
+    s->kvm_dirty_ring_size = value;
+}
+
 static void kvm_accel_instance_init(Object *obj)
 {
     KVMState *s = KVM_STATE(obj);
@@ -3191,6 +3229,8 @@ static void kvm_accel_instance_init(Object *obj)
     s->kvm_shadow_mem = -1;
     s->kernel_irqchip_allowed = true;
     s->kernel_irqchip_split = ON_OFF_AUTO_AUTO;
+    /* KVM dirty ring is by default off */
+    s->kvm_dirty_ring_size = 0;
 }
 
 static void kvm_accel_class_init(ObjectClass *oc, void *data)
@@ -3212,6 +3252,12 @@ static void kvm_accel_class_init(ObjectClass *oc, void *data)
         NULL, NULL);
     object_class_property_set_description(oc, "kvm-shadow-mem",
         "KVM shadow MMU size");
+
+    object_class_property_add(oc, "dirty-ring-size", "uint32",
+        kvm_get_dirty_ring_size, kvm_set_dirty_ring_size,
+        NULL, NULL);
+    object_class_property_set_description(oc, "dirty-ring-size",
+        "Size of KVM dirty page ring buffer (default: 0, i.e. use bitmap)");
 }
 
 static const TypeInfo kvm_accel_type = {
diff --git a/qemu-options.hx b/qemu-options.hx
index e22fb94d99..ecdb064409 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -141,6 +141,7 @@ DEF("accel", HAS_ARG, QEMU_OPTION_accel,
     "                kvm-shadow-mem=size of KVM shadow MMU in bytes\n"
     "                split-wx=on|off (enable TCG split w^x mapping)\n"
     "                tb-size=n (TCG translation block cache size)\n"
+    "                dirty-ring-size=n (KVM dirty ring GFN count, default 0)\n"
     "                thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL)
 SRST
 ``-accel name[,prop=value[,...]]``
@@ -181,6 +182,17 @@ SRST
         where both the back-end and front-ends support it and no
         incompatible TCG features have been enabled (e.g.
         icount/replay).
+
+    ``dirty-ring-size=n``
+        When the KVM accelerator is used, it controls the size of the per-vCPU
+        dirty page ring buffer (number of entries for each vCPU). It should
+        be a value that is power of two, and it should be 1024 or bigger (but
+        still less than the maximum value that the kernel supports).  4096
+        could be a good initial value if you have no idea which is the best.
+        Set this value to 0 to disable the feature.  By default, this feature
+        is disabled (dirty-ring-size=0).  When enabled, KVM will instead
+        record dirty pages in a bitmap.
+
 ERST
 
 DEF("smp", HAS_ARG, QEMU_OPTION_smp,
-- 
2.31.1




  parent reply	other threads:[~2021-05-20  8:44 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-20  8:22 [PULL 00/26] Misc patches for 2021-05-20 Paolo Bonzini
2021-05-20  8:22 ` [PULL 01/26] configure: Only clone softfloat-3 repositories if TCG is enabled Paolo Bonzini
2021-05-20  8:22 ` [PULL 02/26] configure: check for submodules if --with-git-submodules=ignore Paolo Bonzini
2021-05-20  8:22 ` [PULL 03/26] configure: simplify assignment to GIT_SUBMODULES Paolo Bonzini
2021-05-20  8:22 ` [PULL 04/26] hw/mem/nvdimm: Use Kconfig 'imply' instead of 'depends on' Paolo Bonzini
2021-05-20  8:22 ` [PULL 05/26] i386/cpu: Expose AVX_VNNI instruction to guest Paolo Bonzini
2021-05-20  8:22 ` [PULL 06/26] meson: bump submodule to 0.57.2 Paolo Bonzini
2021-05-20  8:22 ` [PULL 07/26] object: add more commands to preconfig mode Paolo Bonzini
2021-05-20  8:22 ` [PULL 08/26] qtest: add a QOM object for qtest Paolo Bonzini
2021-05-20  8:22 ` [PULL 09/26] KVM: do not allow setting properties at runtime Paolo Bonzini
2021-05-20  8:22 ` [PULL 10/26] memory: Introduce log_sync_global() to memory listener Paolo Bonzini
2021-05-20  8:22 ` [PULL 11/26] KVM: Use a big lock to replace per-kml slots_lock Paolo Bonzini
2021-05-20  8:22 ` [PULL 12/26] KVM: Create the KVMSlot dirty bitmap on flag changes Paolo Bonzini
2021-05-20  8:22 ` [PULL 13/26] KVM: Provide helper to get kvm dirty log Paolo Bonzini
2021-05-20  8:22 ` [PULL 14/26] KVM: Provide helper to sync dirty bitmap from slot to ramblock Paolo Bonzini
2021-05-20  8:22 ` [PULL 15/26] KVM: Simplify dirty log sync in kvm_set_phys_mem Paolo Bonzini
2021-05-20  8:22 ` [PULL 16/26] KVM: Cache kvm slot dirty bitmap size Paolo Bonzini
2021-05-20  8:22 ` Paolo Bonzini [this message]
2021-05-20  8:22 ` [PULL 18/26] KVM: Disable manual dirty log when dirty ring enabled Paolo Bonzini
2021-05-20  8:22 ` [PULL 19/26] KVM: Dirty ring support Paolo Bonzini
2021-05-20  8:22 ` [PULL 20/26] tests/qtest/fuzz: Fix build failure Paolo Bonzini
2021-05-20  8:22 ` [PULL 21/26] meson: Set implicit_include_directories to false Paolo Bonzini
2021-05-20  8:22 ` [PULL 22/26] remove qemu-options* from root directory Paolo Bonzini
2021-05-20  8:22 ` [PULL 23/26] replication: move include out of " Paolo Bonzini
2021-05-20  8:22 ` [PULL 24/26] vl: allow not specifying size in -m when using -M memory-backend Paolo Bonzini
2021-05-20  8:22 ` [PULL 25/26] qemu-config: load modules when instantiating option groups Paolo Bonzini
2021-05-20  8:22 ` [PULL 26/26] scsi-generic: pass max_segments via max_iov field in BlockLimits Paolo Bonzini
2021-05-20  8:54 ` [PULL 00/26] Misc patches for 2021-05-20 no-reply
2021-05-20 13:26 ` Peter Maydell
2021-05-20 14:20   ` Peter Maydell
2021-05-20 14:25     ` Peter Maydell
2021-05-21 13:27   ` Paolo Bonzini
2021-05-21 13:44     ` Peter Maydell
2021-05-24  9:42       ` Paolo Bonzini

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=20210520082257.187061-18-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).