WO2012122796A1 - 一种创建虚拟机的方法、虚拟机监控器及虚拟机系统 - Google Patents

一种创建虚拟机的方法、虚拟机监控器及虚拟机系统 Download PDF

Info

Publication number
WO2012122796A1
WO2012122796A1 PCT/CN2011/080573 CN2011080573W WO2012122796A1 WO 2012122796 A1 WO2012122796 A1 WO 2012122796A1 CN 2011080573 W CN2011080573 W CN 2011080573W WO 2012122796 A1 WO2012122796 A1 WO 2012122796A1
Authority
WO
WIPO (PCT)
Prior art keywords
page
virtual machine
memory
zero
gfn
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Ceased
Application number
PCT/CN2011/080573
Other languages
English (en)
French (fr)
Inventor
邱军
叶川
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to ES11799061.4T priority Critical patent/ES2581597T3/es
Priority to EP11799061.4A priority patent/EP2581828B1/en
Priority to US13/339,862 priority patent/US9183157B2/en
Publication of WO2012122796A1 publication Critical patent/WO2012122796A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/10Address translation
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operations
    • G06F11/1479Generic software techniques for error detection or fault masking
    • G06F11/1482Generic software techniques for error detection or fault masking using middleware or operating system [OS] functionalities
    • G06F11/1484Generic software techniques for error detection or fault masking using middleware or operating system [OS] functionalities involving virtual machines
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45562Creating, deleting, cloning virtual machine instances
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45583Memory management, e.g. access or allocation

