qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Wang, Wei W" <wei.w.wang@intel.com>
To: David Hildenbrand <david@redhat.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: "mst@redhat.com" <mst@redhat.com>,
	"dgilbert@redhat.com" <dgilbert@redhat.com>,
	"peterx@redhat.com" <peterx@redhat.com>,
	"quintela@redhat.com" <quintela@redhat.com>
Subject: RE: [PATCH v2] migration: clear the memory region dirty bitmap when skipping free pages
Date: Mon, 19 Jul 2021 05:18:29 +0000	[thread overview]
Message-ID: <bcf1c9a8817e41669b0c95a194a160fd@intel.com> (raw)
In-Reply-To: <3c3a44c8-c819-5946-e1f6-a0d69215e2fe@redhat.com>

On Friday, July 16, 2021 4:26 PM, David Hildenbrand wrote:
> >>> +    /*
> >>> +     * CLEAR_BITMAP_SHIFT_MIN should always guarantee this... this
> >>> +     * can make things easier sometimes since then start address
> >>> +     * of the small chunk will always be 64 pages aligned so the
> >>> +     * bitmap will always be aligned to unsigned long. We should
> >>> +     * even be able to remove this restriction but I'm simply
> >>> +     * keeping it.
> >>> +     */
> >>> +    assert(shift >= 6);
> >>> +
> >>> +    size = 1ULL << (TARGET_PAGE_BITS + shift);
> >>> +    start = (((ram_addr_t)page) << TARGET_PAGE_BITS) & (-size);
> >>
> >> these as well as.
> >
> > Is there any coding style requirement for this?
> 
> Don't think so. It simply results in less LOC and less occurrences of variables.
> 
> > My thought was that those operations could mostly be avoided if they
> > don't pass the above if condition (e.g. just once per 1GB chunk).
> 
> Usually the compiler will reshuffle as possible to optimize. But in this case, due
> to clear_bmap_test_and_clear(), it might not be able to move the
> computations behind that call. So the final code might actually differ.
> 
> Not that we really care about this micro-optimization, though.

OK, looks that's just a personal favor. I'm inclined to keeping the micro-optimization.

> 
> >
> >>
> >>> +    trace_migration_bitmap_clear_dirty(rb->idstr, start, size, page);
> >>> +    memory_region_clear_dirty_bitmap(rb->mr, start, size); }
> >>> +
> >>> +static void
> >>> +migration_clear_memory_region_dirty_bitmap_range(RAMState *rs,
> >>> +                                                 RAMBlock
> *rb,
> >>> +                                                 unsigned
> long
> >> start,
> >>> +                                                 unsigned
> long
> >>> +npages) {
> >>> +    unsigned long page_to_clear, i, nchunks;
> >>> +    unsigned long chunk_pages = 1UL << rb->clear_bmap_shift;
> >>> +
> >>> +    nchunks = (start + npages) / chunk_pages - start / chunk_pages
> >>> + + 1;
> >>
> >> Wouldn't you have to align the start and the end range up/down to
> >> properly calculate the number of chunks?
> >
> > No, divide will round it to the integer (beginning of the chunk to clear).
> 
> 
> nchunks = (start + npages) / chunk_pages - start / chunk_pages + 1;

I had a mistake on the right boundary, it should be [start, start + npages), instead of [start, start + npages].
i.e. nchunks = (start + npages - 1) / chunk_pages - start / chunk_pages + 1

But I can take your approach here, thanks.

Best,
Wei


      reply	other threads:[~2021-07-19  5:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15  7:53 [PATCH v2] migration: clear the memory region dirty bitmap when skipping free pages Wei Wang
2021-07-15  9:28 ` David Hildenbrand
2021-07-16  6:15   ` Wang, Wei W
2021-07-16  8:26     ` David Hildenbrand
2021-07-19  5:18       ` Wang, Wei W [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=bcf1c9a8817e41669b0c95a194a160fd@intel.com \
    --to=wei.w.wang@intel.com \
    --cc=david@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=mst@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 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).