From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32935) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNx5t-0000Mv-5O for qemu-devel@nongnu.org; Wed, 30 May 2018 05:08:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNx5q-0003Yg-01 for qemu-devel@nongnu.org; Wed, 30 May 2018 05:08:33 -0400 Received: from mga09.intel.com ([134.134.136.24]:61512) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fNx5p-0003XN-MU for qemu-devel@nongnu.org; Wed, 30 May 2018 05:08:29 -0400 Message-ID: <5B0E6AE9.2030505@intel.com> Date: Wed, 30 May 2018 17:12:09 +0800 From: Wei Wang MIME-Version: 1.0 References: <1524550428-27173-1-git-send-email-wei.w.wang@intel.com> <1524550428-27173-5-git-send-email-wei.w.wang@intel.com> <20180529181221-mutt-send-email-mst@kernel.org> In-Reply-To: <20180529181221-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v7 4/5] virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_HINT List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, virtio-dev@lists.oasis-open.org, quintela@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, liliang.opensource@gmail.com, yang.zhang.wz@gmail.com, quan.xu0@gmail.com, nilal@redhat.com, riel@redhat.com, zhang.zhanghailiang@huawei.com On 05/29/2018 11:24 PM, Michael S. Tsirkin wrote: > On Tue, Apr 24, 2018 at 02:13:47PM +0800, Wei Wang wrote: >> +/* >> + * Balloon will report pages which were free at the time of this call. As the >> + * reporting happens asynchronously, dirty bit logging must be enabled before >> + * this call is made. >> + */ >> +void balloon_free_page_start(void) >> +{ >> + balloon_free_page_start_fn(balloon_opaque); >> +} > Please create notifier support, not a single global. OK. The start is called at the end of bitmap_sync, and the stop is called at the beginning of bitmap_sync. In this case, we will need to add two migration states, MIGRATION_STATUS_BEFORE_BITMAP_SYNC and MIGRATION_STATUS_AFTER_BITMAP_SYNC, right? > > +static void virtio_balloon_poll_free_page_hints(void *opaque) > +{ > + VirtQueueElement *elem; > + VirtIOBalloon *dev = opaque; > + VirtIODevice *vdev = VIRTIO_DEVICE(dev); > + VirtQueue *vq = dev->free_page_vq; > + uint32_t id; > + size_t size; > + > + while (1) { > + qemu_mutex_lock(&dev->free_page_lock); > + while (dev->block_iothread) { > + qemu_cond_wait(&dev->free_page_cond, &dev->free_page_lock); > + } > + > + /* > + * If the migration thread actively stops the reporting, exit > + * immediately. > + */ > + if (dev->free_page_report_status == FREE_PAGE_REPORT_S_STOP) { > Please refactor this : move loop body into a function so > you can do lock/unlock in a single place. Sounds good. > > + > +static bool virtio_balloon_free_page_support(void *opaque) > +{ > + VirtIOBalloon *s = opaque; > + VirtIODevice *vdev = VIRTIO_DEVICE(s); > + > + return virtio_vdev_has_feature(vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT); > or if poison is negotiated. Will make it return virtio_vdev_has_feature(vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT) && !virtio_vdev_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON) Best, Wei