Add support for superpages (hugepages) in PV domain
PATCH 1/1 Add support for superpages (hugepages) in PV domain
This patch adds the option "superpages" to the domain configuration file. If it is set, the domain is populated using 2M pages.
This code does not support fallback to small pages. If the domain can not be created with 2M pages, the create will fail.
The patch also includes support for saving and restoring domains with the superpage flag set. However, if a domain has freed small pages within its physical page array and then extended the array, the restore will fill in those freed pages. It will then attempt to allocate more than its memory limit and will fail. This is significant because apparently Linux does this during boot, thus a freshly booted Linux image can not be saved and restored successfully.
Dave McCracken
Oracle Corp.
./tools/xcutils/xc_restore.c +8 -3
@@ -21,11 +21,12 @@ main(int argc, char **argv)unsigned int domid, store_evtchn, console_evtchn;unsigned int hvm, pae, apic;int xc_fd, io_fd, ret; +int superpages;unsigned long store_mfn, console_mfn; -if ( argc !=8 ) +if ( (argc !=8 ) && (argc !=9 ) )errx (1 ,"usage: %s iofd domid store_evtchn " -"console_evtchn hvm pae apic" , argv[0 ]); +"console_evtchn hvm pae apic [superpages]" , argv[0 ]); xc_fd =xc_interface_open ();if ( xc_fd <0 )
@@ -38,9 +39,13 @@ main(int argc, char **argv) hvm =atoi (argv[5 ]); pae =atoi (argv[6 ]); apic =atoi (argv[7 ]); +if ( argc ==9 ) + superpages =atoi (argv[8 ]); +else + superpages =0 ; ret =xc_domain_restore (xc_fd, io_fd, domid, store_evtchn, &store_mfn, - console_evtchn, &console_mfn, hvm, pae); + console_evtchn, &console_mfn, hvm, pae, superpages);if ( ret ==0 ) {
./tools/python/xen/xend/XendCheckpoint.py +3 -1
@@ -272,9 +272,11 @@ def restore(xd, fd, dominfo = None, paus shadow_cur = xc.shadow_mem_control(dominfo.getDomid(), shadow / 1024) dominfo.info['shadow_memory'] = shadow_cur + superpages = restore_image.superpages + cmd = map(str, [xen.util.auxbin.pathTo(XC_RESTORE), fd, dominfo.getDomid(), - store_port, console_port, int(is_hvm), pae, apic]) + store_port, console_port, int(is_hvm), pae, apic, superpages]) log.debug("[xc_restore]: %s", string.join(cmd)) handler = RestoreInputHandler()
./tools/python/xen/xend/XendConfig.py +6 -0
@@ -220,6 +220,7 @@ XENAPI_CFG_TYPES = { 'machine_address_size': int, 'suppress_spurious_page_faults': bool0, 's3_integrity' : int, + 'superpages' : int, } # List of legacy configuration keys that have no equivalent in the
@@ -392,6 +393,7 @@ class XendConfig(dict): 'other_config': {}, 'platform': {}, 'target': 0, + 'superpages': 0, } return defaults
@@ -2014,6 +2016,8 @@ class XendConfig(dict): image.append(['ramdisk', self['PV_ramdisk']]) if self.has_key('PV_args') and self['PV_args']: image.append(['args', self['PV_args']]) + if self.has_key('superpages'): + image.append(['superpages', self['superpages']]) for key in XENAPI_PLATFORM_CFG_TYPES.keys(): if key in self['platform']:
@@ -2051,6 +2055,8 @@ class XendConfig(dict): self['PV_ramdisk'] = sxp.child_value(image_sxp, 'ramdisk','') self['PV_args'] = kernel_args + self['superpages'] = sxp.child_value(image_sxp, 'superpages',0) + for key in XENAPI_PLATFORM_CFG_TYPES.keys(): val = sxp.child_value(image_sxp, key, None) if val is not None and val != '':
./tools/python/xen/xend/image.py +4 -1
@@ -651,6 +651,7 @@ class LinuxImageHandler(ImageHandler): ImageHandler.configure(self, vmConfig) self.vramsize = int(vmConfig['platform'].get('videoram',4)) * 1024 self.is_stubdom = (self.kernel.find('stubdom') >= 0) + self.superpages = vmConfig['superpages'] def buildDomain(self): store_evtchn = self.vm.getStorePort()
@@ -668,6 +669,7 @@ class LinuxImageHandler(ImageHandler): log.debug("vcpus = %d", self.vm.getVCpuCount()) log.debug("features = %s", self.vm.getFeatures()) log.debug("flags = %d", self.flags) + log.debug("superpages = %d", self.superpages) if arch.type == "ia64": log.debug("vhpt = %d", self.vhpt)
@@ -680,7 +682,8 @@ class LinuxImageHandler(ImageHandler): ramdisk = self.ramdisk, features = self.vm.getFeatures(), flags = self.flags, - vhpt = self.vhpt) + vhpt = self.vhpt, + superpages = self.superpages) def getRequiredAvailableMemory(self, mem_kb): if self.is_stubdom :
./tools/python/xen/xm/create.dtd +1 -0
@@ -54,6 +54,7 @@ actions_after_reboot %NORMAL_EXIT; #REQUIRED actions_after_crash %CRASH_BEHAVIOUR; #REQUIRED PCI_bus CDATA #REQUIRED + superpages CDATA #REQUIRED security_label CDATA #IMPLIED> <!ELEMENT memory EMPTY>
./tools/python/xen/xm/create.py +2 -0
@@ -661,6 +661,8 @@ def configure_image(vals): config_image.append(['videoram', vals.videoram]) if vals.extra: config_image.append(['args', vals.extra]) + if vals.superpages: + config_image.append(['superpages', vals.superpages]) if vals.builder == 'hvm': configure_hvm(config_image, vals)
./tools/python/xen/xm/xenapi_create.py +4 -0
@@ -271,6 +271,8 @@ class xenapi_create: vm.attributes["auto_power_on"].value == 'true', "s3_integrity": vm.attributes["s3_integrity"].value, + "superpages": + vm.attributes["superpages"].value, "memory_static_max": get_child_node_attribute(vm, "memory", "static_max"), "memory_static_min":
@@ -654,6 +656,8 @@ class sxp2xml: = str(get_child_by_name(config, "vcpus", 1)) vm.attributes["s3_integrity"] \ = str(get_child_by_name(config, "s3_integrity", 0)) + vm.attributes["superpages"] \ + = str(get_child_by_name(config, "superpages", 0)) sec_data = get_child_by_name(config, "security") if sec_data:
./tools/python/xen/lowlevel/xc/xc.c +5 -4
@@ -405,6 +405,7 @@ static PyObject *pyxc_linux_build(XcObjeint flags =0 ;int store_evtchn, console_evtchn;int vhpt =0 ; +int superpages =0 ;unsigned int mem_mb;unsigned long store_mfn =0 ;unsigned long console_mfn =0 ;
@@ -417,14 +418,14 @@ static PyObject *pyxc_linux_build(XcObje"console_evtchn" ,"image" ,/* optional */ "ramdisk" ,"cmdline" ,"flags" , - "features", "vhpt", NULL }; + "features", "vhpt", "superpages", NULL }; -if ( !PyArg_ParseTupleAndKeywords (args, kwds,"iiiis|ssisi" , kwd_list, +if ( !PyArg_ParseTupleAndKeywords (args, kwds,"iiiis|ssisii" , kwd_list, &domid, &store_evtchn, &mem_mb, &console_evtchn, &image,/* optional */ &ramdisk, &cmdline, &flags, - &features, &vhpt) ) + &features, &vhpt, &superpages) )return NULL ;xc_dom_loginit ();
@@ -436,7 +437,7 @@ static PyObject *pyxc_linux_build(XcObjeif (xc_dom_linux_build (self->xc_handle, dom, domid, mem_mb, image, ramdisk, flags, store_evtchn, &store_mfn, - console_evtchn, &console_mfn) !=0 ) { + console_evtchn, &console_mfn, superpages) !=0 ) { goto out; }
./tools/libxc/xc_dom_compat_linux.c +12 -8
@@ -28,7 +28,8 @@ static int xc_linux_build_internal(strucunsigned int store_evtchn, unsigned long *store_mfn, unsigned int console_evtchn, - unsigned long *console_mfn) + unsigned long *console_mfn, + int superpages) { int rc;
@@ -42,7 +43,7 @@ static int xc_linux_build_internal(struc goto out;if ( (rc =xc_dom_mem_init (dom, mem_mb)) !=0 ) goto out; -if ( (rc =xc_dom_boot_mem_init (dom)) !=0 ) +if ( (rc =xc_dom_boot_mem_init (dom, superpages)) !=0 ) goto out;if ( (rc =xc_dom_build_image (dom)) !=0 ) goto out;
@@ -67,7 +68,8 @@ int xc_linux_build_mem(int xc_handle, uiunsigned long flags, unsigned int store_evtchn, unsigned long *store_mfn, - unsigned int console_evtchn, unsigned long *console_mfn) + unsigned int console_evtchn, unsigned long *console_mfn, + int superpages) { struct xc_dom_image *dom;int rc;
@@ -82,7 +84,7 @@ int xc_linux_build_mem(int xc_handle, ui rc =xc_linux_build_internal (dom, xc_handle, domid, mem_mb, flags, store_evtchn, store_mfn, - console_evtchn, console_mfn); + console_evtchn, console_mfn, superpages); out:xc_dom_release (dom);
@@ -98,7 +100,8 @@ int xc_linux_build(int xc_handle, uint32unsigned long flags, unsigned int store_evtchn, unsigned long *store_mfn, - unsigned int console_evtchn, unsigned long *console_mfn) + unsigned int console_evtchn, unsigned long *console_mfn, + int superpages) { struct xc_dom_image *dom;int rc;
@@ -114,7 +117,7 @@ int xc_linux_build(int xc_handle, uint32 rc =xc_linux_build_internal (dom, xc_handle, domid, mem_mb, flags, store_evtchn, store_mfn, - console_evtchn, console_mfn); + console_evtchn, console_mfn, superpages); out:xc_dom_release (dom);
@@ -130,7 +133,8 @@ int xc_dom_linux_build(int xc_handle,unsigned long flags, unsigned int store_evtchn, unsigned long *store_mfn, - unsigned int console_evtchn, unsigned long *console_mfn) + unsigned int console_evtchn, unsigned long *console_mfn, + int superpages) { int rc;
@@ -143,7 +147,7 @@ int xc_dom_linux_build(int xc_handle,return xc_linux_build_internal (dom, xc_handle, domid, mem_mb, flags, store_evtchn, store_mfn, - console_evtchn, console_mfn); + console_evtchn, console_mfn, superpages); }/*
./tools/libxc/xc_dom_boot.c +2 -2
@@ -129,13 +129,13 @@ int xc_dom_boot_xen_init(struct xc_dom_ireturn 0 ; } -int xc_dom_boot_mem_init (struct xc_dom_image *dom) +int xc_dom_boot_mem_init (struct xc_dom_image *dom,int superpages) {long rc;xc_dom_printf ("%s: called\n" , __FUNCTION__); - rc =arch_setup_meminit (dom); + rc =arch_setup_meminit (dom, superpages);if ( rc !=0 ) { xc_dom_panic(XC_OUT_OF_MEMORY,
./tools/libxc/xc_dom_x86.c +44 -11
76 lines not on this page · raw message
./tools/libxc/xenguest.h +10 -4
@@ -40,12 +40,13 @@ int xc_domain_save(int xc_handle, int io* @parm store_mfn returned with the mfn of the store page * @parm hvm non-zero if this is a HVM restore * @parm pae non-zero if this HVM domain has PAE support enabled +* @parm superpages non-zero to allocate guest memory with superpages * @return 0 on success, -1 on failure */ int xc_domain_restore (int xc_handle,int io_fd,uint32_t dom,unsigned int store_evtchn,unsigned long *store_mfn,unsigned int console_evtchn,unsigned long *console_mfn, -unsigned int hvm,unsigned int pae); +unsigned int hvm,unsigned int pae,int superpages);/** * This function will create a domain for a paravirtualized Linux
@@ -62,6 +63,7 @@ int xc_domain_restore(int xc_handle, int* @parm store_mfn returned with the mfn of the store page * @parm console_evtchn the console event channel for this domain to use * @parm conole_mfn returned with the mfn of the console page +* @parm superpages populate memory in guest with superpages * @return 0 on success, -1 on failure */ int xc_linux_build(int xc_handle,
@@ -75,7 +77,8 @@ int xc_linux_build(int xc_handle,unsigned int store_evtchn, unsigned long *store_mfn, unsigned int console_evtchn, - unsigned long *console_mfn); + unsigned long *console_mfn, + int superpages);/** The same interface, but the dom structure is managed by the caller */ struct xc_dom_image ;
@@ -89,7 +92,8 @@ int xc_dom_linux_build(int xc_handle,unsigned int store_evtchn, unsigned long *store_mfn, unsigned int console_evtchn, - unsigned long *console_mfn); + unsigned long *console_mfn, + int superpages);/** * This function will create a domain for a paravirtualized Linux
@@ -108,6 +112,7 @@ int xc_dom_linux_build(int xc_handle,* @parm store_mfn returned with the mfn of the store page * @parm console_evtchn the console event channel for this domain to use * @parm conole_mfn returned with the mfn of the console page +* @parm superpages populate memory in guest with superpages * @return 0 on success, -1 on failure */ int xc_linux_build_mem(int xc_handle,
@@ -123,7 +128,8 @@ int xc_linux_build_mem(int xc_handle,unsigned int store_evtchn, unsigned long *store_mfn, unsigned int console_evtchn, - unsigned long *console_mfn); + unsigned long *console_mfn, + int superpages); int xc_hvm_build(int xc_handle, uint32_t domid,
./tools/libxc/xc_dom.h +2 -2
@@ -174,7 +174,7 @@ int xc_dom_build_image(struct xc_dom_imaint xc_dom_update_guest_p2m (struct xc_dom_image *dom);int xc_dom_boot_xen_init (struct xc_dom_image *dom,int xc,domid_t domid); -int xc_dom_boot_mem_init (struct xc_dom_image *dom); +int xc_dom_boot_mem_init (struct xc_dom_image *dom,int superpages);void *xc_dom_boot_domU_map (struct xc_dom_image *dom,xen_pfn_t pfn,xen_pfn_t count);int xc_dom_boot_image (struct xc_dom_image *dom);
@@ -260,7 +260,7 @@ static inline xen_pfn_t xc_dom_p2m_guest/* --- arch bits --------------------------------------------------- */ -int arch_setup_meminit (struct xc_dom_image *dom); +int arch_setup_meminit (struct xc_dom_image *dom,int superpages);int arch_setup_bootearly (struct xc_dom_image *dom);int arch_setup_bootlate (struct xc_dom_image *dom);
./tools/libxc/xc_domain_restore.c +106 -115
312 lines not on this page · raw message
./tools/libxc/xc_dom_ia64.c +1 -1
@@ -149,7 +149,7 @@ static void __init register_arch_hooks(v#include "xc_efi.h" -int arch_setup_meminit (struct xc_dom_image *dom) +int arch_setup_meminit (struct xc_dom_image *dom,int superpages) {xen_pfn_t pfn;int rc;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Unfortunately this patch forces user to specify superpages=? in their config file.
Can we default the behaviour to superpages=0 instead?
Quoted 18 lines · Dave McCracken
This patch adds the option "superpages" to the domain configuration file. If it is set, the domain is populated using 2M pages.
This code does not support fallback to small pages. If the domain can not be created with 2M pages, the create will fail.
The patch also includes support for saving and restoring domains with the superpage flag set. However, if a domain has freed small pages within its physical page array and then extended the array, the restore will fill in those freed pages. It will then attempt to allocate more than its memory limit and will fail. This is significant because apparently Linux does this during boot, thus a freshly booted Linux image can not be saved and restored successfully.
Dave McCracken
Oracle Corp.
Quoted 3 lines · Stefano Stabellini
Unfortunately this patch forces user to specify superpages=? in their config file.
Can we default the behaviour to superpages=0 instead?
Sorry. That wasn't intentional. I'll fix it.
Dave McCracken
Oracle Corp.