All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Straub <lukasstraub2@web.de>
To: Juan Quintela <quintela@redhat.com>
Cc: qemu-devel@nongnu.org, Peter Xu <peterx@redhat.com>,
	Leonardo Bras <leobras@redhat.com>
Subject: Re: [PATCH 12/18] migration: Create compression_update_rates()
Date: Thu, 22 Jun 2023 13:46:55 +0200	[thread overview]
Message-ID: <20230622134655.2d6b6377@mobian> (raw)
In-Reply-To: <20230613145757.10131-13-quintela@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 6296 bytes --]

On Tue, 13 Jun 2023 16:57:51 +0200
Juan Quintela <quintela@redhat.com> wrote:

> So we can move more compression_counters stuff to ram-compress.c.
> Create compression_counters struct to add the stuff that was on
> MigrationState.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>

With the comment below fixed:
Reviewed-by: Lukas Straub <lukasstraub2@web.de>

> ---
>  migration/ram-compress.h |  1 +
>  migration/ram.h          |  1 -
>  migration/ram-compress.c | 41 +++++++++++++++++++++++++++++++++++++++-
>  migration/ram.c          | 29 +---------------------------
>  4 files changed, 42 insertions(+), 30 deletions(-)
> 
> diff --git a/migration/ram-compress.h b/migration/ram-compress.h
> index b228640092..a7eb028849 100644
> --- a/migration/ram-compress.h
> +++ b/migration/ram-compress.h
> @@ -71,5 +71,6 @@ void decompress_data_with_multi_threads(QEMUFile *f, void *host, int len);
>  void populate_compress(MigrationInfo *info);
>  uint64_t ram_compressed_pages(void);
>  void update_compress_thread_counts(const CompressParam *param, int bytes_xmit);
> +void compression_update_rates(uint64_t page_count);
>  
>  #endif
> diff --git a/migration/ram.h b/migration/ram.h
> index ea1f3c25b5..60bc4c9e3a 100644
> --- a/migration/ram.h
> +++ b/migration/ram.h
> @@ -34,7 +34,6 @@
>  #include "io/channel.h"
>  
>  extern XBZRLECacheStats xbzrle_counters;
> -extern CompressionStats compression_counters;
>  
>  bool ramblock_is_ignored(RAMBlock *block);
>  /* Should be holding either ram_list.mutex, or the RCU lock. */
> diff --git a/migration/ram-compress.c b/migration/ram-compress.c
> index 2652cdee8b..5e1bb82fcd 100644
> --- a/migration/ram-compress.c
> +++ b/migration/ram-compress.c
> @@ -41,7 +41,20 @@
>  #include "ram.h"
>  #include "migration-stats.h"
>  
> -CompressionStats compression_counters;
> +static struct {
> +    int64_t pages;
> +    int64_t busy;
> +    double busy_rate;
> +    int64_t compressed_size;
> +    double compression_rate;
> +    /* compression statistics since the beginning of the period */
> +    /* amount of count that no free thread to compress data */
> +    uint64_t compress_thread_busy_prev;
> +    /* amount bytes after compression */
> +    uint64_t compressed_size_prev;
> +    /* amount of compressed pages */
> +    uint64_t compress_pages_prev;
> +} compression_counters;
>  
>  static CompressParam *comp_param;
>  static QemuThread *compress_threads;
> @@ -529,3 +542,29 @@ void update_compress_thread_counts(const CompressParam *param, int bytes_xmit)
>      compression_counters.pages++;
>  }
>  
> +void compression_update_rates(uint64_t page_count)
> +{
> +    if (migrate_compress()) {

Use early return.

> +        compression_counters.busy_rate = (double)(compression_counters.busy -
> +            compression_counters.compress_thread_busy_prev) / page_count;
> +        compression_counters.compress_thread_busy_prev =
> +            compression_counters.busy;
> +
> +        double compressed_size = compression_counters.compressed_size -
> +                                 compression_counters.compressed_size_prev;
> +        if (compressed_size) {
> +            double uncompressed_size = (compression_counters.pages -
> +                compression_counters.compress_pages_prev) *
> +                qemu_target_page_size();
> +
> +            /* Compression-Ratio = Uncompressed-size / Compressed-size */
> +            compression_counters.compression_rate =
> +                                        uncompressed_size / compressed_size;
> +
> +            compression_counters.compress_pages_prev =
> +                compression_counters.pages;
> +            compression_counters.compressed_size_prev =
> +                compression_counters.compressed_size;
> +        }
> +    }
> +}
> diff --git a/migration/ram.c b/migration/ram.c
> index 60f24006bc..1bd586c23a 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -364,13 +364,6 @@ struct RAMState {
>      bool xbzrle_started;
>      /* Are we on the last stage of migration */
>      bool last_stage;
> -    /* compression statistics since the beginning of the period */
> -    /* amount of count that no free thread to compress data */
> -    uint64_t compress_thread_busy_prev;
> -    /* amount bytes after compression */
> -    uint64_t compressed_size_prev;
> -    /* amount of compressed pages */
> -    uint64_t compress_pages_prev;
>  
>      /* total handled target pages at the beginning of period */
>      uint64_t target_page_count_prev;
> @@ -933,7 +926,6 @@ uint64_t ram_get_total_transferred_pages(void)
>  static void migration_update_rates(RAMState *rs, int64_t end_time)
>  {
>      uint64_t page_count = rs->target_page_count - rs->target_page_count_prev;
> -    double compressed_size;
>  
>      /* calculate period counters */
>      stat64_set(&mig_stats.dirty_pages_rate,
> @@ -961,26 +953,7 @@ static void migration_update_rates(RAMState *rs, int64_t end_time)
>          rs->xbzrle_pages_prev = xbzrle_counters.pages;
>          rs->xbzrle_bytes_prev = xbzrle_counters.bytes;
>      }
> -
> -    if (migrate_compress()) {
> -        compression_counters.busy_rate = (double)(compression_counters.busy -
> -            rs->compress_thread_busy_prev) / page_count;
> -        rs->compress_thread_busy_prev = compression_counters.busy;
> -
> -        compressed_size = compression_counters.compressed_size -
> -                          rs->compressed_size_prev;
> -        if (compressed_size) {
> -            double uncompressed_size = (compression_counters.pages -
> -                                    rs->compress_pages_prev) * TARGET_PAGE_SIZE;
> -
> -            /* Compression-Ratio = Uncompressed-size / Compressed-size */
> -            compression_counters.compression_rate =
> -                                        uncompressed_size / compressed_size;
> -
> -            rs->compress_pages_prev = compression_counters.pages;
> -            rs->compressed_size_prev = compression_counters.compressed_size;
> -        }
> -    }
> +    compression_update_rates(page_count);
>  }
>  
>  static void migration_trigger_throttle(RAMState *rs)


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2023-06-22 11:47 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-13 14:57 [PATCH 00/18] Migration compression cleanup Juan Quintela
2023-06-13 14:57 ` [PATCH 01/18] migration: Give one error if trying to set MULTIFD and XBZRLE Juan Quintela
2023-06-22 11:36   ` Lukas Straub
2023-06-22 12:15     ` Juan Quintela
2023-06-13 14:57 ` [PATCH 02/18] migration: Give one error if trying to set COMPRESSION " Juan Quintela
2023-06-22 11:37   ` Lukas Straub
2023-06-13 14:57 ` [PATCH 03/18] migration: RDMA is not compatible with anything else Juan Quintela
2023-06-22 11:44   ` Lukas Straub
2023-06-13 14:57 ` [PATCH 04/18] migration: Remove save_page_use_compression() Juan Quintela
2023-06-13 14:57 ` [PATCH 05/18] migration: Move compression_counters cleanup ram-compress.c Juan Quintela
2023-06-22 11:44   ` Lukas Straub
2023-06-13 14:57 ` [PATCH 06/18] migration: Create populate_compress() Juan Quintela
2023-06-22 11:45   ` Lukas Straub
2023-06-13 14:57 ` [PATCH 07/18] migration: Create ram_compressed_pages() Juan Quintela
2023-06-22 11:45   ` Lukas Straub
2023-06-13 14:57 ` [PATCH 08/18] migration: Move update_compress_threads_counts() to ram-compress.c Juan Quintela
2023-06-22 11:45   ` Lukas Straub
2023-06-13 14:57 ` [PATCH 09/18] migration: Make compress_data_with_multithreads return bool Juan Quintela
2023-06-22 11:46   ` Lukas Straub
2023-06-13 14:57 ` [PATCH 10/18] migration: Simplify compress_page_with_multithread() Juan Quintela
2023-06-22 11:46   ` Lukas Straub
2023-06-13 14:57 ` [PATCH 11/18] migration: Move busy++ to migrate_with_multithread Juan Quintela
2023-06-22 11:46   ` Lukas Straub
2023-06-13 14:57 ` [PATCH 12/18] migration: Create compression_update_rates() Juan Quintela
2023-06-22 11:46   ` Lukas Straub [this message]
2023-06-13 14:57 ` [PATCH 13/18] migration: Simplify decompress_data_with_multi_threads() Juan Quintela
2023-06-22 11:47   ` Lukas Straub
2023-06-13 14:57 ` [PATCH 14/18] migration: Use "i" as an for index in ram-compress.c Juan Quintela
2023-06-22 11:47   ` Lukas Straub
2023-06-13 14:57 ` [PATCH 15/18] migration: save_compress_page() can take block through pss Juan Quintela
2023-06-22 11:47   ` Lukas Straub
2023-06-13 14:57 ` [PATCH 16/18] migration: control_save_page() " Juan Quintela
2023-06-22 11:48   ` Lukas Straub
2023-06-13 14:57 ` [PATCH 17/18] migration: Remove not needed block parameter for save_zero_page* Juan Quintela
2023-06-22 11:48   ` Lukas Straub
2023-06-13 14:57 ` [PATCH 18/18] migration: Remove not needed file " Juan Quintela
2023-06-22 11:48   ` Lukas Straub

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=20230622134655.2d6b6377@mobian \
    --to=lukasstraub2@web.de \
    --cc=leobras@redhat.com \
    --cc=peterx@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.