qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Juan Quintela <quintela@redhat.com>,
	"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
	peterx@redhat.com,
	Leonardo Bras Soares Passos <lsoaresp@redhat.com>
Subject: [PATCH RFC 10/15] migration: Move static var in ram_block_from_stream() into global
Date: Wed, 19 Jan 2022 16:09:24 +0800	[thread overview]
Message-ID: <20220119080929.39485-11-peterx@redhat.com> (raw)
In-Reply-To: <20220119080929.39485-1-peterx@redhat.com>

Static variable is very unfriendly to threading of ram_block_from_stream().
Move it into MigrationIncomingState.

Make the incoming state pointer to be passed over to ram_block_from_stream() on
both caller sites.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 migration/migration.h |  3 ++-
 migration/ram.c       | 13 +++++++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/migration/migration.h b/migration/migration.h
index 35e7f7babe..34b79cb961 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -66,7 +66,8 @@ typedef struct {
 /* State for the incoming migration */
 struct MigrationIncomingState {
     QEMUFile *from_src_file;
-
+    /* Previously received RAM's RAMBlock pointer */
+    RAMBlock *last_recv_block;
     /* A hook to allow cleanup at the end of incoming migration */
     void *transport_data;
     void (*transport_cleanup)(void *data);
diff --git a/migration/ram.c b/migration/ram.c
index 3f823ffffc..3a7d943f9c 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -3183,12 +3183,14 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host)
  *
  * Returns a pointer from within the RCU-protected ram_list.
  *
+ * @mis: the migration incoming state pointer
  * @f: QEMUFile where to read the data from
  * @flags: Page flags (mostly to see if it's a continuation of previous block)
  */
-static inline RAMBlock *ram_block_from_stream(QEMUFile *f, int flags)
+static inline RAMBlock *ram_block_from_stream(MigrationIncomingState *mis,
+                                              QEMUFile *f, int flags)
 {
-    static RAMBlock *block;
+    RAMBlock *block = mis->last_recv_block;
     char id[256];
     uint8_t len;
 
@@ -3215,6 +3217,8 @@ static inline RAMBlock *ram_block_from_stream(QEMUFile *f, int flags)
         return NULL;
     }
 
+    mis->last_recv_block = block;
+
     return block;
 }
 
@@ -3667,7 +3671,7 @@ static int ram_load_postcopy(QEMUFile *f)
         trace_ram_load_postcopy_loop((uint64_t)addr, flags);
         if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE |
                      RAM_SAVE_FLAG_COMPRESS_PAGE)) {
-            block = ram_block_from_stream(f, flags);
+            block = ram_block_from_stream(mis, f, flags);
             if (!block) {
                 ret = -EINVAL;
                 break;
@@ -3881,6 +3885,7 @@ void colo_flush_ram_cache(void)
  */
 static int ram_load_precopy(QEMUFile *f)
 {
+    MigrationIncomingState *mis = migration_incoming_get_current();
     int flags = 0, ret = 0, invalid_flags = 0, len = 0, i = 0;
     /* ADVISE is earlier, it shows the source has the postcopy capability on */
     bool postcopy_advised = postcopy_is_advised();
@@ -3919,7 +3924,7 @@ static int ram_load_precopy(QEMUFile *f)
 
         if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE |
                      RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE)) {
-            RAMBlock *block = ram_block_from_stream(f, flags);
+            RAMBlock *block = ram_block_from_stream(mis, f, flags);
 
             host = host_from_ram_block_offset(block, addr);
             /*
-- 
2.32.0



  parent reply	other threads:[~2022-01-19  8:34 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-19  8:09 [PATCH RFC 00/15] migration: Postcopy Preemption Peter Xu
2022-01-19  8:09 ` [PATCH RFC 01/15] migration: No off-by-one for pss->page update in host page size Peter Xu
2022-01-19 12:58   ` Dr. David Alan Gilbert
2022-01-27  9:40   ` Juan Quintela
2022-01-19  8:09 ` [PATCH RFC 02/15] migration: Allow pss->page jump over clean pages Peter Xu
2022-01-19 13:42   ` Dr. David Alan Gilbert
2022-01-20  2:12     ` Peter Xu
2022-02-03 18:19       ` Dr. David Alan Gilbert
2022-02-08  3:20         ` Peter Xu
2022-01-19  8:09 ` [PATCH RFC 03/15] migration: Enable UFFD_FEATURE_THREAD_ID even without blocktime feat Peter Xu
2022-01-19 14:15   ` Dr. David Alan Gilbert
2022-01-27  9:40   ` Juan Quintela
2022-01-19  8:09 ` [PATCH RFC 04/15] migration: Add postcopy_has_request() Peter Xu
2022-01-19 14:27   ` Dr. David Alan Gilbert
2022-01-27  9:41   ` Juan Quintela
2022-01-19  8:09 ` [PATCH RFC 05/15] migration: Simplify unqueue_page() Peter Xu
2022-01-19 16:36   ` Dr. David Alan Gilbert
2022-01-20  2:23     ` Peter Xu
2022-01-25 11:01       ` Dr. David Alan Gilbert
2022-01-27  9:41   ` Juan Quintela
2022-01-19  8:09 ` [PATCH RFC 06/15] migration: Move temp page setup and cleanup into separate functions Peter Xu
2022-01-19 16:58   ` Dr. David Alan Gilbert
2022-01-27  9:43   ` Juan Quintela
2022-01-19  8:09 ` [PATCH RFC 07/15] migration: Introduce postcopy channels on dest node Peter Xu
2022-02-03 15:08   ` Dr. David Alan Gilbert
2022-02-08  3:27     ` Peter Xu
2022-02-08  9:43       ` Dr. David Alan Gilbert
2022-02-08 10:07         ` Peter Xu
2022-01-19  8:09 ` [PATCH RFC 08/15] migration: Dump ramblock and offset too when non-same-page detected Peter Xu
2022-02-03 15:15   ` Dr. David Alan Gilbert
2022-01-19  8:09 ` [PATCH RFC 09/15] migration: Add postcopy_thread_create() Peter Xu
2022-02-03 15:19   ` Dr. David Alan Gilbert
2022-02-08  3:37     ` Peter Xu
2022-02-08 11:16       ` Dr. David Alan Gilbert
2022-01-19  8:09 ` Peter Xu [this message]
2022-02-03 17:48   ` [PATCH RFC 10/15] migration: Move static var in ram_block_from_stream() into global Dr. David Alan Gilbert
2022-02-08  3:51     ` Peter Xu
2022-01-19  8:09 ` [PATCH RFC 11/15] migration: Add pss.postcopy_requested status Peter Xu
2022-02-03 15:42   ` Dr. David Alan Gilbert
2022-01-19  8:09 ` [PATCH RFC 12/15] migration: Move migrate_allow_multifd and helpers into migration.c Peter Xu
2022-02-03 15:44   ` Dr. David Alan Gilbert
2022-01-19  8:09 ` [PATCH RFC 13/15] migration: Add postcopy-preempt capability Peter Xu
2022-02-03 15:46   ` Dr. David Alan Gilbert
2022-01-19  8:09 ` [PATCH RFC 14/15] migration: Postcopy preemption on separate channel Peter Xu
2022-02-03 17:45   ` Dr. David Alan Gilbert
2022-02-08  4:22     ` Peter Xu
2022-02-08 11:24       ` Dr. David Alan Gilbert
2022-02-08 11:39         ` Peter Xu
2022-02-08 13:23           ` Dr. David Alan Gilbert
2022-02-09  2:16             ` Peter Xu
2022-01-19  8:09 ` [PATCH RFC 15/15] tests: Add postcopy preempt test Peter Xu
2022-02-03 15:53   ` Dr. David Alan Gilbert
2022-01-19 12:32 ` [PATCH RFC 00/15] migration: Postcopy Preemption Dr. David Alan Gilbert

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=20220119080929.39485-11-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=lsoaresp@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.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).