Definitions

  • the present invention relates to virtual machine technology, and in particular, to a method for creating a virtual machine, a virtual machine monitor, and a virtual machine system.
  • a virtualization technology is a decoupling method for separating an underlying hardware device from an upper layer operating system and an application program, and introduces a virtual machine monitor (VMM) layer to directly manage the underlying hardware resources, and creates and bottom layers.
  • Hardware-independent virtual machines (VMs) are used by upper-layer operating systems and applications.
  • VMs virtualization technology can greatly improve the resource utilization efficiency of physical devices. As shown in Figure 1, after the system is virtualized, multiple virtual machine VMs can be run simultaneously on one physical machine. The number of virtual machines supported on the physical machine is called Virtual Machine Density. The larger the resource utilization, the higher the resource utilization.
  • the virtualization of the virtual machine can be shared by the virtual processor of the virtual machine. If the performance is not considered, any number of virtual CPUs can theoretically be virtualized. Peripheral virtualization can be virtualized out of any number by software emulation or by connecting to an external subsystem, such as a SAN (Storage Area Network).
  • SAN Storage Area Network
  • Peripheral virtualization can be virtualized out of any number by software emulation or by connecting to an external subsystem, such as a SAN (Storage Area Network).
  • SAN Storage Area Network
  • the industry has proposed the Memory Overcommitted method, which includes: Balloon Driver, page content-based memory page sharing (Content Based Page Sharing) , CBPS), Memory Page Swap, Memory Page Compression, and Populate on Demand (PoD).
  • the Balloon Driver is installed inside the Guest Operating System (GOS) and induces the GOS to release or allocate memory.
  • the balloon driver reclaims or allocates the corresponding memory to the GOS for automatic expansion memory adjustment.
  • the CBPS method scans global physical pages and finds that pages with the same page content are shared, thereby freeing redundant pages and reducing the virtual machine's physical memory usage.
  • Memory Page Swap or Memory Page Compression Selects several pages of a virtual machine to be swapped to an external device such as a disk, or losslessly compressed to a 1/n page size, thereby freeing up memory for more The virtual machine is used.
  • the PoD method allocates a specified number of memory pages to each virtual machine as a memory pool.
  • the virtual memory of the virtual machine is empty, and there is no corresponding physical memory page, only when the virtual memory is actually accessed. When you take the physical page from the memory pool.
  • Embodiments of the present invention provide a method for creating a virtual machine, a virtual machine monitor, and a virtual machine system.
  • the embodiment of the present invention provides a method for creating a virtual machine, where the method includes: mapping a client page frame number GFN corresponding to a virtual machine's pseudo physical memory (Pseudo-physical Memory) to a shared zero page.
  • the shared zero page is a page in the physical memory whose page content is all zero; when the virtual machine writes the GFN, if a page exception occurs, a physical memory page is allocated to release the client page frame number GFN and the The mapping relationship of the zero pages is shared, and the mapping relationship between the client page frame number GFN and the machine page frame number MFN of the physical memory page is established.
  • an embodiment of the present invention provides a virtual machine monitor, where the virtual machine monitor includes: an initial virtual memory unit, configured to map a client page frame number GFN corresponding to a pseudo physical memory of the virtual machine to a virtual machine Sharing a zero page, the shared zero page is a page in the physical memory whose page content is all zero; a copy-on-write unit is configured to allocate a physical memory page to cancel when a page exception occurs when the virtual machine writes the GFN a mapping relationship between the client page frame number GFN and the shared zero page, and establishing a mapping relationship between the client page frame number GFN and a machine page frame number MFN of the physical memory page.
  • the embodiment of the present invention provides a virtual machine system, where the system includes: a virtual machine monitor and a virtual machine; wherein the virtual machine monitor is used to connect a virtual machine with a pseudo physical memory.
  • the machine frame number GFN is mapped to a shared zero page, and the shared zero page is a page in the physical memory whose page content is all zero; when the virtual machine writes the GFN, if a page exception occurs, the physical memory page is allocated.
  • the mapping relationship between the client page frame number GFN and the shared zero page is released, and a mapping relationship between the client page frame number GFN and the machine page frame number MFN of the physical memory page is established.
  • the virtual machine monitor initializes the virtual memory by mapping the pseudo physical memory of the virtual machine to the shared zero page, so that the virtual machine does not need to consume physical memory; when the virtualization starts to use the virtual memory
  • the virtual machine monitor allocates physical memory to the virtual machine by copy-on-write and releases the mapping to the shared zero page, the memory usage during the virtual machine startup process can be reduced, and the virtual machine density can be increased.
  • FIG. 1 is a schematic diagram of a prior art virtual machine architecture
  • 2 is a schematic structural diagram of a system according to Embodiment 1 of the present invention and a device according to Embodiment 2
  • FIG. 3 is a flowchart of a method for creating a virtual machine according to Embodiment 3 of the present invention
  • FIG. 4 is a flowchart of a method for creating a virtual machine according to Embodiment 4 of the present invention.
  • FIG. 5 is a flowchart of a method for creating a virtual machine according to Embodiment 5 of the present invention.
  • the technical solutions in the embodiments of the present invention are clearly and completely described in the following with reference to the accompanying drawings in the embodiments of the present invention.
  • the embodiments are a part of the embodiments of the invention, and not all of the embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments of the present invention without creative efforts are within the scope of the present invention.
  • Embodiment 1 is a diagrammatic representation of Embodiment 1:
  • FIG. 2 is a schematic structural diagram of a virtual machine system according to an embodiment of the present invention. As shown in FIG. 2, the system includes: a virtual machine monitor and a virtual machine; wherein
  • the virtual machine monitor is configured to map a client page frame number GFN corresponding to the pseudo physical memory of the virtual machine to a shared zero page, where the shared zero page is a page in the physical memory whose page content is all zero;
  • a virtual memory page is allocated to release the mapping relationship between the client page frame number GFN and the shared zero page, and the client page frame number GFN is established and the The mapping relationship between the machine page frame number MFN of the physical memory page.
  • the virtual machine monitor may further be configured to update a memory usage increment of the virtual machine after allocating a physical memory page for the virtual machine; when the memory usage increment reaches a preset threshold , scan the physical memory page allocated during the virtual machine startup process, release or add the searched memory page to the memory pool, and remap the GFN to the shared zero page, and then store the memory after the scan is completed. Use incremental zeroing.
  • Hardware layer The entire hardware platform running as a virtualized environment, which may specifically include a processor High-speed I/O devices such as CPU, memory Memory, NIC (Network Interface Card), external storage devices, and low-speed devices such as basic input and output.
  • High-speed I/O devices such as CPU, memory Memory, NIC (Network Interface Card), external storage devices, and low-speed devices such as basic input and output.
  • VMM Virtual Machine Monitor
  • VMM Virtual Machine Monitor
  • main functions include: complete management and allocation of hardware resources; present a virtual hardware platform for virtual machines; and perform virtual machine scheduling And isolation.
  • some VMM implementations require a privileged virtual machine to work together to form a host.
  • the virtual hardware platform provides various hardware resources to the virtual machines on it, such as virtual processor VCPUs, virtual memory, virtual disks, virtual network cards, and so on.
  • the virtual memory is an isolated, zero-based and continuous pseudo-physical memory space for the VM.
  • the VMM creates a P2M table for each VM to convert the GFN into an MFN (Machine Frame Number). ), so that virtual memory is discretely distributed in physical memory.
  • MFN Machine Frame Number
  • One or more virtual machine VMs The virtual machine runs in the virtual platform it is prepared for. Most of the time, the execution of the virtual machine is not affected by the host.
  • the mapping of GFN to MFN is recorded by the p2m table.
  • the p2m table consists of p2m entries, and mfn is recorded in p2m entries.
  • gfn as an index, you can find a unique p2m entry and find mfn.
  • host/vmm uses the GFN corresponding to the virtual machine pseudo physical memory to index the p2m table corresponding to the virtual machine, and the MFN in the p2m item of each GFN index.
  • the virtual machine monitor is further configured to allocate a physical memory page for the virtual machine After that, the memory usage increment of the virtual machine is updated; when the memory usage increment reaches a preset threshold, the physical memory page allocated during the virtual machine startup process is scanned, and the searched memory page with zero content is released. Or join to the memory pool, and remap GFN to the shared zero page, zeroing the memory usage increment after the scan is complete.
  • the memory page used in the startup process of the virtual machine is scanned in real time, instead of the global scan, thereby improving the scanning efficiency and reducing the scanning interval.
  • release means that host/vmm reclaims a page of memory, making it free.
  • the memory usage increment of the virtual machine is a count value, which is used to indicate that the virtual machine has released the number of GFNs originally mapped to the shared zero page due to the write memory since the last zero page scan; When the value exceeds the threshold, a new zero-page scan is started. After the scan ends, the count value is set to zero, that is, the memory usage increment is set to zero, and the next round of counting is started. That is to say, the memory usage increment is the number of GFNs that are unmapped to the shared zero page within the zero page scan interval.
  • the system of the embodiment of the invention can reduce the memory usage during the startup process of the virtual machine, increase the virtual machine density, support concurrently starting the memory overcommitted number of virtual machines, and monotonically increase the memory usage during the startup process of the virtual machine.
  • Embodiment 2 is a diagrammatic representation of Embodiment 1:
  • the second embodiment of the present invention provides a virtual machine monitor VMM.
  • the virtual machine monitor includes:
  • the virtual memory unit 210 is configured to map the client page number GFN corresponding to the virtual physical memory of the virtual machine to a shared zero page, where the shared zero page is a page in the physical memory whose page content is all zero;
  • a copy-on-write unit 220 configured to allocate a physical memory page to cancel a mapping relationship between the client page frame number GFN and the shared zero page, and establish a location when the virtual machine writes the GFN The mapping relationship between the client page frame number GFN and the machine page frame number MFN of the physical memory page.
  • the virtual memory unit 210 is initialized, and is specifically used to map all the pseudo physical memory of the virtual machine in the P2M table of the virtual machine pseudo physical address to the physical address of the machine.
  • the GFN is indexed to the machine page frame number MFN of the shared zero page.
  • the copy-on-write unit 220 is specifically configured to index the client page frame number GFN to a machine page frame number of the physical memory page in a mapping relationship P2M table of a virtual machine pseudo physical address to a machine physical address. MFN.
  • the virtual memory unit 210 is initialized to map all GFNs of the VM to
  • VMM is allocated on a shared zero page.
  • the initialized virtual memory unit 210 is called by the VMM when the virtual machine is created.
  • the copy-on-write copy on Write unit 220 has the following functions: first allocate a physical memory page and clear the page; then unmap the GFN to the shared zero page; and finally remap the generated GFN to the above allocation
  • the physical memory page corresponds to the MFN.
  • the copy-on-write unit is also used to determine whether the memory pool contains zero pages, and if so, obtain zero pages from the memory pool and allocate them to the virtual machine.
  • the virtual machine monitor further includes: a threshold control unit 230 and a zero page scanning unit 240; the threshold control unit 230 is configured to determine the allocated physical memory page. Whether the quantity reaches a preset threshold, if yes, starting the zero page scanning unit; the zero page scanning unit 240 is configured to scan the allocated physical memory page, and release the scanned zero page or scan to Zero pages into the memory pool
  • the threshold control unit 230 is connected to the copy-on-write unit 220. As the VM continuously writes the GFN mapped to the shared zero page, the physical memory page occupied by the VM is also continuously increased. Therefore, the functions of the threshold control unit 230 include: Determining whether the number of memory pages added by the VM exceeds a preset threshold. If the number of memory pages added by the VM exceeds a preset threshold, the zero page scanning unit is started, for example, when the amount of memory used by the VM exceeds 4096 pages, the zero page scanning unit is started. .
  • the zero page scanning unit 240 is connected to the threshold control unit 230.
  • the GOS mass write operation is to write zeros into the memory page, so the functions of the zero page scanning unit 240 include: After the VM triggers the write exception, the write copy unit is called to scan the physical memory page allocated by the virtual machine to search for the page whose internal content is all zero in the allocated physical memory page, and the GFN corresponding to the memory page with all contents is zero. Remap the shared zero page, and release the physical memory page that was mapped before the GFN.
  • the copy-on-write unit 220 may be further configured to determine whether the memory pool contains zero pages. If yes, the zero page is obtained from the memory pool and allocated to the virtual machine. If not, the page is allocated from the free memory to the virtual machine. .
  • the virtual machine monitor of the embodiment of the present invention can reduce the memory usage during the startup process of the virtual machine, increase the virtual machine density, support concurrently starting the memory overcommitted number of virtual machines, and monotonically increase the memory usage during the virtual machine startup process. If the memory usage of the virtual machine is monotonically increasing, it can be determined that the total amount of memory used by all virtual machines at a certain time does not exceed a certain value, which can reduce the Memory Overcommitted failure. If the memory usage of the virtual machine and the timeline form a curve with peaks and valleys, it is not possible to determine how many virtual machines can be started at the same time. If the memory usage of the virtual machine forms a straight line parallel to the time axis with the time axis, then the number of virtual machines that can be started is limited by the size of the memory.
  • Embodiment 3 is a diagrammatic representation of Embodiment 3
  • FIG. 3 is an overall flowchart of a method for creating a virtual machine according to Embodiment 3 of the present invention. As shown in FIG. 3, the method includes:
  • Step 310 Map a client page frame number GFN corresponding to the pseudo physical memory of the virtual machine to a shared zero page, where the shared zero page is a page in the physical memory whose page content is all zero;
  • Step 320 When the virtual machine writes the GFN, if a page exception occurs, a physical memory page is allocated to release a mapping relationship between the client page frame number GFN and the shared zero page, and the client page is established. The mapping relationship between the frame number GFN and the machine page frame number MFN of the physical memory page.
  • mapping the client page frame number GFN corresponding to the pseudo physical memory of the virtual machine to a shared zero page in the step 310 may include the following process: mapping the virtual machine pseudo physical address to the machine physical address P2M table All GFNs corresponding to the pseudo physical memory of the virtual machine Both are indexed to the machine page frame number MFN of the shared zero page.
  • mapping relationship between the client page frame number GFN and the machine page frame number MFN of the physical memory page may be included in the following process: the mapping relationship between the virtual machine pseudo physical address and the machine physical address P2M table
  • the client page frame number MFN is indexed to the machine page frame number MFN of the physical memory page.
  • the method shown in FIG. 3 may further include the steps of: determining whether the number of allocated physical memory pages reaches a preset threshold, and if yes, the allocated physical The memory page is scanned and the scanned zero pages are released or the scanned zero pages are placed in the memory pool.
  • the specific process of allocating the physical memory page in step 320 may further include: determining whether the memory pool contains zero pages, and if yes, obtaining zero pages from the memory pool and assigning to the virtual machine, if no, Allocate pages from free memory to the virtual machine.
  • the method of the third embodiment of the present invention can reduce the memory usage during the startup process of the virtual machine, increase the virtual machine density, support concurrently starting the memory overcommitted number of virtual machines, and monotonically increase the memory usage during the virtual machine startup process.
  • Embodiment 4 is a diagrammatic representation of Embodiment 4:
  • the virtual machine startup can be divided into two processes: First, in the virtual machine creation phase, the virtual machine is created and the necessary resources are allocated. For security reasons, the memory allocated to the virtual machine is cleared by the VMM. Second, the guest is started. During the OS (Customer Operating System, GOS) phase, GOS's use of memory consists of two parts, memory and free memory for storing kernel code and data. GOS will clear the free memory for security reasons. As can be seen from the foregoing analysis, in the existing Memory Overcommitted method, either the virtual machine is not considered to start the scenario, or the memory usage of the Guest OS during the virtual machine startup process is not considered.
  • OS Customer Operating System
  • FIG. 4 is a flow chart of a method according to Embodiment 4 of the present invention. Referring to Figure 2 and Figure 4, the process includes the following steps:
  • Step 10 Create a VM.
  • Step 11 Map all GFNs to shared zero pages; Zero pages refer to memory pages whose VM data is all zero; the zero pages in the VM are redundant. In the whole system, only one copy of the zero page is required. Therefore, in the embodiment of the present invention, the GFN which is originally a zero page in the VM is shared and mapped to the zero page. The zero page shared by the VM is called the shared zero page.
  • Step 12 Start the guest operating system Guest OS
  • step 10-12 the virtual machine is created and the guest OS is started.
  • the virtual machine is not allocated any physical memory resources, but the virtual memory unit is initialized to map all the GFNs of the VM to the VMM. Assigned on shared zero pages.
  • the VM does not have physical memory resources at this time, the VM can still know the full amount of virtual memory with zero content through the P2M table, so the Guest OS can still start.
  • Step 20 The VM writes the GFN
  • Step 21 determining whether a page abnormal pageFault is generated, and if yes, proceeding to step 22a, if not, proceeding to step 22b;
  • Step 22a the CoW unit applies for a physical memory page, updates the P2M table, and increments the memory usage increment by one; updating the P2M table means: releasing the mapping relationship between the accessed GFN and the shared zero page, and mapping the accessed GFN to Applied physical memory page;
  • Step 22b the VM accesses the page that has been applied; Specifically, in steps 20, 21, and 22a, the VM starts using virtual memory, and the memory operations include reading memory and writing memory. If the write is a memory operation and the accessed GFN is mapped to a shared zero page, the processor will generate a page exception PageFault. The VMM starts to handle this exception. The VMM calls the CoW unit to release the mapping of the accessed GFN to the shared zero page. The CoW unit then remaps the accessed GFN to a newly allocated MFN with page content all zeros. In this case, the VMM also updates the memory usage increment count of the VM, and increments this count value by one.
  • step 20 The de-mapping relationship and remapping are performed by the CoW unit.
  • step 21 and step 22b if the GFN written by the VM is not mapped to the shared zero page, the PageFault exception will not be generated, and the VM uses the memory normally.
  • Step 30 Determine whether the memory usage increment of the VM is less than a preset threshold, and if yes, go to step 20, if no, go to step 40;
  • Step 40 Scan the zero page, and set the memory usage increment to zero;
  • Step 41 Release the zero page.
  • the threshold control unit determines whether it is necessary to start the zero-page scanning unit according to the relationship between the memory usage increment and the preset threshold. If it is not necessary to start the zero page scanning unit, the VMM exits from the abnormal processing flow, returns to the VM, and the VM continues to run, as shown in step 30 and step 20 in FIG. 4;
  • the zero page scan unit is started.
  • the size of the threshold can be determined by the virtual configuration file or the default value set by the VMM, for example, 32MB.
  • step 40 if a zero page scan is required, the zero page scan unit starts scanning the physical memory that has been allocated to the VM, remaps the GFN corresponding to the page with all zeros to the shared zero page, and releases the content as Zero physical page and set the memory increment to zero.
  • Scanning zero pages means: Find the page with all zeros in the memory page of the VM. When you scan a physical page of a VM, you can scan all physical pages that the VM currently has, or you can scan only incremental memory. If only the incremental memory is scanned, the corresponding MFN, that is, the MFN corresponding to the physical page added by the VM, is recorded after the completion of step 22a.
  • the data structure of the record can be a binary bitmap (Bitmap) or a data structure such as a linked list. After this step is completed, it exits from the exception handling process, returns to the VM, and the VM continues to run.
  • the flow in Figure 4 runs until the threshold control unit receives a start completion notification message, and the sender of this message can be the VMM itself, the privileged domain, or the front end driver of the VM.
  • the method of the fourth embodiment of the present invention can reduce the memory usage during the startup process of the virtual machine, increase the virtual machine density, support concurrently starting the memory overcommitted number of virtual machines, and monotonically increase the memory usage during the virtual machine startup process.
  • Embodiment 5 is a diagrammatic representation of Embodiment 5:
  • the fifth embodiment In the process of the fourth embodiment, after the zero page scanning unit remaps the zero page to the shared zero page, the physical memory page is directly released, and the CoW unit reapplies for one physical memory page each time, so in order to improve performance, the fifth embodiment
  • the zero page found by the zero page scanning unit is first put into a memory pool, and the CoW unit first obtains the memory page from the memory pool, and if the memory is already empty, the physical page is allocated by the VMM.
  • the operation of releasing the application after repeated application in the implementation process of the present invention can be reduced, thereby improving efficiency.
  • step 22a in Fig. 4 corresponds to the following two cases in Fig. 5:
  • step 120 when the memory pool is not empty, the VMM takes a page from the memory pool when reallocating the page for the GFN, and maps the GFN to the On the MFN corresponding to the page, the memory usage increment is then incremented by one.
  • step 120, step 121a, step 122, and step 123 in FIG. 5 are performed to complete the operation similar to 22a in FIG. 4, that is, the VMM reallocates a physical memory page and clears Zero, then map the GFN to the MFN corresponding to the physical memory page, and finally increase the memory usage increment by one.
  • step 41 in FIG. 4 becomes step 141 in FIG.
  • the zero page scanning unit finds a page with zero content, maps the GFN of the page to the shared zero page, and puts the scanned zero page into the page. In the pool.
  • the MFN corresponding to the GFN is placed in the memory pool, and the CoW unit takes the page from the memory pool when applying for the memory, so it is not necessary to release zero.
  • the step of releasing the zero page is replaced by the step of adding the zero page to the memory pool. This helps reduce duplicate application memory pools and free memory.
  • the size of the memory pool does not exceed the incremental threshold, so the memory can be represented by a linear table data structure such as an array or a linked list.
  • This linear meter is simple and efficient.
  • the beneficial effects of the embodiments of the present invention are as follows: 1. Saving the memory usage during the startup process of the virtual machine; 2. Supporting concurrently starting the memory of the Memory Overcommitted number; the emphasis is on the number of concurrent, because the method of the embodiment of the present invention can The VM occupies as little memory as possible, and the memory usage of the VM is monotonically increasing, so the number of concurrently booting VMs can be increased. 3. The memory usage during the startup process of the virtual machine is monotonically increasing; 4. The virtual machine density is increased; The method can be applied to virtualization areas such as minicomputer virtualization and converged virtualization.
  • RAM random access memory
  • ROM read only memory
  • EEPROM electrically programmable ROM
  • EEPROM electrically erasable programmable ROM
  • registers hard disk, removable disk, CD-ROM, or technical field Any other form of storage medium known.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Description

