[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 17/34] migration/multifd: Make MultiFDPages_t:offset a flexible ar
From: |
Fabiano Rosas |
Subject: |
[PULL 17/34] migration/multifd: Make MultiFDPages_t:offset a flexible array member |
Date: |
Wed, 4 Sep 2024 09:44:00 -0300 |
We're about to use MultiFDPages_t from inside the MultiFDSendData
payload union, which means we cannot have pointers to allocated data
inside the pages structure, otherwise we'd lose the reference to that
memory once another payload type touches the union. Move the offset
array into the end of the structure and turn it into a flexible array
member, so it is allocated along with the rest of MultiFDSendData in
the next patches.
Note that other pointers, such as the ramblock pointer are still fine
as long as the storage for them is not owned by the migration code and
can be correctly released at some point.
Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
migration/multifd.c | 19 ++++++++++++-------
migration/multifd.h | 4 ++--
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/migration/multifd.c b/migration/multifd.c
index 640e4450ff..717e71f539 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -98,6 +98,17 @@ struct {
MultiFDMethods *ops;
} *multifd_recv_state;
+static size_t multifd_ram_payload_size(void)
+{
+ uint32_t n = multifd_ram_page_count();
+
+ /*
+ * We keep an array of page offsets at the end of MultiFDPages_t,
+ * add space for it in the allocation.
+ */
+ return sizeof(MultiFDPages_t) + n * sizeof(ram_addr_t);
+}
+
static bool multifd_use_packets(void)
{
return !migrate_mapped_ram();
@@ -394,18 +405,12 @@ static int multifd_recv_initial_packet(QIOChannel *c,
Error **errp)
static MultiFDPages_t *multifd_pages_init(uint32_t n)
{
- MultiFDPages_t *pages = g_new0(MultiFDPages_t, 1);
-
- pages->offset = g_new0(ram_addr_t, n);
-
- return pages;
+ return g_malloc0(multifd_ram_payload_size());
}
static void multifd_pages_clear(MultiFDPages_t *pages)
{
multifd_pages_reset(pages);
- g_free(pages->offset);
- pages->offset = NULL;
g_free(pages);
}
diff --git a/migration/multifd.h b/migration/multifd.h
index 7bb4a2cbc4..a7fdd97f70 100644
--- a/migration/multifd.h
+++ b/migration/multifd.h
@@ -77,9 +77,9 @@ typedef struct {
uint32_t num;
/* number of normal pages */
uint32_t normal_num;
+ RAMBlock *block;
/* offset of each page */
- ram_addr_t *offset;
- RAMBlock *block;
+ ram_addr_t offset[];
} MultiFDPages_t;
struct MultiFDRecvData {
--
2.35.3
- [PULL 06/34] tests/qtest/migration-helpers: Fix migrate_get_socket_address() leak, (continued)
- [PULL 06/34] tests/qtest/migration-helpers: Fix migrate_get_socket_address() leak, Fabiano Rosas, 2024/09/04
- [PULL 07/34] tests/qtest/migration-test: Free QCRyptoTLSTestCertReq objects, Fabiano Rosas, 2024/09/04
- [PULL 08/34] tests/unit/crypto-tls-x509-helpers: deinit privkey in test_tls_cleanup, Fabiano Rosas, 2024/09/04
- [PULL 09/34] tests/qtest/migration-helpers: Don't dup argument to qdict_put_str(), Fabiano Rosas, 2024/09/04
- [PULL 11/34] tests/qtest/migration-test: Don't leak QTestState in test_multifd_tcp_cancel(), Fabiano Rosas, 2024/09/04
- [PULL 10/34] tests/qtest/migration-test: Don't strdup in get_dirty_rate(), Fabiano Rosas, 2024/09/04
- [PULL 15/34] migration/multifd: Pass in MultiFDPages_t to file_write_ramblock_iov, Fabiano Rosas, 2024/09/04
- [PULL 16/34] migration/multifd: Introduce MultiFDSendData, Fabiano Rosas, 2024/09/04
- [PULL 14/34] migration/multifd: Remove pages->allocated, Fabiano Rosas, 2024/09/04
- [PULL 12/34] migration/multifd: Reduce access to p->pages, Fabiano Rosas, 2024/09/04
- [PULL 17/34] migration/multifd: Make MultiFDPages_t:offset a flexible array member,
Fabiano Rosas <=
- [PULL 13/34] migration/multifd: Inline page_size and page_count, Fabiano Rosas, 2024/09/04
- [PULL 18/34] migration/multifd: Replace p->pages with an union pointer, Fabiano Rosas, 2024/09/04
- [PULL 19/34] migration/multifd: Move pages accounting into multifd_send_zero_page_detect(), Fabiano Rosas, 2024/09/04
- [PULL 20/34] migration/multifd: Remove total pages tracing, Fabiano Rosas, 2024/09/04
- [PULL 21/34] migration/multifd: Isolate ram pages packet data, Fabiano Rosas, 2024/09/04
- [PULL 22/34] migration/multifd: Don't send ram data during SYNC, Fabiano Rosas, 2024/09/04
- [PULL 23/34] migration/multifd: Replace multifd_send_state->pages with client data, Fabiano Rosas, 2024/09/04
- [PULL 24/34] migration/multifd: Allow multifd sync without flush, Fabiano Rosas, 2024/09/04
- [PULL 25/34] migration/multifd: Standardize on multifd ops names, Fabiano Rosas, 2024/09/04
- [PULL 26/34] migration/multifd: Register nocomp ops dynamically, Fabiano Rosas, 2024/09/04