From: Rafal Wojtczuk Subject: Re: Improving domU restore time Date: Mon, 31 May 2010 11:42:43 +0200 Message-ID: <20100531094243.GB3374@emperor2.itldev.org> References: <20100525103557.GC23903@emperor2.itldev.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="ew6BAiZeqk4r7MaW" Return-path: Content-Disposition: inline In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Keir Fraser Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org --ew6BAiZeqk4r7MaW Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline Hello, > I would be grateful for the comments on possible methods to improve domain > restore performance. Focusing on the PV case, if it matters. Continuing the topic; thank you to everyone that responded so far. Focusing on xen-3.4.3 case for now, dom0/domU still 2.6.32.x pvops x86_64. Let me just reiterate that for our purposes, the domain save time (and possible related post-processing) is not critical, it is only the restore time that matters. I did some experiments; they involve: 1) before saving a domain, have domU allocate all free memory in an userland process, then fill it with some MAGIC_PATTERN. Save domU, then process the savefile, removing all pfns (and their page content) that refer to a page containing MAGIC_PATTERN. This reduces the savefile size. 2) instead of executing "xm restore savefile", just poke the xmlrpc request to Xend unix socket via socat 3) change the /etc/xen/scripts/block so that in the "add file:" case, it calls only 3 processes (xenstore-read, losetup, xenstore-write); assuming the sharing check can be done elsewhere, this should provide realistic lower bound for the execution time For a domain with 400MB RAM and 4 vbds, with the savefile in the fs cache, this cuts down the restore real time from 2700 ms to 1153 ms. Some questions: a) is the 1) method safe ? Normally, xc_domain_restore() allocates mfns via xc_domain_memory_populate_physmap() and then calls xc_add_mmu_update(MMU_MACHPHYS_UPDATE) on the pfn/mfn pairs. If we remove some pfns from the savefile, this will not happen. Instead, the mfn for the removed pfn (referring to memory whose content we don't care for) will be allocated in uncanonicalize_pagetable(), because there will be a pte entry for this page. But uncanonicalize_pagetable() does not call xc_add_mmu_update(). Still, the domain seems to be restored properly (naturally the buffer filled previously with MAGIC_PATTERN now contains junk, but this is the whole purpose of it). Again, is xc_add_mmu_update(MMU_MACHPHYS_UPDATE) really needed in the above scenario ? It basically does set_gpfn_from_mfn(mfn, gpfn) but this should already be taken care for by xc_domain_memory_populate_physmap() ? b) There still seems to be some discrepancy between the real time (1153ms) and the CPU time (970ms); considering this is a machine with 2 cores (and at least the hotplug scripts execute in parallel), it is notable. What can cause the involved processes to sleep (we read the savefile from fs cache, so there should be no disk reads at all). Is the single threaded nature of xenstored the possible cause for the delays ? Generally xenstored seems to be quite busy during the restore. Do you think some of the queries (from Xend?) are redundant ? Is there anything else that can be removed from the relevant Xend code with no harm ? This question may sound too blunt; but given the fact that "xm restore savefile" wastes 220 ms of CPU time doing apparently nothing useful, I would assume there is some overhead in Xend too. The systemtap trace in the attachment; it does not contain a line about the xenstored CPU ticks (259ms, really a lot?), as xenstored does not terminate any thread. c) >> Also, it looks really excessive that basically copying 400MB of memory takes >> over 1.3s cpu time. Is IOCTL_PRIVCMD_MMAPBATCH the culprit (its > I would expect IOCTL_PRIVCMD_MMAPBATCH to be the most significant part of > that loop. Let's imagine there is a hypercall do_direct_memcpy_from_dom0_to_mfn(int mfn_count, mfn* mfn_array, char * pages_content). Would it make xc_restore faster if instead of using the xc_map_foreign_batch() interface, it would call the above hypercall ? On x86_64 all the physical memory is already mapped in the hypervisor (is this correct?), so this could be quicker, as no page table setup would be necessary ? Regards, Rafal Wojtczuk Principal Researcher Invisible Things Lab, Qubes-os project --ew6BAiZeqk4r7MaW Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: attachment; filename="probe.systemtap" global process_start probe kernel.function("do_execve").return { p=pid() t=gettimeofday_us() process_start[p]=t printf("executed pid %d parent %d time=%d name=%s\n", p, ppid(), t, execname()) } probe timer.profile { tid=tid() if (!user_mode()) kticks[tid] <<< 1 else uticks[tid] <<< 1 tids[tid] <<< 1 } global uticks, kticks, tids function logit() { tid=tid() p=pid() t=gettimeofday_us() elapsed=t-process_start[p] printf("finishing tid %d pid %d parent %d ticks %d real %d time=%d name=%s\n", tid, p, ppid(), @count(kticks[tid])+@count(uticks[tid]), elapsed, t, execname()) } probe syscall.exit { logit() } --ew6BAiZeqk4r7MaW Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: attachment; filename="probeoutput.txt" # slightly postprocessed, to include [delta_from_prev, abstime] values before # each event logged 0 0 executed pid 10521 parent 2232 time=1275054562565050 name=socat 254543 254543 executed pid 10523 parent 10215 time=1275054562819593 name=block 28076 282619 executed pid 10524 parent 10220 time=1275054562847669 name=block 4585 287204 executed pid 10525 parent 10523 time=1275054562852254 name=xenstore-read 2645 289849 executed pid 10526 parent 10524 time=1275054562854899 name=xenstore-read 13441 303290 finishing tid 10525 pid 10525 parent 10523 ticks 3 real 16086 time=1275054562868340 name=xenstore-read 6564 309854 executed pid 10528 parent 10523 time=1275054562874904 name=losetup 4772 314626 finishing tid 10526 pid 10526 parent 10524 ticks 3 real 24777 time=1275054562879676 name=xenstore-read 2782 317408 executed pid 10530 parent 10524 time=1275054562882458 name=losetup 1715 319123 executed pid 10529 parent 10527 time=1275054562884173 name=block 1816 320939 finishing tid 10530 pid 10530 parent 10524 ticks 2 real 3531 time=1275054562885989 name=losetup 4658 325597 executed pid 10532 parent 10524 time=1275054562890647 name=xenstore-write 1820 327417 executed pid 10533 parent 10529 time=1275054562892467 name=xenstore-read 4007 331424 finishing tid 10532 pid 10532 parent 10524 ticks 2 real 5827 time=1275054562896474 name=xenstore-write 538 331962 finishing tid 10524 pid 10524 parent 10220 ticks 7 real 49343 time=1275054562897012 name=block 1133 333095 finishing tid 10528 pid 10528 parent 10523 ticks 4 real 23241 time=1275054562898145 name=losetup 3605 336700 finishing tid 10533 pid 10533 parent 10529 ticks 2 real 9283 time=1275054562901750 name=xenstore-read 1714 338414 executed pid 10535 parent 10523 time=1275054562903464 name=xenstore-write 3556 341970 executed pid 10536 parent 10529 time=1275054562907020 name=losetup 2064 344034 finishing tid 10536 pid 10536 parent 10529 ticks 3 real 2064 time=1275054562909084 name=losetup 1382 345416 finishing tid 10535 pid 10535 parent 10523 ticks 3 real 7002 time=1275054562910466 name=xenstore-write 591 346007 finishing tid 10523 pid 10523 parent 10215 ticks 7 real 91464 time=1275054562911057 name=block 3332 349339 executed pid 10538 parent 10529 time=1275054562914389 name=xenstore-write 4557 353896 finishing tid 10538 pid 10538 parent 10529 ticks 2 real 4557 time=1275054562918946 name=xenstore-write 549 354445 finishing tid 10529 pid 10529 parent 10527 ticks 7 real 35322 time=1275054562919495 name=block 25937 380382 executed pid 10539 parent 10215 time=1275054562945432 name=block 6636 387018 executed pid 10540 parent 10539 time=1275054562952068 name=xenstore-read 4327 391345 finishing tid 10540 pid 10540 parent 10539 ticks 3 real 4327 time=1275054562956395 name=xenstore-read 3895 395240 executed pid 10541 parent 10539 time=1275054562960290 name=losetup 1603 396843 finishing tid 10541 pid 10541 parent 10539 ticks 3 real 1603 time=1275054562961893 name=losetup 2141 398984 executed pid 10543 parent 10539 time=1275054562964034 name=xenstore-write 5343 404327 finishing tid 10543 pid 10543 parent 10539 ticks 2 real 5343 time=1275054562969377 name=xenstore-write 577 404904 finishing tid 10539 pid 10539 parent 10215 ticks 7 real 24522 time=1275054562969954 name=block 67293 472197 executed pid 10544 parent 8826 time=1275054563037247 name=xc_restore 407415 879612 finishing tid 10544 pid 10544 parent 8826 ticks 387 real 407415 time=1275054563444662 name=xc_restore 2571 882183 finishing tid 10545 pid 8826 parent 1 ticks 15 real 1275054563447233 time=1275054563447233 name=xend 271673 1153856 finishing tid 10521 pid 10521 parent 2232 ticks 8 real 1153856 time=1275054563718906 name=socat 73 1153929 finishing tid 10522 pid 8826 parent 1 ticks 238 real 1275054563718979 time=1275054563718979 name=xend 2258682 3412611 finishing tid 10215 pid 10215 parent 748 ticks 5 real 1275054565977661 time=1275054565977661 name=udevd --ew6BAiZeqk4r7MaW Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --ew6BAiZeqk4r7MaW--