一种创建虚拟机的方法、 虚拟机监控器及虚拟机系统 技术领域 本发明涉及虚拟机技术, 具体地涉及一种创建虚拟机的方法、 虚拟机监 控器及虚拟机系统。 背景技术 虚拟化技术是一种将底层硬件设备与上层操作系统、 应用程序分离的去 耦合方法, 其引入虚拟机监控器 (Virtual Machine Monitor, VMM ) 层来直接 管理底层硬件资源, 并创建与底层硬件无关的虚拟机 (Virtual Machine , VM ) 供上层操作系统和应用程序使用。 虚拟化技术作为当前流行的云计算 (Cloud Computing ) 平台的底层重要支撑技术之一, 可以大大提高物理设备 的资源使用效率。 如图 1所示, 经过系统虚拟化后, 一台物理机器上可以同 时运行多个虚拟机 VM, 物理机器上支持同时运行的虚拟机数量称为虚拟机 密度 (Virtual Machine Density), 虚拟机密度越大, 资源利用率越高。
为提高虚拟机密度, CPU虚拟化时采用调度的方式使得虚拟机的虚拟 处理器可以共享物理 CPU, 如果不考虑性能, 理论上可以虚拟出任意多个虚 拟 CPU。 外设虚拟化通过软件模拟或连接到外部子系统, 例如 SAN (存储 域网络, Storage Area Network) , 同样可以虚拟出任意多份。 但在内存虚拟 化方面, 将同一个物理内存页给多个虚拟机同时使用的前提是虚拟机之间具 有页面内容完全相同的页, 因此虚拟内存量理论上不能超过物理内存量。 为 使虚拟内存量大于物理内存量的限制, 业界提出了 Memory Overcommitted (虚拟内存量大于物理内存) 方法, 该方法包括: 气球驱动 (Balloon Driver) 、 基于页内容的内存页共享 (Content Based Page Sharing, CBPS ) 、 内存页交换 ( Memory Page Swap ) 、 内存页压缩 ( Memory Page Compression) 禾口 Populate on Demand (PoD) 等。 气球驱动 (Balloon Driver ) 安装在客户机操作系统 (Guest Operating System, GOS ) 内部, 并诱导 GOS释放或分配内存, 气球驱动将相应的内存 收回或分配给 GOS , 从而实现自动伸缩内存调节。
基于页内容的内存页共享 CBPS方法是扫描全局物理页, 发现页内容 相同的页就共享, 从而释放冗余页, 减少虚拟机的物理内存使用量。
内存页交换 ( Memory Page Swap ) 或内存页压缩方法 ( Memory Page Compression) 选择虚拟机的若干页交换到磁盘等外部设备上, 或无损压缩成 1/n页大小, 从而释放出内存给更多的虚拟机使用。
PoD方法为每个虚拟机分配指定数量的内存页作为内存池 (Memory Pool ) , 刚启动的时候虚拟机的虚拟内存都是空的, 没有对应到物理内存 页, 只有当虚拟内存真正被访问的时候才从内存池中拿出物理页。
发明人在实现本发明的过程中发现, 现有技术至少存在以下不足: 以上技术都没有考虑虚拟机创建后并启动 GOS这个过程当中内存使用 情况, 而是先将虚拟机需要的内存全部分配给虚拟机, 然后再回收部分内 存, 这使得物理机器能并发启动虚拟机的数量受到物理内存量的限制, 从而 降低了虚拟机密度。 发明内容 本发明实施例提供一种创建虚拟机的方法、 虚拟机监控器及虚拟机系 统。
一方面, 本发明实施例提供了一种创建虚拟机的方法, 所述方法包括: 将虚拟机的伪物理内存 (Pseudo-physical Memory ) 对应的客户机页框号 GFN映射到一共享零页, 所述共享零页为物理内存中页面内容全为零的页; 当所述虚拟机写所述 GFN时, 如果产生页面异常则分配物理内存页以解除 所述客户机页框号 GFN与所述共享零页的映射关系, 并建立所述客户机页 框号 GFN与物理内存页的机器页框号 MFN的映射关系。 另一方面, 本发明实施例提供了一种虚拟机监控器, 所述虚拟机监控器 包括: 初始化虚拟内存单元, 用于将虚拟机的伪物理内存对应的客户机页框 号 GFN映射到一共享零页, 所述共享零页为物理内存中页面内容全为零的 页; 写时拷贝单元, 用于当所述虚拟机写所述 GFN时, 如果产生页面异常 则分配物理内存页以解除所述客户机页框号 GFN与所述共享零页的映射关 系, 并建立所述客户机页框号 GFN与所述物理内存页的机器页框号 MFN的 映射关系。
又一方面, 本发明实施例提供了一种虚拟机系统, 所述系统包括: 虚拟 机监控器和虚拟机; 其中, 所述虚拟机监控器, 用于将虚拟机的伪物理内存 对应的客户机页框号 GFN映射到一共享零页, 所述共享零页为物理内存中 页面内容全为零的页; 当所述虚拟机写所述 GFN时, 如果产生页面异常则 分配物理内存页以解除所述客户机页框号 GFN与所述共享零页的映射关 系, 并建立所述客户机页框号 GFN与物理内存页的机器页框号 MFN的映射 关系。
本发明实施例提供的上述技术方案, 虚拟机监控器通过将虚拟机的伪物 理内存映射到共享零页的方式初始化虚拟内存, 使得创建虚拟机不需要消耗 物理内存; 当虚拟化开始使用虚拟内存时, 虚拟机监控器通过写时拷贝分配 物理内存给虚拟机并解除到共享零页的映射关系, 从而可以减少虚拟机启动 过程中的内存使用量, 提高虚拟机密度。 附图说明 为了更清楚地说明本发明实施例或现有技术中的技术方案, 下面将对实 施例或现有技术描述中所需要使用的附图作简单地介绍, 显而易见地, 下面 描述中的附图仅仅是本发明的一些实施例, 对于本领域普通技术人员来讲, 在不付出创造性劳动性的前提下, 还可以根据这些附图获得其他的附图。
图 1为现有技术的虚拟机架构示意图; 图 2为本发明实施例一的系统及实施例二的装置的结构示意图; 图 3是本发明实施例三的一种创建虚拟机的方法的流程图;
图 4为本发明实施例四的一种创建虚拟机的方法的流程图;
图 5为本发明实施例五的一种创建虚拟机的方法的流程图。 具体实施方式 为使本发明实施例的目的、 技术方案和优点更加清楚, 下面将结合本发 明实施例中的附图, 对本发明实施例中的技术方案进行清楚、 完整地描述, 显然, 所描述的实施例是本发明一部分实施例, 而不是全部的实施例。 基于 本发明中的实施例, 本领域普通技术人员在没有做出创造性劳动前提下所获 得的所有其他实施例, 都属于本发明保护的范围。
实施例一:
图 2为本发明实施例的虚拟机系统的体系架构示意图。 如图 2所示, 该 系统包括: 虚拟机监控器和虚拟机; 其中,
该虚拟机监控器, 用于将虚拟机的伪物理内存对应的客户机页框号 GFN 映射到一共享零页, 所述共享零页为物理内存中页面内容全为零的页; 当所 述虚拟机写所述 GFN时, 如果产生页面异常则分配物理内存页以解除所述 客户机页框号 GFN与所述共享零页的映射关系, 并建立所述客户机页框号 GFN与所述物理内存页的机器页框号 MFN的映射关系。
进一步地, 该虚拟机监控器, 还可以用于在为所述虚拟机分配了物理内 存页后, 更新所述虚拟机的内存使用增量; 当所述内存使用增量达到预设的 阈值时, 对虚拟机启动过程中分配的物理内存页进行扫描, 将搜索到的内容 为零的内存页释放或加入至内存池中, 并将 GFN重新映射到共享零页上, 在扫描完成后将内存使用增量置零。
再请参阅图 2, 以下进行更为详细的说明:
硬件层: 作为虚拟化环境运行的整个硬件平台, 具体可以包括处理器 CPU, 内存 Memory、 网卡 (NIC, Network Interface Card) 、 外部存储设备 等高速 I/O设备和基本输入输出等低速设备。
宿主机 Host或者虚拟机监控器 VMM: 虚拟机监控器 (VMM) 作为一 个管理层, 其主要功能包括: 完成硬件资源的管理、 分配; 为虚拟机呈现一 个虚拟硬件平台; 以及执行虚拟机的调度和隔离。 可选地, 有些 VMM的实 现里面需要一个特权虚拟机配合, 两者结合组成宿主机。 虚拟硬件平台对其 上的虚拟机提供各种硬件资源, 如虚拟处理器 VCPU、 虚拟内存、 虚拟磁 盘、 虚拟网卡等。 其中虚拟内存对于 VM而言, 是一个隔离的、 从零开始且 具有连续性的伪物理内存空间, VMM为每个 VM建立一个 P2M表以将 GFN转换成 MFN (Machine Frame Number, 机器页框号) , 从而使虚拟内 存离散分布在物理内存中。
一个或多个虚拟机 VM: 虚拟机运行宿主机为其准备的虚拟平台中。 大 多数时间虚拟机的执行不受宿主机的影响。
较佳地, GFN到 MFN的映射由 p2m表记录。 如图 2中的 p2m表所示, p2m表由 p2m表项组成, p2m表项中记录了 mfn。 把 gfn作为索引, 能找到 唯一一个 p2m表项, 从而找到 mfn。 假设共享零页的 mfn等于 ml, 那么在 虚拟机创建阶段, host/vmm用虚拟机伪物理内存对应的全部 GFN去索引该 虚拟机对应的 p2m表, 在每个 GFN索引到的 p2m项中 MFN的位置填入 ml ; 假设虚拟机创建完成后, 开始写内存, 该内存所在的 GFN为 g2, 且产 生页面异常, host/vmm开始处理该异常, 并分配一页物理内存, 假设该物理 内存的 MFN等于 m2, host/vmm将 m2内存页清零后把 m2填入 g2索引 p2m 表得到的表项, 从而解除 g2到共享零页的映射; 在零页扫描阶段, 假设 host/vmm发现虚拟机伪物理内存的 GFN为 g3对应的 MFN 内存页 m3是零 页, host/vmm把 g3索引 p2m表得到的表项中填入 ml , 使其重新映射到共 享零页上, 最后 host/vmm回收 m3, 使其成为空闲内存页。
可选地, 该虚拟机监控器还可以用于在为所述虚拟机分配了物理内存页 后, 更新所述虚拟机的内存使用增量; 当内存使用增量达到预设的阈值时, 对虚拟机启动过程中分配的物理内存页进行扫描, 将搜索到的内容为零的内 存页释放或加入至内存池中, 并将 GFN重新映射到共享零页上, 在扫描完 成后将内存使用增量置零。 本发明实施例是实时扫描虚拟机启动过程中使用 的内存页, 而不是全局扫描, 从而可以提高扫描效率低, 降低扫描间隔。 其 中, 释放表示 host/vmm 回收一页内存, 使其成为空闲内存。 需要说明的 是, 虚拟机的内存使用增量是一个计数值, 用来表示距离上一次零页扫描以 来, 虚拟机由于写内存而解除原本映射到共享零页上的 GFN的数量; 如果 这个计数值超过了阈值, 那么就启动新的一次零页扫描, 扫描结束后将计数 值置零, 即把内存使用增量置零, 开始下一轮计数。 也就是说内存使用增量 就是零页扫描间隔内解除映射到共享零页上的 GFN的数量。
本发明实施例的系统, 可以减少虚拟机启动过程中的内存使用量, 提高 虚拟机密度, 支持并发启动 Memory Overcommitted数量的虚拟机, 并使虚 拟机启动过程当中内存使用量单调递增。
实施例二:
本发明实施例二提供了一种虚拟机监控器 VMM。 请继续参阅图 2, 该 虚拟机监控器包括:
初始化虚拟内存单元 210, 用于将虚拟机的伪物理内存对应的客户机页 框号 GFN映射到一共享零页, 该共享零页为物理内存中页面内容全为零的 页;
写时拷贝单元 220, 用于当上述虚拟机写所述 GFN时, 如果产生页面异 常则分配物理内存页以解除所述客户机页框号 GFN与所述共享零页的映射 关系, 并建立所述客户机页框号 GFN与物理内存页的机器页框号 MFN的映 射关系。
具体地, 初始化虚拟内存单元 210, 具体用于在虚拟机伪物理地址到机 器物理地址的映射关系 P2M表中, 将所述虚拟机的伪物理内存对应的全部 GFN都索引至所述共享零页的机器页框号 MFN。
具体地, 写时拷贝单元 220, 具体用于在虚拟机伪物理地址到机器物理 地址的映射关系 P2M表中, 将所述客户机页框号 GFN索引至所述物理内存 页的机器页框号 MFN。
具体地, 初始化虚拟内存单元 210, 用于将 VM的所有 GFN都映射到
VMM分配的共享零页上。 该初始化虚拟内存单元 210在创建虚拟机时被 VMM调用。
由于 VM的 GFN到该共享零页的映射是只读映射, 所以当 VM写映射 到共享零页的 GFN时会产生异常, VMM捕获该异常并调用写时拷贝 Copy on Write单元。 写时拷贝 Copy on Write单元 220具有以下功能: 首先分配一 块物理内存页并将这页清零; 接着解除产生异常的 GFN到共享零页的映射 关系; 最后将产生异常的 GFN重新映射到上述分配的物理内存页对应的 MFN上。 写时拷贝单元, 还用于判断内存池中是否包含零页, 如是, 则从所 述内存池中获取零页并分配给虚拟机。
在一较佳实施例中, 如图 2所示, 该虚拟机监控器还进一步包括: 阈值 控制单元 230和零页扫描单元 240; 该阈值控制单元 230, 用于判断已分配 的物理内存页的数量是否达到预设的阈值, 如是, 则启动该零页扫描单元; 该零页扫描单元 240, 用于对上述已分配的物理内存页进行扫描, 并释放扫 描到的的零页或者将扫描到的零页放入内存池中
具体地, 阈值控制单元 230, 与写时拷贝单元 220连接, 随着 VM不断 地写映射到共享零页的 GFN, VM占用的物理内存页也在不断增加, 因此阈 值控制单元 230的功能包括: 判断 VM增加的内存页数量是否超过预设的阈 值, 如果 VM增加的内存页数量超过预设的阈值, 则启动零页扫描单元, 例 如当 VM使用的内存量超过 4096页时启动零页扫描单元。
零页扫描单元 240, 与阈值控制单元 230连接, 在 VM启动阶段中 GOS 大量写内存操作是往内存页中写零, 所以零页扫描单元 240的功能包括: 对 VM触发写异常后调用写时拷贝单元为虚拟机分配的物理内存页进行扫描, 以搜索到上述分配的物理内存页中内面内容全为零的页, 将内容为全零的内 存页对应的 GFN重新映射共享零页上, 并释放该 GFN之前映射的物理内存 页。
写时拷贝单元 220, 还可进一步用于判断内存池中是否包含零页, 如 是, 则从该内存池中获取零页并分配给虚拟机, 如否, 则从空闲内存中分配 页给虚拟机。
本发明实施例的虚拟机监控器, 可以减少虚拟机启动过程中的内存使用 量, 提高虚拟机密度, 支持并发启动 Memory Overcommitted数量的虚拟 机, 并使虚拟机启动过程当中内存使用量单调递增。 如果虚拟机的内存使用 量是单调递增的, 那么可以确定某个时刻所有虚拟机使用的内存总量不会超 过某个值, 这样可以减少 Memory Overcommitted失效。 如果虚拟机的内存 使用量与时间轴形成的是带有波峰波谷的曲线, 那么无法确定到底最多能同 时启动多少台虚拟机。 如果虚拟机的内存使用量与时间轴形成的是与时间轴 平行的直线, 那么能够启动虚拟机的数量受到理内存大小的限制。
实施例三:
本发明实施例三提供了一种创建虚拟机的方法, 图 3是本发明实施例 3 的一种创建虚拟机的方法的整体流程图, 如图 3所示, 该方法包括:
步骤 310、 将虚拟机的伪物理内存对应的客户机页框号 GFN映射到共享 零页, 所述共享零页为物理内存中页面内容全为零的页;
步骤 320、 当所述虚拟机写所述 GFN时, 如果产生页面异常则分配物理 内存页以解除所述客户机页框号 GFN与所述共享零页的映射关系, 并建立 所述客户机页框号 GFN与所述物理内存页的机器页框号 MFN的映射关系。
具体地, 步骤 310 中将所述虚拟机的伪物理内存对应的客户机页框号 GFN都映射到一共享零页可以包括如下过程: 在虚拟机伪物理地址到机器物 理地址的映射关系 P2M表中, 将所述虚拟机的伪物理内存对应的全部 GFN 都索引至所述共享零页的机器页框号 MFN。
具体地, 步骤 320中建立所述客户机页框号 GFN与所述物理内存页的机 器页框号 MFN的映射关系可以包括如下过程: 在虚拟机伪物理地址到机器 物理地址的映射关系 P2M表中, 将所述客户机页框号 MFN索引至所述物理 内存页的机器页框号 MFN。
较佳地, 在步骤 320中分配物理内存页后, 图 3所示方法还可以包括步 骤: 判断已分配的物理内存页的数量是否达到预设的阈值, 如是, 则对所述 已分配的物理内存页进行扫描, 并释放扫描到的零页或者将扫描到的零页放 入内存池中。
较佳地, 在步骤 320中分配物理内存页的具体过程还可以包括: 判断内 存池中是否包含零页, 如是, 则从所述内存池中获取零页并分配给虚拟机, 如否, 则从空闲内存中分配页给虚拟机。
本发明实施例三的方法, 可以减少虚拟机启动过程中的内存使用量, 提 高虚拟机密度, 支持并发启动 Memory Overcommitted数量的虚拟机, 并使 虚拟机启动过程当中内存使用量单调递增。
以下通过实施例四和实施例五, 对实施例三的方法进行更为详细的说 明。
实施例四:
虚拟机启动可以分为两个过程: 第一, 在虚拟机创建阶段, 创建虚拟机 并分配必要的资源, VMM为了安全起见, 分配给虚拟机的内存是经过清零 的; 第二, 启动 Guest OS (客户操作系统, GOS) 的阶段, GOS对内存的使 用包括两部分, 即用于存放内核代码及数据的内存和空闲内存, GOS为了安 全起见会对空闲内存做清零工作。 从前述分析可以看出, 在现有 Memory Overcommitted方法中, 要么没有考虑虚拟机启动这种场景, 要么没有考虑 虚拟机启动过程中 Guest OS对内存的使用。
在本发明实施例中, 充分考虑了上述两种场景, 首先, 在创建虚拟机时 将客户机内存页全部共享映射到一张内容为零的机器物理页, 即共享零页 上, 接着, 在虚拟机写 GFN (Guest Frame Number, 客户机页框号) 时产生 异常并用 CoW (Copy on Write, 写时拷贝) 机制解除共享, 并记录虚拟机的 内存使用增量, 当内存使用增量超过预设的阈值时, 启用零页扫描, 搜索到 内容为零的空闲页, 将内容为零的页释放并将 GFN重新映射到共享零页 上, 通过上述方法可减少虚拟机启动时内存使用量。
图 4为本发明实施例四的方法流程图。 结合参阅图 2和图 4, 该流程包 括如下步骤:
步骤 10、 创建 VM;
步骤 11、 将所有 GFN都映射到共享零页; 零页是指 VM的数据全为零 的内存页; VM中的零页是冗余的, 在整个系统中, 零页只需要一份就行, 因此本发明实施例将 VM中的原本是零页的 GFN都共享映射到这一份零页 上, 这份给 VM共享的零页叫共享零页。
步骤 12、 启动客户操作系统 Guest OS;
具体地, 在步骤 10-12中, 创建虚拟机并启动 Guest OS, 在创建虚拟内 存时并不给虚拟机分配任何物理内存资源, 而是由初始化虚拟内存单元将 VM的所有 GFN都映射到 VMM分配的共享零页上。 尽管此时 VM没有物理 内存资源, 但是 VM通过 P2M表仍然能获知全额并且内容都为零的虚拟内 存, 所以 Guest OS仍能够启动。
步骤 20、 VM写 GFN;
步骤 21、 判断是否产生页面异常 PageFault, 如是, 则转入步骤 22a, 如 否, 则转入步骤 22b;
步骤 22a、 CoW单元申请物理内存页, 更新 P2M表, 并使内存使用增量 加 1 ; 更新 P2M表是指: 解除所访问的 GFN与共享零页的映射关系, 并将 所访问的 GFN映射至申请的物理内存页;
步骤 22b、 VM访问已经申请的页; 具体地, 在步骤 20、 步骤 21和步骤 22a中, VM开始使用虚拟内存, 使 用内存操作包括读内存和写内存。 如果是写内存操作并且所访问的 GFN是 映射到共享零页上的, 则处理器将产生页面异常 PageFault。 VMM开始处理 这个异常, VMM调用 CoW单元解除所访问的 GFN到共享零页的映射关 系, CoW单元再将所访问的 GFN重新映射到一个新分配的且页内容为全零 的 MFN上, 在这种情况下, VMM还更新 VM的内存使用增量计数, 将这个 计数值加 1。 其中解除映射关系及重新映射是由 CoW单元完成。 在步骤 20、 步骤 21和步骤 22b中, 如果 VM写的 GFN不是映射到共享零页上, 则 不会产生 PageFault异常, VM正常使用内存。
步骤 30、 判断 VM的内存使用增量是否小于预设的阈值, 如是, 则转入 步骤 20, 如否, 则转入步骤 40;
步骤 40、 扫描零页, 并将内存使用增量置零;
步骤 41、 释放零页。
具体地, 在 CoW单元写成申请物理内存页、 解除及重新建立映射关系 之后, 阈值控制单元, 根据内存使用增量与预设的阈值之间的关系判断是否 需要启动零页扫描单元。 如果不需要启动零页扫描单元, 则 VMM从异常处 理流程中退出, 返回到 VM中, VM继续运行, 如图 4中步骤 30和步骤 20 所示;
如果内存增量已经超过阈值, 则启动零页扫描单元, 阈值的大小可以由 虚拟配置文件制定, 也可以是 VMM设定的默认值, 例如 32MB。
在步骤 40 中, 如果需要进行零页扫描, 则零页扫描单元开始扫描已经 分配给 VM的物理内存, 把内容为全零的页对应的 GFN重新映射到共享零 页上, 并释放这些内容为零的物理页且将内存增量置为 0。 扫描零页是指: 找到 VM的内存页中内容为全零的页。 扫描 VM的物理页时, 可以扫描 VM 当前拥有的全部物理页, 也可以只扫描增量内存。 如果只扫描增量内存则需 要步骤 22a完成后记录相应的 MFN, 也即 VM新增的物理页对应的 MFN, 记录的数据结构可以是二进制位图 (Bitmap) 或是链表等数据结构。 这一步 完成后从异常处理流程中退出, 返回到 VM中, VM继续运行。 图 4中的流 程运行直到阈值控制单元单元收到启动完成通知消息, 这个消息的发送者可 以是 VMM本身、 特权域或者 VM的前端驱动。
本发明实施例四的方法, 可以减少虚拟机启动过程中的内存使用量, 提 高虚拟机密度, 支持并发启动 Memory Overcommitted数量的虚拟机, 并使 虚拟机启动过程当中内存使用量单调递增。
实施例五:
实施例四的流程中, 零页扫描单元将零页重新映射到共享零页上后, 直 接释放物理内存页, 而 CoW单元每次都重新申请一块物理内存页, 因此为 提高性能, 实施例五中将零页扫描单元发现的零页先放入一个内存池, CoW 单元申请内存页时先从该内存池中获取, 如果内存已经为空再由 VMM分配 物理页。 通过本发明实施例五, 可以减少本发明实现流程中的反复先申请后 释放的操作, 从而提高效率。
本发明实施例五图 5的具体流程与本发明实施例四图 4类似, 不同之处 在于:
第一, 图 4中步骤 22a在图 5中对应于以下两种情况:
一种情况, 如图 5中步骤 120、 步骤 121b和步骤 123所示, 当内存池不 为空的时候, VMM在为 GFN重新分配页时从内存池中取出一页, 并把 GFN 映射到该页对应的 MFN上, 接着将内存使用增量加一。
另一种情况, 当内存池为空时, 执行图 5中的步骤 120、 步骤 121a、 步 骤 122和步骤 123, 完成与图 4中 22a—样的操作, 即 VMM重新分配一块 物理内存页并清零, 然后把 GFN映射到该物理内存页对应的 MFN上, 最后 将内存使用增量加一。
第二, 图 4中的步骤 41变为图 5中的步骤 141。 当零页扫描单元发现内 容为零的页后将该页的 GFN映射到共享零页上, 并把扫描到的零页放入内 存池中。
零页扫描单元扫描到的零页 GFN重新映射到共享零页后, 将 GFN之 前对应得 MFN被放入了内存池, 而 CoW单元申请内存时又从内存池中取 页, 因此可以不要释放零页这个步骤, 相应地把释放零页这个步骤换成了将 零页加入内存池的步骤。 从而有利于减少重复的申请内存池和释放内存。
根据图 5流程可知, 内存池的大小不会超过增量阈值, 因此内存可以 用数组或链表等线性表数据结构表示。 这种线性表适用简单且效率高。
本发明实施例的有益效果: 1、 节省虚拟机启动过程中的内存使用量; 2、 支持并发启动 Memory Overcommitted数量的虚拟机; 这里强调的是并发 数量, 因为通过本发明实施例的方法能使 VM尽量少的占用内存, 并且 VM 的内存使用量是单调递增的, 因此能够增加并发启动 VM的数量 3、 虚拟机 启动过程当中内存使用量单调递增; 4、 提高了虚拟机密度; 5、 该方法可以 应用于小型机虚拟化和聚合虚拟化等虚拟化领域。
本领域普通技术人员可以意识到, 结合本文中所公开的实施例描述的各 示例的单元及算法步骤, 能够以电子硬件、 计算机软件或者二者的结合来实 现, 为了清楚地说明硬件和软件的可互换性, 在上述说明中已经按照功能一 般性地描述了各示例的组成及步骤。 这些功能究竟以硬件还是软件方式来执 行, 取决于技术方案的特定应用和设计约束条件。 专业技术人员可以对每个 特定的应用来使用不同方法来实现所描述的功能, 但是这种实现不应认为超 出本发明的范围。
结合本文中所公开的实施例描述的方法或算法的步骤可以用硬件、 处理 器执行的软件模块, 或者二者的结合来实施。 软件模块可以置于随机存储器 (RAM) 、 内存、 只读存储器 (ROM) 、 电可编程 ROM、 电可擦除可编程 ROM, 寄存器、 硬盘、 可移动磁盘、 CD-ROM、 或技术领域内所公知的任意 其它形式的存储介质中。
以上所述, 仅为本发明较佳的具体实施方式, 但本发明的保护范围并不 局限于此, 任何熟悉本技术领域的技术人员在本发明揭露的技术范围内, 可 轻易想到的变化或替换, 都应涵盖在本发明的保护范围之内。 因此本发明的 保护范围应该以权利要求的保护范围为准。

