From e8e4f37156b847cb79e81fcec2622e183a4e20e6 Mon Sep 17 00:00:00 2001 From: Juergen Gross Date: Tue, 19 Jul 2016 07:23:02 +0200 Subject: [PATCH] mini-os: get maximum memory size from hypervisor Add support for obtaining the maximum memory size from the hypervisor. This will make it possible to support ballooning. Signed-off-by: Juergen Gross Acked-by: Samuel Thibault --- balloon.c | 22 ++++++++++++++++++++++ include/balloon.h | 6 ++++++ mm.c | 2 ++ 3 files changed, 30 insertions(+) diff --git a/balloon.c b/balloon.c index f9cf23b..1ec113d 100644 --- a/balloon.c +++ b/balloon.c @@ -21,4 +21,26 @@ * DEALINGS IN THE SOFTWARE. */ +#include #include +#include +#include +#include + +unsigned long nr_max_pages; + +void get_max_pages(void) +{ + long ret; + domid_t domid = DOMID_SELF; + + ret = HYPERVISOR_memory_op(XENMEM_maximum_reservation, &domid); + if ( ret < 0 ) + { + printk("Could not get maximum pfn\n"); + return; + } + + nr_max_pages = ret; + printk("Maximum memory size: %ld pages\n", nr_max_pages); +} diff --git a/include/balloon.h b/include/balloon.h index 9756a3f..cd79017 100644 --- a/include/balloon.h +++ b/include/balloon.h @@ -26,7 +26,13 @@ #ifdef CONFIG_BALLOON +extern unsigned long nr_max_pages; + +void get_max_pages(void); + #else /* CONFIG_BALLOON */ +static inline void get_max_pages(void) { } + #endif /* CONFIG_BALLOON */ #endif /* _BALLOON_H_ */ diff --git a/mm.c b/mm.c index 8cf3210..6d82f2a 100644 --- a/mm.c +++ b/mm.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -361,6 +362,7 @@ void init_mm(void) printk("MM: Init\n"); + get_max_pages(); arch_init_mm(&start_pfn, &max_pfn); /* * now we can initialise the page allocator -- 2.39.5