yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
d740ea
From cc224bcb3c12238466f8a6a366d3f813fb866a16 Mon Sep 17 00:00:00 2001
d740ea
From: Alex Williamson <alex.williamson@redhat.com>
d740ea
Date: Thu, 13 Dec 2018 21:54:28 +0100
d740ea
Subject: [PATCH 1/5] Inhibit ballooning during postcopy
d740ea
d740ea
RH-Author: Alex Williamson <alex.williamson@redhat.com>
d740ea
Message-id: <154473806860.22725.2305869657628116679.stgit@gimli.home>
d740ea
Patchwork-id: 83493
d740ea
O-Subject: [RHEL-7.7 qemu-kvm PATCH 1/5] Inhibit ballooning during postcopy
d740ea
Bugzilla: 1659229
d740ea
RH-Acked-by: Peter Xu <peterx@redhat.com>
d740ea
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
d740ea
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
d740ea
d740ea
From: Dr. David Alan Gilbert <dgilbert@redhat.com>
d740ea
d740ea
Bugzilla: 1659229
d740ea
Notes: Dropped all but balloon inhibitor infrastructure
d740ea
d740ea
Postcopy detects accesses to pages that haven't been transferred yet
d740ea
using userfaultfd, and it causes exceptions on pages that are 'not
d740ea
present'.
d740ea
Ballooning also causes pages to be marked as 'not present' when the
d740ea
guest inflates the balloon.
d740ea
Potentially a balloon could be inflated to discard pages that are
d740ea
currently inflight during postcopy and that may be arriving at about
d740ea
the same time.
d740ea
d740ea
To avoid this confusion, disable ballooning during postcopy.
d740ea
d740ea
When disabled we drop balloon requests from the guest.  Since ballooning
d740ea
is generally initiated by the host, the management system should avoid
d740ea
initiating any balloon instructions to the guest during migration,
d740ea
although it's not possible to know how long it would take a guest to
d740ea
process a request made prior to the start of migration.
d740ea
Guest initiated ballooning will not know if it's really freed a page
d740ea
of host memory or not.
d740ea
d740ea
Queueing the requests until after migration would be nice, but is
d740ea
non-trivial, since the set of inflate/deflate requests have to
d740ea
be compared with the state of the page to know what the final
d740ea
outcome is allowed to be.
d740ea
d740ea
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
d740ea
Reviewed-by: Juan Quintela <quintela@redhat.com>
d740ea
Reviewed-by: Amit Shah <amit.shah@redhat.com>
d740ea
Signed-off-by: Juan Quintela <quintela@redhat.com>
d740ea
(cherry picked from commit 371ff5a3f04cd7d05bab49ac6e80da319026d95b)
d740ea
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
d740ea
---
d740ea
 balloon.c                  | 11 +++++++++++
d740ea
 hw/virtio/virtio-balloon.c |  4 +++-
d740ea
 include/sysemu/balloon.h   |  2 ++
d740ea
 3 files changed, 16 insertions(+), 1 deletion(-)
d740ea
d740ea
diff --git a/balloon.c b/balloon.c
d740ea
index e321f2c..c7a0cf1 100644
d740ea
--- a/balloon.c
d740ea
+++ b/balloon.c
d740ea
@@ -35,6 +35,17 @@
d740ea
 static QEMUBalloonEvent *balloon_event_fn;
d740ea
 static QEMUBalloonStatus *balloon_stat_fn;
d740ea
 static void *balloon_opaque;
d740ea
+static bool balloon_inhibited;
d740ea
+
d740ea
+bool qemu_balloon_is_inhibited(void)
d740ea
+{
d740ea
+    return balloon_inhibited;
d740ea
+}
d740ea
+
d740ea
+void qemu_balloon_inhibit(bool state)
d740ea
+{
d740ea
+    balloon_inhibited = state;
d740ea
+}
d740ea
 
d740ea
 int qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
d740ea
                              QEMUBalloonStatus *stat_func, void *opaque)
d740ea
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
d740ea
index 1a60d3c..c9562ef 100644
d740ea
--- a/hw/virtio/virtio-balloon.c
d740ea
+++ b/hw/virtio/virtio-balloon.c
d740ea
@@ -34,9 +34,11 @@
d740ea
 static void balloon_page(void *addr, int deflate)
d740ea
 {
d740ea
 #if defined(__linux__)
d740ea
-    if (!kvm_enabled() || kvm_has_sync_mmu())
d740ea
+    if (!qemu_balloon_is_inhibited() && (!kvm_enabled() ||
d740ea
+                                         kvm_has_sync_mmu())) {
d740ea
         qemu_madvise(addr, TARGET_PAGE_SIZE,
d740ea
                 deflate ? QEMU_MADV_WILLNEED : QEMU_MADV_DONTNEED);
d740ea
+    }
d740ea
 #endif
d740ea
 }
d740ea
 
d740ea
diff --git a/include/sysemu/balloon.h b/include/sysemu/balloon.h
d740ea
index bd9d395..eb5af19 100644
d740ea
--- a/include/sysemu/balloon.h
d740ea
+++ b/include/sysemu/balloon.h
d740ea
@@ -23,6 +23,8 @@ typedef void (QEMUBalloonStatus)(void *opaque, BalloonInfo *info);
d740ea
 int qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
d740ea
 			     QEMUBalloonStatus *stat_func, void *opaque);
d740ea
 void qemu_remove_balloon_handler(void *opaque);
d740ea
+bool qemu_balloon_is_inhibited(void);
d740ea
+void qemu_balloon_inhibit(bool state);
d740ea
 
d740ea
 void qemu_balloon_changed(int64_t actual);
d740ea
 
d740ea
-- 
d740ea
1.8.3.1
d740ea