ia64/linux-2.6.18-xen.hg

annotate drivers/atm/adummy.c @ 897:329ea0ccb344

balloon: try harder to balloon up under memory pressure.

Currently if the balloon driver is unable to increase the guest's
reservation it assumes the failure was due to reaching its full
allocation, gives up on the ballooning operation and records the limit
it reached as the "hard limit". The driver will not try again until
the target is set again (even to the same value).

However it is possible that ballooning has in fact failed due to
memory pressure in the host and therefore it is desirable to keep
attempting to reach the target in case memory becomes available. The
most likely scenario is that some guests are ballooning down while
others are ballooning up and therefore there is temporary memory
pressure while things stabilise. You would not expect a well behaved
toolstack to ask a domain to balloon to more than its allocation nor
would you expect it to deliberately over-commit memory by setting
balloon targets which exceed the total host memory.

This patch drops the concept of a hard limit and causes the balloon
driver to retry increasing the reservation on a timer in the same
manner as when decreasing the reservation.

Also if we partially succeed in increasing the reservation
(i.e. receive less pages than we asked for) then we may as well keep
those pages rather than returning them to Xen.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jun 05 14:01:20 2009 +0100 (2009-06-05)
parents 831230e53067
children
rev   line source
ian@0 1 /*
ian@0 2 * adummy.c: a dummy ATM driver
ian@0 3 */
ian@0 4
ian@0 5 #include <linux/module.h>
ian@0 6 #include <linux/version.h>
ian@0 7 #include <linux/kernel.h>
ian@0 8 #include <linux/skbuff.h>
ian@0 9 #include <linux/pci.h>
ian@0 10 #include <linux/errno.h>
ian@0 11 #include <linux/types.h>
ian@0 12 #include <linux/string.h>
ian@0 13 #include <linux/delay.h>
ian@0 14 #include <linux/init.h>
ian@0 15 #include <linux/mm.h>
ian@0 16 #include <linux/sched.h>
ian@0 17 #include <linux/timer.h>
ian@0 18 #include <linux/interrupt.h>
ian@0 19 #include <asm/io.h>
ian@0 20 #include <asm/byteorder.h>
ian@0 21 #include <asm/uaccess.h>
ian@0 22
ian@0 23 #include <linux/atmdev.h>
ian@0 24 #include <linux/atm.h>
ian@0 25 #include <linux/sonet.h>
ian@0 26
ian@0 27 /* version definition */
ian@0 28
ian@0 29 #define DRV_VERSION "1.0"
ian@0 30
ian@0 31 #define DEV_LABEL "adummy"
ian@0 32
ian@0 33 #define ADUMMY_DEV(dev) ((struct adummy_dev *) (dev)->dev_data)
ian@0 34
ian@0 35 struct adummy_dev {
ian@0 36 struct atm_dev *atm_dev;
ian@0 37
ian@0 38 struct list_head entry;
ian@0 39 };
ian@0 40
ian@0 41 /* globals */
ian@0 42
ian@0 43 static LIST_HEAD(adummy_devs);
ian@0 44
ian@0 45 static int __init
ian@0 46 adummy_start(struct atm_dev *dev)
ian@0 47 {
ian@0 48 dev->ci_range.vpi_bits = 4;
ian@0 49 dev->ci_range.vci_bits = 12;
ian@0 50
ian@0 51 return 0;
ian@0 52 }
ian@0 53
ian@0 54 static int
ian@0 55 adummy_open(struct atm_vcc *vcc)
ian@0 56 {
ian@0 57 short vpi = vcc->vpi;
ian@0 58 int vci = vcc->vci;
ian@0 59
ian@0 60 if (vci == ATM_VCI_UNSPEC || vpi == ATM_VPI_UNSPEC)
ian@0 61 return 0;
ian@0 62
ian@0 63 set_bit(ATM_VF_ADDR, &vcc->flags);
ian@0 64 set_bit(ATM_VF_READY, &vcc->flags);
ian@0 65
ian@0 66 return 0;
ian@0 67 }
ian@0 68
ian@0 69 static void
ian@0 70 adummy_close(struct atm_vcc *vcc)
ian@0 71 {
ian@0 72 clear_bit(ATM_VF_READY, &vcc->flags);
ian@0 73 clear_bit(ATM_VF_ADDR, &vcc->flags);
ian@0 74 }
ian@0 75
ian@0 76 static int
ian@0 77 adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
ian@0 78 {
ian@0 79 if (vcc->pop)
ian@0 80 vcc->pop(vcc, skb);
ian@0 81 else
ian@0 82 dev_kfree_skb_any(skb);
ian@0 83 atomic_inc(&vcc->stats->tx);
ian@0 84
ian@0 85 return 0;
ian@0 86 }
ian@0 87
ian@0 88 static int
ian@0 89 adummy_proc_read(struct atm_dev *dev, loff_t *pos, char *page)
ian@0 90 {
ian@0 91 int left = *pos;
ian@0 92
ian@0 93 if (!left--)
ian@0 94 return sprintf(page, "version %s\n", DRV_VERSION);
ian@0 95
ian@0 96 return 0;
ian@0 97 }
ian@0 98
ian@0 99 static struct atmdev_ops adummy_ops =
ian@0 100 {
ian@0 101 .open = adummy_open,
ian@0 102 .close = adummy_close,
ian@0 103 .send = adummy_send,
ian@0 104 .proc_read = adummy_proc_read,
ian@0 105 .owner = THIS_MODULE
ian@0 106 };
ian@0 107
ian@0 108 static int __init adummy_init(void)
ian@0 109 {
ian@0 110 struct atm_dev *atm_dev;
ian@0 111 struct adummy_dev *adummy_dev;
ian@0 112 int err = 0;
ian@0 113
ian@0 114 printk(KERN_ERR "adummy: version %s\n", DRV_VERSION);
ian@0 115
ian@0 116 adummy_dev = (struct adummy_dev *) kmalloc(sizeof(struct adummy_dev),
ian@0 117 GFP_KERNEL);
ian@0 118 if (!adummy_dev) {
ian@0 119 printk(KERN_ERR DEV_LABEL ": kmalloc() failed\n");
ian@0 120 err = -ENOMEM;
ian@0 121 goto out;
ian@0 122 }
ian@0 123 memset(adummy_dev, 0, sizeof(struct adummy_dev));
ian@0 124
ian@0 125 atm_dev = atm_dev_register(DEV_LABEL, &adummy_ops, -1, NULL);
ian@0 126 if (!atm_dev) {
ian@0 127 printk(KERN_ERR DEV_LABEL ": atm_dev_register() failed\n");
ian@0 128 err = -ENODEV;
ian@0 129 goto out_kfree;
ian@0 130 }
ian@0 131
ian@0 132 adummy_dev->atm_dev = atm_dev;
ian@0 133 atm_dev->dev_data = adummy_dev;
ian@0 134
ian@0 135 if (adummy_start(atm_dev)) {
ian@0 136 printk(KERN_ERR DEV_LABEL ": adummy_start() failed\n");
ian@0 137 err = -ENODEV;
ian@0 138 goto out_unregister;
ian@0 139 }
ian@0 140
ian@0 141 list_add(&adummy_dev->entry, &adummy_devs);
ian@0 142 out:
ian@0 143 return err;
ian@0 144
ian@0 145 out_unregister:
ian@0 146 atm_dev_deregister(atm_dev);
ian@0 147 out_kfree:
ian@0 148 kfree(adummy_dev);
ian@0 149 goto out;
ian@0 150 }
ian@0 151
ian@0 152 static void __exit adummy_cleanup(void)
ian@0 153 {
ian@0 154 struct adummy_dev *adummy_dev, *next;
ian@0 155
ian@0 156 list_for_each_entry_safe(adummy_dev, next, &adummy_devs, entry) {
ian@0 157 atm_dev_deregister(adummy_dev->atm_dev);
ian@0 158 kfree(adummy_dev);
ian@0 159 }
ian@0 160 }
ian@0 161
ian@0 162 module_init(adummy_init);
ian@0 163 module_exit(adummy_cleanup);
ian@0 164
ian@0 165 MODULE_AUTHOR("chas williams <chas@cmf.nrl.navy.mil>");
ian@0 166 MODULE_DESCRIPTION("dummy ATM driver");
ian@0 167 MODULE_LICENSE("GPL");