Skip to contentSkip to conversation

xen-hvm: increase maxmem before calling xc_domain_populate_physmap

PATCH In review Don Slutz 2 participants 7 messages Dec 3, 2014 – Jan 14, 2015

lore
Share & tools
lore

Don Slutz

author
#0 lore raw

PATCH v2 1/1 xen-hvm: increase maxmem before calling xc_domain_populate_physmap

From: Stefano Stabellini <[email protected]>

Increase maxmem before calling xc_domain_populate_physmap_exact to avoid the risk of running out of guest memory. This way we can also avoid complex memory calculations in libxl at domain construction time.

This patch fixes an abort() when assigning more than 4 NICs to a VM.

---
v2: Changes by Don Slutz
Switch from xc_domain_getinfo to xc_domain_getinfolist Fix error check for xc_domain_getinfolist Limit increase of maxmem to only do when needed:
Add QEMU_SPARE_PAGES (How many pages to leave free) Add free_pages calculation

 xen-hvm.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
xen-hvm.c +19 -0
index 7548794..d30e77e 100644
@@ -90,6 +90,7 @@ static inline ioreq_t *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vcpu)
 #endif
 
 #define BUFFER_IO_MAX_DELAY  100
+#define QEMU_SPARE_PAGES 16
 
 typedef struct XenPhysmap {
     hwaddr start_addr;
@@ -244,6 +245,8 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr)
     unsigned long nr_pfn;
     xen_pfn_t *pfn_list;
     int i;
+    xc_domaininfo_t info;
+    unsigned long free_pages;
 
     if (runstate_check(RUN_STATE_INMIGRATE)) {
         /* RAM already populated in Xen */
@@ -266,6 +269,22 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr)
         pfn_list[i] = (ram_addr >> TARGET_PAGE_BITS) + i;
     }
 
+    if ((xc_domain_getinfolist(xen_xc, xen_domid, 1, &info) != 1) ||
+        (info.domain != xen_domid)) {
+        hw_error("xc_domain_getinfolist failed");
+    }
+    free_pages = info.max_pages - info.tot_pages;
+    if (free_pages > QEMU_SPARE_PAGES) {
+        free_pages -= QEMU_SPARE_PAGES;
+    } else {
+        free_pages = 0;
+    }
+    if ((free_pages < nr_pfn) &&
+        (xc_domain_setmaxmem(xen_xc, xen_domid,
+                             ((info.max_pages + nr_pfn - free_pages)
+                              << (XC_PAGE_SHIFT - 10))) < 0)) {
+        hw_error("xc_domain_setmaxmem failed");
+    }
     if (xc_domain_populate_physmap_exact(xen_xc, xen_domid, nr_pfn, 0, 0, pfn_list)) {
         hw_error("xen: failed to populate ram at " RAM_ADDR_FMT, ram_addr);
     }
Signature · 1 line
1.8.4
author
#1 lore raw

Ping.

Quoted 66 lines · Don Slutz

From: Stefano Stabellini <[email protected]>

Increase maxmem before calling xc_domain_populate_physmap_exact to avoid the risk of running out of guest memory. This way we can also avoid complex memory calculations in libxl at domain construction time.

This patch fixes an abort() when assigning more than 4 NICs to a VM.

---
v2: Changes by Don Slutz
Switch from xc_domain_getinfo to xc_domain_getinfolist Fix error check for xc_domain_getinfolist Limit increase of maxmem to only do when needed:
Add QEMU_SPARE_PAGES (How many pages to leave free) Add free_pages calculation

  xen-hvm.c | 19 +++++++++++++++++++
  1 file changed, 19 insertions(+)
xen-hvm.c +19 -0
index 7548794..d30e77e 100644
@@ -90,6 +90,7 @@ static inline ioreq_t *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vcpu)
  #endif
 
  #define BUFFER_IO_MAX_DELAY  100
