2 * SPDX-License-Identifier: BSD-3-Clause
4 * This header is BSD licensed so anyone can use the definitions to implement
5 * compatible drivers/servers.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of IBM nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * $FreeBSD: head/sys/dev/virtio/balloon/virtio_balloon.h 326022 2017-11-20 19:36:21Z pfg $
33 * Copyright (c) 2018 The DragonFly Project. All rights reserved.
35 * This code is derived from software contributed to The DragonFly Project
36 * by Diederik de Groot <info@talon.nl>
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
48 * 3. Neither the name of The DragonFly Project nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific, prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
55 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
56 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
57 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
58 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
59 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
60 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
61 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
62 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 /* Driver for VirtIO memory balloon devices. */
68 #ifndef _VIRTIO_BALLOON_H
69 #define _VIRTIO_BALLOON_H
72 #define VIRTIO_BALLOON_F_MUST_TELL_HOST 0x1 /* Tell before reclaiming pages */
73 #define VIRTIO_BALLOON_F_STATS_VQ 0x2 /* Memory stats virtqueue */
74 #define VIRTIO_BALLOON_F_DEFLATE_ON_OOM 0x3 /* Deflate on Out Of Memory */
76 /* Size of a PFN in the balloon interface. */
77 #define VIRTIO_BALLOON_PFN_SHIFT 12
79 struct virtio_balloon_config {
80 /* Number of pages host wants Guest to give up. */
83 /* Number of pages we've actually got in balloon. */
87 #define VTBALLOON_S_SWAP_IN 0 /* The amount of memory that has been swapped in (in bytes) */
88 #define VTBALLOON_S_SWAP_OUT 1 /* The amount of memory that has been swapped out to disk (in bytes). */
89 #define VTBALLOON_S_MAJFLT 2 /* The number of major page faults that have occurred. */
90 #define VTBALLOON_S_MINFLT 3 /* The number of minor page faults that have occurred. */
91 #define VTBALLOON_S_MEMFREE 4 /* The amount of memory not being used for any purpose (in bytes). */
92 #define VTBALLOON_S_MEMTOT 5 /* The total amount of memory available (in bytes). */
93 #define VTBALLOON_S_AVAIL 6 /* The amount of availabe memory (in bytes) as in linux-proc */
94 #define VTBALLOON_S_CACHES 7 /* Disk-File caches */
95 #define VTBALLOON_S_HTLB_PGALLOC 8 /* Hugetlb page allocations */
96 #define VTBALLOON_S_HTLB_PGFAIL 9 /* Hugetlb page allocation failures */
97 #define VTBALLOON_S_NR 10
99 #define VTBALLOON_S_NAMES_WITH_PREFIX(VTBALLOON_S_NAMES_prefix) { \
100 VTBALLOON_S_NAMES_prefix "swap-in", \
101 VTBALLOON_S_NAMES_prefix "swap-out", \
102 VTBALLOON_S_NAMES_prefix "major-faults", \
103 VTBALLOON_S_NAMES_prefix "minor-faults", \
104 VTBALLOON_S_NAMES_prefix "free-memory", \
105 VTBALLOON_S_NAMES_prefix "total-memory", \
106 VTBALLOON_S_NAMES_prefix "available-memory", \
107 VTBALLOON_S_NAMES_prefix "disk-file-caches", \
108 VTBALLOON_S_NAMES_prefix "hugetlb-allocations", \
109 VTBALLOON_S_NAMES_prefix "hugetlb-failures" \
111 #define VTBALLOON_S_NAMES VTBALLOON_S_NAMES_WITH_PREFIX("")
114 * Memory statistics structure.
115 * Driver fills an array of these structures and passes to device.
117 * NOTE: fields are laid out in a way that would make compiler add padding
118 * between and after fields, but the virtio specification does not allow
119 * for this. So the struct has to be packed.
121 struct vtballoon_stat {
126 #endif /* _VIRTIO_BALLOON_H */