22 #include <linux/virtio.h>
28 #include <linux/slab.h>
29 #include <linux/module.h>
36 #define VIRTIO_BALLOON_PAGES_PER_PAGE (PAGE_SIZE >> VIRTIO_BALLOON_PFN_SHIFT)
84 static struct page *balloon_pfn_to_page(
u32 pfn)
90 static void balloon_ack(
struct virtqueue *vq)
113 static void set_page_pfns(
u32 pfns[],
struct page *
page)
120 pfns[i] = page_to_balloon_pfn(page) +
i;
129 vb->
num_pfns += VIRTIO_BALLOON_PAGES_PER_PAGE) {
133 if (printk_ratelimit())
135 "Out of puff! Can't get %zu pages\n",
154 static void release_pages_by_pfn(
const u32 pfns[],
unsigned int num)
173 vb->
num_pfns += VIRTIO_BALLOON_PAGES_PER_PAGE) {
197 #define pages_to_bytes(x) ((u64)(x) << PAGE_SHIFT)
205 all_vm_events(events);
228 static void stats_request(
struct virtqueue *vq)
243 update_balloon_stats(vb);
279 &actual,
sizeof(actual));
282 static int balloon(
void *_vballoon)
292 (diff = towards_target(vb)) != 0
297 stats_handle_request(vb);
299 fill_balloon(vb, diff);
301 leak_balloon(vb, -diff);
302 update_balloon_size(vb);
310 vq_callback_t *callbacks[] = { balloon_ack, balloon_ack, stats_request };
311 const char *names[] = {
"inflate",
"deflate",
"stats" };
319 err = vb->
vdev->config->find_vqs(vb->
vdev, nvqs, vqs, callbacks, names);
353 INIT_LIST_HEAD(&vb->
pages);
366 err = PTR_ERR(vb->
thread);
373 vdev->
config->del_vqs(vdev);
385 update_balloon_size(vb);
390 vb->
vdev->config->del_vqs(vb->
vdev);
421 ret = init_vqs(vdev->
priv);
425 fill_balloon(vb, towards_target(vb));
426 update_balloon_size(vb);
439 .driver.name = KBUILD_MODNAME,
442 .probe = virtballoon_probe,
444 .config_changed = virtballoon_changed,
446 .freeze = virtballoon_freeze,
447 .restore = virtballoon_restore,
456 static void __exit fini(
void)