qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: "Михаил Северов" <senserk71@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: Re: Possible memory release problem
Date: Tue, 12 Mar 2024 20:42:42 +0000	[thread overview]
Message-ID: <87r0gfmbb1.fsf@draig.linaro.org> (raw)
In-Reply-To: <CAL1vMp0KdjfVMOnLcDxr9Cdcvr34jp2aHorZ3F6ibiSRavLiiw@mail.gmail.com> ("Михаил Северов"'s message of "Tue, 12 Mar 2024 21:45:24 +0300")

Михаил Северов <senserk71@gmail.com> writes:

> Colleagues, can you tell me in /migration/ram.c :2837 whether it is not necessary to perform memory release for
> block->bmap, after memory has been allocated in :2831. If not please
> explain why

It's easier if you post the context for the code as things do move
around:

  static void ram_list_init_bitmaps(void)
  {
      MigrationState *ms = migrate_get_current();
      RAMBlock *block;
      unsigned long pages;
      uint8_t shift;

      /* Skip setting bitmap if there is no RAM */
      if (ram_bytes_total()) {
          shift = ms->clear_bitmap_shift;
          if (shift > CLEAR_BITMAP_SHIFT_MAX) {
              error_report("clear_bitmap_shift (%u) too big, using "
                           "max value (%u)", shift, CLEAR_BITMAP_SHIFT_MAX);
              shift = CLEAR_BITMAP_SHIFT_MAX;
          } else if (shift < CLEAR_BITMAP_SHIFT_MIN) {
              error_report("clear_bitmap_shift (%u) too small, using "
                           "min value (%u)", shift, CLEAR_BITMAP_SHIFT_MIN);
              shift = CLEAR_BITMAP_SHIFT_MIN;
          }

          RAMBLOCK_FOREACH_NOT_IGNORED(block) {
              pages = block->max_length >> TARGET_PAGE_BITS;
              /*
               * The initial dirty bitmap for migration must be set with all
               * ones to make sure we'll migrate every guest RAM page to
               * destination.
               * Here we set RAMBlock.bmap all to 1 because when rebegin a
               * new migration after a failed migration, ram_list.
               * dirty_memory[DIRTY_MEMORY_MIGRATION] don't include the whole
               * guest memory.
               */
              block->bmap = bitmap_new(pages);
              bitmap_set(block->bmap, 0, pages);
              if (migrate_mapped_ram()) {
                  block->file_bmap = bitmap_new(pages);
              }
              block->clear_bmap_shift = shift;
              block->clear_bmap = bitmap_new(clear_bmap_size(pages, shift));
          }
      }
  }

On my copy the code the two bitmap_new()'s are for different variables.
Are you asking where they are freed? AFAICT here:

  static void ram_save_cleanup(void *opaque)
  {
      RAMState **rsp = opaque;
      RAMBlock *block;

      /* We don't use dirty log with background snapshots */
      if (!migrate_background_snapshot()) {
          /* caller have hold BQL or is in a bh, so there is
           * no writing race against the migration bitmap
           */
          if (global_dirty_tracking & GLOBAL_DIRTY_MIGRATION) {
              /*
               * do not stop dirty log without starting it, since
               * memory_global_dirty_log_stop will assert that
               * memory_global_dirty_log_start/stop used in pairs
               */
              memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION);
          }
      }

      RAMBLOCK_FOREACH_NOT_IGNORED(block) {
          g_free(block->clear_bmap);
          block->clear_bmap = NULL;
          g_free(block->bmap);
          block->bmap = NULL;
      }

      xbzrle_cleanup();
      compress_threads_save_cleanup();
      ram_state_cleanup(rsp);
      g_free(migration_ops);
      migration_ops = NULL;
  }


-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


      reply	other threads:[~2024-03-12 20:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-12 18:45 Possible memory release problem Михаил Северов
2024-03-12 20:42 ` Alex Bennée [this message]

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=87r0gfmbb1.fsf@draig.linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=senserk71@gmail.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).