Claims

权利要求书
1、 一种创建虚拟机的方法, 其特征在于, 所述方法包括:
将虚拟机的伪物理内存对应的客户机页框号 GFN映射到共享零页, 所 述共享零页为物理内存中页面内容全为零的页;
当所述虚拟机写所述 GFN时, 如果产生页面异常则分配物理内存页以 解除所述客户机页框号 GFN与所述共享零页的映射关系, 并建立所述客户 机页框号 GFN与所述物理内存页的机器页框号 MFN的映射关系。
2、 根据权利要求 1所述的方法, 其特征在于, 将所述虚拟机的伪物理 内存对应的客户机页框号 GFN映射到一共享零页包括:
在虚拟机伪物理地址到机器物理地址的映射关系 P2M表中, 将所述虚拟 机的伪物理内存对应的全部 GFN都索引至所述共享零页的机器页框号
3、 根据权利要求 1所述的方法, 其特征在于, 建立所述客户机页框号 GFN与所述物理内存页的机器页框号 MFN的映射关系包括:
在虚拟机伪物理地址到机器物理地址的映射关系 P2M表中, 将所述客户 机页框号 GFN索引至所述物理内存页的机器页框号 MFN。
4、 根据权利要求 1所述的方法, 其特征在于, 在分配物理内存页后, 所述方法还包括:
判断已分配的物理内存页的数量是否达到预设的阈值, 如是, 则对所述 已分配的物理内存页进行扫描, 并释放扫描到的零页或者将扫描到的零页放 入内存池中。
5、 根据权利要求 1所述的方法, 其特征在于, 所述分配物理内存页包 括:
判断内存池中是否包含零页, 如是, 则从所述内存池中获取零页并分配 给虚拟机, 如否, 则从空闲内存中分配页给虚拟机。
6、 一种虚拟机监控器, 其特征在于, 所述虚拟机监控器包括: 初始化虚拟内存单元, 用于将虚拟机的伪物理内存对应的客户机页框号 GFN映射到一共享零页, 所述共享零页为物理内存中页面内容全为零的页; 写时拷贝单元, 用于当所述虚拟机写所述 GFN时, 如果产生页面异常 则分配物理内存页以解除所述客户机页框号 GFN与所述共享零页的映射关 系, 并建立所述客户机页框号 GFN与所述物理内存页的机器页框号 MFN的 映射关系。
7、 根据权利要求 6所述的虚拟机监控器, 其特征在于, 所述初始化虚 拟内存单元, 具体用于在虚拟机伪物理地址到机器物理地址的映射关系 P2M 表中, 将所述虚拟机的伪物理内存对应的全部 GFN都索引至所述共享零页 的机器页框号 MFN。
8、 根据权利要求 6所述的虚拟机监控器, 其特征在于, 所述写时拷贝 单元, 具体用于在虚拟机伪物理地址到机器物理地址的映射关系 P2M表中, 将所述客户机页框号 GFN索引至所述物理内存页的机器页框号 MFN。
9、 根据权利要求 6所述的虚拟机监控器, 其特征在于, 所述虚拟机监 控器还包括: 阈值控制单元和零页扫描单元;
所述阈值控制单元, 用于判断已分配的物理内存页的数量是否达到预设 的阈值, 如是, 则启动所述零页扫描单元;
所述零页扫描单元, 用于对所述已分配的物理内存页进行扫描, 并释放 扫描到的零页或者将扫描到的零页放入内存池中。
10、 根据权利要求 6所述的虚拟机监控器, 其特征在于, 所述写时拷贝 单元, 还用于判断内存池中是否包含零页, 如是, 则从所述内存池中获取零 页并分配给虚拟机, 如否, 则从空闲内存中分配页给虚拟机。
11、 一种虚拟机系统, 其特征在于, 所述系统包括: 虚拟机监控器和虚 拟机;
所述虚拟机监控器, 用于将虚拟机的伪物理内存对应的客户机页框号 GFN映射到一共享零页, 所述共享零页为物理内存中页面内容全为零的页; 当所述虚拟机写所述 GFN时, 如果产生页面异常则分配物理内存页以解除 所述客户机页框号 GFN与所述共享零页的映射关系, 并建立所述客户机页 框号 GFN与所述物理内存页的机器页框号 MFN的映射关系。
12、 根据权利要求 11所述的虚拟机系统, 其特征在于, 所述虚拟机监 控器, 还用于在为所述虚拟机分配了物理内存页后, 更新所述虚拟机的内存 使用增量; 当所述内存使用增量达到预设的阈值时, 对虚拟机启动过程中分 配的物理内存页进行扫描, 将搜索到的内容为零的内存页释放或加入至内存 池中, 并将 GFN重新映射到共享零页上, 在扫描完成后将内存使用增量置
PCT/CN2011/080573 2011-03-15 2011-10-09 一种创建虚拟机的方法、虚拟机监控器及虚拟机系统 Ceased WO2012122796A1 (zh)

