All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Juan Quintela <quintela@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 23/31] ram: Move migration_bitmap_rcu into RAMState
Date: Fri, 17 Mar 2017 09:51:49 +0000	[thread overview]
Message-ID: <20170317095149.GA2396@work-vm> (raw)
In-Reply-To: <20170315135021.6978-24-quintela@redhat.com>

* Juan Quintela (quintela@redhat.com) wrote:
> Once there, rename the type to be shorter.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  migration/ram.c | 79 ++++++++++++++++++++++++++++++---------------------------
>  1 file changed, 42 insertions(+), 37 deletions(-)
> 
> diff --git a/migration/ram.c b/migration/ram.c
> index c14293c..d39d185 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -132,6 +132,19 @@ out:
>      return ret;
>  }
>  
> +struct RAMBitmap {
> +    struct rcu_head rcu;
> +    /* Main migration bitmap */
> +    unsigned long *bmap;
> +    /* bitmap of pages that haven't been sent even once
> +     * only maintained and used in postcopy at the moment
> +     * where it's used to send the dirtymap at the start
> +     * of the postcopy phase
> +     */
> +    unsigned long *unsentmap;
> +};
> +typedef struct RAMBitmap RAMBitmap;
> +

I'm OK with this; although I can see the idea of naming it BitmapRcu,
given that the actual bmap is inside that and most of the rest of the type
is just the rcu wrapper.

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

