Re: PATCH: Virtio memory balooning
Hi, I'm not good at writing manuals, but here is man page bits for viomb(4): Index: Makefile === RCS file: /cvs/src/share/man/man4/Makefile,v retrieving revision 1.540 diff -u -r1.540 Makefile --- src/share/man/man4/Makefile 20 Sep 2012 15:11:44 - 1.540 +++ src/share/man/man4/Makefile 12 Nov 2012 06:38:51 - @@ -66,7 +66,7 @@ uthum.4 uticom.4 utwitch.4 utrh.4 uts.4 uvideo.4 uvisor.4 uvscom.4 \ uyap.4 \ vether.4 vga.4 vgafb.4 vge.4 \ - viapm.4 viasio.4 vic.4 video.4 vio.4 vioblk.4 virtio.4 vlan.4 \ + viapm.4 viasio.4 vic.4 video.4 vio.4 vioblk.4 viomb.4 virtio.4 vlan.4 \ vmt.4 vnd.4 vr.4 \ vscsi.4 vte.4 \ watchdog.4 wb.4 wbenv.4 wbng.4 wbsd.4 wbsio.4 wd.4 wdc.4 we.4 \ --- /dev/null Mon Nov 12 10:39:15 2012 +++ src/share/man/man4/viomb.4 Mon Nov 12 10:37:07 2012 @@ -0,0 +1,75 @@ +.\"$NetBSD: viomb.4,v 1.2 2011/11/26 22:36:14 wiz Exp $ +.\"$OpenBSD$ +.\" Copyright (c) 2012 Dinar Talypov +.\" Copyright (C) 2011 Minoura Makoto. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\"notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\"notice, this list of conditions and the following disclaimer in the +.\"documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd $Mdocdate$ +.Dt VIOMB 4 +.Os +.Sh NAME +.Nm viomb +.Nd VirtIO memory ballooning driver +.Sh SYNOPSIS +.Cd "virtio* at pci? dev ? function ?" +.Cd "viomb* at virtio?" +.Sh DESCRIPTION +The +.Nm +driver supports the virtio-compliant memory ballooning device. +.Pp +Memory ballooning works as follows: +.Pp +.Bl -enum -compact +.It +The host operator requests a guest to return some amount of memory to the host +(via e.g. Qemu monitor balloon command). +.It +The hypervisor sends the request via VirtIO memory ballooning device. +.It +The guest +.Nm +driver requests allocation of that amount of physical memory from the +.Ox +memory management system. +.It +The +.Nm +device tells the hypervisor the guest physical memory address of the +allocated memory via VirtIO memory ballooning device. +.El +.Pp +.Sh SEE ALSO +.Xr virtio 4 +.Pp +.Rs +.%A Rusty Russell, IBM Corporation +.%T Virtio PCI Card Specification +.%U http://ozlabs.org/~rusty/virtio-spec/ +.Re +.Sh HISTORY +The +.Nm +device driver appeared in +.Ox 5.3 .
Re: PATCH: Virtio memory balooning
Hi, Here is a updated version: - fixes panic when host requests more memory to deflate than guest has - some cleanup Index: files.pci === RCS file: /cvs/src/sys/dev/pci/files.pci,v retrieving revision 1.289 diff -u -r1.289 files.pci --- files.pci 29 Oct 2012 18:36:42 - 1.289 +++ files.pci 6 Nov 2012 10:34:22 - @@ -837,3 +837,7 @@ device vioblk: scsi attach vioblk at virtio file dev/pci/vioblk.cvioblk + +device viomb +attach viomb at virtio +file dev/pci/viomb.c viomb Index: GENERIC === RCS file: /cvs/src/sys/arch/i386/conf/GENERIC,v retrieving revision 1.741 diff -u -r1.741 GENERIC --- GENERIC 8 Oct 2012 17:26:02 - 1.741 +++ GENERIC 6 Nov 2012 10:36:25 - @@ -799,3 +799,4 @@ virtio*at pci? # Virtio PCI device vioblk*at virtio? # Virtio block device vio* at virtio? # Virtio network device +viomb* at virtio? # Virtio memory ballooning device --- /dev/null Thu Nov 8 11:03:03 2012 +++ sys/dev/pci/viomb.c Thu Nov 8 11:02:31 2012 @@ -0,0 +1,447 @@ +/* $OpenBSD$*/ +/* $NetBSD: viomb.c,v 1.1 2011/10/30 12:12:21 hannken Exp $ */ +/* + * Copyright (c) 2012 Dinar Talypov + * Copyright (c) 2010 Minoura Makoto. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#defineDEVNAME(sc) sc->sc_dev.dv_xname + +#if VIRTIO_DEBUG +#define VIOMBDEBUG(sc, format, args...)\ + do { printf("%s: " format, sc->sc_dev.dv_xname, ##args);} \ + while (0) +#else +#define VIOMBDEBUG(...) +#endif + +/* flags used to specify kind of operation, + * actually should be moved to virtiovar.h + */ +#define VRING_READ 0 +#define VRING_WRITE1 + +/* notify or don't notify */ +#define VRING_NO_NOTIFY0 +#define VRING_NOTIFY 1 + +/* Configuration registers */ +#define VIRTIO_BALLOON_CONFIG_NUM_PAGES0 /* 32bit */ +#define VIRTIO_BALLOON_CONFIG_ACTUAL 4 /* 32bit */ + +/* Feature bits */ +#define VIRTIO_BALLOON_F_MUST_TELL_HOST (1<<0) +#define VIRTIO_BALLOON_F_STATS_VQ (1<<1) + +static const struct virtio_feature_name viomb_feature_names[] = { + {VIRTIO_BALLOON_F_MUST_TELL_HOST, "TellHost"}, + {VIRTIO_BALLOON_F_STATS_VQ, "StatVQ"}, + {0, NULL} +}; +#define PGS_PER_REQ256 /* 1MB, 4KB/page */ +#define VQ_INFLATE 0 +#define VQ_DEFLATE 1 + +struct balloon_req { + bus_dmamap_tbl_dmamap; + struct pglist bl_pglist; + int bl_nentries; + uint32_tbl_pages[PGS_PER_REQ]; +}; + +struct viomb_softc { + struct device sc_dev; + struct virtio_softc *sc_virtio; + + struct virtqueuesc_vq[2]; + u_int32_t sc_npages; + u_int32_t sc_actual; + u_int32_t sc_balloon_size; + int sc_inflight; + struct balloon_req sc_req; + struct pglist sc_balloon_pages; + int sc_flags; +#define INFALTE_DONE 0x01 +#define DEFLATE_DONE 0x02 +}; + +int viomb_match(struct device *, void *, void *); +voidviomb_attach(struct device *, struct device *, void *); +int viomb_intr(void *); +voidviomb_inflate(void *, void *); +voidviomb_deflate(void *, void *); +int viomb_config_change(struct virtio_softc *); +
Re: PATCH: Virtio memory balooning
Ok, so I added the required line to amd64 GENERIC and ran a KVM guest with it, dmesg now says: virtio1 at pci0 dev 5 function 0 "Qumranet Virtio Memory" rev 0x00: Virtio Memory Balloon Device viomb0 at virtio1 virtio1: apic 1 int 10 Dont think I have enough shiny GUIs to monitor ballooning stats, but I'll see if I can dig something up on the host machine. 2012/11/7 Janne Johansson : > Any reason for this being i386 or just not tested on virtual amd64s? > > 2012/11/6 Dinar Talypov : >> Hi, >> This patch adds virtio memory ballooning device support. >> Actually code was taken from NetBSD and I rewrote some >> OpenBSD specific parts. >> > > > >> +static const struct virtio_feature_name viomb_feature_names[] = { >> + {VIRTIO_BALLOON_F_MUST_TELL_HOST, "TellHost"}, >> + {VIRTIO_BALLOON_F_STATS_VQ, "StatVQ"}, >> + {0, NULL} >> +}; >> +#define PGS_PER_REQ256 /* 1MB, 4KB/page */ > > ---cut-- > >> + >> +#define PGS_PER_REQ256 /* 1MB, 4KB/page */ >> + > > Small nit, but this appears twice. > > > -- > To our sweethearts and wives. May they never meet. -- 19th century toast -- To our sweethearts and wives. May they never meet. -- 19th century toast
Re: PATCH: Virtio memory balooning
Any reason for this being i386 or just not tested on virtual amd64s? 2012/11/6 Dinar Talypov : > Hi, > This patch adds virtio memory ballooning device support. > Actually code was taken from NetBSD and I rewrote some > OpenBSD specific parts. > > +static const struct virtio_feature_name viomb_feature_names[] = { > + {VIRTIO_BALLOON_F_MUST_TELL_HOST, "TellHost"}, > + {VIRTIO_BALLOON_F_STATS_VQ, "StatVQ"}, > + {0, NULL} > +}; > +#define PGS_PER_REQ256 /* 1MB, 4KB/page */ ---cut-- > + > +#define PGS_PER_REQ256 /* 1MB, 4KB/page */ > + Small nit, but this appears twice. -- To our sweethearts and wives. May they never meet. -- 19th century toast