Priority Applications (3)

Application Number Priority Date Filing Date Title
ES11799061.4T ES2581597T3 (es) 2011-03-15 2011-10-09 Método para crear una máquina virtual, monitor de máquinas virtuales y sistema de máquinas virtuales
EP11799061.4A EP2581828B1 (en) 2011-03-15 2011-10-09 Method for creating virtual machine, virtual machine monitor and virtual machine system
US13/339,862 US9183157B2 (en) 2011-03-15 2011-12-29 Method for creating virtual machine, a virtual machine monitor, and a virtual machine system

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201110061738.5A CN102141931B (zh) 2011-03-15 2011-03-15 一种创建虚拟机的方法、虚拟机监控器及虚拟机系统
CN201110061738.5 2011-03-15

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US13/339,862 Continuation US9183157B2 (en) 2011-03-15 2011-12-29 Method for creating virtual machine, a virtual machine monitor, and a virtual machine system

Publications (1)

Publication Number Publication Date
WO2012122796A1 true WO2012122796A1 (zh) 2012-09-20

Family

ID=44409470

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2011/080573 Ceased WO2012122796A1 (zh) 2011-03-15 2011-10-09 一种创建虚拟机的方法、虚拟机监控器及虚拟机系统

Country Status (5)

Country Link
US (1) US9183157B2 (zh)
EP (1) EP2581828B1 (zh)
CN (1) CN102141931B (zh)
ES (1) ES2581597T3 (zh)
WO (1) WO2012122796A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113254147A (zh) * 2021-04-29 2021-08-13 中国科学院信息工程研究所 一种基于物理地址陷入的虚拟机行为监控方法及系统
CN113449292A (zh) * 2020-03-27 2021-09-28 支付宝(杭州)信息技术有限公司 一种可信应用的运行方法、装置及设备

