balloon.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /******************************************************************************
  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
  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.
  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. #define pr_fmt(fmt) "xen:" KBUILD_MODNAME ": " fmt
  39. #include <linux/cpu.h>
  40. #include <linux/kernel.h>
  41. #include <linux/sched.h>
  42. #include <linux/errno.h>
  43. #include <linux/module.h>
  44. #include <linux/mm.h>
  45. #include <linux/bootmem.h>
  46. #include <linux/pagemap.h>
  47. #include <linux/highmem.h>
  48. #include <linux/mutex.h>
  49. #include <linux/list.h>
  50. #include <linux/gfp.h>
  51. #include <linux/notifier.h>
  52. #include <linux/memory.h>
  53. #include <linux/memory_hotplug.h>
  54. #include <linux/percpu-defs.h>
  55. #include <linux/slab.h>
  56. #include <linux/sysctl.h>
  57. #include <asm/page.h>
  58. #include <asm/pgalloc.h>
  59. #include <asm/pgtable.h>
  60. #include <asm/tlb.h>
  61. #include <asm/xen/hypervisor.h>
  62. #include <asm/xen/hypercall.h>
  63. #include <xen/xen.h>
  64. #include <xen/interface/xen.h>
  65. #include <xen/interface/memory.h>
  66. #include <xen/balloon.h>
  67. #include <xen/features.h>
  68. #include <xen/page.h>
  69. static int xen_hotplug_unpopulated;
  70. #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG
  71. static int zero;
  72. static int one = 1;
  73. static struct ctl_table balloon_table[] = {
  74. {
  75. .procname = "hotplug_unpopulated",
  76. .data = &xen_hotplug_unpopulated,
  77. .maxlen = sizeof(int),
  78. .mode = 0644,
  79. .proc_handler = proc_dointvec_minmax,
  80. .extra1 = &zero,
  81. .extra2 = &one,
  82. },
  83. { }
  84. };
  85. static struct ctl_table balloon_root[] = {
  86. {
  87. .procname = "balloon",
  88. .mode = 0555,
  89. .child = balloon_table,
  90. },
  91. { }
  92. };
  93. static struct ctl_table xen_root[] = {
  94. {
  95. .procname = "xen",
  96. .mode = 0555,
  97. .child = balloon_root,
  98. },
  99. { }
  100. };
  101. #endif
  102. /*
  103. * balloon_process() state:
  104. *
  105. * BP_DONE: done or nothing to do,
  106. * BP_WAIT: wait to be rescheduled,
  107. * BP_EAGAIN: error, go to sleep,
  108. * BP_ECANCELED: error, balloon operation canceled.
  109. */
  110. enum bp_state {
  111. BP_DONE,
  112. BP_WAIT,
  113. BP_EAGAIN,
  114. BP_ECANCELED
  115. };
  116. static DEFINE_MUTEX(balloon_mutex);
  117. struct balloon_stats balloon_stats;
  118. EXPORT_SYMBOL_GPL(balloon_stats);
  119. /* We increase/decrease in batches which fit in a page */
  120. static xen_pfn_t frame_list[PAGE_SIZE / sizeof(unsigned long)];
  121. /* List of ballooned pages, threaded through the mem_map array. */
  122. static LIST_HEAD(ballooned_pages);
  123. static DECLARE_WAIT_QUEUE_HEAD(balloon_wq);
  124. /* Main work function, always executed in process context. */
  125. static void balloon_process(struct work_struct *work);
  126. static DECLARE_DELAYED_WORK(balloon_worker, balloon_process);
  127. /* When ballooning out (allocating memory to return to Xen) we don't really
  128. want the kernel to try too hard since that can trigger the oom killer. */
  129. #define GFP_BALLOON \
  130. (GFP_HIGHUSER | __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC)
  131. static void scrub_page(struct page *page)
  132. {
  133. #ifdef CONFIG_XEN_SCRUB_PAGES
  134. clear_highpage(page);
  135. #endif
  136. }
  137. /* balloon_append: add the given page to the balloon. */
  138. static void __balloon_append(struct page *page)
  139. {
  140. /* Lowmem is re-populated first, so highmem pages go at list tail. */
  141. if (PageHighMem(page)) {
  142. list_add_tail(&page->lru, &ballooned_pages);
  143. balloon_stats.balloon_high++;
  144. } else {
  145. list_add(&page->lru, &ballooned_pages);
  146. balloon_stats.balloon_low++;
  147. }
  148. wake_up(&balloon_wq);
  149. }
  150. static void balloon_append(struct page *page)
  151. {
  152. __balloon_append(page);
  153. adjust_managed_page_count(page, -1);
  154. }
  155. /* balloon_retrieve: rescue a page from the balloon, if it is not empty. */
  156. static struct page *balloon_retrieve(bool require_lowmem)
  157. {
  158. struct page *page;
  159. if (list_empty(&ballooned_pages))
  160. return NULL;
  161. page = list_entry(ballooned_pages.next, struct page, lru);
  162. if (require_lowmem && PageHighMem(page))
  163. return NULL;
  164. list_del(&page->lru);
  165. if (PageHighMem(page))
  166. balloon_stats.balloon_high--;
  167. else
  168. balloon_stats.balloon_low--;
  169. adjust_managed_page_count(page, 1);
  170. return page;
  171. }
  172. static struct page *balloon_next_page(struct page *page)
  173. {
  174. struct list_head *next = page->lru.next;
  175. if (next == &ballooned_pages)
  176. return NULL;
  177. return list_entry(next, struct page, lru);
  178. }
  179. static enum bp_state update_schedule(enum bp_state state)
  180. {
  181. if (state == BP_WAIT)
  182. return BP_WAIT;
  183. if (state == BP_ECANCELED)
  184. return BP_ECANCELED;
  185. if (state == BP_DONE) {
  186. balloon_stats.schedule_delay = 1;
  187. balloon_stats.retry_count = 1;
  188. return BP_DONE;
  189. }
  190. ++balloon_stats.retry_count;
  191. if (balloon_stats.max_retry_count != RETRY_UNLIMITED &&
  192. balloon_stats.retry_count > balloon_stats.max_retry_count) {
  193. balloon_stats.schedule_delay = 1;
  194. balloon_stats.retry_count = 1;
  195. return BP_ECANCELED;
  196. }
  197. balloon_stats.schedule_delay <<= 1;
  198. if (balloon_stats.schedule_delay > balloon_stats.max_schedule_delay)
  199. balloon_stats.schedule_delay = balloon_stats.max_schedule_delay;
  200. return BP_EAGAIN;
  201. }
  202. #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG
  203. static struct resource *additional_memory_resource(phys_addr_t size)
  204. {
  205. struct resource *res;
  206. int ret;
  207. res = kzalloc(sizeof(*res), GFP_KERNEL);
  208. if (!res)
  209. return NULL;
  210. res->name = "System RAM";
  211. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  212. ret = allocate_resource(&iomem_resource, res,
  213. size, 0, -1,
  214. PAGES_PER_SECTION * PAGE_SIZE, NULL, NULL);
  215. if (ret < 0) {
  216. pr_err("Cannot allocate new System RAM resource\n");
  217. kfree(res);
  218. return NULL;
  219. }
  220. return res;
  221. }
  222. static void release_memory_resource(struct resource *resource)
  223. {
  224. if (!resource)
  225. return;
  226. /*
  227. * No need to reset region to identity mapped since we now
  228. * know that no I/O can be in this region
  229. */
  230. release_resource(resource);
  231. kfree(resource);
  232. }
  233. static enum bp_state reserve_additional_memory(void)
  234. {
  235. long credit;
  236. struct resource *resource;
  237. int nid, rc;
  238. unsigned long balloon_hotplug;
  239. credit = balloon_stats.target_pages + balloon_stats.target_unpopulated
  240. - balloon_stats.total_pages;
  241. /*
  242. * Already hotplugged enough pages? Wait for them to be
  243. * onlined.
  244. */
  245. if (credit <= 0)
  246. return BP_WAIT;
  247. balloon_hotplug = round_up(credit, PAGES_PER_SECTION);
  248. resource = additional_memory_resource(balloon_hotplug * PAGE_SIZE);
  249. if (!resource)
  250. goto err;
  251. nid = memory_add_physaddr_to_nid(resource->start);
  252. #ifdef CONFIG_XEN_HAVE_PVMMU
  253. /*
  254. * add_memory() will build page tables for the new memory so
  255. * the p2m must contain invalid entries so the correct
  256. * non-present PTEs will be written.
  257. *
  258. * If a failure occurs, the original (identity) p2m entries
  259. * are not restored since this region is now known not to
  260. * conflict with any devices.
  261. */
  262. if (!xen_feature(XENFEAT_auto_translated_physmap)) {
  263. unsigned long pfn, i;
  264. pfn = PFN_DOWN(resource->start);
  265. for (i = 0; i < balloon_hotplug; i++) {
  266. if (!set_phys_to_machine(pfn + i, INVALID_P2M_ENTRY)) {
  267. pr_warn("set_phys_to_machine() failed, no memory added\n");
  268. goto err;
  269. }
  270. }
  271. }
  272. #endif
  273. rc = add_memory_resource(nid, resource);
  274. if (rc) {
  275. pr_warn("Cannot add additional memory (%i)\n", rc);
  276. goto err;
  277. }
  278. balloon_stats.total_pages += balloon_hotplug;
  279. return BP_WAIT;
  280. err:
  281. release_memory_resource(resource);
  282. return BP_ECANCELED;
  283. }
  284. static void xen_online_page(struct page *page)
  285. {
  286. __online_page_set_limits(page);
  287. mutex_lock(&balloon_mutex);
  288. __balloon_append(page);
  289. mutex_unlock(&balloon_mutex);
  290. }
  291. static int xen_memory_notifier(struct notifier_block *nb, unsigned long val, void *v)
  292. {
  293. if (val == MEM_ONLINE)
  294. schedule_delayed_work(&balloon_worker, 0);
  295. return NOTIFY_OK;
  296. }
  297. static struct notifier_block xen_memory_nb = {
  298. .notifier_call = xen_memory_notifier,
  299. .priority = 0
  300. };
  301. #else
  302. static enum bp_state reserve_additional_memory(void)
  303. {
  304. balloon_stats.target_pages = balloon_stats.current_pages;
  305. return BP_ECANCELED;
  306. }
  307. #endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */
  308. static long current_credit(void)
  309. {
  310. return balloon_stats.target_pages - balloon_stats.current_pages;
  311. }
  312. static bool balloon_is_inflated(void)
  313. {
  314. return balloon_stats.balloon_low || balloon_stats.balloon_high;
  315. }
  316. static enum bp_state increase_reservation(unsigned long nr_pages)
  317. {
  318. int rc;
  319. unsigned long pfn, i;
  320. struct page *page;
  321. struct xen_memory_reservation reservation = {
  322. .address_bits = 0,
  323. .extent_order = 0,
  324. .domid = DOMID_SELF
  325. };
  326. if (nr_pages > ARRAY_SIZE(frame_list))
  327. nr_pages = ARRAY_SIZE(frame_list);
  328. page = list_first_entry_or_null(&ballooned_pages, struct page, lru);
  329. for (i = 0; i < nr_pages; i++) {
  330. if (!page) {
  331. nr_pages = i;
  332. break;
  333. }
  334. frame_list[i] = page_to_pfn(page);
  335. page = balloon_next_page(page);
  336. }
  337. set_xen_guest_handle(reservation.extent_start, frame_list);
  338. reservation.nr_extents = nr_pages;
  339. rc = HYPERVISOR_memory_op(XENMEM_populate_physmap, &reservation);
  340. if (rc <= 0)
  341. return BP_EAGAIN;
  342. for (i = 0; i < rc; i++) {
  343. page = balloon_retrieve(false);
  344. BUG_ON(page == NULL);
  345. pfn = page_to_pfn(page);
  346. #ifdef CONFIG_XEN_HAVE_PVMMU
  347. if (!xen_feature(XENFEAT_auto_translated_physmap)) {
  348. set_phys_to_machine(pfn, frame_list[i]);
  349. /* Link back into the page tables if not highmem. */
  350. if (!PageHighMem(page)) {
  351. int ret;
  352. ret = HYPERVISOR_update_va_mapping(
  353. (unsigned long)__va(pfn << PAGE_SHIFT),
  354. mfn_pte(frame_list[i], PAGE_KERNEL),
  355. 0);
  356. BUG_ON(ret);
  357. }
  358. }
  359. #endif
  360. /* Relinquish the page back to the allocator. */
  361. __free_reserved_page(page);
  362. }
  363. balloon_stats.current_pages += rc;
  364. return BP_DONE;
  365. }
  366. static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
  367. {
  368. enum bp_state state = BP_DONE;
  369. unsigned long pfn, i;
  370. struct page *page;
  371. int ret;
  372. struct xen_memory_reservation reservation = {
  373. .address_bits = 0,
  374. .extent_order = 0,
  375. .domid = DOMID_SELF
  376. };
  377. if (nr_pages > ARRAY_SIZE(frame_list))
  378. nr_pages = ARRAY_SIZE(frame_list);
  379. for (i = 0; i < nr_pages; i++) {
  380. page = alloc_page(gfp);
  381. if (page == NULL) {
  382. nr_pages = i;
  383. state = BP_EAGAIN;
  384. break;
  385. }
  386. scrub_page(page);
  387. frame_list[i] = page_to_pfn(page);
  388. }
  389. /*
  390. * Ensure that ballooned highmem pages don't have kmaps.
  391. *
  392. * Do this before changing the p2m as kmap_flush_unused()
  393. * reads PTEs to obtain pages (and hence needs the original
  394. * p2m entry).
  395. */
  396. kmap_flush_unused();
  397. /* Update direct mapping, invalidate P2M, and add to balloon. */
  398. for (i = 0; i < nr_pages; i++) {
  399. pfn = frame_list[i];
  400. frame_list[i] = pfn_to_gfn(pfn);
  401. page = pfn_to_page(pfn);
  402. #ifdef CONFIG_XEN_HAVE_PVMMU
  403. if (!xen_feature(XENFEAT_auto_translated_physmap)) {
  404. if (!PageHighMem(page)) {
  405. ret = HYPERVISOR_update_va_mapping(
  406. (unsigned long)__va(pfn << PAGE_SHIFT),
  407. __pte_ma(0), 0);
  408. BUG_ON(ret);
  409. }
  410. __set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
  411. }
  412. #endif
  413. balloon_append(page);
  414. }
  415. flush_tlb_all();
  416. set_xen_guest_handle(reservation.extent_start, frame_list);
  417. reservation.nr_extents = nr_pages;
  418. ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
  419. BUG_ON(ret != nr_pages);
  420. balloon_stats.current_pages -= nr_pages;
  421. return state;
  422. }
  423. /*
  424. * As this is a work item it is guaranteed to run as a single instance only.
  425. * We may of course race updates of the target counts (which are protected
  426. * by the balloon lock), or with changes to the Xen hard limit, but we will
  427. * recover from these in time.
  428. */
  429. static void balloon_process(struct work_struct *work)
  430. {
  431. enum bp_state state = BP_DONE;
  432. long credit;
  433. do {
  434. mutex_lock(&balloon_mutex);
  435. credit = current_credit();
  436. if (credit > 0) {
  437. if (balloon_is_inflated())
  438. state = increase_reservation(credit);
  439. else
  440. state = reserve_additional_memory();
  441. }
  442. if (credit < 0)
  443. state = decrease_reservation(-credit, GFP_BALLOON);
  444. state = update_schedule(state);
  445. mutex_unlock(&balloon_mutex);
  446. cond_resched();
  447. } while (credit && state == BP_DONE);
  448. /* Schedule more work if there is some still to be done. */
  449. if (state == BP_EAGAIN)
  450. schedule_delayed_work(&balloon_worker, balloon_stats.schedule_delay * HZ);
  451. }
  452. /* Resets the Xen limit, sets new target, and kicks off processing. */
  453. void balloon_set_new_target(unsigned long target)
  454. {
  455. /* No need for lock. Not read-modify-write updates. */
  456. balloon_stats.target_pages = target;
  457. schedule_delayed_work(&balloon_worker, 0);
  458. }
  459. EXPORT_SYMBOL_GPL(balloon_set_new_target);
  460. static int add_ballooned_pages(int nr_pages)
  461. {
  462. enum bp_state st;
  463. if (xen_hotplug_unpopulated) {
  464. st = reserve_additional_memory();
  465. if (st != BP_ECANCELED) {
  466. mutex_unlock(&balloon_mutex);
  467. wait_event(balloon_wq,
  468. !list_empty(&ballooned_pages));
  469. mutex_lock(&balloon_mutex);
  470. return 0;
  471. }
  472. }
  473. st = decrease_reservation(nr_pages, GFP_USER);
  474. if (st != BP_DONE)
  475. return -ENOMEM;
  476. return 0;
  477. }
  478. /**
  479. * alloc_xenballooned_pages - get pages that have been ballooned out
  480. * @nr_pages: Number of pages to get
  481. * @pages: pages returned
  482. * @return 0 on success, error otherwise
  483. */
  484. int alloc_xenballooned_pages(int nr_pages, struct page **pages)
  485. {
  486. int pgno = 0;
  487. struct page *page;
  488. int ret;
  489. mutex_lock(&balloon_mutex);
  490. balloon_stats.target_unpopulated += nr_pages;
  491. while (pgno < nr_pages) {
  492. page = balloon_retrieve(true);
  493. if (page) {
  494. pages[pgno++] = page;
  495. #ifdef CONFIG_XEN_HAVE_PVMMU
  496. ret = xen_alloc_p2m_entry(page_to_pfn(page));
  497. if (ret < 0)
  498. goto out_undo;
  499. #endif
  500. } else {
  501. ret = add_ballooned_pages(nr_pages - pgno);
  502. if (ret < 0)
  503. goto out_undo;
  504. }
  505. }
  506. mutex_unlock(&balloon_mutex);
  507. return 0;
  508. out_undo:
  509. mutex_unlock(&balloon_mutex);
  510. free_xenballooned_pages(pgno, pages);
  511. return ret;
  512. }
  513. EXPORT_SYMBOL(alloc_xenballooned_pages);
  514. /**
  515. * free_xenballooned_pages - return pages retrieved with get_ballooned_pages
  516. * @nr_pages: Number of pages
  517. * @pages: pages to return
  518. */
  519. void free_xenballooned_pages(int nr_pages, struct page **pages)
  520. {
  521. int i;
  522. mutex_lock(&balloon_mutex);
  523. for (i = 0; i < nr_pages; i++) {
  524. if (pages[i])
  525. balloon_append(pages[i]);
  526. }
  527. balloon_stats.target_unpopulated -= nr_pages;
  528. /* The balloon may be too large now. Shrink it if needed. */
  529. if (current_credit())
  530. schedule_delayed_work(&balloon_worker, 0);
  531. mutex_unlock(&balloon_mutex);
  532. }
  533. EXPORT_SYMBOL(free_xenballooned_pages);
  534. static void __init balloon_add_region(unsigned long start_pfn,
  535. unsigned long pages)
  536. {
  537. unsigned long pfn, extra_pfn_end;
  538. struct page *page;
  539. /*
  540. * If the amount of usable memory has been limited (e.g., with
  541. * the 'mem' command line parameter), don't add pages beyond
  542. * this limit.
  543. */
  544. extra_pfn_end = min(max_pfn, start_pfn + pages);
  545. for (pfn = start_pfn; pfn < extra_pfn_end; pfn++) {
  546. page = pfn_to_page(pfn);
  547. /* totalram_pages and totalhigh_pages do not
  548. include the boot-time balloon extension, so
  549. don't subtract from it. */
  550. __balloon_append(page);
  551. }
  552. balloon_stats.total_pages += extra_pfn_end - start_pfn;
  553. }
  554. static int __init balloon_init(void)
  555. {
  556. int i;
  557. if (!xen_domain())
  558. return -ENODEV;
  559. pr_info("Initialising balloon driver\n");
  560. balloon_stats.current_pages = xen_pv_domain()
  561. ? min(xen_start_info->nr_pages - xen_released_pages, max_pfn)
  562. : get_num_physpages();
  563. balloon_stats.target_pages = balloon_stats.current_pages;
  564. balloon_stats.balloon_low = 0;
  565. balloon_stats.balloon_high = 0;
  566. balloon_stats.total_pages = balloon_stats.current_pages;
  567. balloon_stats.schedule_delay = 1;
  568. balloon_stats.max_schedule_delay = 32;
  569. balloon_stats.retry_count = 1;
  570. balloon_stats.max_retry_count = RETRY_UNLIMITED;
  571. #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG
  572. set_online_page_callback(&xen_online_page);
  573. register_memory_notifier(&xen_memory_nb);
  574. register_sysctl_table(xen_root);
  575. #endif
  576. /*
  577. * Initialize the balloon with pages from the extra memory
  578. * regions (see arch/x86/xen/setup.c).
  579. */
  580. for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++)
  581. if (xen_extra_mem[i].n_pfns)
  582. balloon_add_region(xen_extra_mem[i].start_pfn,
  583. xen_extra_mem[i].n_pfns);
  584. return 0;
  585. }
  586. subsys_initcall(balloon_init);
  587. MODULE_LICENSE("GPL");