ia64/linux-2.6.18-xen.hg

view drivers/md/dm-zero.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
line source
1 /*
2 * Copyright (C) 2003 Christophe Saout <christophe@saout.de>
3 *
4 * This file is released under the GPL.
5 */
7 #include "dm.h"
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/bio.h>
13 #define DM_MSG_PREFIX "zero"
15 /*
16 * Construct a dummy mapping that only returns zeros
17 */
18 static int zero_ctr(struct dm_target *ti, unsigned int argc, char **argv)
19 {
20 if (argc != 0) {
21 ti->error = "No arguments required";
22 return -EINVAL;
23 }
25 return 0;
26 }
28 /*
29 * Return zeros only on reads
30 */
31 static int zero_map(struct dm_target *ti, struct bio *bio,
32 union map_info *map_context)
33 {
34 switch(bio_rw(bio)) {
35 case READ:
36 zero_fill_bio(bio);
37 break;
38 case READA:
39 /* readahead of null bytes only wastes buffer cache */
40 return -EIO;
41 case WRITE:
42 /* writes get silently dropped */
43 break;
44 }
46 bio_endio(bio, bio->bi_size, 0);
48 /* accepted bio, don't make new request */
49 return 0;
50 }
52 static struct target_type zero_target = {
53 .name = "zero",
54 .version = {1, 0, 0},
55 .module = THIS_MODULE,
56 .ctr = zero_ctr,
57 .map = zero_map,
58 };
60 static int __init dm_zero_init(void)
61 {
62 int r = dm_register_target(&zero_target);
64 if (r < 0)
65 DMERR("register failed %d", r);
67 return r;
68 }
70 static void __exit dm_zero_exit(void)
71 {
72 int r = dm_unregister_target(&zero_target);
74 if (r < 0)
75 DMERR("unregister failed %d", r);
76 }
78 module_init(dm_zero_init)
79 module_exit(dm_zero_exit)
81 MODULE_AUTHOR("Christophe Saout <christophe@saout.de>");
82 MODULE_DESCRIPTION(DM_NAME " dummy target returning zeros");
83 MODULE_LICENSE("GPL");