From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLCct-0008S5-Tf for qemu-devel@nongnu.org; Fri, 31 Jul 2015 11:53:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZLCcn-00055h-Vm for qemu-devel@nongnu.org; Fri, 31 Jul 2015 11:53:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33708) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLCcn-00053r-OK for qemu-devel@nongnu.org; Fri, 31 Jul 2015 11:53:33 -0400 Date: Fri, 31 Jul 2015 16:53:26 +0100 From: "Dr. David Alan Gilbert" Message-ID: <20150731155325.GA6794@work-vm> References: <1434450415-11339-1-git-send-email-dgilbert@redhat.com> <1434450415-11339-37-git-send-email-dgilbert@redhat.com> <87mvyyg4vh.fsf@neno.neno> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87mvyyg4vh.fsf@neno.neno> Subject: Re: [Qemu-devel] [PATCH v7 36/42] Host page!=target page: Cleanup bitmaps List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Juan Quintela Cc: aarcange@redhat.com, yamahata@private.email.ne.jp, liang.z.li@intel.com, qemu-devel@nongnu.org, luis@cs.umu.se, amit.shah@redhat.com, pbonzini@redhat.com, david@gibson.dropbear.id.au * Juan Quintela (quintela@redhat.com) wrote: > "Dr. David Alan Gilbert (git)" wrote: > > From: "Dr. David Alan Gilbert" > > > > Prior to the start of postcopy, ensure that everything that will > > be transferred later is a whole host-page in size. > > > > This is accomplished by discarding partially transferred host pages > > and marking any that are partially dirty as fully dirty. > > > > Signed-off-by: Dr. David Alan Gilbert > > > /* > > + * Helper for postcopy_chunk_hostpages where HPS/TPS >= bits-in-long > > + * > > + * !! Untested !! > > You continue in the race for best comment ever O:-) I prefer honesty in comments, especially for the next person who tries to use it! > > + */ > > +static int hostpage_big_chunk_helper(const char *block_name, void *host_addr, > > + ram_addr_t offset, ram_addr_t length, > > + void *opaque) > > +{ > > + MigrationState *ms = opaque; > > + unsigned long long_bits = sizeof(long) * 8; > > + unsigned int host_len = (qemu_host_page_size / TARGET_PAGE_SIZE) / > > + long_bits; > > + unsigned long first_long, last_long, cur_long, current_hp; > > + unsigned long first = offset >> TARGET_PAGE_BITS; > > + unsigned long last = (offset + (length - 1)) >> TARGET_PAGE_BITS; > > + > > + PostcopyDiscardState *pds = postcopy_discard_send_init(ms, > > + first, > > + block_name); > > Minor > > PostcopyDiscardState *pds = > postcopy_discard_send_init(ms, first, block_name); > > ?? Done. > No need for this: > > find_first_bit() > find_first_zero_bit() > > You are warking all the words when a single search is enough? > creative use of bitmap_zero(), bitmap_fill() and just doing o whelo > postcopy_discard_send_rand() would not be better? > > + mask &= (((unsigned long)1) << ((end & long_bits_mask) + 1)) - 1; > > bitmap_set(&mask, 0, end); > > > Adjust +1/-1 depending on how you do limits? > > BTW, when I need inspiration about how to code functions that deal with > bits, I searc for inspiration in bitmap.c. Sometimes function already > exist, and otherwise, things like BITS_PER_LONG, etc, are already > defined there. OK, I've reworked it using the bitmap/bitops.h functions: 1 file changed, 128 insertions(+), 220 deletions(-) (still untested). Doing it this way it's hand to be two iterations, one for fixing up partially sent host pages, and the second for fixing up partially dirtied pages. I'll try and find a !x86 to try it on. > > + /* Easiest way to make sure we don't resume in the middle of a host-page */ > > + last_seen_block = NULL; > > + last_sent_block = NULL; > > Best names ever. And you have to blame me at least for the second one > to appear :p > > > > + > > + /* > > + * The currently worst known ratio is ARM that has 1kB target pages, and > > + * can have 64kB host pages, which is thus inconveniently larger than a long > > + * on ARM (32bits), and a long is the underlying element of the migration > > + * bitmaps. > > + */ > > + if (host_bits >= long_bits) { > > + /* Deal with the odd case separately */ > > + return qemu_ram_foreach_block(hostpage_big_chunk_helper, ms); > > + } else { > > + host_mask = (1ul << host_bits) - 1; > > + } > > You can remove the else enterily and just put the code at top level. > > So, we have three cases: > > - host_bits == target_bits -> NOP > - host_bits >= long_bits > - host_bits < long_bits > > Couldn't we merge the last two? they are very similar, and having two > code paths looks too much to me? Yep, so those are gone now. > > @@ -1405,9 +1664,17 @@ int ram_postcopy_send_discard_bitmap(MigrationState *ms) > > int ret; > > > > rcu_read_lock(); > > + > Another not needed. Moved that back to where the rest of the function came from. Dave -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK