xen/balloon: only hotplug additional memory if required
[deliverable/linux.git] / drivers / xen / balloon.c
CommitLineData
1775826c 1/******************************************************************************
1775826c
JF
2 * Xen balloon driver - enables returning/claiming memory to/from Xen.
3 *
4 * Copyright (c) 2003, B Dragovic
5 * Copyright (c) 2003-2004, M Williamson, K Fraser
6 * Copyright (c) 2005 Dan M. Smith, IBM Corporation
080e2be7
DK
7 * Copyright (c) 2010 Daniel Kiper
8 *
9 * Memory hotplug support was written by Daniel Kiper. Work on
10 * it was sponsored by Google under Google Summer of Code 2010
11 * program. Jeremy Fitzhardinge from Citrix was the mentor for
12 * this project.
1775826c
JF
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License version 2
16 * as published by the Free Software Foundation; or, when distributed
17 * separately from the Linux kernel or incorporated into other
18 * software packages, subject to the following license:
19 *
20 * Permission is hereby granted, free of charge, to any person obtaining a copy
21 * of this source file (the "Software"), to deal in the Software without
22 * restriction, including without limitation the rights to use, copy, modify,
23 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
24 * and to permit persons to whom the Software is furnished to do so, subject to
25 * the following conditions:
26 *
27 * The above copyright notice and this permission notice shall be included in
28 * all copies or substantial portions of the Software.
29 *
30 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
35 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
36 * IN THE SOFTWARE.
37 */
38
283c0972
JP
39#define pr_fmt(fmt) "xen:" KBUILD_MODNAME ": " fmt
40
cd9151e2 41#include <linux/cpu.h>
1775826c 42#include <linux/kernel.h>
1775826c
JF
43#include <linux/sched.h>
44#include <linux/errno.h>
72ee5112 45#include <linux/module.h>
1775826c
JF
46#include <linux/mm.h>
47#include <linux/bootmem.h>
48#include <linux/pagemap.h>
49#include <linux/highmem.h>
50#include <linux/mutex.h>
1775826c 51#include <linux/list.h>
5a0e3ad6 52#include <linux/gfp.h>
080e2be7
DK
53#include <linux/notifier.h>
54#include <linux/memory.h>
55#include <linux/memory_hotplug.h>
cd9151e2 56#include <linux/percpu-defs.h>
55b3da98 57#include <linux/slab.h>
1775826c 58
1775826c
JF
59#include <asm/page.h>
60#include <asm/pgalloc.h>
61#include <asm/pgtable.h>
1775826c
JF
62#include <asm/tlb.h>
63
ecbf29cd
JF
64#include <asm/xen/hypervisor.h>
65#include <asm/xen/hypercall.h>
1ccbf534
JF
66
67#include <xen/xen.h>
ecbf29cd 68#include <xen/interface/xen.h>
1775826c 69#include <xen/interface/memory.h>
803eb047 70#include <xen/balloon.h>
1775826c
JF
71#include <xen/features.h>
72#include <xen/page.h>
73
95d2ac4a
DK
74/*
75 * balloon_process() state:
76 *
77 * BP_DONE: done or nothing to do,
b2ac6aa8 78 * BP_WAIT: wait to be rescheduled,
95d2ac4a
DK
79 * BP_EAGAIN: error, go to sleep,
80 * BP_ECANCELED: error, balloon operation canceled.
81 */
1775826c 82
95d2ac4a
DK
83enum bp_state {
84 BP_DONE,
b2ac6aa8 85 BP_WAIT,
95d2ac4a
DK
86 BP_EAGAIN,
87 BP_ECANCELED
1775826c
JF
88};
89
1775826c 90
1775826c 91static DEFINE_MUTEX(balloon_mutex);
1775826c 92
803eb047
DDG
93struct balloon_stats balloon_stats;
94EXPORT_SYMBOL_GPL(balloon_stats);
1775826c
JF
95
96/* We increase/decrease in batches which fit in a page */
965c0aaa 97static xen_pfn_t frame_list[PAGE_SIZE / sizeof(unsigned long)];
cd9151e2 98
1775826c 99
1775826c
JF
100/* List of ballooned pages, threaded through the mem_map array. */
101static LIST_HEAD(ballooned_pages);
102
103/* Main work function, always executed in process context. */
104static void balloon_process(struct work_struct *work);
95170b2e 105static DECLARE_DELAYED_WORK(balloon_worker, balloon_process);
1775826c
JF
106
107/* When ballooning out (allocating memory to return to Xen) we don't really
108 want the kernel to try too hard since that can trigger the oom killer. */
109#define GFP_BALLOON \
110 (GFP_HIGHUSER | __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC)
111
112static void scrub_page(struct page *page)
113{
114#ifdef CONFIG_XEN_SCRUB_PAGES
26a3e991 115 clear_highpage(page);
1775826c
JF
116#endif
117}
118
119/* balloon_append: add the given page to the balloon. */
9be4d457 120static void __balloon_append(struct page *page)
1775826c
JF
121{
122 /* Lowmem is re-populated first, so highmem pages go at list tail. */
123 if (PageHighMem(page)) {
124 list_add_tail(&page->lru, &ballooned_pages);
125 balloon_stats.balloon_high++;
1775826c
JF
126 } else {
127 list_add(&page->lru, &ballooned_pages);
128 balloon_stats.balloon_low++;
129 }
9be4d457 130}
3d65c948 131
9be4d457
JF
132static void balloon_append(struct page *page)
133{
134 __balloon_append(page);
3dcc0571 135 adjust_managed_page_count(page, -1);
1775826c
JF
136}
137
138/* balloon_retrieve: rescue a page from the balloon, if it is not empty. */
b6f30679 139static struct page *balloon_retrieve(bool prefer_highmem)
1775826c
JF
140{
141 struct page *page;
142
143 if (list_empty(&ballooned_pages))
144 return NULL;
145
b6f30679
KRW
146 if (prefer_highmem)
147 page = list_entry(ballooned_pages.prev, struct page, lru);
148 else
149 page = list_entry(ballooned_pages.next, struct page, lru);
1775826c
JF
150 list_del(&page->lru);
151
3dcc0571 152 if (PageHighMem(page))
1775826c 153 balloon_stats.balloon_high--;
3dcc0571 154 else
1775826c
JF
155 balloon_stats.balloon_low--;
156
3dcc0571 157 adjust_managed_page_count(page, 1);
3d65c948 158
1775826c
JF
159 return page;
160}
161
1775826c
JF
162static struct page *balloon_next_page(struct page *page)
163{
164 struct list_head *next = page->lru.next;
165 if (next == &ballooned_pages)
166 return NULL;
167 return list_entry(next, struct page, lru);
168}
169
95d2ac4a 170static enum bp_state update_schedule(enum bp_state state)
1775826c 171{
b2ac6aa8
DV
172 if (state == BP_WAIT)
173 return BP_WAIT;
174
fd8b7951
BO
175 if (state == BP_ECANCELED)
176 return BP_ECANCELED;
177
95d2ac4a
DK
178 if (state == BP_DONE) {
179 balloon_stats.schedule_delay = 1;
180 balloon_stats.retry_count = 1;
181 return BP_DONE;
182 }
183
95d2ac4a
DK
184 ++balloon_stats.retry_count;
185
186 if (balloon_stats.max_retry_count != RETRY_UNLIMITED &&
187 balloon_stats.retry_count > balloon_stats.max_retry_count) {
95d2ac4a
DK
188 balloon_stats.schedule_delay = 1;
189 balloon_stats.retry_count = 1;
190 return BP_ECANCELED;
191 }
192
193 balloon_stats.schedule_delay <<= 1;
194
195 if (balloon_stats.schedule_delay > balloon_stats.max_schedule_delay)
196 balloon_stats.schedule_delay = balloon_stats.max_schedule_delay;
197
198 return BP_EAGAIN;
1775826c
JF
199}
200
080e2be7 201#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG
55b3da98
DV
202static struct resource *additional_memory_resource(phys_addr_t size)
203{
204 struct resource *res;
205 int ret;
206
207 res = kzalloc(sizeof(*res), GFP_KERNEL);
208 if (!res)
209 return NULL;
210
211 res->name = "System RAM";
212 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
213
214 ret = allocate_resource(&iomem_resource, res,
215 size, 0, -1,
216 PAGES_PER_SECTION * PAGE_SIZE, NULL, NULL);
217 if (ret < 0) {
218 pr_err("Cannot allocate new System RAM resource\n");
219 kfree(res);
220 return NULL;
221 }
222
223 return res;
224}
225
226static void release_memory_resource(struct resource *resource)
227{
228 if (!resource)
229 return;
230
231 /*
232 * No need to reset region to identity mapped since we now
233 * know that no I/O can be in this region
234 */
235 release_resource(resource);
236 kfree(resource);
237}
080e2be7 238
b2ac6aa8 239static enum bp_state reserve_additional_memory(void)
080e2be7 240{
b2ac6aa8 241 long credit;
55b3da98 242 struct resource *resource;
080e2be7 243 int nid, rc;
55b3da98 244 unsigned long balloon_hotplug;
080e2be7 245
b2ac6aa8
DV
246 credit = balloon_stats.target_pages - balloon_stats.total_pages;
247
248 /*
249 * Already hotplugged enough pages? Wait for them to be
250 * onlined.
251 */
252 if (credit <= 0)
253 return BP_WAIT;
254
55b3da98
DV
255 balloon_hotplug = round_up(credit, PAGES_PER_SECTION);
256
257 resource = additional_memory_resource(balloon_hotplug * PAGE_SIZE);
258 if (!resource)
259 goto err;
260
261 nid = memory_add_physaddr_to_nid(resource->start);
080e2be7 262
3c56b3a1
JG
263#ifdef CONFIG_XEN_HAVE_PVMMU
264 /*
265 * add_memory() will build page tables for the new memory so
266 * the p2m must contain invalid entries so the correct
267 * non-present PTEs will be written.
268 *
269 * If a failure occurs, the original (identity) p2m entries
270 * are not restored since this region is now known not to
271 * conflict with any devices.
272 */
273 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
274 unsigned long pfn, i;
275
55b3da98 276 pfn = PFN_DOWN(resource->start);
3c56b3a1
JG
277 for (i = 0; i < balloon_hotplug; i++) {
278 if (!set_phys_to_machine(pfn + i, INVALID_P2M_ENTRY)) {
279 pr_warn("set_phys_to_machine() failed, no memory added\n");
55b3da98 280 goto err;
3c56b3a1
JG
281 }
282 }
283 }
284#endif
285
55b3da98 286 rc = add_memory_resource(nid, resource);
080e2be7 287 if (rc) {
3dcf6367 288 pr_warn("Cannot add additional memory (%i)\n", rc);
55b3da98 289 goto err;
080e2be7
DK
290 }
291
de5a77d8 292 balloon_stats.total_pages += balloon_hotplug;
080e2be7 293
b2ac6aa8 294 return BP_WAIT;
55b3da98
DV
295 err:
296 release_memory_resource(resource);
297 return BP_ECANCELED;
080e2be7
DK
298}
299
300static void xen_online_page(struct page *page)
301{
302 __online_page_set_limits(page);
303
304 mutex_lock(&balloon_mutex);
305
306 __balloon_append(page);
307
080e2be7
DK
308 mutex_unlock(&balloon_mutex);
309}
310
311static int xen_memory_notifier(struct notifier_block *nb, unsigned long val, void *v)
312{
313 if (val == MEM_ONLINE)
314 schedule_delayed_work(&balloon_worker, 0);
315
316 return NOTIFY_OK;
317}
318
319static struct notifier_block xen_memory_nb = {
320 .notifier_call = xen_memory_notifier,
321 .priority = 0
322};
323#else
b2ac6aa8 324static enum bp_state reserve_additional_memory(void)
1775826c 325{
de5a77d8
DV
326 balloon_stats.target_pages = balloon_stats.current_pages;
327 return BP_DONE;
1775826c 328}
de5a77d8 329#endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */
1775826c 330
de5a77d8 331static long current_credit(void)
080e2be7 332{
de5a77d8 333 return balloon_stats.target_pages - balloon_stats.current_pages;
080e2be7
DK
334}
335
de5a77d8 336static bool balloon_is_inflated(void)
080e2be7 337{
de5a77d8 338 return balloon_stats.balloon_low || balloon_stats.balloon_high;
080e2be7 339}
080e2be7 340
95d2ac4a 341static enum bp_state increase_reservation(unsigned long nr_pages)
1775826c 342{
95d2ac4a 343 int rc;
2f70e0ac 344 unsigned long pfn, i;
1775826c 345 struct page *page;
1775826c
JF
346 struct xen_memory_reservation reservation = {
347 .address_bits = 0,
348 .extent_order = 0,
349 .domid = DOMID_SELF
350 };
351
352 if (nr_pages > ARRAY_SIZE(frame_list))
353 nr_pages = ARRAY_SIZE(frame_list);
354
9346c2a8 355 page = list_first_entry_or_null(&ballooned_pages, struct page, lru);
1775826c 356 for (i = 0; i < nr_pages; i++) {
95d2ac4a
DK
357 if (!page) {
358 nr_pages = i;
359 break;
360 }
a419aef8 361 frame_list[i] = page_to_pfn(page);
1775826c
JF
362 page = balloon_next_page(page);
363 }
364
a90971eb 365 set_xen_guest_handle(reservation.extent_start, frame_list);
fde28e8f
JF
366 reservation.nr_extents = nr_pages;
367 rc = HYPERVISOR_memory_op(XENMEM_populate_physmap, &reservation);
40095de1 368 if (rc <= 0)
95d2ac4a 369 return BP_EAGAIN;
1775826c 370
bc2c0303 371 for (i = 0; i < rc; i++) {
b6f30679 372 page = balloon_retrieve(false);
1775826c
JF
373 BUG_ON(page == NULL);
374
375 pfn = page_to_pfn(page);
1775826c 376
c2374bf5 377#ifdef CONFIG_XEN_HAVE_PVMMU
c1d15f5c
SS
378 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
379 set_phys_to_machine(pfn, frame_list[i]);
380
381 /* Link back into the page tables if not highmem. */
382 if (!PageHighMem(page)) {
383 int ret;
384 ret = HYPERVISOR_update_va_mapping(
385 (unsigned long)__va(pfn << PAGE_SHIFT),
386 mfn_pte(frame_list[i], PAGE_KERNEL),
387 0);
388 BUG_ON(ret);
389 }
1775826c 390 }
c2374bf5 391#endif
1775826c
JF
392
393 /* Relinquish the page back to the allocator. */
3dcc0571 394 __free_reserved_page(page);
1775826c
JF
395 }
396
bc2c0303 397 balloon_stats.current_pages += rc;
1775826c 398
95d2ac4a 399 return BP_DONE;
1775826c
JF
400}
401
b6f30679 402static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
1775826c 403{
95d2ac4a 404 enum bp_state state = BP_DONE;
2f70e0ac 405 unsigned long pfn, i;
1775826c 406 struct page *page;
1775826c
JF
407 int ret;
408 struct xen_memory_reservation reservation = {
409 .address_bits = 0,
410 .extent_order = 0,
411 .domid = DOMID_SELF
412 };
413
414 if (nr_pages > ARRAY_SIZE(frame_list))
415 nr_pages = ARRAY_SIZE(frame_list);
416
417 for (i = 0; i < nr_pages; i++) {
fce92683
LN
418 page = alloc_page(gfp);
419 if (page == NULL) {
1775826c 420 nr_pages = i;
95d2ac4a 421 state = BP_EAGAIN;
1775826c
JF
422 break;
423 }
09ed3d5b 424 scrub_page(page);
1775826c 425
09ed3d5b
WL
426 frame_list[i] = page_to_pfn(page);
427 }
1775826c 428
09ed3d5b
WL
429 /*
430 * Ensure that ballooned highmem pages don't have kmaps.
431 *
432 * Do this before changing the p2m as kmap_flush_unused()
433 * reads PTEs to obtain pages (and hence needs the original
434 * p2m entry).
435 */
436 kmap_flush_unused();
437
438 /* Update direct mapping, invalidate P2M, and add to balloon. */
439 for (i = 0; i < nr_pages; i++) {
440 pfn = frame_list[i];
0df4f266 441 frame_list[i] = pfn_to_gfn(pfn);
09ed3d5b 442 page = pfn_to_page(pfn);
1058a75f 443
c1d15f5c 444#ifdef CONFIG_XEN_HAVE_PVMMU
04660bb5 445 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
c1d15f5c
SS
446 if (!PageHighMem(page)) {
447 ret = HYPERVISOR_update_va_mapping(
448 (unsigned long)__va(pfn << PAGE_SHIFT),
0bb599fd 449 __pte_ma(0), 0);
c1d15f5c 450 BUG_ON(ret);
fb9a0c44
DV
451 }
452 __set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
04660bb5 453 }
c1d15f5c 454#endif
24f69373 455
09ed3d5b 456 balloon_append(page);
1775826c
JF
457 }
458
24f69373 459 flush_tlb_all();
2bad07ce 460
a90971eb 461 set_xen_guest_handle(reservation.extent_start, frame_list);
1775826c
JF
462 reservation.nr_extents = nr_pages;
463 ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
464 BUG_ON(ret != nr_pages);
465
466 balloon_stats.current_pages -= nr_pages;
1775826c 467
95d2ac4a 468 return state;
1775826c
JF
469}
470
471/*
929423fa 472 * As this is a work item it is guaranteed to run as a single instance only.
1775826c
JF
473 * We may of course race updates of the target counts (which are protected
474 * by the balloon lock), or with changes to the Xen hard limit, but we will
475 * recover from these in time.
476 */
477static void balloon_process(struct work_struct *work)
478{
95d2ac4a 479 enum bp_state state = BP_DONE;
1775826c
JF
480 long credit;
481
1775826c
JF
482
483 do {
929423fa
JG
484 mutex_lock(&balloon_mutex);
485
83be7e52 486 credit = current_credit();
95d2ac4a 487
080e2be7
DK
488 if (credit > 0) {
489 if (balloon_is_inflated())
490 state = increase_reservation(credit);
491 else
b2ac6aa8 492 state = reserve_additional_memory();
080e2be7 493 }
95d2ac4a 494
1775826c 495 if (credit < 0)
b6f30679 496 state = decrease_reservation(-credit, GFP_BALLOON);
95d2ac4a
DK
497
498 state = update_schedule(state);
1775826c 499
929423fa
JG
500 mutex_unlock(&balloon_mutex);
501
502 cond_resched();
503
95d2ac4a 504 } while (credit && state == BP_DONE);
1775826c
JF
505
506 /* Schedule more work if there is some still to be done. */
95d2ac4a
DK
507 if (state == BP_EAGAIN)
508 schedule_delayed_work(&balloon_worker, balloon_stats.schedule_delay * HZ);
1775826c
JF
509}
510
511/* Resets the Xen limit, sets new target, and kicks off processing. */
803eb047 512void balloon_set_new_target(unsigned long target)
1775826c
JF
513{
514 /* No need for lock. Not read-modify-write updates. */
1775826c 515 balloon_stats.target_pages = target;
95170b2e 516 schedule_delayed_work(&balloon_worker, 0);
1775826c 517}
803eb047 518EXPORT_SYMBOL_GPL(balloon_set_new_target);
1775826c 519
b6f30679
KRW
520/**
521 * alloc_xenballooned_pages - get pages that have been ballooned out
522 * @nr_pages: Number of pages to get
523 * @pages: pages returned
72e9cf2a 524 * @highmem: allow highmem pages
b6f30679
KRW
525 * @return 0 on success, error otherwise
526 */
693394b8 527int alloc_xenballooned_pages(int nr_pages, struct page **pages, bool highmem)
1775826c 528{
b6f30679 529 int pgno = 0;
e882dc9c 530 struct page *page;
b6f30679
KRW
531 mutex_lock(&balloon_mutex);
532 while (pgno < nr_pages) {
693394b8 533 page = balloon_retrieve(highmem);
72e9cf2a 534 if (page && (highmem || !PageHighMem(page))) {
b6f30679
KRW
535 pages[pgno++] = page;
536 } else {
537 enum bp_state st;
693394b8
SS
538 if (page)
539 balloon_append(page);
540 st = decrease_reservation(nr_pages - pgno,
541 highmem ? GFP_HIGHUSER : GFP_USER);
b6f30679
KRW
542 if (st != BP_DONE)
543 goto out_undo;
544 }
1775826c 545 }
b6f30679
KRW
546 mutex_unlock(&balloon_mutex);
547 return 0;
548 out_undo:
549 while (pgno)
550 balloon_append(pages[--pgno]);
551 /* Free the memory back to the kernel soon */
552 schedule_delayed_work(&balloon_worker, 0);
553 mutex_unlock(&balloon_mutex);
554 return -ENOMEM;
1775826c 555}
b6f30679 556EXPORT_SYMBOL(alloc_xenballooned_pages);
1775826c 557
b6f30679
KRW
558/**
559 * free_xenballooned_pages - return pages retrieved with get_ballooned_pages
560 * @nr_pages: Number of pages
561 * @pages: pages to return
562 */
e882dc9c 563void free_xenballooned_pages(int nr_pages, struct page **pages)
1775826c 564{
b6f30679 565 int i;
1775826c 566
b6f30679 567 mutex_lock(&balloon_mutex);
1775826c 568
b6f30679
KRW
569 for (i = 0; i < nr_pages; i++) {
570 if (pages[i])
571 balloon_append(pages[i]);
572 }
573
574 /* The balloon may be too large now. Shrink it if needed. */
83be7e52 575 if (current_credit())
b6f30679 576 schedule_delayed_work(&balloon_worker, 0);
1775826c 577
b6f30679
KRW
578 mutex_unlock(&balloon_mutex);
579}
580EXPORT_SYMBOL(free_xenballooned_pages);
1775826c 581
8b5d44a5
DV
582static void __init balloon_add_region(unsigned long start_pfn,
583 unsigned long pages)
1775826c 584{
4dfe22f5 585 unsigned long pfn, extra_pfn_end;
1775826c
JF
586 struct page *page;
587
8b5d44a5
DV
588 /*
589 * If the amount of usable memory has been limited (e.g., with
590 * the 'mem' command line parameter), don't add pages beyond
591 * this limit.
592 */
593 extra_pfn_end = min(max_pfn, start_pfn + pages);
594
595 for (pfn = start_pfn; pfn < extra_pfn_end; pfn++) {
596 page = pfn_to_page(pfn);
597 /* totalram_pages and totalhigh_pages do not
598 include the boot-time balloon extension, so
599 don't subtract from it. */
600 __balloon_append(page);
601 }
de5a77d8
DV
602
603 balloon_stats.total_pages += extra_pfn_end - start_pfn;
8b5d44a5
DV
604}
605
606static int __init balloon_init(void)
607{
0bb599fd 608 int i;
8b5d44a5 609
53d5522c 610 if (!xen_domain())
1775826c
JF
611 return -ENODEV;
612
283c0972 613 pr_info("Initialising balloon driver\n");
1775826c 614
aa24411b
DV
615 balloon_stats.current_pages = xen_pv_domain()
616 ? min(xen_start_info->nr_pages - xen_released_pages, max_pfn)
c275a57f 617 : get_num_physpages();
1775826c
JF
618 balloon_stats.target_pages = balloon_stats.current_pages;
619 balloon_stats.balloon_low = 0;
620 balloon_stats.balloon_high = 0;
de5a77d8 621 balloon_stats.total_pages = balloon_stats.current_pages;
1775826c 622
95d2ac4a
DK
623 balloon_stats.schedule_delay = 1;
624 balloon_stats.max_schedule_delay = 32;
625 balloon_stats.retry_count = 1;
40095de1 626 balloon_stats.max_retry_count = RETRY_UNLIMITED;
1775826c 627
080e2be7 628#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG
080e2be7
DK
629 set_online_page_callback(&xen_online_page);
630 register_memory_notifier(&xen_memory_nb);
631#endif
632
2a4c92fa 633 /*
b1cbf9b1 634 * Initialize the balloon with pages from the extra memory
8b5d44a5 635 * regions (see arch/x86/xen/setup.c).
2a4c92fa 636 */
8b5d44a5 637 for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++)
626d7508
JG
638 if (xen_extra_mem[i].n_pfns)
639 balloon_add_region(xen_extra_mem[i].start_pfn,
640 xen_extra_mem[i].n_pfns);
1775826c 641
1775826c
JF
642 return 0;
643}
644
645subsys_initcall(balloon_init);
646
1775826c 647MODULE_LICENSE("GPL");
This page took 0.404723 seconds and 5 git commands to generate.