From patchwork Wed May 25 10:37:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 9135177 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8C7D6607D7 for ; Wed, 25 May 2016 11:12:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FD47282D7 for ; Wed, 25 May 2016 11:12:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 74E0A282DC; Wed, 25 May 2016 11:12:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 06E39282D7 for ; Wed, 25 May 2016 11:12:36 +0000 (UTC) Received: from localhost ([::1]:59002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5Wjr-0003tK-7m for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 May 2016 07:12:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5WCR-0006Rk-H9 for qemu-devel@nongnu.org; Wed, 25 May 2016 06:38:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5WCN-0005GF-05 for qemu-devel@nongnu.org; Wed, 25 May 2016 06:38:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45055) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5WCM-0005G2-Nf for qemu-devel@nongnu.org; Wed, 25 May 2016 06:37:58 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1BB137F0A2; Wed, 25 May 2016 10:37:58 +0000 (UTC) Received: from redhat.com (vpn1-7-192.ams2.redhat.com [10.36.7.192]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id u4PAbsmL018506; Wed, 25 May 2016 06:37:55 -0400 Date: Wed, 25 May 2016 13:37:54 +0300 From: "Michael S. Tsirkin" To: "Li, Liang Z" Message-ID: <20160525131716-mutt-send-email-mst@redhat.com> References: <1463738386-30868-1-git-send-email-liang.z.li@intel.com> <20160520120038.GA28757@redhat.com> <20160524130041-mutt-send-email-mst@redhat.com> <20160525115419-mutt-send-email-mst@redhat.com> <20160525123546-mutt-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 25 May 2016 10:37:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: Re: [Qemu-devel] [PATCH RFC kernel] balloon: speed up inflating/deflating process X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "kvm@vger.kernel.org" , "qemu-devel@nongnu.org" , "linux-kernel@vger.kernel.org" , "virtualization@lists.linux-foundation.org" , "amit.shah@redhat.com" , "pbonzini@redhat.com" , "akpm@linux-foundation.org" , "dgilbert@redhat.com" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Wed, May 25, 2016 at 10:10:47AM +0000, Li, Liang Z wrote: > > > > > > > > > > Hi MST, > > > > > > > > > > I have measured the performance when using a 32K page bitmap, > > > > > > > > Just to make sure. Do you mean a 32Kbyte bitmap? > > > > Covering 1Gbyte of memory? > > > Yes. > > > > > > > > > > > > and inflate the balloon to 3GB > > > > > of an idle guest with 4GB RAM. > > > > > > > > Should take 3 requests then, right? > > > > > > > > > > No, we can't assign the PFN when allocating page in balloon driver, > > > So the PFNs of pages allocated may be across a large range, we will > > > tell the host once the pfn_max -pfn_min >= 0x40000(1GB range), so the > > > requests count is most likely to be more than 3. > > > > > > > > Now: > > > > > total inflating time: 338ms > > > > > the count of virtio data transmission: 373 > > > > > > > > Why was this so high? I would expect 3 transmissions. > > > > > > I follow your suggestion: > > > ---------------------------------------------------------------------- > > > -------------- Suggestion to address all above comments: > > > 1. allocate a bunch of pages and link them up, > > > calculating the min and the max pfn. > > > if max-min exceeds the allocated bitmap size, > > > tell host. > > > 2. limit allocated bitmap size to something reasonable. > > > How about 32Kbytes? This is 256kilo bit in the map, which comes > > > out to 1Giga bytes of memory in the balloon. > > > ---------------------------------------------------------------------- > > > --------------- Because the PFNs of the allocated pages are not linear > > > increased, so 3 transmissions are impossible. > > > > > > > > > Liang > > > > Interesting. How about instead of tell host, we do multiple scans, each time > > ignoring pages out of range? > > > > for (pfn = min pfn; pfn < max pfn; pfn += 1G) { > > foreach page > > if page pfn < pfn || page pfn >= pfn + 1G > > continue > > set bit > > tell host > > } > > > > That means we have to allocate/free all the requested pages first, and then tell the host. > It works fine for inflating, but for deflating, because the page has been deleted from the vb-> vb_dev_info->pages, > so, we have to use a struct to save the dequeued pages before calling release_pages_balloon(), struct list_head? I think you can just replace set_page_pfns with list_add(&page->lru, &page_list); > I think a page bitmap is the best struct to save these pages, because it consumes less memory. > And that bitmap should be large enough to save pfn 0 to max_pfn. > > If the above is true, then we are back to the square one. we really need a large page bitmap. Right? > > Liang These look like implementation issues to me. I think the below might be helpful (completely untested), your work can go on top. ---> virtio-balloon: rework deflate to add page to a tmp list Will allow faster notifications using a bitmap down the road. Signed-off-by: Michael S. Tsirkin diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 476c0e3..44050a3 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -195,8 +195,9 @@ static void release_pages_balloon(struct virtio_balloon *vb) static unsigned leak_balloon(struct virtio_balloon *vb, size_t num) { unsigned num_freed_pages; - struct page *page; + struct page *page, *next; struct balloon_dev_info *vb_dev_info = &vb->vb_dev_info; + LIST_HEAD(pages); /* Pages dequeued for handing to Host */ /* We can only do one array worth at a time. */ num = min(num, ARRAY_SIZE(vb->pfns)); @@ -207,10 +208,13 @@ static unsigned leak_balloon(struct virtio_balloon *vb, size_t num) page = balloon_page_dequeue(vb_dev_info); if (!page) break; - set_page_pfns(vb, vb->pfns + vb->num_pfns, page); + list_add(&page->lru, &pages); vb->num_pages -= VIRTIO_BALLOON_PAGES_PER_PAGE; } + list_for_each_entry_safe(page, next, &pages, lru) + set_page_pfns(vb, vb->pfns + vb->num_pfns, page); + num_freed_pages = vb->num_pfns; /* * Note that if