qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Liang Li <liang.z.li@intel.com>
To: qemu-devel@nongnu.org
Cc: amit.shah@redhat.com, yang.z.zhang@intel.com,
	Liang Li <liang.z.li@intel.com>,
	dgilbert@redhat.com, quintela@redhat.com
Subject: [Qemu-devel] [PATCH 2/3] migration: optimization for one compression thread
Date: Tue, 25 Aug 2015 19:59:09 +0800	[thread overview]
Message-ID: <1440503950-14174-3-git-send-email-liang.z.li@intel.com> (raw)
In-Reply-To: <1440503950-14174-1-git-send-email-liang.z.li@intel.com>

When the compression thread count is set to 1, the current implementation
is inefficient because of the following reason:
1. Thread synchronization cost;
2. Data copy;
3. No benefit from the separate compression thread;

This patch optimizes the performance for the case of 1 compress thread.
In this case, the compression is done in the migration thread, for some
fast compression algorithm, it can help to improve the performance.

Signed-off-by: Liang Li <liang.z.li@intel.com>
---
 migration/ram.c | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index 7f007e6..0cc4f81 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -318,8 +318,13 @@ void migrate_compress_threads_join(void)
     if (!migrate_use_compression()) {
         return;
     }
-    terminate_compression_threads();
+
     thread_count = migrate_compress_threads();
+    if (thread_count == 1) {
+        return;
+    }
+
+    terminate_compression_threads();
     for (i = 0; i < thread_count; i++) {
         qemu_thread_join(compress_threads + i);
         qemu_fclose(comp_param[i].file);
@@ -345,9 +350,12 @@ void migrate_compress_threads_create(void)
     if (!migrate_use_compression()) {
         return;
     }
+    thread_count = migrate_compress_threads();
+    if (thread_count == 1) {
+        return;
+    }
     quit_comp_thread = false;
     compression_switch = true;
-    thread_count = migrate_compress_threads();
     compress_threads = g_new0(QemuThread, thread_count);
     comp_param = g_new0(CompressParam, thread_count);
     comp_done_cond = g_new0(QemuCond, 1);
@@ -782,6 +790,9 @@ static void flush_compressed_data(QEMUFile *f)
         return;
     }
     thread_count = migrate_compress_threads();
+    if (thread_count == 1) {
+        return;
+    }
     for (idx = 0; idx < thread_count; idx++) {
         if (!comp_param[idx].done) {
             qemu_mutex_lock(comp_done_lock);
@@ -883,18 +894,16 @@ static int ram_save_compressed_page(QEMUFile *f, RAMBlock *block,
          * out, keeping this order is important, because the 'cont' flag
          * is used to avoid resending the block name.
          */
-        if (block != last_sent_block) {
+        if (block != last_sent_block || migrate_compress_threads() == 1) {
             flush_compressed_data(f);
             pages = save_zero_page(f, block, offset, p, bytes_transferred);
             if (pages == -1) {
-                set_compress_params(&comp_param[0], block, offset);
-                /* Use the qemu thread to compress the data to make sure the
-                 * first page is sent out before other pages
-                 */
-                bytes_xmit = do_compress_ram_page(&comp_param[0]);
-                acct_info.norm_pages++;
-                qemu_put_qemu_file(f, comp_param[0].file);
+                bytes_xmit = save_page_header(f, block, offset |
+                                              RAM_SAVE_FLAG_COMPRESS_PAGE);
+                bytes_xmit += qemu_put_compression_data(f, p, TARGET_PAGE_SIZE,
+                                                migrate_compress_level());
                 *bytes_transferred += bytes_xmit;
+                acct_info.norm_pages++;
                 pages = 1;
             }
         } else {
-- 
1.9.1

  parent reply	other threads:[~2015-08-25 12:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-25 11:59 [Qemu-devel] [PATCH 0/3] Optimize the performance for single thread (de)compression Liang Li
2015-08-25 11:59 ` [Qemu-devel] [PATCH 1/3] qemu-file: improve qemu_put_compression_data Liang Li
2015-08-25 11:59 ` Liang Li [this message]
2015-08-25 11:59 ` [Qemu-devel] [PATCH 3/3] migration: optimization for one decompression thread Liang Li

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=1440503950-14174-3-git-send-email-liang.z.li@intel.com \
    --to=liang.z.li@intel.com \
    --cc=amit.shah@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=yang.z.zhang@intel.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).