>  /* State of RAM for migration */
>  struct RAMState {
>      /* Last block that we have visited searching for dirty pages */
> @@ -180,6 +193,8 @@ struct RAMState {
>      uint64_t migration_dirty_pages;
>      /* protects modification of the bitmap */
>      QemuMutex bitmap_mutex;
> +    /* Ram Bitmap protected by RCU */
> +    RAMBitmap *ram_bitmap;
>  };
>  typedef struct RAMState RAMState;
>  
> @@ -236,18 +251,6 @@ struct PageSearchStatus {
>  };
>  typedef struct PageSearchStatus PageSearchStatus;
>  
> -static struct BitmapRcu {
> -    struct rcu_head rcu;
> -    /* Main migration bitmap */
> -    unsigned long *bmap;
> -    /* bitmap of pages that haven't been sent even once
> -     * only maintained and used in postcopy at the moment
> -     * where it's used to send the dirtymap at the start
> -     * of the postcopy phase
> -     */
> -    unsigned long *unsentmap;
> -} *migration_bitmap_rcu;
> -
>  struct CompressParam {
>      bool done;
>      bool quit;
> @@ -554,7 +557,7 @@ ram_addr_t migration_bitmap_find_dirty(RAMState *rs, RAMBlock *rb,
>  
>      unsigned long next;
>  
> -    bitmap = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
> +    bitmap = atomic_rcu_read(&rs->ram_bitmap)->bmap;
>      if (rs->ram_bulk_stage && nr > base) {
>          next = nr + 1;
>      } else {
> @@ -569,7 +572,7 @@ static inline bool migration_bitmap_clear_dirty(RAMState *rs, ram_addr_t addr)
>  {
>      bool ret;
>      int nr = addr >> TARGET_PAGE_BITS;
> -    unsigned long *bitmap = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
> +    unsigned long *bitmap = atomic_rcu_read(&rs->ram_bitmap)->bmap;
>  
>      ret = test_and_clear_bit(nr, bitmap);
>  
> @@ -583,7 +586,7 @@ static void migration_bitmap_sync_range(RAMState *rs, ram_addr_t start,
>                                          ram_addr_t length)
>  {
>      unsigned long *bitmap;
> -    bitmap = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
> +    bitmap = atomic_rcu_read(&rs->ram_bitmap)->bmap;
>      rs-> migration_dirty_pages +=
>          cpu_physical_memory_sync_dirty_bitmap(bitmap, start, length);
>  }
> @@ -1115,14 +1118,14 @@ static bool get_queued_page(RAMState *rs, MigrationState *ms, PageSearchStatus *
>           */
>          if (block) {
>              unsigned long *bitmap;
> -            bitmap = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
> +            bitmap = atomic_rcu_read(&rs->ram_bitmap)->bmap;
>              dirty = test_bit(*ram_addr_abs >> TARGET_PAGE_BITS, bitmap);
>              if (!dirty) {
>                  trace_get_queued_page_not_dirty(
>                      block->idstr, (uint64_t)offset,
>                      (uint64_t)*ram_addr_abs,
>                      test_bit(*ram_addr_abs >> TARGET_PAGE_BITS,
> -                         atomic_rcu_read(&migration_bitmap_rcu)->unsentmap));
> +                         atomic_rcu_read(&rs->ram_bitmap)->unsentmap));
>              } else {
>                  trace_get_queued_page(block->idstr,
>                                        (uint64_t)offset,
> @@ -1276,7 +1279,7 @@ static int ram_save_target_page(RAMState *rs, MigrationState *ms, QEMUFile *f,
>          if (res < 0) {
>              return res;
>          }
> -        unsentmap = atomic_rcu_read(&migration_bitmap_rcu)->unsentmap;
> +        unsentmap = atomic_rcu_read(&rs->ram_bitmap)->unsentmap;
>          if (unsentmap) {
>              clear_bit(dirty_ram_abs >> TARGET_PAGE_BITS, unsentmap);
>          }
> @@ -1440,7 +1443,7 @@ void free_xbzrle_decoded_buf(void)
>      xbzrle_decoded_buf = NULL;
>  }
>  
> -static void migration_bitmap_free(struct BitmapRcu *bmap)
> +static void migration_bitmap_free(struct RAMBitmap *bmap)
>  {
>      g_free(bmap->bmap);
>      g_free(bmap->unsentmap);
> @@ -1449,11 +1452,13 @@ static void migration_bitmap_free(struct BitmapRcu *bmap)
>  
>  static void ram_migration_cleanup(void *opaque)
>  {
> +    RAMState *rs = opaque;
> +
>      /* caller have hold iothread lock or is in a bh, so there is
>       * no writing race against this migration_bitmap
>       */
> -    struct BitmapRcu *bitmap = migration_bitmap_rcu;
> -    atomic_rcu_set(&migration_bitmap_rcu, NULL);
> +    struct RAMBitmap *bitmap = rs->ram_bitmap;
> +    atomic_rcu_set(&rs->ram_bitmap, NULL);
>      if (bitmap) {
>          memory_global_dirty_log_stop();
>          call_rcu(bitmap, migration_bitmap_free, rcu);
> @@ -1488,9 +1493,9 @@ void migration_bitmap_extend(ram_addr_t old, ram_addr_t new)
>      /* called in qemu main thread, so there is
>       * no writing race against this migration_bitmap
>       */
> -    if (migration_bitmap_rcu) {
> -        struct BitmapRcu *old_bitmap = migration_bitmap_rcu, *bitmap;
> -        bitmap = g_new(struct BitmapRcu, 1);
> +    if (ram_state.ram_bitmap) {
> +        struct RAMBitmap *old_bitmap = ram_state.ram_bitmap, *bitmap;
> +        bitmap = g_new(struct RAMBitmap, 1);
>          bitmap->bmap = bitmap_new(new);
>  
>          /* prevent migration_bitmap content from being set bit
> @@ -1508,7 +1513,7 @@ void migration_bitmap_extend(ram_addr_t old, ram_addr_t new)
>           */
>          bitmap->unsentmap = NULL;
>  
> -        atomic_rcu_set(&migration_bitmap_rcu, bitmap);
> +        atomic_rcu_set(&ram_state.ram_bitmap, bitmap);
>          qemu_mutex_unlock(&ram_state.bitmap_mutex);
>          ram_state.migration_dirty_pages += new - old;
>          call_rcu(old_bitmap, migration_bitmap_free, rcu);
> @@ -1529,7 +1534,7 @@ void ram_debug_dump_bitmap(unsigned long *todump, bool expected)
>      char linebuf[129];
>  
>      if (!todump) {
> -        todump = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
> +        todump = atomic_rcu_read(&ram_state.ram_bitmap)->bmap;
>      }
>  
>      for (cur = 0; cur < ram_pages; cur += linelen) {
> @@ -1559,7 +1564,7 @@ void ram_debug_dump_bitmap(unsigned long *todump, bool expected)
>  void ram_postcopy_migrated_memory_release(MigrationState *ms)
>  {
>      struct RAMBlock *block;
> -    unsigned long *bitmap = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
> +    unsigned long *bitmap = atomic_rcu_read(&ram_state.ram_bitmap)->bmap;
>  
>      QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
>          unsigned long first = block->offset >> TARGET_PAGE_BITS;
> @@ -1591,7 +1596,7 @@ static int postcopy_send_discard_bm_ram(MigrationState *ms,
>      unsigned long current;
>      unsigned long *unsentmap;
>  
> -    unsentmap = atomic_rcu_read(&migration_bitmap_rcu)->unsentmap;
> +    unsentmap = atomic_rcu_read(&ram_state.ram_bitmap)->unsentmap;
>      for (current = start; current < end; ) {
>          unsigned long one = find_next_bit(unsentmap, end, current);
>  
> @@ -1680,8 +1685,8 @@ static void postcopy_chunk_hostpages_pass(MigrationState *ms, bool unsent_pass,
>          return;
>      }
>  
> -    bitmap = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
> -    unsentmap = atomic_rcu_read(&migration_bitmap_rcu)->unsentmap;
> +    bitmap = atomic_rcu_read(&ram_state.ram_bitmap)->bmap;
> +    unsentmap = atomic_rcu_read(&ram_state.ram_bitmap)->unsentmap;
>  
>      if (unsent_pass) {
>          /* Find a sent page */
> @@ -1836,7 +1841,7 @@ int ram_postcopy_send_discard_bitmap(MigrationState *ms)
>      /* This should be our last sync, the src is now paused */
>      migration_bitmap_sync(&ram_state);
>  
> -    unsentmap = atomic_rcu_read(&migration_bitmap_rcu)->unsentmap;
> +    unsentmap = atomic_rcu_read(&ram_state.ram_bitmap)->unsentmap;
>      if (!unsentmap) {
>          /* We don't have a safe way to resize the sentmap, so
>           * if the bitmap was resized it will be NULL at this
> @@ -1857,7 +1862,7 @@ int ram_postcopy_send_discard_bitmap(MigrationState *ms)
>      /*
>       * Update the unsentmap to be unsentmap = unsentmap | dirty
>       */
> -    bitmap = atomic_rcu_read(&migration_bitmap_rcu)->bmap;
> +    bitmap = atomic_rcu_read(&ram_state.ram_bitmap)->bmap;
>      bitmap_or(unsentmap, unsentmap, bitmap,
>                 last_ram_offset() >> TARGET_PAGE_BITS);
>  
> @@ -1950,16 +1955,16 @@ static int ram_state_init(RAMState *rs)
>      bytes_transferred = 0;
>      ram_state_reset(rs);
>  
> -    migration_bitmap_rcu = g_new0(struct BitmapRcu, 1);
> +    rs->ram_bitmap = g_new0(struct RAMBitmap, 1);
>      /* Skip setting bitmap if there is no RAM */
>      if (ram_bytes_total()) {
>          ram_bitmap_pages = last_ram_offset() >> TARGET_PAGE_BITS;
> -        migration_bitmap_rcu->bmap = bitmap_new(ram_bitmap_pages);
> -        bitmap_set(migration_bitmap_rcu->bmap, 0, ram_bitmap_pages);
> +        rs->ram_bitmap->bmap = bitmap_new(ram_bitmap_pages);
> +        bitmap_set(rs->ram_bitmap->bmap, 0, ram_bitmap_pages);
>  
>          if (migrate_postcopy_ram()) {
> -            migration_bitmap_rcu->unsentmap = bitmap_new(ram_bitmap_pages);
> -            bitmap_set(migration_bitmap_rcu->unsentmap, 0, ram_bitmap_pages);
> +            rs->ram_bitmap->unsentmap = bitmap_new(ram_bitmap_pages);
> +            bitmap_set(rs->ram_bitmap->unsentmap, 0, ram_bitmap_pages);
>          }
>      }
>  
> -- 
> 2.9.3
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

  reply	other threads:[~2017-03-17  9:51 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-15 13:49 [Qemu-devel] [PATCH 00/31] Creating RAMState for migration Juan Quintela
2017-03-15 13:49 ` [Qemu-devel] [PATCH 01/31] ram: move more fields into RAMState Juan Quintela
2017-03-16 12:09   ` Dr. David Alan Gilbert
2017-03-16 21:32     ` Philippe Mathieu-Daudé
2017-03-20 19:36     ` Juan Quintela
2017-03-15 13:49 ` [Qemu-devel] [PATCH 02/31] ram: Add dirty_rate_high_cnt to RAMState Juan Quintela
2017-03-16 12:20   ` Dr. David Alan Gilbert
2017-03-16 21:32     ` Philippe Mathieu-Daudé
2017-03-20 19:39     ` Juan Quintela
2017-03-15 13:49 ` [Qemu-devel] [PATCH 03/31] ram: move bitmap_sync_count into RAMState Juan Quintela
2017-03-16 12:21   ` Dr. David Alan Gilbert
2017-03-16 21:33     ` Philippe Mathieu-Daudé
2017-03-15 13:49 ` [Qemu-devel] [PATCH 04/31] ram: Move start time " Juan Quintela
2017-03-16 12:21   ` Dr. David Alan Gilbert
2017-03-16 21:33     ` Philippe Mathieu-Daudé
2017-03-15 13:49 ` [Qemu-devel] [PATCH 05/31] ram: Move bytes_xfer_prev " Juan Quintela
2017-03-16 12:22   ` Dr. David Alan Gilbert
2017-03-16 21:34     ` Philippe Mathieu-Daudé
2017-03-15 13:49 ` [Qemu-devel] [PATCH 06/31] ram: Move num_dirty_pages_period " Juan Quintela
2017-03-16 12:23   ` Dr. David Alan Gilbert
2017-03-16 21:35     ` Philippe Mathieu-Daudé
2017-03-15 13:49 ` [Qemu-devel] [PATCH 07/31] ram: Move xbzrle_cache_miss_prev " Juan Quintela
2017-03-16 12:24   ` Dr. David Alan Gilbert
2017-03-16 21:35     ` Philippe Mathieu-Daudé
2017-03-15 13:49 ` [Qemu-devel] [PATCH 08/31] ram: Move iterations_prev " Juan Quintela
2017-03-16 12:26   ` Dr. David Alan Gilbert
2017-03-16 21:36     ` Philippe Mathieu-Daudé
2017-03-15 13:49 ` [Qemu-devel] [PATCH 09/31] ram: Move dup_pages " Juan Quintela
2017-03-16 12:27   ` Dr. David Alan Gilbert
2017-03-15 13:50 ` [Qemu-devel] [PATCH 10/31] ram: Remove unused dump_mig_dbytes_transferred() Juan Quintela
2017-03-16 15:48   ` Dr. David Alan Gilbert
2017-03-15 13:50 ` [Qemu-devel] [PATCH 11/31] ram: Remove unused pages_skiped variable Juan Quintela
2017-03-16 15:52   ` Dr. David Alan Gilbert
2017-03-15 13:50 ` [Qemu-devel] [PATCH 12/31] ram: Move norm_pages to RAMState Juan Quintela
2017-03-16 16:09   ` Dr. David Alan Gilbert
2017-03-15 13:50 ` [Qemu-devel] [PATCH 13/31] ram: Remove norm_mig_bytes_transferred Juan Quintela
2017-03-16 16:14   ` Dr. David Alan Gilbert
2017-03-15 13:50 ` [Qemu-devel] [PATCH 14/31] ram: Move iterations into RAMState Juan Quintela
2017-03-16 20:04   ` Dr. David Alan Gilbert
2017-03-16 21:40     ` Philippe Mathieu-Daudé
2017-03-15 13:50 ` [Qemu-devel] [PATCH 15/31] ram: Move xbzrle_bytes " Juan Quintela
2017-03-15 13:50 ` [Qemu-devel] [PATCH 16/31] ram: Move xbzrle_pages " Juan Quintela
2017-03-15 13:50 ` [Qemu-devel] [PATCH 17/31] ram: Move xbzrle_cache_miss " Juan Quintela
2017-03-15 13:50 ` [Qemu-devel] [PATCH 18/31] ram: move xbzrle_cache_miss_rate " Juan Quintela
2017-03-15 13:50 ` [Qemu-devel] [PATCH 19/31] ram: move xbzrle_overflows " Juan Quintela
2017-03-16 20:07   ` Dr. David Alan Gilbert
2017-03-15 13:50 ` [Qemu-devel] [PATCH 20/31] ram: move migration_dirty_pages to RAMState Juan Quintela
2017-03-15 13:50 ` [Qemu-devel] [PATCH 21/31] ram: Everything was init to zero, so use memset Juan Quintela
2017-03-16 20:15   ` Dr. David Alan Gilbert
2017-03-15 13:50 ` [Qemu-devel] [PATCH 22/31] ram: move migration_bitmap_mutex into RAMState Juan Quintela
2017-03-16 20:21   ` Dr. David Alan Gilbert
2017-03-15 13:50 ` [Qemu-devel] [PATCH 23/31] ram: Move migration_bitmap_rcu " Juan Quintela
2017-03-17  9:51   ` Dr. David Alan Gilbert [this message]
2017-03-20 20:10     ` Juan Quintela
2017-03-15 13:50 ` [Qemu-devel] [PATCH 24/31] ram: Move bytes_transferred " Juan Quintela
2017-03-15 13:50 ` [Qemu-devel] [PATCH 25/31] ram: Use the RAMState bytes_transferred parameter Juan Quintela
2017-03-17  9:57   ` Dr. David Alan Gilbert
2017-03-15 13:50 ` [Qemu-devel] [PATCH 26/31] ram: Remove ram_save_remaining Juan Quintela
2017-03-15 13:50 ` [Qemu-devel] [PATCH 27/31] ram: Move last_req_rb to RAMState Juan Quintela
2017-03-17 10:14   ` Dr. David Alan Gilbert
2017-03-20 20:13     ` Juan Quintela
2017-03-15 13:50 ` [Qemu-devel] [PATCH 28/31] ram: Create ram_dirty_sync_count() Juan Quintela
2017-03-15 13:50 ` [Qemu-devel] [PATCH 29/31] ram: Remove dirty_bytes_rate Juan Quintela
2017-03-17 10:21   ` Dr. David Alan Gilbert
2017-03-15 13:50 ` [Qemu-devel] [PATCH 30/31] ram: move dirty_pages_rate to RAMState Juan Quintela
2017-03-17 10:45   ` Dr. David Alan Gilbert
2017-03-15 13:50 ` [Qemu-devel] [PATCH 31/31] ram: move postcopy_requests into RAMState Juan Quintela
2017-03-15 14:25 ` [Qemu-devel] [PATCH 00/31] Creating RAMState for migration no-reply

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=20170317095149.GA2396@work-vm \
    --to=dgilbert@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.