From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rusty Russell Subject: Re: [PATCH v11 5/7] virtio_balloon: introduce migration primitives to balloon pages Date: Mon, 12 Nov 2012 18:19:23 +1030 Message-ID: <87lie71csc.fsf@rustcorp.com.au> References: <265aaff9a79f503672f0cdcdff204114b5b5ba5b.1352256088.git.aquini@redhat.com> <87625h3tl1.fsf@rustcorp.com.au> <20121108003403.GE10444@optiplex.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20121108003403.GE10444@optiplex.redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: virtualization-bounces@lists.linux-foundation.org Errors-To: virtualization-bounces@lists.linux-foundation.org To: Rafael Aquini Cc: Rik van Riel , "Michael S. Tsirkin" , Konrad Rzeszutek Wilk , linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-mm@kvack.org, Peter Zijlstra , Andi Kleen , Minchan Kim , Andrew Morton , "Paul E. McKenney" List-Id: virtualization@lists.linuxfoundation.org Rafael Aquini writes: > On Thu, Nov 08, 2012 at 09:32:18AM +1030, Rusty Russell wrote: >> The first one can be delayed, the second one can be delayed if the host >> didn't ask for VIRTIO_BALLOON_F_MUST_TELL_HOST (qemu doesn't). >> >> We could implement a proper request queue for these, and return -EAGAIN >> if the queue fills. Though in practice, it's not important (it might >> help performance). > > I liked the idea. Give me the directions to accomplish it and I'll give it a try > for sure. OK, let's get this applied first, but here are some pointers: Here's the current callback function when the host has processed the buffers we put in the queue: static void balloon_ack(struct virtqueue *vq) { struct virtio_balloon *vb = vq->vdev->priv; wake_up(&vb->acked); } It's almost a noop: here's how we use it to make our queues synchronous: static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq) { struct scatterlist sg; unsigned int len; sg_init_one(&sg, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns); /* We should always be able to add one buffer to an empty queue. */ if (virtqueue_add_buf(vq, &sg, 1, 0, vb, GFP_KERNEL) < 0) BUG(); virtqueue_kick(vq); /* When host has read buffer, this completes via balloon_ack */ wait_event(vb->acked, virtqueue_get_buf(vq, &len)); } And we set up the callback when we create the virtqueue: vq_callback_t *callbacks[] = { balloon_ack, balloon_ack, stats_request }; ... err = vb->vdev->config->find_vqs(vb->vdev, nvqs, vqs, callbacks, names); So off the top of my head it should be as simple as changing tell_host() to only wait if the virtqueue_add_buf() fails (ie. queue is full). Hmm, though you will want to synchronize the inflate and deflate queues: if we tell the host we're giving a page up we want it to have seen that before we tell it we're using it again... Cheers, Rusty. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx158.postini.com [74.125.245.158]) by kanga.kvack.org (Postfix) with SMTP id 8FAF96B004D for ; Mon, 12 Nov 2012 02:50:14 -0500 (EST) From: Rusty Russell Subject: Re: [PATCH v11 5/7] virtio_balloon: introduce migration primitives to balloon pages In-Reply-To: <20121108003403.GE10444@optiplex.redhat.com> References: <265aaff9a79f503672f0cdcdff204114b5b5ba5b.1352256088.git.aquini@redhat.com> <87625h3tl1.fsf@rustcorp.com.au> <20121108003403.GE10444@optiplex.redhat.com> Date: Mon, 12 Nov 2012 18:19:23 +1030 Message-ID: <87lie71csc.fsf@rustcorp.com.au> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-linux-mm@kvack.org List-ID: To: Rafael Aquini Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, "Michael S. Tsirkin" , Rik van Riel , Mel Gorman , Andi Kleen , Andrew Morton , Konrad Rzeszutek Wilk , Minchan Kim , Peter Zijlstra , "Paul E. McKenney" Rafael Aquini writes: > On Thu, Nov 08, 2012 at 09:32:18AM +1030, Rusty Russell wrote: >> The first one can be delayed, the second one can be delayed if the host >> didn't ask for VIRTIO_BALLOON_F_MUST_TELL_HOST (qemu doesn't). >> >> We could implement a proper request queue for these, and return -EAGAIN >> if the queue fills. Though in practice, it's not important (it might >> help performance). > > I liked the idea. Give me the directions to accomplish it and I'll give it a try > for sure. OK, let's get this applied first, but here are some pointers: Here's the current callback function when the host has processed the buffers we put in the queue: static void balloon_ack(struct virtqueue *vq) { struct virtio_balloon *vb = vq->vdev->priv; wake_up(&vb->acked); } It's almost a noop: here's how we use it to make our queues synchronous: static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq) { struct scatterlist sg; unsigned int len; sg_init_one(&sg, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns); /* We should always be able to add one buffer to an empty queue. */ if (virtqueue_add_buf(vq, &sg, 1, 0, vb, GFP_KERNEL) < 0) BUG(); virtqueue_kick(vq); /* When host has read buffer, this completes via balloon_ack */ wait_event(vb->acked, virtqueue_get_buf(vq, &len)); } And we set up the callback when we create the virtqueue: vq_callback_t *callbacks[] = { balloon_ack, balloon_ack, stats_request }; ... err = vb->vdev->config->find_vqs(vb->vdev, nvqs, vqs, callbacks, names); So off the top of my head it should be as simple as changing tell_host() to only wait if the virtqueue_add_buf() fails (ie. queue is full). Hmm, though you will want to synchronize the inflate and deflate queues: if we tell the host we're giving a page up we want it to have seen that before we tell it we're using it again... Cheers, Rusty. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751653Ab2KLHuN (ORCPT ); Mon, 12 Nov 2012 02:50:13 -0500 Received: from ozlabs.org ([203.10.76.45]:44436 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750856Ab2KLHuM (ORCPT ); Mon, 12 Nov 2012 02:50:12 -0500 From: Rusty Russell To: Rafael Aquini Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, "Michael S. Tsirkin" , Rik van Riel , Mel Gorman , Andi Kleen , Andrew Morton , Konrad Rzeszutek Wilk , Minchan Kim , Peter Zijlstra , "Paul E. McKenney" Subject: Re: [PATCH v11 5/7] virtio_balloon: introduce migration primitives to balloon pages In-Reply-To: <20121108003403.GE10444@optiplex.redhat.com> References: <265aaff9a79f503672f0cdcdff204114b5b5ba5b.1352256088.git.aquini@redhat.com> <87625h3tl1.fsf@rustcorp.com.au> <20121108003403.GE10444@optiplex.redhat.com> User-Agent: Notmuch/0.14 (http://notmuchmail.org) Emacs/23.4.1 (i686-pc-linux-gnu) Date: Mon, 12 Nov 2012 18:19:23 +1030 Message-ID: <87lie71csc.fsf@rustcorp.com.au> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rafael Aquini writes: > On Thu, Nov 08, 2012 at 09:32:18AM +1030, Rusty Russell wrote: >> The first one can be delayed, the second one can be delayed if the host >> didn't ask for VIRTIO_BALLOON_F_MUST_TELL_HOST (qemu doesn't). >> >> We could implement a proper request queue for these, and return -EAGAIN >> if the queue fills. Though in practice, it's not important (it might >> help performance). > > I liked the idea. Give me the directions to accomplish it and I'll give it a try > for sure. OK, let's get this applied first, but here are some pointers: Here's the current callback function when the host has processed the buffers we put in the queue: static void balloon_ack(struct virtqueue *vq) { struct virtio_balloon *vb = vq->vdev->priv; wake_up(&vb->acked); } It's almost a noop: here's how we use it to make our queues synchronous: static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq) { struct scatterlist sg; unsigned int len; sg_init_one(&sg, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns); /* We should always be able to add one buffer to an empty queue. */ if (virtqueue_add_buf(vq, &sg, 1, 0, vb, GFP_KERNEL) < 0) BUG(); virtqueue_kick(vq); /* When host has read buffer, this completes via balloon_ack */ wait_event(vb->acked, virtqueue_get_buf(vq, &len)); } And we set up the callback when we create the virtqueue: vq_callback_t *callbacks[] = { balloon_ack, balloon_ack, stats_request }; ... err = vb->vdev->config->find_vqs(vb->vdev, nvqs, vqs, callbacks, names); So off the top of my head it should be as simple as changing tell_host() to only wait if the virtqueue_add_buf() fails (ie. queue is full). Hmm, though you will want to synchronize the inflate and deflate queues: if we tell the host we're giving a page up we want it to have seen that before we tell it we're using it again... Cheers, Rusty.