Families Citing this family (37)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9135038B1 (en) * 2010-05-28 2015-09-15 Bromium, Inc. Mapping free memory pages maintained by a guest operating system to a shared zero page within a machine frame
US9104544B1 (en) 2010-05-28 2015-08-11 Bromium, Inc. Mitigating eviction by maintaining mapping tables
US9354906B1 (en) 2010-05-28 2016-05-31 Bromium, Inc. Managing the eviction process
CN102141931B (zh) * 2011-03-15 2014-06-11 华为技术有限公司 一种创建虚拟机的方法、虚拟机监控器及虚拟机系统
US9280458B2 (en) * 2011-05-12 2016-03-08 Citrix Systems, Inc. Reclaiming memory pages in a computing system hosting a set of virtual machines
CN102779074B (zh) * 2012-06-18 2015-04-08 中国人民解放军国防科学技术大学 基于内存空洞机制的虚拟机内存资源分配方法
CN102981962B (zh) * 2012-10-26 2015-03-04 华中科技大学 一种快速扫描全虚拟化虚拟机脏页位图的方法
CN103970555B (zh) * 2013-01-31 2017-09-12 中兴通讯股份有限公司 自适应的虚拟机启动控制方法及装置
US9712610B2 (en) * 2013-10-01 2017-07-18 Vmware, Inc. System and method for increasing physical memory page sharing by workloads
MY175073A (en) * 2013-11-29 2020-06-04 Mimos Berhad Method and system for iaas image creation
US9459900B2 (en) 2014-01-13 2016-10-04 Red Hat Israel, Ltd. Hypervisor-based balloon page initialization
GB2526088B (en) * 2014-05-12 2016-03-30 Sony Comp Entertainment Europe Apparatus and method of data capture
CN105204977A (zh) * 2014-06-30 2015-12-30 中兴通讯股份有限公司 一种系统异常的捕获方法、主系统、影子系统及智能设备
US9389901B2 (en) * 2014-09-09 2016-07-12 Vmware, Inc. Load balancing of cloned virtual machines
US9965311B2 (en) 2015-11-10 2018-05-08 Red Hat Israel, Ltd. Application of a pattern to inactive pages in guest memory
US10216529B1 (en) * 2015-11-19 2019-02-26 Virtuozzo International Gmbh Method and system for sharing driver pages
WO2017119128A1 (ja) * 2016-01-08 2017-07-13 株式会社日立製作所 計算機システム、物理計算機、及び、メモリ制御方法
CN107783812B (zh) * 2016-08-24 2022-03-08 阿里巴巴集团控股有限公司 虚拟机内存管理方法及装置
US9672062B1 (en) * 2016-12-01 2017-06-06 Red Hat, Inc. Batched memory page hinting
CN108196934B (zh) * 2016-12-08 2022-04-26 阿里巴巴集团控股有限公司 一种定时器的定时设置方法、装置和虚拟化设备
US10735279B2 (en) 2017-04-14 2020-08-04 Futurewei Technologies, Inc. Networking service level agreements for computer datacenters
US10579439B2 (en) 2017-08-29 2020-03-03 Red Hat, Inc. Batched storage hinting with fast guest storage allocation
US10956216B2 (en) 2017-08-31 2021-03-23 Red Hat, Inc. Free page hinting with multiple page sizes
CN109426547B (zh) * 2017-09-04 2022-05-17 华为技术有限公司 一种虚拟机的热迁移方法、装置和系统
CN107832143B (zh) * 2017-10-17 2020-11-03 北京京东尚科信息技术有限公司 一种物理机资源的处理方法和装置
US10474382B2 (en) 2017-12-01 2019-11-12 Red Hat, Inc. Fast virtual machine storage allocation with encrypted storage
CN109309584A (zh) * 2018-09-03 2019-02-05 郑州云海信息技术有限公司 一种虚拟机密度配置方法、装置、终端及存储介质
JP7151530B2 (ja) * 2019-02-13 2022-10-12 日本電信電話株式会社 サーバ基盤および物理cpu割当プログラム
US10713181B1 (en) * 2019-02-21 2020-07-14 Virtuozzo International Gmbh Method and system for sharing driver pages
US20200409576A1 (en) * 2019-06-25 2020-12-31 Intel Corporation Physical page tracking for handling overcommitted memory in a virtualized environment
CN110888823B (zh) * 2019-11-26 2022-01-21 深圳忆联信息系统有限公司 页扫描效率的提升方法、装置及计算机设备
US11436141B2 (en) 2019-12-13 2022-09-06 Red Hat, Inc. Free memory page hinting by virtual machines
US11409619B2 (en) 2020-04-29 2022-08-09 The Research Foundation For The State University Of New York Recovering a virtual machine after failure of post-copy live migration
CN114077379B (zh) * 2020-08-19 2024-03-26 华为技术有限公司 一种计算机设备、异常处理的方法以及中断处理的方法
CN115408138B (zh) * 2021-05-26 2025-05-16 华为技术有限公司 一种内存页处理方法及其相关设备
CN113900775B (zh) * 2021-12-08 2022-08-02 北京交研智慧科技有限公司 一种边端云计算跨节点虚拟机处理方法及装置
CN119718610A (zh) * 2023-09-27 2025-03-28 华为技术有限公司 处理物理内存中的零页的方法、装置、设备和存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050235123A1 (en) * 2004-04-19 2005-10-20 Zimmer Vincent J Method to manage memory in a platform with virtual machines
CN101158924A (zh) * 2007-11-27 2008-04-09 北京大学 一种虚拟机管理器的动态内存映射方法
CN101697134A (zh) * 2009-10-27 2010-04-21 北京大学 一种支持相似虚拟机快速启动的方法
CN102141931A (zh) * 2011-03-15 2011-08-03 华为技术有限公司 一种创建虚拟机的方法、虚拟机监控器及虚拟机系统

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7222221B1 (en) * 2004-02-06 2007-05-22 Vmware, Inc. Maintaining coherency of derived data in a computer system
US8615643B2 (en) * 2006-12-05 2013-12-24 Microsoft Corporation Operational efficiency of virtual TLBs
CN101477492B (zh) * 2009-01-21 2010-12-29 华中科技大学 一种用于固态硬盘的循环重写闪存均衡方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050235123A1 (en) * 2004-04-19 2005-10-20 Zimmer Vincent J Method to manage memory in a platform with virtual machines
CN101158924A (zh) * 2007-11-27 2008-04-09 北京大学 一种虚拟机管理器的动态内存映射方法
CN101697134A (zh) * 2009-10-27 2010-04-21 北京大学 一种支持相似虚拟机快速启动的方法
CN102141931A (zh) * 2011-03-15 2011-08-03 华为技术有限公司 一种创建虚拟机的方法、虚拟机监控器及虚拟机系统

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP2581828A4 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113449292A (zh) * 2020-03-27 2021-09-28 支付宝(杭州)信息技术有限公司 一种可信应用的运行方法、装置及设备
CN113449292B (zh) * 2020-03-27 2022-07-29 支付宝(杭州)信息技术有限公司 一种可信应用的运行方法、装置及设备
CN113254147A (zh) * 2021-04-29 2021-08-13 中国科学院信息工程研究所 一种基于物理地址陷入的虚拟机行为监控方法及系统
CN113254147B (zh) * 2021-04-29 2024-01-16 中国科学院信息工程研究所 一种基于物理地址陷入的虚拟机行为监控方法及系统