+#define QEMU_SPARE_PAGES 16
 
  typedef struct XenPhysmap {
      hwaddr start_addr;
@@ -244,6 +245,8 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr)
      unsigned long nr_pfn;
      xen_pfn_t *pfn_list;
      int i;
+    xc_domaininfo_t info;
+    unsigned long free_pages;
 
      if (runstate_check(RUN_STATE_INMIGRATE)) {
          /* RAM already populated in Xen */
@@ -266,6 +269,22 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr)
          pfn_list[i] = (ram_addr >> TARGET_PAGE_BITS) + i;
      }
 
+    if ((xc_domain_getinfolist(xen_xc, xen_domid, 1, &info) != 1) ||
+        (info.domain != xen_domid)) {
+        hw_error("xc_domain_getinfolist failed");
+    }
+    free_pages = info.max_pages - info.tot_pages;
+    if (free_pages > QEMU_SPARE_PAGES) {
+        free_pages -= QEMU_SPARE_PAGES;
+    } else {
+        free_pages = 0;
+    }
+    if ((free_pages < nr_pfn) &&
+        (xc_domain_setmaxmem(xen_xc, xen_domid,
+                             ((info.max_pages + nr_pfn - free_pages)
+                              << (XC_PAGE_SHIFT - 10))) < 0)) {
+        hw_error("xc_domain_setmaxmem failed");
+    }
      if (xc_domain_populate_physmap_exact(xen_xc, xen_domid, nr_pfn, 0, 0, pfn_list)) {
          hw_error("xen: failed to populate ram at " RAM_ADDR_FMT, ram_addr);
      }
author
#2 lore raw

Ping

Quoted 71 lines · Don Slutz

Ping.

Quoted 67 lines · Don Slutz

From: Stefano Stabellini <[email protected]>

Increase maxmem before calling xc_domain_populate_physmap_exact to avoid the risk of running out of guest memory. This way we can also avoid complex memory calculations in libxl at domain construction time.

This patch fixes an abort() when assigning more than 4 NICs to a VM.

---
v2: Changes by Don Slutz
Switch from xc_domain_getinfo to xc_domain_getinfolist Fix error check for xc_domain_getinfolist Limit increase of maxmem to only do when needed:
Add QEMU_SPARE_PAGES (How many pages to leave free) Add free_pages calculation

  xen-hvm.c | 19 +++++++++++++++++++
  1 file changed, 19 insertions(+)
xen-hvm.c +18 -0
index 7548794..d30e77e 100644
@@ -90,6 +90,7 @@ static inline ioreq_t
 *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vcpu)
  #endif
    #define BUFFER_IO_MAX_DELAY  100
+#define QEMU_SPARE_PAGES 16
    typedef struct XenPhysmap {
      hwaddr start_addr;
@@ -244,6 +245,8 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t
 size, MemoryRegion *mr)
      unsigned long nr_pfn;
      xen_pfn_t *pfn_list;
      int i;
+    xc_domaininfo_t info;
+    unsigned long free_pages;
        if (runstate_check(RUN_STATE_INMIGRATE)) {
          /* RAM already populated in Xen */
@@ -266,6 +269,22 @@ void xen_ram_alloc(ram_addr_t ram_addr,
 ram_addr_t size, MemoryRegion *mr)
          pfn_list[i] = (ram_addr >> TARGET_PAGE_BITS) + i;
      }
  +    if ((xc_domain_getinfolist(xen_xc, xen_domid, 1, &info) != 1) ||
+        (info.domain != xen_domid)) {
+        hw_error("xc_domain_getinfolist failed");
+    }
+    free_pages = info.max_pages - info.tot_pages;
+    if (free_pages > QEMU_SPARE_PAGES) {
+        free_pages -= QEMU_SPARE_PAGES;
+    } else {
+        free_pages = 0;
+    }
+    if ((free_pages < nr_pfn) &&
+        (xc_domain_setmaxmem(xen_xc, xen_domid,
+                             ((info.max_pages + nr_pfn - free_pages)
+                              << (XC_PAGE_SHIFT - 10))) < 0)) {
+        hw_error("xc_domain_setmaxmem failed");
+    }
      if (xc_domain_populate_physmap_exact(xen_xc, xen_domid, nr_pfn,
 0, 0, pfn_list)) {
          hw_error("xen: failed to populate ram at " RAM_ADDR_FMT,
ram_addr);
      }
#3 lore raw
In reply to Don Slutz
Quoted 27 lines · Don Slutz

From: Stefano Stabellini <[email protected]>

Increase maxmem before calling xc_domain_populate_physmap_exact to avoid the risk of running out of guest memory. This way we can also avoid complex memory calculations in libxl at domain construction time.

This patch fixes an abort() when assigning more than 4 NICs to a VM.

---
v2: Changes by Don Slutz
Switch from xc_domain_getinfo to xc_domain_getinfolist Fix error check for xc_domain_getinfolist Limit increase of maxmem to only do when needed:
Add QEMU_SPARE_PAGES (How many pages to leave free) Add free_pages calculation

 xen-hvm.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
xen-hvm.c +0 -0
index 7548794..d30e77e 100644

xen-hvm.c static inline ioreq_t *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vcpu) · line 93

Quoted 4 lines
xen-hvm.c +1 -0
@@ -90,6 +90,7 @@ static inline ioreq_t *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vcpu)
 #endif
 
 #define BUFFER_IO_MAX_DELAY  100
+#define QEMU_SPARE_PAGES 16

We need a big comment here to explain why we have this parameter and when we'll be able to get rid of it.

Other than that the patch is fine.

Thanks!

Quoted 37 lines
xen-hvm.c +18 -0
 typedef struct XenPhysmap {
     hwaddr start_addr;
@@ -244,6 +245,8 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr)
     unsigned long nr_pfn;
     xen_pfn_t *pfn_list;
     int i;
+    xc_domaininfo_t info;
+    unsigned long free_pages;
 
     if (runstate_check(RUN_STATE_INMIGRATE)) {
         /* RAM already populated in Xen */
@@ -266,6 +269,22 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr)
         pfn_list[i] = (ram_addr >> TARGET_PAGE_BITS) + i;
     }
 
+    if ((xc_domain_getinfolist(xen_xc, xen_domid, 1, &info) != 1) ||
+        (info.domain != xen_domid)) {
+        hw_error("xc_domain_getinfolist failed");
+    }
+    free_pages = info.max_pages - info.tot_pages;
+    if (free_pages > QEMU_SPARE_PAGES) {
+        free_pages -= QEMU_SPARE_PAGES;
+    } else {
+        free_pages = 0;
+    }
+    if ((free_pages < nr_pfn) &&
+        (xc_domain_setmaxmem(xen_xc, xen_domid,
+                             ((info.max_pages + nr_pfn - free_pages)
+                              << (XC_PAGE_SHIFT - 10))) < 0)) {
+        hw_error("xc_domain_setmaxmem failed");
+    }
     if (xc_domain_populate_physmap_exact(xen_xc, xen_domid, nr_pfn, 0, 0, pfn_list)) {
         hw_error("xen: failed to populate ram at " RAM_ADDR_FMT, ram_addr);
     }
Signature · 1 line
1.8.4
#4 lore raw
Quoted 36 lines · Stefano Stabellini
Quoted 27 lines · Don Slutz

From: Stefano Stabellini <[email protected]>

Increase maxmem before calling xc_domain_populate_physmap_exact to avoid the risk of running out of guest memory. This way we can also avoid complex memory calculations in libxl at domain construction time.

This patch fixes an abort() when assigning more than 4 NICs to a VM.

---
v2: Changes by Don Slutz
Switch from xc_domain_getinfo to xc_domain_getinfolist Fix error check for xc_domain_getinfolist Limit increase of maxmem to only do when needed:
Add QEMU_SPARE_PAGES (How many pages to leave free) Add free_pages calculation

 xen-hvm.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
