From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Juan Quintela <quintela@redhat.com>
Cc: aarcange@redhat.com, liang.z.li@intel.com, qemu-devel@nongnu.org,
luis@cs.umu.se, bharata@linux.vnet.ibm.com, amit.shah@redhat.com,
pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH v8 32/54] Postcopy: Maintain sentmap and calculate discard
Date: Fri, 30 Oct 2015 18:43:00 +0000 [thread overview]
Message-ID: <20151030184259.GP2417@work-vm> (raw)
In-Reply-To: <87lhawa2sj.fsf@neno.neno>
* Juan Quintela (quintela@redhat.com) wrote:
> "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com> wrote:
> > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> >
> > Where postcopy is preceeded by a period of precopy, the destination will
> > have received pages that may have been dirtied on the source after the
> > page was sent. The destination must throw these pages away before
> > starting it's CPUs.
> >
> > Maintain a 'sentmap' of pages that have already been sent.
> > Calculate list of sent & dirty pages
> > Provide helpers on the destination side to discard these.
> >
> > Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> > Reviewed-by: Amit Shah <amit.shah@redhat.com>
>
>
> Hi
(I'm going to reply to this mail in a few separate mails as I get
to them)
> > /* Flag set once the migration has been asked to enter postcopy */
> > bool start_postcopy;
>
>
> This is from a previous patch, but ....
>
> Change the name of the variable or the comment? From the comment it
> sholud be "in_postcopy", no?
We have to be careful to differentiate between two separate things:
1) The user has issued 'migrate_start_postcopy'
- that sets this 'start_postcopy' flag
2) The non-postcopiable data has dropped below the limit and we've
now been able to take notice of 'start_postcopy' and actually
enter postcopy.
I think 'in_postcopy' would imply (2); while 'start_postcopy'
matches the command that's been issued.
> > +struct PostcopyDiscardState {
> > + const char *name;
>
> Iht is not obvious to me what name means here. I assume ram block name,
> change it to block_name, ramblock?
Now ramblock_name.
>
> > + * returns: 0 on success.
> > + */
> > +int postcopy_ram_discard_range(MigrationIncomingState *mis, uint8_t *start,
> > + size_t length)
> > +{
> > + trace_postcopy_ram_discard_range(start, length);
> > + if (madvise(start, length, MADV_DONTNEED)) {
> > + error_report("%s MADV_DONTNEED: %s", __func__, strerror(errno));
> > + return -1;
> > + }
> > +
> > + return 0;
> > +}
> > +
> > #else
> > /* No target OS support, stubs just fail */
> > bool postcopy_ram_supported_by_host(void)
> > @@ -153,5 +192,95 @@ bool postcopy_ram_supported_by_host(void)
> > return false;
> > }
> >
> > +int postcopy_ram_discard_range(MigrationIncomingState *mis, uint8_t *start,
> > + size_t length)
> > +{
> > + assert(0);
>
> I will assume that just returning -1 would work here.
>
> But yes, I understand that this code shouldn't be reach ...
Yes, it really shouldn't happen if the previous code that says
postcopy isn't supported has been obeyed; I'm happy to change
it if you want.
> > +}
> > #endif
> >
> > +/* ------------------------------------------------------------------------- */
> > +
> > +/**
> > + * postcopy_discard_send_init: Called at the start of each RAMBlock before
> > + * asking to discard individual ranges.
> > + *
> > + * @ms: The current migration state.
> > + * @offset: the bitmap offset of the named RAMBlock in the migration
> > + * bitmap.
> > + * @name: RAMBlock that discards will operate on.
> > + *
> > + * returns: a new PDS.
> > + */
> > +PostcopyDiscardState *postcopy_discard_send_init(MigrationState *ms,
> > + unsigned long offset,
> > + const char *name)
> > +{
> > + PostcopyDiscardState *res = g_try_malloc(sizeof(PostcopyDiscardState));
>
> Why are we using here g_try_malloc instead of g_malloc()? Even
> g_malloc0()?
>
> Specially when we don't check if res is NULL on return. Please change.
Eek yes; I've gone with malloc0.
>
>
> > +
> > + if (res) {
> > + res->name = name;
> > + res->cur_entry = 0;
> > + res->nsentwords = 0;
> > + res->nsentcmds = 0;
>
> With the zero variant, this three can be removed.
Done.
>
> > + res->offset = offset;
> > + }
> > +
> > + return res;
> > +}
>
> > -/* Called with rcu_read_lock() to protect migration_bitmap */
> > +/* Called with rcu_read_lock() to protect migration_bitmap
> > + * mr: The region to search for dirty pages in
>
> Haha, you forgot to update the comment when you moved the function to
> use ram blocks O:-)
Oops, fixed :-)
(Rest of the patch another time)
Dave
> > @@ -662,6 +672,24 @@ static int save_zero_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
> > }
> >
> > /**
> > + * ram_find_block_by_id: Find a ramblock by name.
> > + *
> > + * Returns: The RAMBlock with matching ID, or NULL.
> > + */
> > +static RAMBlock *ram_find_block_by_id(const char *id)
> > +{
> > + RAMBlock *block;
> > +
> > + QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
> > + if (!strcmp(id, block->idstr)) {
> > + return block;
> > + }
> > + }
> > +
> > + return NULL;
> > +}
>
> We don't have this function already.....
>
> Once here, could we split it in its own patch and use it in ram_load?
>
>
> QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
> if (!strncmp(id, block->idstr, sizeof(id))) {
> if (length != block->used_length) {
> Error *local_err = NULL;
>
> ret = qemu_ram_resize(block->offset, length, &local_err);
> if (local_err) {
> error_report_err(local_err);
> }
> }
> ram_control_load_hook(f, RAM_CONTROL_BLOCK_REG,
> block->idstr);
> break;
> }
> }
>
> if (!block) {
> error_report("Unknown ramblock \"%s\", cannot "
> "accept migration", id);
> ret = -EINVAL;
> }
>
>
> We could also use it in:
>
> host_from_stream_offset
>
>
> > +/* **** functions for postcopy ***** */
> > +
> > +/*
> > + * Callback from postcopy_each_ram_send_discard for each RAMBlock
> > + * start,end: Indexes into the bitmap for the first and last bit
> > + * representing the named block
> > + */
> > +static int postcopy_send_discard_bm_ram(MigrationState *ms,
> > + PostcopyDiscardState *pds,
> > + unsigned long start, unsigned long end)
> > +{
> > + unsigned long current;
> > +
> > + for (current = start; current <= end; ) {
> > + unsigned long set = find_next_bit(ms->sentmap, end + 1, current);
> > +
> > + if (set <= end) {
> > + unsigned long zero = find_next_zero_bit(ms->sentmap,
> > + end + 1, set + 1);
> > +
> > + if (zero > end) {
> > + zero = end + 1;
> > + }
> > + postcopy_discard_send_range(ms, pds, set, zero - 1);
> > + current = zero + 1;
> > + } else {
> > + current = set;
> > + }
> > + }
>
> I think I undrestood the logic here at the end....
>
> But if we change the meaning of postcopy_discard_send_range() from
> (begin, end), to (begin, length), I think everything goes clearer, no?
>
> if (set <= end) {
> unsigned long zero = find_next_zero_bit(ms->sentmap,
> end + 1, set + 1);
> unsigned long length;
>
> if (zero > end) {
> length = end - set;
> } else {
> lenght = zero - 1 - set;
> current = zero + 1;
> }
> postcopy_discard_send_range(ms, pds, set, len);
> } else {
> current = set;
> }
> }
>
> Y would clame that if we call one zero, the other would be called one.
> Or change to set/unset, but that is just me. Yes, I haven't tested, and
> it is possible that there is a off-by-one somewhere...
>
>
> Looking at postocpy_eand_ram_send_discard, I even think that it would be
> a good idea to pass length to this function.
>
> > +/*
> > + * Transmit the set of pages to be discarded after precopy to the target
> > + * these are pages that:
> > + * a) Have been previously transmitted but are now dirty again
> > + * b) Pages that have never been transmitted, this ensures that
> > + * any pages on the destination that have been mapped by background
> > + * tasks get discarded (transparent huge pages is the specific concern)
> > + * Hopefully this is pretty sparse
> > + */
> > +int ram_postcopy_send_discard_bitmap(MigrationState *ms)
> > +{
> > + int ret;
> > +
> > + rcu_read_lock();
> > +
> > + /* This should be our last sync, the src is now paused */
> > + migration_bitmap_sync();
> > +
> > + /*
> > + * Update the sentmap to be sentmap = ~sentmap | dirty
> > + */
> > + bitmap_complement(ms->sentmap, ms->sentmap,
> > + last_ram_offset() >> TARGET_PAGE_BITS);
> > +
> > + bitmap_or(ms->sentmap, ms->sentmap, migration_bitmap,
> > + last_ram_offset() >> TARGET_PAGE_BITS);
>
> This bitmaps are really big, I don't know how long would take to do this
> operations here, but I think that we can avoid (at least) the
> bitmap_complement. We can change the bitmap name to notsentbitmap, init
> it to one and clear it each time that we sent a page, no?
>
> We can also do the bitmap_or() at migration_sync_bitmap() time, at that
> point, we shouldn't be on the critical path?
>
> Later, Juan.
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2015-10-30 18:43 UTC|newest]
Thread overview: 118+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-29 8:37 [Qemu-devel] [PATCH v8 00/54] Postcopy implementation Dr. David Alan Gilbert (git)
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 01/54] Add postcopy documentation Dr. David Alan Gilbert (git)
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 02/54] Provide runtime Target page information Dr. David Alan Gilbert (git)
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 03/54] Init page sizes in qtest Dr. David Alan Gilbert (git)
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 04/54] Move configuration section writing Dr. David Alan Gilbert (git)
2015-10-05 6:44 ` Amit Shah
2015-10-30 12:47 ` Dr. David Alan Gilbert
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 05/54] qemu_ram_block_from_host Dr. David Alan Gilbert (git)
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 06/54] Rename mis->file to from_src_file Dr. David Alan Gilbert (git)
2015-09-29 10:41 ` Amit Shah
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 07/54] Add qemu_get_buffer_in_place to avoid copies some of the time Dr. David Alan Gilbert (git)
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 08/54] Add wrapper for setting blocking status on a QEMUFile Dr. David Alan Gilbert (git)
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 09/54] Add QEMU_MADV_NOHUGEPAGE Dr. David Alan Gilbert (git)
2015-10-28 10:35 ` Amit Shah
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 10/54] migration/ram.c: Use RAMBlock rather than MemoryRegion Dr. David Alan Gilbert (git)
2015-10-28 10:36 ` Amit Shah
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 11/54] ram_debug_dump_bitmap: Dump a migration bitmap as text Dr. David Alan Gilbert (git)
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 12/54] migrate_init: Call from savevm Dr. David Alan Gilbert (git)
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 13/54] Move dirty page search state into separate structure Dr. David Alan Gilbert (git)
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 14/54] ram_find_and_save_block: Split out the finding Dr. David Alan Gilbert (git)
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 15/54] Rename save_live_complete to save_live_complete_precopy Dr. David Alan Gilbert (git)
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 16/54] Return path: Open a return path on QEMUFile for sockets Dr. David Alan Gilbert (git)
2015-10-02 15:29 ` Daniel P. Berrange
2015-10-02 16:32 ` Dr. David Alan Gilbert
2015-10-02 17:03 ` Daniel P. Berrange
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 17/54] Return path: socket_writev_buffer: Block even on non-blocking fd's Dr. David Alan Gilbert (git)
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 18/54] Migration commands Dr. David Alan Gilbert (git)
2015-10-20 11:22 ` Juan Quintela
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 19/54] Return path: Control commands Dr. David Alan Gilbert (git)
2015-10-20 11:27 ` Juan Quintela
2015-10-26 11:42 ` Dr. David Alan Gilbert
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 20/54] Return path: Send responses from destination to source Dr. David Alan Gilbert (git)
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 21/54] Return path: Source handling of return path Dr. David Alan Gilbert (git)
2015-10-20 11:33 ` Juan Quintela
2015-10-26 12:06 ` Dr. David Alan Gilbert
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 22/54] Rework loadvm path for subloops Dr. David Alan Gilbert (git)
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 23/54] Add migration-capability boolean for postcopy-ram Dr. David Alan Gilbert (git)
2015-09-29 20:22 ` Eric Blake
2015-09-30 7:00 ` Amit Shah
2015-09-30 12:44 ` Eric Blake
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 24/54] Add wrappers and handlers for sending/receiving the postcopy-ram migration messages Dr. David Alan Gilbert (git)
2015-10-20 11:50 ` Juan Quintela
2015-10-26 12:22 ` Dr. David Alan Gilbert
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 25/54] MIG_CMD_PACKAGED: Send a packaged chunk of migration stream Dr. David Alan Gilbert (git)
2015-10-20 13:25 ` Juan Quintela
2015-10-26 16:21 ` Dr. David Alan Gilbert
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 26/54] Modify save_live_pending for postcopy Dr. David Alan Gilbert (git)
2015-10-28 11:03 ` Amit Shah
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 27/54] postcopy: OS support test Dr. David Alan Gilbert (git)
2015-10-20 13:31 ` Juan Quintela
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 28/54] migrate_start_postcopy: Command to trigger transition to postcopy Dr. David Alan Gilbert (git)
2015-09-30 16:25 ` Eric Blake
2015-09-30 16:30 ` Dr. David Alan Gilbert
2015-10-20 13:33 ` Juan Quintela
2015-10-28 11:17 ` Amit Shah
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 29/54] MIGRATION_STATUS_POSTCOPY_ACTIVE: Add new migration state Dr. David Alan Gilbert (git)
2015-10-20 13:35 ` Juan Quintela
2015-10-30 18:19 ` Dr. David Alan Gilbert
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 30/54] Avoid sending vmdescription during postcopy Dr. David Alan Gilbert (git)
2015-10-20 13:35 ` Juan Quintela
2015-10-28 11:19 ` Amit Shah
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 31/54] Add qemu_savevm_state_complete_postcopy Dr. David Alan Gilbert (git)
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 32/54] Postcopy: Maintain sentmap and calculate discard Dr. David Alan Gilbert (git)
2015-10-21 11:17 ` Juan Quintela
2015-10-30 18:43 ` Dr. David Alan Gilbert [this message]
2015-11-02 17:31 ` Dr. David Alan Gilbert
2015-11-02 18:19 ` Dr. David Alan Gilbert
2015-11-02 20:14 ` Dr. David Alan Gilbert
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 33/54] postcopy: Incoming initialisation Dr. David Alan Gilbert (git)
2015-10-21 8:35 ` Juan Quintela
2015-11-03 17:59 ` Dr. David Alan Gilbert
2015-11-03 18:32 ` Juan Quintela
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 34/54] postcopy: ram_enable_notify to switch on userfault Dr. David Alan Gilbert (git)
2015-10-28 11:40 ` Amit Shah
2015-09-29 8:37 ` [Qemu-devel] [PATCH v8 35/54] Postcopy: Postcopy startup in migration thread Dr. David Alan Gilbert (git)
2015-10-21 8:57 ` Juan Quintela
2015-10-26 17:12 ` Dr. David Alan Gilbert
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 36/54] Split out end of migration code from migration_thread Dr. David Alan Gilbert (git)
2015-10-21 9:11 ` Juan Quintela
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 37/54] Postcopy: End of iteration Dr. David Alan Gilbert (git)
2015-10-21 9:16 ` Juan Quintela
2015-10-29 5:10 ` Amit Shah
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 38/54] Page request: Add MIG_RP_MSG_REQ_PAGES reverse command Dr. David Alan Gilbert (git)
2015-10-21 11:12 ` Juan Quintela
2015-10-26 16:58 ` Dr. David Alan Gilbert
2015-10-29 5:17 ` Amit Shah
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 39/54] Page request: Process incoming page request Dr. David Alan Gilbert (git)
2015-10-21 11:17 ` Juan Quintela
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 40/54] Page request: Consume pages off the post-copy queue Dr. David Alan Gilbert (git)
2015-10-26 16:32 ` Juan Quintela
2015-11-03 11:52 ` Dr. David Alan Gilbert
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 41/54] postcopy_ram.c: place_page and helpers Dr. David Alan Gilbert (git)
2015-10-28 10:28 ` Juan Quintela
2015-10-28 13:11 ` Dr. David Alan Gilbert
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 42/54] Postcopy: Use helpers to map pages during migration Dr. David Alan Gilbert (git)
2015-10-28 10:58 ` Juan Quintela
2015-10-30 12:59 ` Dr. David Alan Gilbert
2015-10-30 16:35 ` Dr. David Alan Gilbert
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 43/54] Don't sync dirty bitmaps in postcopy Dr. David Alan Gilbert (git)
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 44/54] Don't iterate on precopy-only devices during postcopy Dr. David Alan Gilbert (git)
2015-10-28 11:01 ` Juan Quintela
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 45/54] Host page!=target page: Cleanup bitmaps Dr. David Alan Gilbert (git)
2015-10-28 11:24 ` Juan Quintela
2015-11-03 17:32 ` Dr. David Alan Gilbert
2015-11-03 18:30 ` Juan Quintela
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 46/54] postcopy: Check order of received target pages Dr. David Alan Gilbert (git)
2015-10-28 11:26 ` Juan Quintela
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 47/54] Round up RAMBlock sizes to host page sizes Dr. David Alan Gilbert (git)
2015-10-28 11:28 ` Juan Quintela
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 48/54] Postcopy; Handle userfault requests Dr. David Alan Gilbert (git)
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 49/54] Start up a postcopy/listener thread ready for incoming page data Dr. David Alan Gilbert (git)
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 50/54] postcopy: Wire up loadvm_postcopy_handle_ commands Dr. David Alan Gilbert (git)
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 51/54] Postcopy: Mark nohugepage before discard Dr. David Alan Gilbert (git)
2015-10-28 14:02 ` Juan Quintela
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 52/54] End of migration for postcopy Dr. David Alan Gilbert (git)
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 53/54] Disable mlock around incoming postcopy Dr. David Alan Gilbert (git)
2015-10-21 9:17 ` Juan Quintela
2015-09-29 8:38 ` [Qemu-devel] [PATCH v8 54/54] Inhibit ballooning during postcopy Dr. David Alan Gilbert (git)
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=20151030184259.GP2417@work-vm \
--to=dgilbert@redhat.com \
--cc=aarcange@redhat.com \
--cc=amit.shah@redhat.com \
--cc=bharata@linux.vnet.ibm.com \
--cc=liang.z.li@intel.com \
--cc=luis@cs.umu.se \
--cc=pbonzini@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).