Also Published As

Publication number Publication date
US9183157B2 (en) 2015-11-10
EP2581828A4 (en) 2013-09-18
US20120239850A1 (en) 2012-09-20
CN102141931B (zh) 2014-06-11
EP2581828B1 (en) 2016-04-13
CN102141931A (zh) 2011-08-03
EP2581828A1 (en) 2013-04-17
ES2581597T3 (es) 2016-09-06

Similar Documents

Publication Publication Date Title
WO2012122796A1 (zh) 一种创建虚拟机的方法、虚拟机监控器及虚拟机系统
JP7592584B2 (ja) ホストコンピューティングデバイスの仮想メモリによって支援された仮想マシンメモリへのより高速なアクセス
EP3608787B1 (en) Virtualizing isolation areas of solid-state storage media
US9720717B2 (en) Virtualization support for storage devices
US8788739B2 (en) Hypervisor-based management of local and remote virtual memory pages
US8539137B1 (en) System and method for management of virtual execution environment disk storage
US8601201B2 (en) Managing memory across a network of cloned virtual machines
CN111919201B (zh) 混合式存储器系统
EP2664990A1 (en) Method and device for implementing memory migration
CN111868678B (zh) 混合存储器系统
CN116680233A (zh) 一种文件访问方法、系统、电子设备及机器可读存储介质
US11151064B2 (en) Information processing apparatus and storage device access control method
WO2023165308A1 (zh) 一种内存回收方法、装置及控制设备
US11656982B2 (en) Just-in-time virtual per-VM swap space
CN111868679B (zh) 混合存储器系统
JP2024527054A (ja) 動的割当可能な物理的にアドレス指定されるメタデータストレージ
CN110447019B (zh) 存储器分配管理器及由其执行的用于管理存储器分配的方法
US11366700B1 (en) Hierarchical workload allocation in a storage system
US20220318042A1 (en) Distributed memory block device storage
US20260010489A1 (en) Write-only swapping of memory pages in a computing environment
US20230266992A1 (en) Processor for managing resources using dual queues, and operating method thereof
Kul The Case for Physical Memory Pools: A Vision Paper

Legal Events

Date Code Title Description
WWE Wipo information: entry into national phase

Ref document number: 2011799061

Country of ref document: EP

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 11799061

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE