From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Amit Shah <amit.shah@redhat.com>
Cc: qemu-devel@nongnu.org, quintela@redhat.com
Subject: Re: [Qemu-devel] [PATCH 2/2] ram_find_and_save_block: Split out the finding
Date: Wed, 23 Sep 2015 13:42:10 +0100 [thread overview]
Message-ID: <20150923124210.GG2655@work-vm> (raw)
In-Reply-To: <20150923122627.GB25273@grmbl.mre>
* Amit Shah (amit.shah@redhat.com) wrote:
> On (Wed) 16 Sep 2015 [19:11:54], Dr. David Alan Gilbert (git) wrote:
> > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> >
> > Split out the finding of the dirty page and all the wrap detection
> > into a separate function since it was getting a bit hairy.
> >
> > Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> > ---
> > migration/ram.c | 87 ++++++++++++++++++++++++++++++++++++++++-----------------
> > 1 file changed, 61 insertions(+), 26 deletions(-)
> >
> > diff --git a/migration/ram.c b/migration/ram.c
> > index 1fadf52..d2982e9 100644
> > --- a/migration/ram.c
> > +++ b/migration/ram.c
> > @@ -236,7 +236,7 @@ struct PageSearchStatus {
> > /* Set once we wrap around */
> > bool complete_round;
> > };
> > -typdef struct PageSearchStatus PageSearchStatus;
> > +typedef struct PageSearchStatus PageSearchStatus;
>
> :-)
Ahem - I didn't retest after I split it into two subpatches; thanks; I'll recut this soon.
> > +/*
> > + * Find the next dirty page and update any state associated with
> > + * the search process.
> > + *
> > + * Returns: True if a page is found
> > + *
> > + * @f: Current migration stream.
> > + * @pss: Data about the state of the current dirty page scan.
> > + * @*again: Set to false if the search has scanned the whole of RAM
> > + */
> > +static bool find_dirty_block(QEMUFile *f, PageSearchStatus *pss,
> > + bool *again)
> > +{
> > + pss->offset = migration_bitmap_find_and_reset_dirty(pss->block,
> > + pss->offset);
> > + if (pss->complete_round && pss->block == last_seen_block &&
> > + pss->offset >= last_offset) {
> > + /*
> > + * We've been once around the RAM and haven't found anything
> > + * give up.
> > + */
> > + *again = false;
> > + return false;
> > + }
> > + if (pss->offset >= pss->block->used_length) {
> > + /* Didn't find anything in this RAM Block */
> > + pss->offset = 0;
> > + pss->block = QLIST_NEXT_RCU(pss->block, next);
> > + if (!pss->block) {
> > + /* Hit the end of the list */
> > + pss->block = QLIST_FIRST_RCU(&ram_list.blocks);
> > + /* Flag that we've looped */
> > + pss->complete_round = true;
> > + ram_bulk_stage = false;
> > + if (migrate_use_xbzrle()) {
> > + /* If xbzrle is on, stop using the data compression at this
> > + * point. In theory, xbzrle can do better than compression.
> > + */
> > + flush_compressed_data(f);
> > + compression_switch = false;
> > + }
> > + }
> > + /* Didn't find anything this time, but try again on the new block */
> > + *again = true;
> > + return false;
> > + } else {
> > + /* Can go around again, but... */
> > + *again = true;
> > + /* We've found something so probably don't need to */
> > + return true;
>
> These comments are very good. Had you not introduced them, I'd have
> recommended to just set *again to true before the if; and get the
> 'return true' case handled earlier so that all the nesting too goes
> off (each case has a return, so no point in continuing with if..else).
Yes, I needed to add them to help me understand what was going on.
> Also, the dance with the return value and the 'again' is also slightly
> complex -- but I doubt it can be made any simpler.
>
> > + }
> > +}
> > +
> > /**
> > * ram_find_and_save_block: Finds a dirty page and sends it to f
> > *
> > @@ -935,6 +988,7 @@ static int ram_find_and_save_block(QEMUFile *f, bool last_stage,
> > {
> > PageSearchStatus pss;
> > int pages = 0;
> > + bool again, found;
> >
> > pss.block = last_seen_block;
> > pss.offset = last_offset;
> > @@ -943,29 +997,11 @@ static int ram_find_and_save_block(QEMUFile *f, bool last_stage,
> > if (!pss.block)
> > pss.block = QLIST_FIRST_RCU(&ram_list.blocks);
> >
> > - while (true) {
> > - pss.offset = migration_bitmap_find_and_reset_dirty(pss.block,
> > - pss.offset);
> > - if (pss.complete_round && pss.block == last_seen_block &&
> > - pss.offset >= last_offset) {
> > - break;
> > - }
> > - if (pss.offset >= pss.block->used_length) {
> > - pss.offset = 0;
> > - pss.block = QLIST_NEXT_RCU(pss.block, next);
> > - if (!pss.block) {
> > - pss.block = QLIST_FIRST_RCU(&ram_list.blocks);
> > - pss.complete_round = true;
> > - ram_bulk_stage = false;
> > - if (migrate_use_xbzrle()) {
> > - /* If xbzrle is on, stop using the data compression at this
> > - * point. In theory, xbzrle can do better than compression.
> > - */
> > - flush_compressed_data(f);
> > - compression_switch = false;
> > - }
> > - }
> > - } else {
> > + do {
> > + again = true;
>
> This assignment isn't needed -- did any tool complain?
No, it just seemed neater; I'll remove it when I repost.
Dave
>
> > + found = find_dirty_block(f, &pss, &again);
> > +
> > + if (found) {
>
>
> Amit
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
prev parent reply other threads:[~2015-09-23 12:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-16 18:11 [Qemu-devel] [PATCH 0/2] Split up ram_find_and_save_block Dr. David Alan Gilbert (git)
2015-09-16 18:11 ` [Qemu-devel] [PATCH 1/2] Move dirty page search state into separate structure Dr. David Alan Gilbert (git)
2015-09-23 12:20 ` Amit Shah
2015-09-16 18:11 ` [Qemu-devel] [PATCH 2/2] ram_find_and_save_block: Split out the finding Dr. David Alan Gilbert (git)
2015-09-23 12:26 ` Amit Shah
2015-09-23 12:42 ` Dr. David Alan Gilbert [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=20150923124210.GG2655@work-vm \
--to=dgilbert@redhat.com \
--cc=amit.shah@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).