From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58555) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmO5N-00087b-Vu for qemu-devel@nongnu.org; Fri, 10 Mar 2017 12:12:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmO5M-00034F-Rh for qemu-devel@nongnu.org; Fri, 10 Mar 2017 12:12:13 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:57630) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmO5M-0002j5-Jh for qemu-devel@nongnu.org; Fri, 10 Mar 2017 12:12:12 -0500 Date: Fri, 10 Mar 2017 09:11:44 -0800 From: Matthew Wilcox Message-ID: <20170310171143.GA16328@bombadil.infradead.org> References: <1488519630-89058-1-git-send-email-wei.w.wang@intel.com> <1488519630-89058-4-git-send-email-wei.w.wang@intel.com> <20170309141411.GZ16328@bombadil.infradead.org> <58C28FF8.5040403@intel.com> <20170310175349-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170310175349-mutt-send-email-mst@kernel.org> Subject: Re: [Qemu-devel] [PATCH v7 kernel 3/5] virtio-balloon: implementation of VIRTIO_BALLOON_F_CHUNK_TRANSFER List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: Wei Wang , virtio-dev@lists.oasis-open.org, kvm@vger.kernel.org, qemu-devel@nongnu.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-mm@kvack.org, Liang Li , Paolo Bonzini , Cornelia Huck , Amit Shah , Dave Hansen , Andrea Arcangeli , David Hildenbrand , Liang Li On Fri, Mar 10, 2017 at 05:58:28PM +0200, Michael S. Tsirkin wrote: > One of the issues of current balloon is the 4k page size > assumption. For example if you free a huge page you > have to split it up and pass 4k chunks to host. > Quite often host can't free these 4k chunks at all (e.g. > when it's using huge tlb fs). > It's even sillier for architectures with base page size >4k. I completely agree with you that we should be able to pass a hugepage as a single chunk. Also we shouldn't assume that host and guest have the same page size. I think we can come up with a scheme that actually lets us encode that into a 64-bit word, something like this: bit 0 clear => bits 1-11 encode a page count, bits 12-63 encode a PFN, page size 4k. bit 0 set, bit 1 clear => bits 2-12 encode a page count, bits 13-63 encode a PFN, page size 8k bits 0+1 set, bit 2 clear => bits 3-13 for page count, bits 14-63 for PFN, page size 16k. bits 0-2 set, bit 3 clear => bits 4-14 for page count, bits 15-63 for PFN, page size 32k bits 0-3 set, bit 4 clear => bits 5-15 for page count, bits 16-63 for PFN, page size 64k That means we can always pass 2048 pages (of whatever page size) in a single chunk. And we support arbitrary power of two page sizes. I suggest something like this: u64 page_to_chunk(struct page *page) { u64 chunk = page_to_pfn(page) << PAGE_SHIFT; chunk |= (1UL << compound_order(page)) - 1; } (note this is a single page of order N, so we leave the page count bits set to 0, meaning one page). > Two things to consider: > - host should pass its base page size to guest > this can be a separate patch and for now we can fall back on 12 bit if not there With this encoding scheme, I don't think we need to do this? As long as it's *at least* 12 bit, then we're fine. > - guest should pass full huge pages to host > this should be done correctly to avoid breaking up huge pages > I would say yes let's use a single format but drop the "normal chunk" > and always use the extended one. > Also, size is in units of 4k, right? Please document that low 12 bit > are reserved, they will be handy as e.g. flags. What per-chunk flags are you thinking would be useful?