Back to home page

OSCL-LXR

 
 

    


0001 #ifndef _LINUX_VIRTIO_BALLOON_H
0002 #define _LINUX_VIRTIO_BALLOON_H
0003 /* This header is BSD licensed so anyone can use the definitions to implement
0004  * compatible drivers/servers.
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  * 3. Neither the name of IBM nor the names of its contributors
0015  *    may be used to endorse or promote products derived from this software
0016  *    without specific prior written permission.
0017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
0018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0020  * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
0021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0027  * SUCH DAMAGE. */
0028 #include <linux/types.h>
0029 #include <linux/virtio_types.h>
0030 #include <linux/virtio_ids.h>
0031 #include <linux/virtio_config.h>
0032 
0033 /* The feature bitmap for virtio balloon */
0034 #define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */
0035 #define VIRTIO_BALLOON_F_STATS_VQ   1 /* Memory Stats virtqueue */
0036 #define VIRTIO_BALLOON_F_DEFLATE_ON_OOM 2 /* Deflate balloon on OOM */
0037 #define VIRTIO_BALLOON_F_FREE_PAGE_HINT 3 /* VQ to report free pages */
0038 #define VIRTIO_BALLOON_F_PAGE_POISON    4 /* Guest is using page poisoning */
0039 #define VIRTIO_BALLOON_F_REPORTING  5 /* Page reporting virtqueue */
0040 
0041 /* Size of a PFN in the balloon interface. */
0042 #define VIRTIO_BALLOON_PFN_SHIFT 12
0043 
0044 #define VIRTIO_BALLOON_CMD_ID_STOP  0
0045 #define VIRTIO_BALLOON_CMD_ID_DONE  1
0046 struct virtio_balloon_config {
0047     /* Number of pages host wants Guest to give up. */
0048     __le32 num_pages;
0049     /* Number of pages we've actually got in balloon. */
0050     __le32 actual;
0051     /*
0052      * Free page hint command id, readonly by guest.
0053      * Was previously named free_page_report_cmd_id so we
0054      * need to carry that name for legacy support.
0055      */
0056     union {
0057         __le32 free_page_hint_cmd_id;
0058         __le32 free_page_report_cmd_id; /* deprecated */
0059     };
0060     /* Stores PAGE_POISON if page poisoning is in use */
0061     __le32 poison_val;
0062 };
0063 
0064 #define VIRTIO_BALLOON_S_SWAP_IN  0   /* Amount of memory swapped in */
0065 #define VIRTIO_BALLOON_S_SWAP_OUT 1   /* Amount of memory swapped out */
0066 #define VIRTIO_BALLOON_S_MAJFLT   2   /* Number of major faults */
0067 #define VIRTIO_BALLOON_S_MINFLT   3   /* Number of minor faults */
0068 #define VIRTIO_BALLOON_S_MEMFREE  4   /* Total amount of free memory */
0069 #define VIRTIO_BALLOON_S_MEMTOT   5   /* Total amount of memory */
0070 #define VIRTIO_BALLOON_S_AVAIL    6   /* Available memory as in /proc */
0071 #define VIRTIO_BALLOON_S_CACHES   7   /* Disk caches */
0072 #define VIRTIO_BALLOON_S_HTLB_PGALLOC  8  /* Hugetlb page allocations */
0073 #define VIRTIO_BALLOON_S_HTLB_PGFAIL   9  /* Hugetlb page allocation failures */
0074 #define VIRTIO_BALLOON_S_NR       10
0075 
0076 #define VIRTIO_BALLOON_S_NAMES_WITH_PREFIX(VIRTIO_BALLOON_S_NAMES_prefix) { \
0077     VIRTIO_BALLOON_S_NAMES_prefix "swap-in", \
0078     VIRTIO_BALLOON_S_NAMES_prefix "swap-out", \
0079     VIRTIO_BALLOON_S_NAMES_prefix "major-faults", \
0080     VIRTIO_BALLOON_S_NAMES_prefix "minor-faults", \
0081     VIRTIO_BALLOON_S_NAMES_prefix "free-memory", \
0082     VIRTIO_BALLOON_S_NAMES_prefix "total-memory", \
0083     VIRTIO_BALLOON_S_NAMES_prefix "available-memory", \
0084     VIRTIO_BALLOON_S_NAMES_prefix "disk-caches", \
0085     VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-allocations", \
0086     VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-failures" \
0087 }
0088 
0089 #define VIRTIO_BALLOON_S_NAMES VIRTIO_BALLOON_S_NAMES_WITH_PREFIX("")
0090 
0091 /*
0092  * Memory statistics structure.
0093  * Driver fills an array of these structures and passes to device.
0094  *
0095  * NOTE: fields are laid out in a way that would make compiler add padding
0096  * between and after fields, so we have to use compiler-specific attributes to
0097  * pack it, to disable this padding. This also often causes compiler to
0098  * generate suboptimal code.
0099  *
0100  * We maintain this statistics structure format for backwards compatibility,
0101  * but don't follow this example.
0102  *
0103  * If implementing a similar structure, do something like the below instead:
0104  *     struct virtio_balloon_stat {
0105  *         __virtio16 tag;
0106  *         __u8 reserved[6];
0107  *         __virtio64 val;
0108  *     };
0109  *
0110  * In other words, add explicit reserved fields to align field and
0111  * structure boundaries at field size, avoiding compiler padding
0112  * without the packed attribute.
0113  */
0114 struct virtio_balloon_stat {
0115     __virtio16 tag;
0116     __virtio64 val;
0117 } __attribute__((packed));
0118 
0119 #endif /* _LINUX_VIRTIO_BALLOON_H */