xen-hvm.c +0 -0
index 7548794..d30e77e 100644

xen-hvm.c static inline ioreq_t *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vcpu) · line 93

Quoted 4 lines
xen-hvm.c +1 -0
@@ -90,6 +90,7 @@ static inline ioreq_t *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vcpu)
 #endif
 
 #define BUFFER_IO_MAX_DELAY  100
+#define QEMU_SPARE_PAGES 16

We need a big comment here to explain why we have this parameter and when we'll be able to get rid of it.

Quoted 4 lines

Other than that the patch is fine.

Thanks!

Actually I'll just go ahead and add the comment and commit, if for you is OK.

Cheers,

Stefano

author
#5 lore raw
Quoted 37 lines · Stefano Stabellini
Quoted 36 lines · Stefano Stabellini
Quoted 27 lines · Don Slutz

From: Stefano Stabellini <[email protected]>

Increase maxmem before calling xc_domain_populate_physmap_exact to avoid the risk of running out of guest memory. This way we can also avoid complex memory calculations in libxl at domain construction time.

This patch fixes an abort() when assigning more than 4 NICs to a VM.

---
v2: Changes by Don Slutz
Switch from xc_domain_getinfo to xc_domain_getinfolist Fix error check for xc_domain_getinfolist Limit increase of maxmem to only do when needed:
Add QEMU_SPARE_PAGES (How many pages to leave free) Add free_pages calculation

 xen-hvm.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
xen-hvm.c +0 -0
index 7548794..d30e77e 100644

xen-hvm.c static inline ioreq_t *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vcpu) · line 93

Quoted 4 lines
xen-hvm.c +1 -0
@@ -90,6 +90,7 @@ static inline ioreq_t *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vcpu)
 #endif
 
 #define BUFFER_IO_MAX_DELAY  100
+#define QEMU_SPARE_PAGES 16

We need a big comment here to explain why we have this parameter and when we'll be able to get rid of it.

Quoted 8 lines
Quoted 4 lines

Other than that the patch is fine.

Thanks!

Actually I'll just go ahead and add the comment and commit, if for you is OK.

That would be fine with me. I was still working on a good wording.
-Don Slutz

Quoted 4 lines

Cheers,

Stefano

#6 lore raw
Quoted 43 lines · Don Slutz
Quoted 42 lines · Stefano Stabellini
Quoted 40 lines · Stefano Stabellini
Quoted 27 lines · Don Slutz

From: Stefano Stabellini <[email protected]>

Increase maxmem before calling xc_domain_populate_physmap_exact to avoid the risk of running out of guest memory. This way we can also avoid complex memory calculations in libxl at domain construction time.

This patch fixes an abort() when assigning more than 4 NICs to a VM.

---
v2: Changes by Don Slutz
Switch from xc_domain_getinfo to xc_domain_getinfolist Fix error check for xc_domain_getinfolist Limit increase of maxmem to only do when needed:
Add QEMU_SPARE_PAGES (How many pages to leave free) Add free_pages calculation

 xen-hvm.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
xen-hvm.c +0 -0
index 7548794..d30e77e 100644

xen-hvm.c static inline ioreq_t *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vcpu) · line 93

Quoted 4 lines
xen-hvm.c +1 -0
@@ -90,6 +90,7 @@ static inline ioreq_t *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vcpu)
 #endif
 
 #define BUFFER_IO_MAX_DELAY  100
+#define QEMU_SPARE_PAGES 16

We need a big comment here to explain why we have this parameter and when we'll be able to get rid of it.

Other than that the patch is fine.

Thanks!

Quoted 6 lines
Quoted 3 lines

Actually I'll just go ahead and add the comment and commit, if for you is OK.

That would be fine with me. I was still working on a good wording.
-Don Slutz

No worries. The patch is already upstream :-)