Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp902717ybh; Wed, 15 Jul 2020 19:43:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/H1LTJjPQKsGzMbU9jR6tOE1vF1oS/KRgHF5sf/pFmkiFxiEWyTlaKjyHbUxgTy2Mw9h3 X-Received: by 2002:a50:acc5:: with SMTP id x63mr2339366edc.99.1594867429803; Wed, 15 Jul 2020 19:43:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594867429; cv=none; d=google.com; s=arc-20160816; b=uU+i/Gvey1jeR4lbDdLvrEilaU+edJco6jxbZl8NFfJXMaFf7EazAoTdxRYwg1qI2A GuAJyC1eqhlyzwwmDyc/aveTb1QhLUG2Y7aKxZAdyzpMuRAwaHnfoZnRgtcJrYtZPjI+ DS07cxMqhGaIm1T7t29HxwD7Zlj8VoxvtmrIaMaGNmG/ERIvs1IMSXFkAMm3FovwzuDJ opKkLZAIWHoSoYYQUiMg95/iQmkl8UDWvLewuhpUevHuzTrJ7kXsqn966/XIInmsNQNg RDWy8Bx+uWssiT/aNmQq+qhBD8OQ35LzOsmnfA2eb/vLqye2HUuh1D87CCovTrkdSoCx aZtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=4uUfyzIHX5F8nhg7nCi52MdMV93XJEtQEkOKCnq7iuQ=; b=Oy8Iu92KuTelvtOIZkKAhvBcqTWhEtRcTAGVz5qCT39XitoAXROGFD7dI+wxw0bvxC EjqjQYFOJQ+P/V8Njd0e+vdGoOCZvpU0J/8V8cX1zmIZ+KF/sv5N1RhMXcjRPNd3dA/V ek0q1Ml/guyCqg+aiJPpiS5t/+8cCaOtwwiHdYb2Sq90kiXOHmfvuIu+WkNcmeppSR3N ZylMr/+2EaVsmZCsVCikBCFCfPc01Vg2Hh+qN96PE2qCR9svQpn1UHnz/ic205xAKwb0 CObpul88R8RKZB81svD+Pb+z1QoTlmH18BqBURm6P9aFe0QNO3D3YeYyDW6eOuM0daNI YJtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t24si2266221ejr.733.2020.07.15.19.43.27; Wed, 15 Jul 2020 19:43:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728005AbgGPCmq (ORCPT + 99 others); Wed, 15 Jul 2020 22:42:46 -0400 Received: from out30-43.freemail.mail.aliyun.com ([115.124.30.43]:55362 "EHLO out30-43.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727891AbgGPCmo (ORCPT ); Wed, 15 Jul 2020 22:42:44 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04427;MF=teawaterz@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0U2rVPuE_1594867357; Received: from localhost(mailfrom:teawaterz@linux.alibaba.com fp:SMTPD_---0U2rVPuE_1594867357) by smtp.aliyun-inc.com(127.0.0.1); Thu, 16 Jul 2020 10:42:39 +0800 From: Hui Zhu To: mst@redhat.com, david@redhat.com, jasowang@redhat.com, akpm@linux-foundation.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, qemu-devel@nongnu.org, virtio-dev@lists.oasis-open.org Cc: Hui Zhu , Hui Zhu Subject: [RFC for qemu v4 2/2] virtio_balloon: Add dcvq to deflate continuous pages Date: Thu, 16 Jul 2020 10:41:55 +0800 Message-Id: <1594867315-8626-6-git-send-email-teawater@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1594867315-8626-1-git-send-email-teawater@gmail.com> References: <1594867315-8626-1-git-send-email-teawater@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit adds a vq dcvq to deflate continuous pages. When VIRTIO_BALLOON_F_CONT_PAGES is set, try to get continuous pages from icvq and use madvise MADV_WILLNEED with the pages. Signed-off-by: Hui Zhu --- hw/virtio/virtio-balloon.c | 14 +++++++++----- include/hw/virtio/virtio-balloon.h | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index d36a5c8..165adf7 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -138,7 +138,8 @@ static void balloon_inflate_page(VirtIOBalloon *balloon, } static void balloon_deflate_page(VirtIOBalloon *balloon, - MemoryRegion *mr, hwaddr mr_offset) + MemoryRegion *mr, hwaddr mr_offset, + size_t size) { void *addr = memory_region_get_ram_ptr(mr) + mr_offset; ram_addr_t rb_offset; @@ -153,10 +154,11 @@ static void balloon_deflate_page(VirtIOBalloon *balloon, rb_page_size = qemu_ram_pagesize(rb); host_addr = (void *)((uintptr_t)addr & ~(rb_page_size - 1)); + size &= ~(rb_page_size - 1); /* When a page is deflated, we hint the whole host page it lives * on, since we can't do anything smaller */ - ret = qemu_madvise(host_addr, rb_page_size, QEMU_MADV_WILLNEED); + ret = qemu_madvise(host_addr, size, QEMU_MADV_WILLNEED); if (ret != 0) { warn_report("Couldn't MADV_WILLNEED on balloon deflate: %s", strerror(errno)); @@ -354,7 +356,7 @@ static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq) pa = (hwaddr) p << VIRTIO_BALLOON_PFN_SHIFT; offset += 4; - if (vq == s->icvq) { + if (vq == s->icvq || vq == s->dcvq) { uint32_t psize_ptr; if (iov_to_buf(elem->out_sg, elem->out_num, offset, &psize_ptr, 4) != 4) { break; @@ -383,8 +385,9 @@ static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq) balloon_inflate_page(s, section.mr, section.offset_within_region, psize, &pbp); - } else if (vq == s->dvq) { - balloon_deflate_page(s, section.mr, section.offset_within_region); + } else if (vq == s->dvq || vq == s->dcvq) { + balloon_deflate_page(s, section.mr, section.offset_within_region, + psize); } else { g_assert_not_reached(); } @@ -838,6 +841,7 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp) if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_CONT_PAGES)) { s->icvq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output); + s->dcvq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output); } reset_stats(s); diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-balloon.h index 6a2514d..848a7fb 100644 --- a/include/hw/virtio/virtio-balloon.h +++ b/include/hw/virtio/virtio-balloon.h @@ -42,7 +42,7 @@ enum virtio_balloon_free_page_report_status { typedef struct VirtIOBalloon { VirtIODevice parent_obj; - VirtQueue *ivq, *dvq, *svq, *free_page_vq, *icvq; + VirtQueue *ivq, *dvq, *svq, *free_page_vq, *icvq, *dcvq; uint32_t free_page_report_status; uint32_t num_pages; uint32_t actual; -- 2.7.4