[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 08/10] softmmu/physmem: Extend ram_block_discard_(require|disa
From: |
David Hildenbrand |
Subject: |
[PATCH v3 08/10] softmmu/physmem: Extend ram_block_discard_(require|disable) by two discard types |
Date: |
Wed, 16 Dec 2020 15:11:58 +0100 |
We want to separate the two cases whereby we discard ram
- uncoordinated: e.g., virito-balloon
- coordinated: e.g., virtio-mem coordinated via the RamDiscardMgr
Reviewed-by: Pankaj Gupta <pankaj.gupta@cloud.ionos.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Auger Eric <eric.auger@redhat.com>
Cc: Wei Yang <richard.weiyang@linux.alibaba.com>
Cc: teawater <teawaterz@linux.alibaba.com>
Cc: Marek Kedzierski <mkedzier@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
include/exec/memory.h | 18 +++++++++++++--
softmmu/physmem.c | 54 ++++++++++++++++++++++++++++++++++++++-----
2 files changed, 64 insertions(+), 8 deletions(-)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 67d9f1f3a7..11832cce3c 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -2808,6 +2808,12 @@ static inline MemOp devend_memop(enum device_endian end)
*/
int ram_block_discard_disable(bool state);
+/*
+ * See ram_block_discard_disable(): only disable uncoordinated discards,
+ * keeping coordinated discards (via the RamDiscardMgr) enabled.
+ */
+int ram_block_uncoordinated_discard_disable(bool state);
+
/*
* Inhibit technologies that disable discarding of pages in RAM blocks.
*
@@ -2817,12 +2823,20 @@ int ram_block_discard_disable(bool state);
int ram_block_discard_require(bool state);
/*
- * Test if discarding of memory in ram blocks is disabled.
+ * See ram_block_discard_require(): only inhibit technologies that disable
+ * uncoordinated discarding of pages in RAM blocks, allowing co-existance with
+ * technologies that only inhibit uncoordinated discards (via the
+ * RamDiscardMgr).
+ */
+int ram_block_coordinated_discard_require(bool state);
+
+/*
+ * Test if any discarding of memory in ram blocks is disabled.
*/
bool ram_block_discard_is_disabled(void);
/*
- * Test if discarding of memory in ram blocks is required to work reliably.
+ * Test if any discarding of memory in ram blocks is required to work reliably.
*/
bool ram_block_discard_is_required(void);
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 6281ef6208..3c7e6f3c53 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -3660,8 +3660,14 @@ void mtree_print_dispatch(AddressSpaceDispatch *d,
MemoryRegion *root)
}
}
+/* Require any discards to work. */
static unsigned int ram_block_discard_requirers;
+/* Require only coordinated discards to work. */
+static unsigned int ram_block_coordinated_discard_requirers;
+/* Disable any discards. */
static unsigned int ram_block_discard_disablers;
+/* Disable only uncoordinated discards. */
+static unsigned int ram_block_uncoordinated_discard_disablers;
static QemuMutex ram_block_discard_disable_mutex;
static void ram_block_discard_disable_mutex_lock(void)
@@ -3687,10 +3693,27 @@ int ram_block_discard_disable(bool state)
ram_block_discard_disable_mutex_lock();
if (!state) {
ram_block_discard_disablers--;
- } else if (!ram_block_discard_requirers) {
- ram_block_discard_disablers++;
+ } else if (ram_block_discard_requirers ||
+ ram_block_coordinated_discard_requirers) {
+ ret = -EBUSY;
} else {
+ ram_block_discard_disablers++;
+ }
+ ram_block_discard_disable_mutex_unlock();
+ return ret;
+}
+
+int ram_block_uncoordinated_discard_disable(bool state)
+{
+ int ret = 0;
+
+ ram_block_discard_disable_mutex_lock();
+ if (!state) {
+ ram_block_uncoordinated_discard_disablers--;
+ } else if (ram_block_discard_requirers) {
ret = -EBUSY;
+ } else {
+ ram_block_uncoordinated_discard_disablers++;
}
ram_block_discard_disable_mutex_unlock();
return ret;
@@ -3703,10 +3726,27 @@ int ram_block_discard_require(bool state)
ram_block_discard_disable_mutex_lock();
if (!state) {
ram_block_discard_requirers--;
- } else if (!ram_block_discard_disablers) {
- ram_block_discard_requirers++;
+ } else if (ram_block_discard_disablers ||
+ ram_block_uncoordinated_discard_disablers) {
+ ret = -EBUSY;
} else {
+ ram_block_discard_requirers++;
+ }
+ ram_block_discard_disable_mutex_unlock();
+ return ret;
+}
+
+int ram_block_coordinated_discard_require(bool state)
+{
+ int ret = 0;
+
+ ram_block_discard_disable_mutex_lock();
+ if (!state) {
+ ram_block_coordinated_discard_requirers--;
+ } else if (ram_block_discard_disablers) {
ret = -EBUSY;
+ } else {
+ ram_block_coordinated_discard_requirers++;
}
ram_block_discard_disable_mutex_unlock();
return ret;
@@ -3714,10 +3754,12 @@ int ram_block_discard_require(bool state)
bool ram_block_discard_is_disabled(void)
{
- return qatomic_read(&ram_block_discard_disablers);
+ return qatomic_read(&ram_block_discard_disablers) ||
+ qatomic_read(&ram_block_uncoordinated_discard_disablers);
}
bool ram_block_discard_is_required(void)
{
- return qatomic_read(&ram_block_discard_requirers);
+ return qatomic_read(&ram_block_discard_requirers) ||
+ qatomic_read(&ram_block_coordinated_discard_requirers);
}
--
2.29.2
- [PATCH v3 00/10] virtio-mem: vfio support, David Hildenbrand, 2020/12/16
- [PATCH v3 01/10] memory: Introduce RamDiscardMgr for RAM memory regions, David Hildenbrand, 2020/12/16
- [PATCH v3 02/10] virtio-mem: Factor out traversing unplugged ranges, David Hildenbrand, 2020/12/16
- [PATCH v3 03/10] virtio-mem: Implement RamDiscardMgr interface, David Hildenbrand, 2020/12/16
- [PATCH v3 04/10] vfio: Query and store the maximum number of DMA mappings, David Hildenbrand, 2020/12/16
- [PATCH v3 05/10] vfio: Support for RamDiscardMgr in the !vIOMMU case, David Hildenbrand, 2020/12/16
- [PATCH v3 06/10] vfio: Support for RamDiscardMgr in the vIOMMU case, David Hildenbrand, 2020/12/16
- [PATCH v3 07/10] softmmu/physmem: Don't use atomic operations in ram_block_discard_(disable|require), David Hildenbrand, 2020/12/16
- [PATCH v3 08/10] softmmu/physmem: Extend ram_block_discard_(require|disable) by two discard types,
David Hildenbrand <=
- [PATCH v3 09/10] virtio-mem: Require only coordinated discards, David Hildenbrand, 2020/12/16
- [PATCH v3 10/10] vfio: Disable only uncoordinated discards, David Hildenbrand, 2020/12/16