From nobody Sat Nov 15 13:39:30 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1594867516; cv=none; d=zohomail.com; s=zohoarc; b=nve5T5m6CSu9nbBBYwjT+WvZzq2X4vnlv8yTVbH7Ysi8TWHzuscpz4vtU3mf768oIvTgOheQ1BemoAzgVvK9I0PA8jQs+1+ZuwOjewgvIU4epu2NWmknhmUqyNXS5DgWNe4zK+TcinfFhdAP/XJur/jcVB7x32eG5Q+PUF3unMc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594867516; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=4uUfyzIHX5F8nhg7nCi52MdMV93XJEtQEkOKCnq7iuQ=; b=aq9l9mMfJRWRKk7UxTWgdtRgHG5izeUM6EanvrWDNJOxtWpOirVaCmS1e1rbkcCRY/Po82MUVLE2M4h9N3TZYeLiCA4Smt4Gp1Gj6QE6BoOqikdwqMVEq062u0oEYET+iVDJBjFYfNfD/X62E0t4pYw/2IJEM1Q+JeGyJylcBqQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594867516721870.0119889394088; Wed, 15 Jul 2020 19:45:16 -0700 (PDT) Received: from localhost ([::1]:48368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jvttb-0001Lp-Ic for importer@patchew.org; Wed, 15 Jul 2020 22:45:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jvtrE-0005cH-HI for qemu-devel@nongnu.org; Wed, 15 Jul 2020 22:42:48 -0400 Received: from out4436.biz.mail.alibaba.com ([47.88.44.36]:26625) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jvtrC-00043n-PW for qemu-devel@nongnu.org; Wed, 15 Jul 2020 22:42:48 -0400 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 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; 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 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> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=47.88.44.36; envelope-from=teawaterz@linux.alibaba.com; helo=out4436.biz.mail.alibaba.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/15 22:42:26 X-ACL-Warn: Detected OS = Linux 3.1-3.10 X-Spam_score_int: -71 X-Spam_score: -7.2 X-Spam_bar: ------- X-Spam_report: (-7.2 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, NML_ADSP_CUSTOM_MED=0.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_SPF_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hui Zhu , Hui Zhu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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, } =20 static void balloon_deflate_page(VirtIOBalloon *balloon, - MemoryRegion *mr, hwaddr mr_offset) + MemoryRegion *mr, hwaddr mr_offset, + size_t size) { void *addr =3D memory_region_get_ram_ptr(mr) + mr_offset; ram_addr_t rb_offset; @@ -153,10 +154,11 @@ static void balloon_deflate_page(VirtIOBalloon *ballo= on, rb_page_size =3D qemu_ram_pagesize(rb); =20 host_addr =3D (void *)((uintptr_t)addr & ~(rb_page_size - 1)); + size &=3D ~(rb_page_size - 1); =20 /* When a page is deflated, we hint the whole host page it lives * on, since we can't do anything smaller */ - ret =3D qemu_madvise(host_addr, rb_page_size, QEMU_MADV_WILLNEED); + ret =3D qemu_madvise(host_addr, size, QEMU_MADV_WILLNEED); if (ret !=3D 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 =3D (hwaddr) p << VIRTIO_BALLOON_PFN_SHIFT; offset +=3D 4; =20 - if (vq =3D=3D s->icvq) { + if (vq =3D=3D s->icvq || vq =3D=3D s->dcvq) { uint32_t psize_ptr; if (iov_to_buf(elem->out_sg, elem->out_num, offset, &psize= _ptr, 4) !=3D 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 =3D=3D s->dvq) { - balloon_deflate_page(s, section.mr, section.offset_wit= hin_region); + } else if (vq =3D=3D s->dvq || vq =3D=3D s->dcvq) { + balloon_deflate_page(s, section.mr, section.offset_wit= hin_region, + psize); } else { g_assert_not_reached(); } @@ -838,6 +841,7 @@ static void virtio_balloon_device_realize(DeviceState *= dev, Error **errp) =20 if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_CONT_PAGES))= { s->icvq =3D virtio_add_queue(vdev, 128, virtio_balloon_handle_outp= ut); + s->dcvq =3D virtio_add_queue(vdev, 128, virtio_balloon_handle_outp= ut); } =20 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 { =20 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; --=20 2.7.4