WO2012149844A1 - 一种虚拟机内存快照生成和恢复方法、装置及系统 - Google Patents

一种虚拟机内存快照生成和恢复方法、装置及系统 Download PDF

Info

Publication number
WO2012149844A1
WO2012149844A1 PCT/CN2012/072887 CN2012072887W WO2012149844A1 WO 2012149844 A1 WO2012149844 A1 WO 2012149844A1 CN 2012072887 W CN2012072887 W CN 2012072887W WO 2012149844 A1 WO2012149844 A1 WO 2012149844A1
Authority
WO
WIPO (PCT)
Prior art keywords
page
memory
current
type
recorded
Prior art date
Application number
PCT/CN2012/072887
Other languages
English (en)
French (fr)
Inventor
叶川
Original Assignee
华为技术有限公司
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 华为技术有限公司 filed Critical 华为技术有限公司
Priority to EP12779387.5A priority Critical patent/EP2755132B1/en
Publication of WO2012149844A1 publication Critical patent/WO2012149844A1/zh
Priority to US14/251,785 priority patent/US9507672B2/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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 operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1458Management of the backup or restore process
    • G06F11/1469Backup restoration techniques
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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 operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1415Saving, restoring, recovering or retrying at system level
    • G06F11/1438Restarting or rejuvenating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/46Multiprogramming arrangements
    • G06F9/461Saving or restoring of program or task context
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2201/00Indexing scheme relating to error detection, to error correction, and to monitoring
    • G06F2201/815Virtual
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2201/00Indexing scheme relating to error detection, to error correction, and to monitoring
    • G06F2201/84Using snapshots, i.e. a logical point-in-time copy of the data

Definitions

  • the present invention relates to a memory snapshot technology, and in particular, to a method, device and system for generating and restoring a virtual machine memory snapshot.
  • a user can simulate one or more virtual machines (VMs) on a physical computer, and these virtual machines can work like real computers, for example, users can install an operating system. Install applications, access network resources, and more.
  • Virtual machine snapshot technology is generated simultaneously with virtualization technology. Since the computing and storage resources of virtual machines are virtualized by Virtual Machine Monitor (VMM), we can conveniently reserve virtual machines by snapshot technology. CPU state, memory status, and storage data at the point in time make it easy to implement cumbersome full-state backups on physical machines, making it easy for users to back up and restore virtual machines.
  • VMM Virtual Machine Monitor
  • snapshot applications There are two main types of snapshot applications: one is simple storage snapshots, only the backup data is stored.
  • the virtual machine users may use virtual machines for various reasons (virus, Trojan damage, accidental deletion of system files, misformats).
  • the virtual machine image is damaged or cannot be started normally. If the backup data is backed up when the virtual machine is normal through the storage snapshot, the page data of the backup point can be conveniently restored.
  • the storage snapshot and the memory snapshot are combined, because In these scenarios, users need to quickly create or restore virtual machines (the relevant service deployment is cumbersome and cumbersome, the service recovery time is high, and the VMs are quickly deployed in batches, etc.), or the current service status needs to be retained for some debugging needs.
  • VMWare Virtual Machine ware
  • the overall solution of the virtual machine snapshot is provided, including the storage snapshot and the memory snapshot.
  • the memory snapshot is a full copy of the black box of the memory data.
  • the generated snapshot file size is consistent with the virtual machine memory specification, that is, the virtual machine with 1G memory eventually
  • the generated memory snapshot file size is 1G, which is stored on the distributed storage together with the storage snapshot.
  • the snapshot file is also sequentially read for 1:1 memory restoration. Therefore, the snapshot generation process and the snapshot recovery process take a long time.
  • the generated memory snapshot file is the same as the virtual machine memory size, which is also a waste of storage resources. Summary of the invention
  • the embodiment of the invention provides a method, a device and a system for generating and restoring a virtual machine memory snapshot, so as to shorten the processing time of the virtual machine memory snapshot and save storage resources.
  • the embodiment of the present invention provides a virtual machine memory snapshot generation method, where the method includes: acquiring a current S memory page of the virtual machine;
  • the page type of the current S-th memory page is recorded in the memory snapshot file; when the current S-th memory page is a valid data page, the memory snapshot file Recording the page type and page data of the current S-th memory page.
  • an embodiment of the present invention provides a virtual machine memory snapshot recovery method, where the method includes:
  • an embodiment of the present invention provides a physical host, where the physical host includes: a hardware layer, a virtual machine monitor VMM running on the hardware layer, and a virtual machine monitor running on the virtual machine monitor
  • a virtual machine on the VMM where the virtual machine monitor VMM includes a memory snapshot generation module and a memory page identification module, where:
  • the memory snapshot generation module is configured to: acquire a current S-th memory page of the virtual machine; and when the memory page identification module identifies that the current S-th memory page is an invalid data page, record the location in the memory snapshot file a page type of the current S-th memory page; when the memory page identification module identifies that the current S-th memory page is a valid data page, recording a page type and page data of the current S-th memory page in the memory snapshot file ;
  • the memory page identification module is configured to: identify the current number acquired by the memory snapshot generation module
  • the page type including a non-valid data page and a valid data page
  • the hardware layer includes a storage device, and the storage device is configured to: store the memory snapshot file.
  • an embodiment of the present invention provides a computer system, where the system includes a physical host and a network storage device, where the physical host is a physical host provided by the embodiment of the present invention, and is used to execute a virtual machine memory snapshot file generation and Recovering; the network storage device is configured to store a virtual machine memory snapshot file of the physical host.
  • different snapshot generation processing is performed according to different memory page types in the memory snapshot generation process. , including: when the current S memory page is a non-valid data page, only the page type of the current S memory page is recorded in the memory snapshot file; when the current S memory page is a valid data page, the memory snapshot file Recording the page type and page data of the current Sth memory page; and, during the memory snapshot recovery process, performing different snapshot recovery processes according to different memory page types, including: when the current recorded in the memory snapshot file When the page type of the S-th memory page is a non-valid data page, the page type of the current S-th memory page is recorded as a non-valid data page in the VMM memory space; when the current S-th memory page recorded in the memory snapshot file When the page type is a valid data page, the page type of the current S memory page is recorded as a valid data page in
  • the snapshot file to the memory and recorded in this page data S th memory page corresponding to the copied The S-memory page of the virtual machine, so that only valid data is saved by the embodiment of the present invention, reducing backup and recovery of invalid data, greatly shortening the generation and recovery time of the memory snapshot, and reducing the memory snapshot to the storage resource. Occupied. DRAWINGS
  • FIG. 1 is a schematic flowchart of a method for generating a virtual machine memory snapshot according to an embodiment of the present invention
  • FIG. 2 is a schematic flowchart of another method for generating a virtual machine memory snapshot according to an embodiment of the present invention
  • FIG. 4 is a schematic diagram of a logical structure of a memory snapshot file according to an embodiment of the present invention
  • FIG. 5 is a schematic diagram of a logical structure of a memory snapshot file according to an embodiment of the present invention
  • FIG. 6 is a schematic flowchart of a virtual machine memory snapshot recovery method according to an embodiment of the present invention
  • FIG. 8 is a schematic flowchart of a virtual machine memory snapshot recovery method according to an embodiment of the present invention
  • FIG. 9 is a schematic diagram of a logical structure of a physical host according to an embodiment of the present invention
  • FIG. 10 is a schematic diagram showing the logical structure of a computer system according to an embodiment of the present invention.
  • FIG. 11 is a schematic diagram of physical deployment of a computer system according to an embodiment of the present invention.
  • a method for generating a virtual machine memory snapshot is provided in the first embodiment of the present invention. As shown in FIG. 1 , the method may include: Step S101: Acquire a current S memory page of the virtual machine.
  • This step can be to obtain the memory page in sequence, or to obtain the memory page in reverse order, without limitation.
  • Step S102 Identify a page type of the current Sth memory page, where the page type includes a non-valid data page and a valid data page.
  • Step S102 may be: identifying a page type of the current Sth memory page based on at least page type information saved in the VMM memory space, the page type including a non-valid data page and a valid data page.
  • step S102 is specifically: determining, according to page type information saved in a memory space of the virtual machine monitor VMM, a page type of the current S memory page, where the page type includes a balloon page (Balloon) ), opulate on demand (Pod), share page (share), swap page (swap), and normal page; where balloon page and time allocation page are non-valid data pages, shared pages, exchange pages, and The normal page is a valid data page.
  • the structure variable of the memory page type is maintained in the VMM memory space, where the normal page is the default value, and the type is changed and marked when other types of pages appear.
  • p2m_ram_paged 10 is the swap page
  • p2m-ram - share d 13 for the shared page
  • 2m_ram_rw 1 for the normal page.
  • step S102 may include step S201 and step S202, where:
  • Step S201 Determine, according to page type information saved in the VMM memory space, a page type of the current Sth memory page, where the page type includes a balloon page, a time allocation page, a shared page, a swap page, and a normal page;
  • Step S202 when the page type of the current S-th memory page is a normal page, traversing the content of the current S-th memory page, determining that the page type of the current S-th memory page is zero page or non-zero page; , Balloon pages, time-sharing pages, and zero pages are non-valid data pages, and non-zero pages, shared pages, and swap pages are valid data pages.
  • the memory page types enumerated in the embodiments of the present invention are some memory page types that may appear in the current virtual machine, and some applications are more, such as balloon pages, zero pages, and non-zero pages; For example, shared pages and exchange pages; time-sharing pages are currently not very versatile, but are also used in Xen open source virtual machines.
  • the embodiment of the present invention takes these page types as an example and is not intended to be limited to the identification of these page types. Regardless of other memory page types currently applied, or memory page types that may occur in the future, the memory snapshot generation and recovery method disclosed in the embodiments of the present invention should be within the scope of the present invention.
  • Step S103 when the current S-th memory page is a non-valid data page, record a page type of the current S-th memory page in a memory snapshot file; when the current S-th memory page is a valid data page, The page type and page data of the current S memory page are recorded in the memory snapshot file.
  • Step S103 may specifically include:
  • the page type of the current S memory page is recorded as a balloon page in the memory snapshot file
  • the page type of the current S memory page is recorded in the memory snapshot file as a time allocation page
  • the page type of the current S memory page is recorded as a swap page in the memory snapshot file, and the page data of the swap page is copied from the memory swap file into the memory snapshot file;
  • the page type of the current S memory page is recorded as a shared page in the memory snapshot file, the page data of the shared page is copied to the memory snapshot file, and the current S memory is recorded.
  • the page type of the current S memory page is recorded as a normal page in the memory snapshot file, and the page data of the normal page is copied to the memory snapshot file.
  • Step S103 may specifically include: When the current S memory page is a balloon page, the page type of the current S memory page is recorded as a balloon page in the memory snapshot file;
  • the page type of the current S memory page is recorded in the memory snapshot file as a time allocation page
  • the page type of the current S memory page is recorded as a non-zero page in the memory snapshot file, and the page data of the current S memory page is copied to the memory snapshot file;
  • the page type of the current S memory page is recorded as a swap page in the memory snapshot file, and the page data of the swap page is copied from the memory swap file into the foregoing memory snapshot file;
  • the page type of the current S memory page is recorded as a shared page in the memory snapshot file, the page data of the shared page is copied to the foregoing memory snapshot file, and the current S memory is recorded.
  • the page number of the other memory pages of the page shared memory data is recorded.
  • the virtual machine memory snapshot generation method performs different snapshot generation processing according to different memory page types in the process of generating a memory snapshot by identifying different memory page types, including: When the S memory page is a non-valid data page, only the page type of the current S memory page is recorded in the memory snapshot file; when the current S memory page is a valid data page, the current S is recorded in the memory snapshot file.
  • the page type and the page data of the memory page so that only the valid data is saved by the embodiment of the present invention, the backup of the invalid data is reduced, the generation time of the memory snapshot is greatly shortened, the size of the memory snapshot file is reduced, and the storage resource is saved.
  • the second embodiment of the present invention provides a method for generating a virtual machine memory snapshot.
  • the following describes the flow of the virtual machine memory snapshot generation method in detail with reference to FIG. 3, including the following steps:
  • Step 300 the process begins
  • the process may start by a user triggering a memory snapshot operation, the physical host provides a user interface to the end user, so as to trigger a memory snapshot operation, or may be automatically triggered by the virtual machine, which may be triggered periodically or according to the operation of the virtual machine. The status is automatically triggered.
  • Step 301 Determine a virtual machine actual memory size and a memory page size (also referred to as a page size, Typically such as 4KB or 2MB), this information is used to initialize the memory snapshot file and is used to determine the integrity of the memory snapshot file when the virtual machine memory snapshot is restored;
  • a memory page size also referred to as a page size, Typically such as 4KB or 2MB
  • the virtual machine herein may be a virtual machine specified by a user through a user interface, or may be a virtual machine that is triggered periodically.
  • Step 302 Initialize the memory snapshot file, including the storage space of the pre-application memory snapshot file and the structure and initial information of the initialization memory snapshot file.
  • the initial information refers to a virtual machine memory size, a memory page size, and a memory page number (specifically, the actual memory page number of the virtual machine can be calculated according to the actual memory size of the virtual machine, the memory page size), and a valid data start address, etc.
  • the structure of the memory snapshot file provided in the embodiment of the present invention is as shown in FIG. 4, and includes an information segment 41 and a data segment 42.
  • the information segment 41 includes: global information 411 and a bitmap structure BITMAP of the memory page.
  • the bitmap structure BITMAP is a general-purpose sequential data storage structure in which the page number 4121, the page type 4122, and the data offset 4123 of the memory page are stored in the embodiment of the present invention.
  • the data segment 42 sequentially stores the valid data in the valid data page and corresponds to the data offset 4123 in the information segment 41.
  • the global information 411 can be used to record information such as virtual machine memory size, number of memory pages, memory page size, and valid data start address.
  • the information can be written to the memory snapshot when the memory snapshot file 302 is initialized, or in the memory.
  • the memory snapshot is written;
  • the page number 4121 records the page number of each memory page;
  • the page type 4122 records the page type identifier of the memory page corresponding to the page number;
  • the data offset 4123 records the validity of the corresponding memory page.
  • the offset of the data in the data segment 42 i.e., the valid data recorded in the data segment 42, is indexed according to the data offset 4123 in the information segment 41, by adding the data offset to the valid data start address. The corresponding memory data can then be found in data segment 42.
  • the structure of the memory snapshot file provided in FIG. 4 is not limited to the meaning of such a structure, but is merely an example.
  • the memory snapshot file may also include two fields, page type 51 and valid data 52, as shown in FIG.
  • the page type 51 stores the type identifier of the identified memory page, and the type identifier uniquely identifies a page type, which can be defined autonomously, for example, 000 represents zero page, 001 represents a balloon page, and the like.
  • the valid data 52 stores page data of a valid data page including non-zero pages, shared pages, and exchange pages.
  • the shared page number of the shared page can be stored according to various parts of the memory snapshot file. Information, the capacity of each part or other factors determine its storage location, such as the valid data in Figure 5.
  • the 52 or page type 51 leaves a portion of the space to store the shared page number.
  • a partial storage shared page number can also be separately divided in the memory snapshot.
  • Step 304 Determine, according to the memory page type information stored in the VMM memory space, whether the current memory page is a normal page. When it is determined that the selected memory page is not a normal page, step 305 is performed; when it is determined that the selected memory page is a normal page, Then perform step 306;
  • the memory page type information is stored in a page type structure, where the page type structure is stored in a memory level of a hardware layer of a physical host.
  • the page type structure is stored in the VMM.
  • the VMM memory space is a key area in which the VMM divides a specific area on the physical memory to complete normal work, and stores the data structure used by the VMM to complete functions such as virtual device simulation, memory management, and memory snapshot generation and recovery.
  • Information such as structure variables of virtual machine memory page types, memory shared hash tables, and virtual machine memory and physical memory - mapping relationships.
  • the VMM memory space is divided into separate parts to store information of different VM VMs.
  • the VMM can access the VMM memory space by calling the system interface.
  • Step 305 Perform a corresponding memory snapshot generation process according to a specific page type of the memory page in the memory snapshot file.
  • the page types here include: balloon pages, time-sharing pages, shared pages, and exchange pages.
  • the page type of the memory page is recorded as a balloon page in the page type 4122 field of the foregoing memory snapshot file (refer to FIG. 4); when the memory page is allocated when needed, in the foregoing
  • the page type of the memory page recorded in the page type 4122 field of the memory snapshot file is a time-sharing page; when the memory page is a swap page, the page type of the memory page is recorded in the page type 4122 field of the aforementioned memory snapshot file for exchange Page, copying the valid data of the exchange page from the memory swap file to the foregoing
  • the data segment 42 of the memory snapshot file, and the offset of the valid data in the data segment 42 is recorded in the data offset 4123 field; when the memory page is a shared page, the page type 4122 of the aforementioned memory snapshot file
  • the page type of the memory page is recorded as a shared page, the shared data of the shared page is copied to the data segment 42 of the foregoing memory snapshot file, and the shared data is recorded in the data segment 42 in the
  • Step 306 Determine whether the content of the memory page is all 0 by traversing the content of the memory page. If it is zero, the page is zero page, go to step 307; if it is not zero, the page is non-zero page, go to step 308; Step 307, perform the corresponding processing of zero page in the memory snapshot file, that is, in the The page type 4122 of the memory snapshot file records that the page type of the current S memory page is zero page, and the memory data is not copied; Step 308, performing corresponding processing of the non-zero page in the memory snapshot file, that is, in the memory snapshot file
  • the page type of the current S memory page is recorded as a non-zero page, and the page data of the current S memory page is copied into the data segment 42 of the memory snapshot file, and the data offset is 4123. The offset of the data in data segment 42 is recorded.
  • Step 309 Determine whether all memory pages have been processed; if the result of the determination in step 309 is yes, go to step 310; if the structure is negative in step 309, return to step 303 to select the next memory page to continue the memory snapshot generation. Process.
  • step 309 the memory snapshot processing of each memory page is performed to perform the judgment of step 309, which can be judged by the page number; when the information such as the page number is not saved in the memory snapshot file, the memory page can be marked as read or It has been processed to judge.
  • Step 310 Output a memory snapshot file; the output memory snapshot file may be stored in a hard disk (Disk)
  • Step 311 Stop the memory snapshot generation operation.
  • the virtual machine memory snapshot generation method initializes a memory snapshot file, and the memory snapshot file specifically includes an information segment (global information, page number, page type, data offset) and data.
  • Segment then sequentially acquires and identifies the page type of the memory page of the virtual machine, and performs different memory snapshot generation processing in the memory snapshot file for different page types, including: when the obtained memory page is identified as a balloon page, The page type of the memory page in the page type field of the memory snapshot file is a balloon page; when the obtained memory page is identified as a time-assigned page, the page type of the memory page is recorded in the page type field of the memory snapshot file When the acquired memory page is recognized as a swap page, the page type of the memory page is recorded as a swap page in the page type field of the memory snapshot file, and the valid data of the swap page is copied from the memory swap file. Go to the data segment of the memory snapshot file, and record the data in the data offset field.
  • a third embodiment of the present invention provides a virtual machine memory snapshot recovery method. As shown in FIG. 6, the method may include:
  • Step S401 Acquire and parse a memory snapshot file of the virtual machine.
  • the structure of the memory snapshot file provided by the embodiment of the present invention is as shown in FIG. 4 .
  • S401 may be that the information stored in the structure as shown in FIG. 4 is read and parsed from the memory snapshot file.
  • the memory snapshot file provided by the embodiment of the present invention may also include two fields of page type 51 and valid data 52 as shown in FIG. 5, and S401 may be, read and parsed from the memory snapshot file.
  • S401 may be, read and parsed from the memory snapshot file.
  • Step S402 when the page type of the current S memory page recorded in the memory snapshot file is an invalid data page, the page type of the current S memory page is recorded as a non-effective data page in the VMM memory space; when the memory snapshot file When the page type of the current S memory page recorded is a valid data page, The page type of the current S-th memory page is recorded in the VMM memory space as a valid data page, and the page data of the current S-th memory page recorded in the memory snapshot file is correspondingly copied to the S-th memory page of the virtual machine.
  • the non-effective data page includes a balloon page and a time-sharing page
  • the valid data page includes a shared page, a swap page, and a normal page
  • step S402 may specifically include:
  • the page type of the current S memory page recorded in the memory snapshot file is a balloon page
  • the page type of the current S memory page is recorded in the VMM memory space as a balloon page
  • the page type of the current S memory page recorded in the memory snapshot file is a time allocation page
  • the page type of the current S memory page is recorded in the VMM memory space as a time allocation page
  • the page type of the current S memory page recorded in the memory snapshot file is a shared page
  • the page type of the current S memory page is recorded as a shared page in the VMM memory space
  • the current S memory recorded in the memory snapshot file is recorded.
  • the page data of the page is copied to the S memory page of the virtual machine, or copied to any memory page shared with the current S memory page, and based on the page number recorded in the memory snapshot file, in the VMM memory space Establishing a sharing relationship between the current S-memory page and the memory page corresponding to the aforementioned page number;
  • the page type of the current S memory page recorded in the memory snapshot file is a swap page
  • the page type of the current S memory page is recorded as a swap page in the VMM memory space
  • the current S record in the memory snapshot file is recorded.
  • the page data of the memory page is copied to the new memory swap file; or, the page type of the current S memory page is recorded as a normal page in the VMM memory space, and the page of the current S memory page recorded in the memory snapshot file is recorded.
  • the data is correspondingly copied to the S memory page of the virtual machine;
  • the page type of the current S memory page recorded in the memory snapshot file is a normal page
  • the page type of the current S memory page is recorded as a normal page in the VMM memory space
  • the current page S recorded in the memory snapshot file is recorded.
  • the page data of the memory page is correspondingly copied to the S memory page of the virtual machine.
  • the non-effective data page includes a balloon page, a time allocation page, and a zero page;
  • the valid data page includes a non-zero page, a shared page, and an exchange page, and the following two cases (The same content as above, will not be described here):
  • the page type of the current S memory page recorded in the memory snapshot file is a non-zero page
  • the page type of the current S memory page is recorded as a non-zero page in the VMM memory space, and the current record in the memory snapshot file is recorded.
  • the page data of the S memory page is correspondingly copied to the S memory page of the virtual machine;
  • the method for restoring a virtual machine memory snapshot performs different snapshot recovery processing according to different page types of the memory page recorded in the memory snapshot file by acquiring and parsing the memory file of the virtual machine.
  • the method includes: when the page type of the current S memory page recorded in the memory snapshot file is an invalid data page, recording the page type of the current S memory page in the VMM memory space as an invalid data page; when recording in the memory snapshot file
  • the page type of the current Sth memory page is a valid data page
  • the page type of the current S memory page is recorded as a valid data page in the VMM memory space
  • the page of the current S memory page recorded in the memory snapshot file is recorded.
  • the data is correspondingly copied to the S-th memory page of the virtual machine, so that only the valid data is restored by the embodiment of the present invention, the recovery process of the invalid data is avoided, and the recovery time of the memory snapshot is greatly shortened.
  • FIG. 7 is a schematic diagram of a virtual machine memory snapshot recovery method according to Embodiment 4 of the present invention.
  • step S501 and step S503 are the same as steps S401 and S402 in Embodiments 3 and 4, respectively, except that after step S501, step S502 is added to determine whether the memory snapshot file is complete: If not, the memory recovery operation is stopped; if yes, step S503 is performed.
  • the page type of the current S-th memory page recorded in the memory snapshot file is a non-valid data page
  • the page type of the current S-th memory page is recorded as an invalid data page in the VMM memory space
  • the page type of the current S memory page recorded in the memory snapshot file is a valid data page
  • the page type of the current S memory page is recorded as a valid data page in the VMM memory space
  • the memory snapshot is taken The page data of the current Sth memory page recorded in the file is correspondingly copied into the Sth memory page of the virtual machine.
  • step S502 the method for determining whether the memory snapshot file is complete in step S502 is as follows:
  • Method 1 If the global information of the virtual machine memory is saved in the memory snapshot, including the virtual machine memory size, the number of memory pages, the memory page size, and the like, for example, the memory snapshot file structure shown in FIG. 4 of the second embodiment of the present invention, in this case
  • Calculate the memory size (the number of memory pages multiplied by the memory page size to get the memory size), and then determine whether the estimated memory size is the same as the memory size saved in the global information; or the valid data segment pointed to by the data offset Whether the content exists, that is, whether the saved valid data is lost. If there is an inconsistency or non-existence, the memory snapshot is incomplete and the memory snapshot recovery is stopped.
  • Method 2 If the global snapshot of the virtual machine memory is not stored in the memory snapshot, for example, the memory snapshot file structure shown in FIG. 5 in the second embodiment of the present invention, in this case, in order to judge the integrity of the memory snapshot, the memory size can be calculated. After that, the estimated memory size is the same as the saved memory size in the VM configuration file. If there is an inconsistency, the memory snapshot is incomplete and the memory snapshot recovery is stopped.
  • the memory snapshot integrity judgment is based on whether the virtual machine memory information is completely saved in the snapshot, and all the memory information can be judged. As long as one type of information is incomplete, the memory recovery is stopped; and only important information can be judged according to the actual situation. Integrity, such as information that may cause a virtual machine exception after memory recovery. A person skilled in the art can easily infer the equivalent judgment manner or the combination equivalence judgment manner of other information according to the embodiment of the present invention, which is not described herein again.
  • the memory snapshot may be recovered under the current virtual machine memory snapshot recovery mechanism, but the virtual machine may be abnormal after the memory is recovered due to data loss.
  • the method for restoring a virtual machine memory snapshot obtained and parses a memory file of the virtual machine by using a virtual machine; and then performs different snapshot recovery processing according to different page types of the memory page recorded in the memory snapshot file.
  • the method includes: when the page type of the current S memory page recorded in the memory snapshot file is an invalid data page, recording the page type of the current S memory page in the VMM memory space as an invalid data page; when recording in the memory snapshot file
  • the page type of the current Sth memory page is a valid data page
  • the page type of the current S memory page is recorded as a valid data page in the VMM memory space, and the page of the current S memory page recorded in the memory snapshot file is recorded.
  • the data is correspondingly copied to the S-th memory page of the virtual machine, so that only the valid data is restored by the embodiment of the present invention, the recovery process of the invalid data is avoided, and the recovery time of the memory snapshot is greatly shortened. Further, the memory snapshot file integrity is judged before the memory snapshot is restored, thereby avoiding unnecessary memory recovery operations and improving the reliability of the memory snapshot recovery operation.
  • FIG. 8 is a specific flowchart of a virtual machine memory snapshot recovery method according to Embodiment 5 of the present invention. The method includes:
  • Step 600 the process begins
  • Step 601 reading and parsing the memory snapshot file
  • Step 602 Determine whether the memory snapshot file is complete. If the memory snapshot file is incomplete, go to step 607; if the memory snapshot file is complete, go to step 603.
  • Step 603 sequentially select a piece of memory page information stored in the memory snapshot file, where the memory page information includes a memory page type, valid data, or a valid data offset, etc. (refer to the memory snapshot file structure shown in FIG. 4 or FIG. 5) ;
  • Step 604 Identify a page type of the current memory page according to the page type in the memory page information.
  • Step 605 Perform a corresponding memory snapshot recovery process according to the page type, which may include: if the page type is a balloon page, in the VMM The page type of the memory page recorded in the memory space is a balloon page;
  • the page type of the memory page is recorded in the VMM memory space as a time-sharing page
  • the page type is a non-zero page
  • the page type is a shared page
  • Valid data or a valid data address obtained based on the data offset calculation, copy the valid data of the memory to the corresponding virtual machine memory page, and establish each shared data in the memory shared hash table of the VMM memory space record a shared relationship between memory pages
  • the page type is a swap page
  • the page type of the memory page in the type structure is zero page or non-zero page, and valid data is copied to the corresponding virtual machine memory page.
  • step 605 records the type of the memory page in the VMM memory space, where the page type identifier of the memory page is restored in the page type structure from which the memory page type is obtained when the memory snapshot is generated; or in the VMM memory space. Re-establish a page type structure in which the type of the memory page is recorded, at which point the original page type structure is no longer used.
  • Step 606 Determine whether all pages are processed after each memory snapshot recovery operation is performed, and if yes, execute step 607; if no, return to step 603 to continue the process.
  • Step 607 Stop the memory recovery operation.
  • the memory snapshot recovery process may be triggered by a user, and the physical host provides a memory recovery interface to the end user, so as to trigger the memory snapshot recovery operation; It is automatically triggered by the virtual machine. It can be triggered periodically or automatically according to the running status of the virtual machine.
  • the page data of the swap page may be copied into the memory swap file, and the memory swap file may be a new memory swap file.
  • the swap page is still the swap page; or the page data of the swap page can be copied to the corresponding memory page, at which point the swap page becomes a normal
  • the page can be set to a zero page or a non-zero page according to whether the data in the exchange page is zero. Of course, it can also be set as a normal page according to the third embodiment of the present invention.
  • the memory snapshot file described in Embodiments 3, 4, and 5 of the present invention may be the memory snapshot file structure of FIG. 4, FIG. 5 or other equivalent replacement or obvious modification in the second embodiment of the present invention.
  • the method for restoring a virtual machine memory snapshot obtains and parses a memory file of the virtual machine; and then determines the integrity of the memory snapshot file; and the complete memory snapshot file is based on the memory snapshot file.
  • Performing different snapshot recovery processing for different page types of the recorded memory page including: when the page type of the memory page is a balloon page, recording the VMM memory space The page type of the memory page is a balloon page; when the page type of the memory page is allocated when needed, the page type of the memory page is recorded in the VMM memory space as a time allocation page; when the page type of the memory page is zero When the page is recorded, the page type of the memory page is recorded as zero page in the VMM memory space, and the corresponding memory page content of the virtual machine is set to 0; when the page type of the memory page is non-zero page, in the VMM memory space Record the page type of the memory page as a non-zero page, and copy the valid data of the memory to the corresponding virtual machine according to
  • the page type of the memory page when the page type of the memory page is a shared page, the page type of the memory page is recorded in the VMM memory space as a shared page, according to the valid data directly stored in the memory snapshot file, or according to the data offset And obtaining a valid data address, copying the valid data of the memory to the corresponding virtual machine memory page, and establishing each common memory in the memory sharing hash table of the VMM memory space record
  • the sharing relationship between the memory pages of the data when the page type of the memory page is a swap page, the page type of the memory page is recorded in the VMM memory space as a swap page, according to the valid data directly stored in the memory snapshot file, Or copying the valid data of the memory to a new swap file according to the valid data address obtained by calculating the data offset; or recording the page type of the memory page to zero page in the page type structure saved by the VMM Or a non-zero page, and copy the valid data into the corresponding virtual machine memory page, thereby recovering only the valid data by the embodiment of the invention
  • the sixth embodiment of the present invention further provides a physical host.
  • the physical host includes: a hardware layer 100, a virtual machine monitor VMM200 running on the hardware layer 100, and a virtual machine monitor VMM200.
  • the virtual machine 300, the virtual machine monitor VMM200 includes a memory snapshot generation module 210 and a memory page identification module 220, wherein:
  • the memory snapshot generation module 210 is configured to: obtain a current S memory page of the virtual machine; and when the memory page identification module 220 identifies that the current S memory page is an invalid data page, record the current page of the S memory page in the memory snapshot file. Type; when the memory page identification module 220 identifies that the current S memory page is a valid data page, records the page type and page data of the current S memory page in the memory snapshot file;
  • the memory snapshot file herein may be a physical host stored in an embodiment of the present invention.
  • the meaning that the memory snapshot file must be stored on the hardware layer 100 of the physical host is not limited.
  • the memory snapshot file may be stored in a storage device of the hardware layer 100, such as the hard disk Disk 130, or may be stored on the mobile storage device, such as a USB flash drive or a mobile hard disk, or may be stored in a physical host that is in communication with the embodiment of the present invention. Connected to an external network storage device.
  • the memory page identification module 210 is configured to: identify a page type of a current Sth memory page acquired by the memory snapshot generation module 210, where the page type includes a non-effective data page and a valid data page;
  • the memory page identification module 210 is specifically configured to: identify, according to page type information saved in the VMM memory space, a page type of the current S memory page, where the page type includes a balloon page, and takes time An allocation page, a shared page, an exchange page, and a normal page; wherein, the balloon page and the time allocation page are non-valid data pages, and the shared page, the exchange page, and the normal page are valid data pages;
  • the memory page identification module 210 is specifically configured to: identify, according to the page type information saved in the VMM memory space, a page type of the current S memory page, where the page type includes a balloon page, and takes time Allocating a page, a shared page, a swap page, and a normal page; when the page type of the current S-th memory page is a normal page, traversing the content of the current S-th memory page, according to the result of the traversal (the memory page content is all 0 or incomplete) 0) determining that the page type of the current Sth memory page is zero page or non-zero page; wherein, the balloon page, the time allocation page, and the zero page are non-valid data pages, non-zero pages, shared pages, and exchange pages are Valid data page.
  • the hardware layer 100 includes a storage device, such as a hard disk 130, and the storage device is configured to: store the memory snapshot file.
  • the hardware layer 100 may include a storage device, such as the hard disk 130, or may not include the hard disk 130.
  • the physical host hardware layer 100 may include a processor 110, a physical memory 120, a hard disk 130, and a network interface device 140, where the processor 110 may be one or more; the network interface device 140 may be a network adapter or a network card, and may be connected to any The network is connected, such as the Internet (Internet), enterprise network, and so on.
  • the hardware layer may not include hard disk 130 (see system embodiment).
  • the virtual machine VM300 may include a virtual processor 310, a virtual memory 320, a virtual hard disk 330, and a guest operating system 340, wherein the logical memory page of the virtual memory 320 There is a mapping relationship between the physical memory page and the physical memory page 120.
  • the memory snapshot to be generated in the embodiment of the present invention is the physical memory corresponding to the virtual memory; the guest operating system (Guest)
  • the Operation System, Guest OS 340 is an operating system running on a virtual device such as a virtual processor 310, a virtual memory 320, or a virtual hard disk 330.
  • the virtual machine monitor VMM200 shown in FIG. 9 runs on the hardware layer 100, and has no limitation. In fact, the virtual machine monitor VMM can directly run on the hardware layer; the virtual machine monitor VMM also Can run directly on the host operating system (Host Operation System,
  • the host operating system can run on top of the hardware layer.
  • the virtual machine monitor VMM can run indirectly on the hardware layer.
  • the physical host may be a physical computer, and may specifically be a personal computer PC, a laptop computer, a workstation workstation, a server server, a mainframe mainframe, or a supercomputer.
  • the seventh embodiment of the present invention further provides a physical host.
  • the physical host may further include a memory snapshot recovery module 230 in the virtual machine monitor VMM200 in addition to the foregoing component devices.
  • the memory snapshot recovery module 230 is configured to: obtain and parse a memory snapshot file of the virtual machine; when the page type of the current S memory page recorded in the memory snapshot file is an invalid data page, record the current in the VMM memory space The page type of the S memory page is an invalid data page; when the page type of the current S memory page recorded in the memory snapshot file is a valid data page, the page type of the current S memory page is recorded in the VMM memory space as A valid data page, and correspondingly copying the page data of the current S-th memory page recorded in the memory snapshot file to the S-th memory page of the virtual machine.
  • the non-effective data includes a balloon page and a time-sharing page, where the valid data page includes a shared page, an exchange page, and a normal page;
  • the memory snapshot recovery module 230 is specifically configured to:
  • the page type of the current S memory page recorded in the memory snapshot file is a balloon page
  • the page type of the current S memory page is recorded in the VMM memory space as a balloon page
  • the page type of the current S-th memory page recorded in the memory snapshot file is a time-sharing page
  • the page type of the current S-th memory page is recorded in the VMM memory space as a time-sharing page
  • the page type of the current S memory page recorded in the memory snapshot file is a shared page
  • the page type of the current S memory page is recorded as a shared page in the VMM memory space, and the current S memory recorded in the memory snapshot file is recorded.
  • the page data of the page is copied to the S memory page of the virtual machine, or copied to any memory page shared with the current S memory page, and based on the page number recorded in the memory snapshot file, in the VMM memory space Establishing a sharing relationship between the current S-memory page and the memory page corresponding to the aforementioned page number;
  • the page type of the current S memory page recorded in the memory snapshot file is a swap page
  • the page type of the current S memory page is recorded as a swap page in the VMM memory space
  • the current S record in the memory snapshot file is recorded.
  • the page data of the memory page is copied to the new memory swap file; or, the page type of the current S memory page is recorded as a normal page in the VMM memory space, and the page of the current S memory page recorded in the memory snapshot file is recorded.
  • the data is correspondingly copied to the S memory page of the virtual machine;
  • the page type of the current S memory page recorded in the memory snapshot file is a normal page
  • the page type of the current S memory page is recorded as a normal page in the VMM memory space
  • the current page S recorded in the memory snapshot file is recorded.
  • the page data of the memory page is correspondingly copied to the S memory page of the virtual machine.
  • the non-valid data page includes a balloon page, a time-sharing page, and a zero page;
  • the valid data page includes a non-zero page, a shared page, and an exchange page:
  • the memory snapshot recovery module 230 is specifically configured to:
  • the page type of the current S memory page recorded in the memory snapshot file is a balloon page
  • the page type of the current S memory page is recorded in the VMM memory space as a balloon page
  • the page type of the current S memory page recorded in the VMM memory space is a time allocation page
  • the page type of the current S memory page recorded in the memory snapshot file is a shared page
  • the page type of the current S memory page is recorded as a shared page in the VMM memory space
  • the current S memory recorded in the memory snapshot file is recorded.
  • the page data of the page is copied to the S memory page of the virtual machine, or copied to any memory page shared with the current S memory page, and based on the page number recorded in the memory snapshot file, in the VMM memory space Establishing a sharing relationship between the current S-memory page and the memory page corresponding to the aforementioned page number;
  • the page type of the current S memory page recorded in the memory snapshot file is an exchange page
  • VMM Recording the page type of the current S memory page in the memory space as a swap page, and copying the page data of the current S memory page recorded in the memory snapshot file into a new memory swap file; or recording in the VMM memory space
  • the page type of the current S memory page is a normal page, and the page data of the current S memory page recorded in the memory snapshot file is correspondingly copied to the S memory page of the virtual machine;
  • the page type of the current S memory page recorded in the memory snapshot file is zero page
  • the page type of the current S memory page is recorded as zero page in the VMM memory space, and the content of the S memory page of the virtual machine is set to 0;
  • the page type of the current S memory page recorded in the memory snapshot file is a non-zero page
  • the page type of the current S memory page is recorded as a non-zero page in the VMM memory space, and the current record in the memory snapshot file is recorded.
  • the page data of the S-th memory page is correspondingly copied to the S-th memory page of the virtual machine.
  • the physical host acquires the current S-th memory page of the virtual machine through the memory snapshot generation module, and then performs the page type identification of the current S-th memory page through the memory page identification module, when identifying When the current S memory page is a non-valid data page, the page type of the current S memory page is recorded in the memory snapshot file; when the current S memory page is identified as a valid data page, the memory snapshot file is recorded in the memory snapshot file.
  • the page type and the page data of the current S memory page so that only the valid data is saved by the above embodiment of the invention, the backup of the invalid data is avoided, the generation time of the memory snapshot is greatly shortened, and the occupation of the storage resource by the memory snapshot is reduced.
  • the memory snapshot file of the virtual machine is obtained and parsed by the memory snapshot recovery module; when the page type of the current S-th memory page recorded in the memory snapshot file is an invalid data page, the VMM memory space is Recording that the page type of the current S-th memory page is a non-valid data page; when the page type of the current S-th memory page recorded in the memory snapshot file is a valid data page, recording the location in the VMM memory space
  • the page type of the current S-th memory page is a valid data page
  • the page data of the current S-th memory page recorded in the memory snapshot file is correspondingly copied into the S-th memory page of the virtual machine, thereby Only the valid data is restored by the above embodiment of the invention, the recovery process of the invalid data is avoided, and the recovery time of the memory snapshot is greatly shortened.
  • FIG. 10 is a logical structural diagram of a computer system according to Embodiment 8 of the present invention.
  • the system includes: a physical host 1, a physical host 2, and a network storage device 500.
  • the physical host 1 and the physical host 2 are the present invention.
  • the physical host 1 and the physical host 2 are respectively connected to the Internet 400 through the respective network interface device 1 and the network interface device 2, and then the memory snapshot file of the virtual machine can be stored on the network storage device 500 through the Internet 400.
  • the memory snapshot file may be stored only on the network storage device, or may be stored in the storage device of the network storage device and the physical host hardware layer, which is not limited.
  • FIG. 11 is a network topology diagram of a computer system according to Embodiment 9 of the present invention, wherein a physical host 1 and a physical host 2 are connected to a network storage device 500 via an Internet 400.
  • the network storage device may adopt a centralized storage mode or a distributed storage mode.
  • the network storage device can be one, adopting a centralized storage mode; or it can be multiple, using a single storage mode or a distributed storage mode.
  • the centralized storage mode refers to a memory snapshot file stored in a network storage device;
  • the distributed storage mode refers to a memory snapshot file stored in multiple network storage devices. The latter is more suitable for situations where there are more physical hosts and more memory snapshot files.
  • different snapshot generation processing is performed according to different memory page types in the process of generating a memory snapshot by identifying different memory page types.
  • the method includes: when the current S memory page is a non-valid data page, only the page type of the current S memory page is recorded in the memory snapshot file; when the current S memory page is a valid data page, in the memory snapshot file Recording the page type and page data of the current S-th memory page; and, during the memory snapshot recovery process, performing different snapshot recovery processes according to different memory page types, including: when the current record is recorded in the memory snapshot file When the page type of the S memory page is a non-valid data page, the page type of the current S memory page is recorded as a non-valid data page in the VMM memory space; when the current S memory page recorded in the memory snapshot file When the page type is a valid data page, the page type of the current S memory page is recorded as a valid data page in the VMM memory space, and
  • the virtual machine has a total memory of 4G.
  • the zero page has an average of about 50% of the total memory of the virtual machine, and the bubble page also occupies the virtual machine.
  • the memory snapshot generation and recovery technology provided by the embodiment of the present invention can shorten the generation and recovery time of the memory snapshot to about 40% of the prior art implementation, and at the same time, the memory snapshot file is used. The size is reduced from the original 4G to 1.61G (the data other than the memory page data in the memory snapshot file is approximately 10M).
  • the network storage device stores the memory snapshot file, thereby avoiding the problem that the local access space is insufficient when there are a large number of memory snapshot files; if the distributed network storage mode is also used, the centralized storage mode can also be solved.
  • the storage medium may be a magnetic disk, an optical disk, or a read-only storage memory.
  • ROM Read-Only Memory
  • RAM Random Access Memory

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Quality & Reliability (AREA)
  • Memory System Of A Hierarchy Structure (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Description

一种虚拟机内存快照生成和恢复方法、 装置及系统 技术领域
本发明涉及一种内存快照技术,尤其涉及一种虚拟机内存快照生成和恢复 的方法、 装置及系统。 背景技术 通过虚拟化技术,用户可以在一台物理计算机上模拟出一台或多台虚拟机 ( Virtual Machine, VM ), 这些虚拟机可以像真正的计算机那样进行工作, 例 如用户可以安装操作系统、 安装应用程序、 访问网络资源等等。 虚拟机快照技术随着虚拟化技术同时产生, 由于虚拟机的计算、存储资源 都是通过虚拟机监视器( Virtual Machine Monitor, VMM )进行虚拟化, 我们 可以通过快照技术方便地保留虚拟机某个时间点的 CPU状态、 内存状态以及 存储数据,从而轻松实现物理机上繁瑣的全状态备份, 用户可以方便地备份和 恢复虚拟机。 目前常见的快照应用主要有两种:一是简单的存储快照,仅备份存储数据, 虚拟机用户在使用虚拟机过程中可能由于各种原因(病毒、 木马的破坏, 误删 除系统文件, 误格式化等)导致虚拟机镜像损坏或是无法正常启动, 如果通过 存储快照在虚拟机正常时备份相关数据, 可以方便地恢复备份点的页数据; 二 是存储快照和内存快照相结合, 由于在某些场景下, 用户需要快速创建或恢复 虚拟机(相关业务部署加载繁瑣冗长、 业务恢复中断时间要求高、 批量快速部 署虚拟机等), 或者为了某些调试需求需要保留当前业务状态 (问题定位, 测 试分支选择等), 此时仅仅使用存储快照无法满足需求, 因此内存快照的引入 弥补了这方面的不足,通过 VMM的能力把虚拟机的内存数据保存成外部存储 介质上的内存快照文件, 方便保存和随时恢复, 同时, 这也是虚拟化条件下带 来的便利。
VMWare (Virtual Machine ware)是虚拟化解决方案的领导厂商, 目前已经 能提供虚拟机快照总体方案, 包括存储快照和内存快照, 其内存快照是对内存 数据的黑盒的全量拷贝, 生成的快照文件大小与虚拟机内存规格保持一致, 即 拥有 1G 内存的虚拟机最终生成的内存快照文件大小为 1G, 与存储快照一起 存放在其分布式存储上; 快照恢复时, 也是顺序读取快照文件进行 1 : 1内存还 原。 因此, 快照生成过程和快照恢复过程时间都比较长, 同时, 生成的内存快 照文件与虚拟机内存大小一致, 对存储资源也是一种浪费。 发明内容
本发明实施例提供一种虚拟机内存快照生成和恢复的方法、 装置及系统, 以缩短虚拟机内存快照的处理时间且节约存储资源。
本发明实施例提供如下技术方案:
一方面,本发明实施例提供一种虚拟机内存快照生成方法,所述方法包括: 获取所述虚拟机的当前第 S内存页;
识别所述当前第 S内存页的页类型,所述页类型包括非有效数据页和有效 数据页;
当所述当前第 S内存页为非有效数据页时,在内存快照文件中记录所述当 前第 S内存页的页类型; 当所述当前第 S内存页为有效数据页时,在内存快照 文件中记录所述当前第 S内存页的页类型和页数据。
另一方面, 本发明实施例提供一种虚拟机内存快照恢复方法, 所述方法包 括:
获取并解析所述虚拟机的内存快照文件;
当所述内存快照文件中记录的当前第 S 内存页的页类型为非有效数据页 时,在 VMM内存空间中中记录所述当前第 S内存页的页类型为非有效数据页; 当所述内存快照文件中记录的当前第 S内存页的页类型为有效数据页时,在所 述 VMM内存空间中中记录所述当前第 S内存页的页类型为有效数据页,并将 所述内存快照文件中记录的所述当前第 S 内存页的页数据对应地拷贝到所述 虚拟机的第 S内存页中。 另一方面,本发明实施例提供一种物理主机,所述物理主机包括:硬件层, 运行在所述硬件层之上的虚拟机监视器 VMM, 以及运行在所述虚拟机监视器
VMM上的虚拟机, 所述虚拟机监视器 VMM中包括内存快照生成模块和内存 页识别模块, 其中:
所述内存快照生成模块用于: 获取所述虚拟机的当前第 S内存页; 当所述 内存页识别模块识别所述当前第 S内存页为非有效数据页时,在内存快照文件 中记录所述当前第 S内存页的页类型;当所述内存页识别模块识别所述当前第 S内存页为有效数据页时,在内存快照文件中记录所述当前第 S内存页的页类 型和页数据;
所述内存页识别模块用于:识别所述内存快照生成模块获取的所述当前第
S内存页的页类型, 所述页类型包括非有效数据页和有效数据页;
所述硬件层包括存储设备, 所述存储设备用于: 存储所述内存快照文件。 另一方面, 本发明实施例提供一种计算机系统, 该系统包括物理主机和网 络存储设备, 其中所述物理主机为本发明实施例提供的物理主机, 用来执行虚 拟机内存快照文件的生成和恢复;所述网络存储设备用于存储所述物理主机的 虚拟机内存快照文件。
可见, 本发明实施例提供的虚拟机内存快照生成和恢复的方法、装置及系 统中, 通过识别不同的内存页类型, 在内存快照生成过程中, 根据不同的内存 页类型执行不同的快照生成处理,包括:在当前第 S内存页为非有效数据页时, 在内存快照文件中仅记录所述当前第 S内存页的页类型;在当前第 S内存页为 有效数据页时, 在内存快照文件中记录所述当前第 S 内存页的页类型和页数 据; 以及, 在内存快照恢复过程中, 根据不同的内存页类型执行不同的快照恢 复处理, 包括: 当所述内存快照文件中记录的当前第 S内存页的页类型为非有 效数据页时,在 VMM内存空间中记录所述当前第 S内存页的页类型为非有效 数据页;当所述内存快照文件中记录的当前第 S内存页的页类型为有效数据页 时,在所述 VMM内存空间中记录所述当前第 S内存页的页类型为有效数据页, 并将所述内存快照文件中记录的所述当前第 S 内存页的页数据对应地拷贝到 所述虚拟机的第 S内存页中,从而通过本发明实施例仅保存有效数据,减少无 效数据的备份和恢复, 大大缩短了内存快照的生成和恢复时间, 减小了内存快 照对存储资源的占用。 附图说明
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施 例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地, 下面描述 中的附图仅仅是本发明的一些实施例, 对于本领域普通技术人员来讲,在不付 出创造性劳动性的前提下, 还可以根据这些附图获得其他的附图。
图 1为本发明实施例的一种虚拟机内存快照生成方法的流程示意图; 图 2为本发明实施例的另一种虚拟机内存快照生成方法的流程示意图; 图 3为本发明实施例的再一种虚拟机内存快照生成方法的流程示意图; 图 4为本发明实施例的一种内存快照文件的逻辑结构示意图;
图 5为本发明实施例的另一种内存快照文件的逻辑结构示意图; 图 6为本发明实施例的一种虚拟机内存快照恢复方法的流程示意图; 图 7为本发明实施例的另一种虚拟机内存快照恢复方法的流程示意图; 图 8为本发明实施例的再一种虚拟机内存快照恢复方法的流程示意图; 图 9为本发明实施例的一种物理主机的逻辑结构示意图;
图 10为本发明实施例的一种计算机系统的逻辑结构示意图;
图 11为本发明实施例的一种计算机系统的物理部署示意图。
具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清 楚、 完整地描述, 显然, 所描述的实施例仅仅是本发明一部分实施例, 而不是 全部的实施例。基于本发明中的实施例, 本领域普通技术人员在没有作出创造 性劳动前提下所获得的所有其他实施例, 都属于本发明保护的范围。
本发明实施例一提供一种虚拟机内存快照生成方法,如图 1所示, 该方法 可以包括: 步骤 S101、 获取该虚拟机的当前第 S内存页。
需要说明的是, 本发明实施例中引入 "第 S内存页" 只是为了便于描述, 并非限定具体哪一个内存页, 应当理解的是, 这里的 S可以是 1 , 2, ...N ( N= 该虚拟机实际的页数量), 当 S为 1时, 表示本步骤中获取的当前内存页是所 述虚拟机的第一个内存页;
本步骤可以是顺序获取内存页, 也可以倒序获取内存页, 不做限定。
步骤 S102、 识别所述当前第 S内存页的页类型, 所述页类型包括非有效 数据页和有效数据页。
步骤 S102可以是, 至少根据 VMM内存空间中保存的页类型信息, 识别 该当前第 S内存页的页类型, 所述页类型包括非有效数据页和有效数据页。
具体的,在一种实现方式下, 步骤 S102具体为:根据虚拟机监视器 VMM 内存空间中保存的页类型信息,确定这个当前第 S内存页的页类型, 所述页类 型包括气球页(Balloon)、需时分配页( opulate on demand, Pod )、共享页( share )、 交换页(swap )和普通页; 其中, 气球页和需时分配页为非有效数据页, 共享 页、 交换页和普通页为有效数据页。 在一种具体实现方式下, 在 VMM内存空 间中维护了内存页类型的结构体变量, 其中普通页是默认值, 出现其它类型页 时会改变其类型并进行标记。 在开源虚拟机 Xen 中, 可以通过调用系统接口 从 VMM内存中获取虚拟机内存页的结构体变量 p2m— type— t来判断其类型, 其中 p2m— invalid = 0为气球页 , 2m_populate_on_demand = 6为需时分配页, p2m_ram_paged = 10为交换页 , p2m— ram—共享 d = 13为共享页, 2m_ram_rw = 1为普通页。
在另一种实现方式下, 详见图 2, 步骤 S102可以包括步骤 S201和步骤 S202, 其中:
步骤 S201、 根据所述 VMM内存空间中保存的页类型信息, 确定所述当 前第 S内存页的页类型, 所述页类型包括气球页、 需时分配页、 共享页、 交换 页和普通页;
步骤 S202、 当所述当前第 S内存页的页类型为普通页时, 遍历所述当前 第 S内存页的内容,确定所述当前第 S内存页的页类型为零页或非零页;其中, 气球页、 需时分配页和零页为非有效数据页, 非零页、共享页和交换页为有效 数据页。
需要说明的是,本发明实施例所列举的内存页类型是目前虚拟机中可能出 现的一些内存页类型, 有的应用比较多, 例如气球页、 零页和非零页; 有的应 用比较少; 例如共享页和交换页; 需时分配页目前通用性不高, 但在 Xen开 源虚拟机中也有应用。本发明实施例以这些页类型为例, 无意局限于这些页类 型的识别。无论目前应用的其它内存页类型,还是以后可能出现的内存页类型, 只要应用本发明实施例公开的内存快照生成和恢复方法都应在本发明保护范 围之内。
步骤 S103、 当所述当前第 S内存页为非有效数据页时, 在内存快照文件 中记录所述当前第 S内存页的页类型;当所述当前第 S内存页为有效数据页时, 在内存快照文件中记录所述当前第 S内存页的页类型和页数据。
相应的,在一种实现方式下,其中,气球页和需时分配页为非有效数据页, 共享页、 交换页和普通页为有效数据页; 步骤 S103具体可以包括:
在当前第 S内存页为气球页时,在内存快照文件中记录当前第 S内存页的 页类型为气球页;
在当前第 S内存页为需时分配页时,在内存快照文件中记录当前第 S内存 页的页类型为需时分配页;
在当前第 S内存页为交换页时,在内存快照文件中记录当前第 S内存页的 页类型为交换页,从内存交换文件中拷贝该交换页的页数据到该内存快照文件 中;
在当前第 S内存页为共享页时,在内存快照文件中记录当前第 S内存页的 页类型为共享页,拷贝该共享页的页数据到该内存快照文件中, 并记录与当前 第 S内存页共享内存数据的其它内存页的页号;
在当前第 S内存页为普通页时,在内存快照文件中记录当前第 S内存页的 页类型为普通页, 拷贝该普通页的页数据到所述内存快照文件中。
相应的, 在另一种实现方式下, 其中, 气球页、 需时分配页和零页为非有 效数据页, 非零页、共享页和交换页为有效数据页; 步骤 S103具体可以包括: 在当前第 S内存页为气球页时,在内存快照文件中记录当前第 S内存页的 页类型为气球页;
在当前第 S内存页为需时分配页时,在内存快照文件中记录当前第 S内存 页的页类型为需时分配页;
在当前第 S内存页为零页时,在内存快照文件记录当前第 S内存页的页类 型为零页;
在当前第 S内存页为非零页时,在内存快照文件中记录当前第 S内存页的 页类型为非零页, 拷贝当前第 S内存页的页数据到该内存快照文件中;
在当前第 S内存页为交换页时,在内存快照文件中记录当前第 S内存页的 页类型为交换页,从内存交换文件中拷贝该交换页的页数据到前述内存快照文 件中;
在当前第 S内存页为共享页时,在内存快照文件中记录当前第 S内存页的 页类型为共享页,拷贝该共享页的页数据到前述内存快照文件中, 并记录与当 前第 S内存页共享内存数据的其它内存页的页号。
综上所述, 本发明实施例提供的虚拟机内存快照生成方法,通过识别不同 的内存页类型,在内存快照生成过程中,根据不同的内存页类型执行不同的快 照生成处理, 包括: 在当前第 S内存页为非有效数据页时, 在内存快照文件中 仅记录该当前第 S内存页的页类型;在当前第 S内存页为有效数据页时,在内 存快照文件中记录该当前第 S内存页的页类型和页数据,从而通过本发明实施 例仅保存有效数据, 减少无效数据的备份, 大大缩短了内存快照的生成时间, 并减小了内存快照文件的大小, 节约了存储资源。
本发明实施例二提供一种虚拟机内存快照的生成方法,下面结合图 3来详 细介绍该虚拟机内存快照生成方法的流程, 包括如下步骤:
步骤 300、 流程开始;
该流程的开始可以是由用户触发内存快照操作,物理主机提供用户接口给 最终用户, 以便于触发内存快照操作; 也可以是虚拟机自动触发的, 可以是定 时触发, 也可以根据虚拟机的运行状况等自动触发。
步骤 301、 确定虚拟机实际内存大小、 内存页大小 (亦可称为页大小, 一 般为 4KB或 2MB )等信息, 这些信息用来初始化内存快照文件, 且在虚拟机 内存快照恢复时用来判断内存快照文件的完整性;
需要说明的是, 这里的虚拟机可以是用户通过用户接口所指定的虚拟机, 也可以是定时触发的虚拟机。
步骤 302、 初始化内存快照文件, 包括预申请内存快照文件的存储空间和 初始化内存快照文件的结构及初始信息。 所述初始信息指虚拟机内存大小、 内 存页大小、 内存页数量(具体的, 根据虚拟机实际内存大小、 内存页大小可以 计算出虚拟机实际的内存页数量) 、 以及有效数据起始地址等信息;
优选地, 本发明实施例中提供的内存快照文件结构如图 4所示, 包括信息 段 41和数据段 42, 其中信息段 41包括: 全局信息 411和内存页的位图结构 体 BITMAP, 所述位图结构体 BITMAP是一种通用的顺序数据存储结构, 在 本发明实施例中利用该结构体存储内存页的页号 4121、 页类型 4122以及数据 偏移量 4123。 数据段 42顺序存储有效数据页中的有效数据, 并与信息段 41 中的数据偏移量 4123——对应。全局信息 411可以用来记录虚拟机内存大小、 内存页数量、 内存页大小以及有效数据起始地址等全局类的信息, 这些信息可 以在初始化内存快照文件 302时写入内存快照,也可以在内存页处理完成之后 再写入内存快照; 页号 4121记录每个内存页的页号; 页类型 4122记录对应页 号的内存页的页类型标识; 数据偏移量 4123记录其对应的内存页的有效数据 在数据段 42中的偏移量, 即数据段 42中记录的有效数据按照信息段 41中的 数据偏移量 4123来索引, 通过把数据偏移量与所述有效数据起始地址相加后 可以在数据段 42中找到对应的内存数据。
需要说明的是,图 4提供的内存快照文件结构并无限定仅为此种结构的意 思, 只是举例说明。 在另一种实现方式下, 内存快照文件也可以如图 5所示包 含页类型 51和有效数据 52两个字段。 其中页类型 51存储识别出的内存页的 类型标识, 所述类型标识唯一标识一种页类型, 可以自主定义, 例如 000代表 零页、 001代表气球页等。 有效数据 52存储有效数据页的页数据, 所述有效 数据页包括非零页、 共享页和交换页。
值得一提的是, 共享页的共享页号可以根据内存快照文件各个部分存储 的信息、各个部分的容量或其它因素决定其存储位置, 例如如图 5中有效数据
52或页类型 51中留出部分空间存储所述共享页号, 当然也可以在内存快照中 单独划分一个部分存储共享页号。
需要说明的是,根据以上提到的内存快照文件结构, 本领域技术人员可以 很容易想到其它等同替代方式或明显变型方式。例如图 4中全局信息精简,仅 保存页数量和页大小; 页号信息也可以不保存等; 或者改变内存快照的存储顺 步骤 303、 顺序选取一个内存页;
可以是, 从第一个内存页开始——执行内存页识别。
步骤 304、 根据 VMM内存空间中保存的内存页类型信息判断当前内存页 是否为普通页, 当判断出选取的内存页不是普通页, 则执行步骤 305; 当判断 出选取的内存页是普通页, 则执行步骤 306;
在一种实现方式下, 所述内存页类型信息保存在一个页类型结构体中, 该 页类型结构体存储在物理主机的硬件层的内存 memory中, 具体的, 该页类型 结构体存储在 VMM内存空间中, 可以通过系统调用获得。 所述 VMM内存空 间是 VMM为完成正常工作而在物理内存上划分一块特定区域, 存放了 VMM 在完成虚拟设备模拟、内存管理以及内存快照生成和恢复等各项功能所用到的 数据结构等相关关键信息, 例如虚拟机内存页类型的结构体变量, 内存共享哈 希表以及虚拟机内存与物理内存的——映射关系等。 当 VMM 管理的虚拟机 VM是多个时,这个 VMM内存空间分别划分出独立的部分来存储不同虚拟机 VM的信息。 VMM可以通过调用系统接口访问所述 VMM内存空间。
步骤 305、 在内存快照文件中, 根据该内存页具体的页类型执行相应的内 存快照生成处理。这里的页类型包括: 气球页、需时分配页、共享页和交换页。
具体的, 当内存页为气球页时, 在前述内存快照文件(参照图 4 )的页类 型 4122字段中记录该内存页的页类型为气球页; 当内存页为需时分配页时, 在前述内存快照文件的页类型 4122字段中记录该内存页的页类型为需时分配 页; 当内存页为交换页时, 在前述内存快照文件的页类型 4122字段中记录该 内存页的页类型为交换页,从内存交换文件中拷贝该交换页的有效数据到前述 内存快照文件的数据段 42中,并在数据偏移量 4123字段中记录下这些有效数 据在数据段 42中的偏移量; 当内存页为共享页时, 在前述内存快照文件的页 类型 4122字段中记录该内存页的页类型为共享页, 拷贝该共享页的共享数据 到前述内存快照文件的数据段 42中,并在数据偏移量 4123字段中记录下这些 共享数据在数据段 42中的偏移量和与该共享页共享内存数据的其它内存页的 页号,这里的共享页号可以通过调用系统接口查询 VMM内存中保存的内存共 享哈希表获得。
步骤 306、 通过遍历内存页内容判断内存页内容是否全为 0。 如果为零, 该页即为零页, 转步骤 307; 如果不为零, 该页即为非零页, 转步骤 308; 步骤 307、 在内存快照文件中执行零页的相应处理, 即在所述内存快照文 件的页类型 4122中记录当前第 S内存页的页类型为零页, 不拷贝内存数据; 步骤 308、 在内存快照文件中执行非零页的相应处理, 即在所述内存快照 文件的页类型 4122中记录当前第 S内存页的页类型为非零页, 并拷贝所述当 前第 S内存页的页数据到所述内存快照文件的数据段 42中, 并在数据偏移量 4123中记录下数据在数据段 42中的偏移量。
步骤 309、 判断是否所有内存页都已处理完; 若步骤 309判断结果为是, 则执行步骤 310; 若步骤 309若判断结构为否, 则返回到步骤 303选取下一个 内存页继续该内存快照生成流程。
可以是, 每执行完一个内存页的内存快照处理都要执行步骤 309的判断, 可以通过页号来判断; 当内存快照文件中未保存页号等信息时, 可以通过标记 内存页为已读或已处理来判断。
步骤 310、输出内存快照文件;输出的内存快照文件可以存储在硬盘( Disk ) 中
步骤 311、 停止内存快照生成操作。
可选的, 在本发明实施例中, 当识别内存页为共享页时, 记录所有共享数 据的内存页号, 并拷贝它们共享的内存数据到内存快照文件中, 此时为了提高 内存页识别效率, 可以标记所有共享数据的内存页为已读, 进行内存页识别的 时候可以跳过这些标记为已读的共享页面。 综上所述, 本发明实施例提供的虚拟机内存快照生成方法,通过初始化一 个内存快照文件, 内存快照文件里具体包括信息段(全局信息、 页号、 页类型、 数据偏移量)和数据段; 然后顺序获取并识别虚拟机的内存页的页类型, 针对 不同的页类型在这个内存快照文件中执行不同的内存快照生成处理, 具体包 括: 当获取的内存页识别为气球页时,在这个内存快照文件的页类型字段中记 录该内存页的页类型为气球页; 当获取的内存页识别为需时分配页时,在这个 内存快照文件的页类型字段中记录该内存页的页类型为需时分配页;当获取的 内存页识别为交换页时,在这个内存快照文件的页类型字段中记录该内存页的 页类型为交换页,并从内存交换文件中拷贝交换页的有效数据到该内存快照文 件的数据段中, 并在数据偏移量字段中记录下数据在数据段中的偏移量; 当获 取的内存页识别为共享页时,在该内存快照文件的页类型字段中记录该内存页 的页类型为共享页, 拷贝这个共享页的共享数据到该内存快照文件的数据段 中,并在数据偏移量字段中记录下数据在数据段中的偏移量和与之共享内存数 据的其它内存页的页号,从而通过本发明实施例仅保存有效数据, 减少无效数 据的备份, 大大缩短了内存快照的生成时间, 并减小了内存快照文件的大小, 节约了存储资源。
本发明实施例三提供一种虚拟机内存快照恢复方法,如图 6所示, 该方法 可以包括:
步骤 S401、 获取并解析虚拟机的内存快照文件。
在一种实现方式下, 本发明实施例提供的内存快照文件结构如图 4所示,
S401可以是, 从该内存快照文件中读取并解析如图 4所示的结构中存储的信 息。
在另一种实现方式下, 本发明实施例提供的内存快照文件也可以如图 5 所示包含页类型 51和有效数据 52两个字段, S401可以是, 从该内存快照文 件中读取并解析如图 5所示的结构中存储的信息。
步骤 S402、 当这个内存快照文件中记录的当前第 S内存页的页类型为非 有效数据页时,在 VMM内存空间中记录当前第 S内存页的页类型为非有效数 据页; 当内存快照文件中记录的当前第 S内存页的页类型为有效数据页时,在 VMM内存空间中记录当前第 S内存页的页类型为有效数据页, 并将内存快照 文件中记录的当前第 S内存页的页数据对应地拷贝到所述虚拟机的第 S内存页 中。
具体的, 在一种实现方式下, 非有效数据页包括气球页和需时分配页, 所 述有效数据页包括共享页、 交换页和普通页;
相应的, 步骤 S402具体可以包括:
当内存快照文件中记录的当前第 S内存页的页类型为气球页时,在 VMM 内存空间中记录当前第 S内存页的页类型为气球页;
当内存快照文件中记录的当前第 S 内存页的页类型为需时分配页时, 在 VMM内存空间中记录当前第 S内存页的页类型为需时分配页;
当内存快照文件中记录的当前第 S内存页的页类型为共享页时,在 VMM 内存空间中记录当前第 S内存页的页类型为共享页,将该内存快照文件中记录 的当前第 S内存页的页数据拷贝到虚拟机的第 S内存页中,或者,拷贝到任一 与当前第 S 内存页共享数据的内存页中, 并基于该内存快照文件中记录的页 号,在 VMM内存空间中建立当前第 S内存页与前述页号对应的内存页之间的 共享关系;
当内存快照文件中记录的当前第 S内存页的页类型为交换页时,在 VMM 内存空间中记录当前第 S内存页的页类型为交换页,并将该内存快照文件中记 录的当前第 S内存页的页数据拷贝到新的内存交换文件中; 或者,在 VMM内 存空间中记录当前第 S内存页的页类型为普通页,并将该内存快照文件中记录 的当前第 S内存页的页数据对应地拷贝到虚拟机的第 S内存页中;
当内存快照文件中记录的当前第 S内存页的页类型为普通页时,在 VMM 内存空间中记录当前第 S内存页的页类型为普通页,并将该内存快照文件中记 录的当前第 S内存页的页数据对应地拷贝到虚拟机的第 S内存页中。
或者, 在另一种实现方式下, 所述非有效数据页包括气球页、 需时分配页 和零页;所述有效数据页包括非零页、共享页和交换页,还有以下两种情况(与 上述相同的内容, 这里不再贅述) :
当内存快照文件中记录的当前第 S内存页的页类型为零页时,在 VMM内 存空间中记录当前第 S内存页的页类型为零页,并将虚拟机的第 S内存页内容 置为 0;
当内存快照文件中记录的当前第 S内存页的页类型为非零页时,在 VMM 内存空间中记录当前第 S内存页的页类型为非零页,并将该内存快照文件中记 录的当前第 S内存页的页数据对应地拷贝到虚拟机的第 S内存页中;
综上所述, 本发明实施例提供的虚拟机内存快照恢复的方法,通过获取并 解析虚拟机的内存文件,然后根据内存快照文件中记录的内存页的不同页类型 执行不同的快照恢复处理, 包括: 当内存快照文件中记录的当前第 S内存页的 页类型为非有效数据页时,在 VMM内存空间中记录当前第 S内存页的页类型 为非有效数据页;当内存快照文件中记录的当前第 S内存页的页类型为有效数 据页时,在 VMM内存空间中记录当前第 S内存页的页类型为有效数据页, 并 将该内存快照文件中记录的当前第 S 内存页的页数据对应地拷贝到虚拟机的 第 S内存页中,从而通过本发明实施例仅恢复有效数据,避免了无效数据的恢 复过程, 大大缩短了内存快照的恢复时间。
图 7为本发明实施例四提供的一种虚拟机内存快照恢复方法,该方法步骤
S501和步骤 S503分别与实施例三和四中步骤 S401和步骤 S402相同,只是在 步骤 S501之后加入了步骤 S502判断内存快照文件是否完整: 若否,停止内存 恢复操作; 若是, 执行步骤 S503 , 即当所述内存快照文件中记录的当前第 S 内存页的页类型为非有效数据页时,在所述 VMM内存空间中记录所述当前第 S内存页的页类型为非有效数据页; 当所述内存快照文件中记录的当前第 S内 存页的页类型为有效数据页时, 在所述 VMM 内存空间中记录所述当前第 S 内存页的页类型为有效数据页, 并将所述内存快照文件中记录的所述当前第 S 内存页的页数据对应地拷贝到所述虚拟机的第 S内存页中。
具体的, 步骤 S502判断内存快照文件是否完整的方法主要有:
方法一: 如果内存快照中保存了虚拟机内存的全局信息, 包括虚拟机内存 大小、 内存页数量, 内存页大小等, 例如本发明实施例二图 4所示内存快照文 件结构,在这种情况下为判断内存快照完整性, 可以判断内存快照中的内存页 数量与全局信息的保存的内存页数量是否一致;或通过内存页数量与内存页大 小推算出内存大小(内存页数量与内存页大小相乘即可得内存大小), 再判断 推算出的内存大小与全局信息中保存的内存大小是否一致;或数据偏移量指向 的有效数据段内容是否存在, 即保存的有效数据是否丟失。如果存在不一致或 不存在的情况, 说明内存快照不完整, 停止内存快照恢复。
方法二: 如果内存快照中没有保存虚拟机内存的全局信息, 例如本发明实 施例二中图 5所示内存快照文件结构, 在这种情况下为判断内存快照完整性, 可以在推算出内存大小后判断推算的内存大小与虚拟机配置文件中的保存的 内存大小是否一致, 如果存在不一致, 说明内存快照不完整, 停止内存快照恢 复。
需要说明的是, 前述两种判断内存快照完整性的方法是举例说明, 没有限 制方法仅为这两种的意思。内存快照完整性判断依据的是虚拟机内存信息在快 照中是否保存完整, 所有的内存信息都可以进行判断, 只要一种信息不完整, 就停止内存恢复; 也可以根据实际情况只判断重要信息的完整性, 例如可能造 成内存恢复后虚拟机异常的信息。本领域技术人员根据本发明实施例容易推断 出其它信息的等同判断方式或组合等同判断方式, 本发明实施例在此不再贅 述。
如果不进行内存快照完整性判断,在目前的虚拟机内存快照恢复机制下内 存快照是可能恢复的, 但由于数据的丟失可能会在内存恢复后出现虚拟机异 常。
综上所述, 本发明实施例提供的虚拟机内存快照恢复的方法,通过获取并 解析虚拟机的内存文件;然后根据内存快照文件中记录的内存页的不同页类型 执行不同的快照恢复处理, 包括: 当内存快照文件中记录的当前第 S内存页的 页类型为非有效数据页时,在 VMM内存空间中记录当前第 S内存页的页类型 为非有效数据页;当内存快照文件中记录的当前第 S内存页的页类型为有效数 据页时,在 VMM内存空间中记录当前第 S内存页的页类型为有效数据页, 并 将该内存快照文件中记录的当前第 S 内存页的页数据对应地拷贝到虚拟机的 第 S内存页中,从而通过本发明实施例仅恢复有效数据,避免了无效数据的恢 复过程, 大大缩短了内存快照的恢复时间。 进一步的,在内存快照恢复之前进行内存快照文件完整性的判断,避免了 无谓的内存恢复操作, 提高了内存快照恢复操作的可靠性。
图 8为本发明实施例五提供的虚拟机内存快照恢复方法的具体流程图。该 方法包括:
步骤 600、 流程开始;
步骤 601、 读取并解析内存快照文件;
步骤 602、 判断该内存快照文件是否完整, 若该内存快照文件不完整, 则 转步骤 607; 若该内存快照文件完整, 则转步骤 603。
步骤 603、 顺序选取内存快照文件中存储的一条内存页信息, 所述内存页 信息包括内存页类型、有效数据或有效数据偏移量等(参照图 4或图 5所示的 内存快照文件结构) ;
步骤 604、 根据该内存页信息中的页类型识别当前内存页的页类型; 步骤 605、根据所述页类型执行相应的内存快照恢复处理,具体可以包括: 如果页类型为气球页时,在 VMM内存空间中记录该内存页的页类型为气 球页;
如果页类型为需时分配页时,在 VMM内存空间中记录该内存页的页类型 为需时分配页;
如果页类型为零页时, 在 VMM 内存空间中记录该内存页的页类型为零 页, 并将虚拟机的对应内存页内容置为 0;
如果页类型为非零页时,在 VMM内存空间中记录该内存页的页类型为非 零页, 并根据内存快照文件中直接存储的有效数据, 或者根据数据偏移量计算 而获得的有效数据地址, 将该内存的有效数据拷贝到对应的虚拟机内存页中; 如果页类型为共享页时,在 VMM内存空间中记录该内存页的页类型为共 享页,根据内存快照文件中直接存储的有效数据, 或者根据数据偏移量计算而 获得的有效数据地址,将该内存的有效数据拷贝到对应的虚拟机内存页中, 并 在 VMM 内存空间记录的内存共享哈希表中建立各个共享数据的内存页之间 的共享关系;
如果页类型为交换页时,在 VMM内存空间中记录该内存页的页类型为交 换页,根据内存快照文件中直接存储的有效数据, 或者根据数据偏移量计算而 获得的有效数据地址,将该内存的有效数据拷贝到一个新的交换文件中;或者, 在 VMM保存的页类型结构体中记录该内存页的页类型为零页或非零页,并将 有效数据拷贝到对应的虚拟机内存页中。
可选的, 步骤 605在 VMM内存空间中记录内存页的类型, 可以是在内存 快照生成时从中获取内存页类型的那个页类型结构体中恢复内存页的页类型 标识; 也可以在 VMM内存空间中重新建立一个页类型结构体,在其中记录内 存页的类型, 此时原先的页类型结构体不再使用。
步骤 606、 每执行完一条内存快照恢复操作判断是否所有页都处理完, 若 是, 则执行步骤 607; 若否返回到步骤 603继续该流程。
步骤 607、 停止内存恢复操作。
值得一提的是, 与本发明实施例提供的内存快照生成方法类似, 内存快照 恢复过程可以是由用户触发的, 物理主机提供内存恢复接口给最终用户, 以便 于触发内存快照恢复操作; 也可以是虚拟机自动触发的, 可以是定时触发, 也 可以根据虚拟机的运行状况等自动触发。
需要说明的是, 当内存页的页类型为交换页时, 根据交换页的特点, 既可 以将交换页的页数据拷贝到内存交换文件中,所述内存交换文件可以是新的内 存交换文件, 而不是内存快照生成时从中拷贝数据的那个内存交换文件, 这样 交换页仍然是交换页;或者,也可以将交换页的页数据拷贝到对应的内存页中, 此时交换页就成了一个普通页面,依据交换页中数据是否为零可以将其页类型 设置为零页或非零页, 当然也可以根据本发明实施例三设置为普通页。
另外, 需要说明的是, 本发明实施例三、 四和五中所述内存快照文件可以 是本发明实施例二中图 4、 图 5或其它等同替代或明显变形的内存快照文件结 构。
综上所述, 本发明实施例提供的虚拟机内存快照恢复的方法,通过获取并 解析虚拟机的内存文件; 然后判断内存快照文件的完整性; 对于完整的内存快 照文件根据该内存快照文件中记录的内存页的不同页类型执行不同的快照恢 复处理, 包括: 当该内存页的页类型为气球页时, 在 VMM内存空间中记录该 内存页的页类型为气球页; 当该内存页的页类型为需时分配页时,在 VMM内 存空间中记录该内存页的页类型为需时分配页; 当该内存页的页类型为零页 时,在 VMM内存空间中记录该内存页的页类型为零页, 并将虚拟机的对应内 存页内容置为 0; 当该内存页的页类型为非零页时, 在 VMM内存空间中记录 该内存页的页类型为非零页, 并根据内存快照文件中直接存储的有效数据, 或 者根据数据偏移量计算而获得的有效数据地址,将该内存的有效数据拷贝到对 应的虚拟机内存页中; 当该内存页的页类型为共享页时,在 VMM内存空间中 记录该内存页的页类型为共享页, 根据内存快照文件中直接存储的有效数据, 或者根据数据偏移量计算而获得的有效数据地址,将该内存的有效数据拷贝到 对应的虚拟机内存页中,并在 VMM内存空间记录的内存共享哈希表中建立各 个共享数据的内存页之间的共享关系; 当该内存页的页类型为交换页时, 在 VMM内存空间中记录该内存页的页类型为交换页, 根据内存快照文件中直接 存储的有效数据, 或者根据数据偏移量计算而获得的有效数据地址,将该内存 的有效数据拷贝到一个新的交换文件中; 或者,在 VMM保存的页类型结构体 中记录该内存页的页类型为零页或非零页,并将有效数据拷贝到对应的虚拟机 内存页中,从而通过本发明实施例仅恢复有效数据,避免了无效数据的恢复过 程, 大大缩短了内存快照的恢复时间, 并且在内存快照恢复之前进行内存快照 文件完整性的判断,避免了无谓的内存恢复操作,提高了内存快照恢复操作的 可靠性。
本发明实施例六还提供一种物理主机, 参照图 9, 所述物理主机包括: 硬 件层 100,运行在硬件层 100之上的虚拟机监视器 VMM200, 以及运行在虚拟 机监视器 VMM200上的虚拟机 300, 虚拟机监视器 VMM200中包括内存快照 生成模块 210和内存页识别模块 220, 其中:
内存快照生成模块 210用于: 获取虚拟机的当前第 S内存页; 当内存页识 别模块 220识别当前第 S内存页为非有效数据页时,在内存快照文件中记录当 前第 S内存页的页类型;当内存页识别模块 220识别当前第 S内存页为有效数 据页时, 在内存快照文件中记录当前第 S内存页的页类型和页数据;
需要说明的是,这里的内存快照文件可以是存储在本发明实施例的物理主 机的硬件层 100所包括的存储设备上,但在本发明实施例六中, 并没有限定内 存快照文件必须存储在所述物理主机的硬件层 100上的意思。内存快照文件可 以存储在硬件层 100的存储设备, 如硬盘 Disk 130中, 也可以存储在移动存 储设备上, 如 U盘或移动硬盘, 也可以是存储在与本发明实施例的物理主机 具有通信连接的外部网络存储设备上。
内存页识别模块 210用于: 识别内存快照生成模块 210获取的当前第 S 内存页的页类型, 所述页类型包括非有效数据页和有效数据页;
具体的, 在一种实现方式下, 内存页识别模块 210具体用于: 根据 VMM 内存空间中保存的页类型信息,识别当前第 S内存页的页类型,所述页类型包 括气球页、 需时分配页、 共享页、 交换页和普通页; 其中, 气球页和需时分配 页为非有效数据页, 共享页、 交换页和普通页为有效数据页;
或者, 在另一种实现方式下, 内存页识别模块 210具体用于: 根据 VMM 内存空间中保存的页类型信息,识别当前第 S内存页的页类型,所述页类型包 括气球页、 需时分配页、 共享页、 交换页和普通页; 当当前第 S内存页的页类 型为普通页时, 遍历所述当前第 S内存页的内容, 根据遍历的结果(内存页内 容全为 0或不全为 0 )确定所述当前第 S内存页的页类型为零页或非零页; 其 中, 气球页、 需时分配页和零页为非有效数据页, 非零页、 共享页和交换页为 有效数据页。
进一步的, 本发明实施例提供的物理主机中, 硬件层 100包括存储设备, 如硬盘 130, 所述存储设备用于: 存储所述内存快照文件。
此外, 本发明实施例也不对硬件层 100 的组成作任何限定, 硬件层 100 可以包括存储设备, 如硬盘 130, 也可以不包括硬盘 130, 在一种较优实现方 式下, 该物理主机硬件层 100可以包括处理器 110、 物理内存 120、 硬盘 130 以及网络接口设备 140, 其中处理器 110可以是一个, 也可以是多个; 网络接 口设备 140可以是网络适配器或网卡, 用于跟任何可连接的网络做连接, 例如 互联网(Internet )、 企业网等。 在另一种实现方式下, 硬件层可以不包括硬盘 130 (参见系统实施例)。 虚拟机 VM300可以包括虚拟处理器 310、 虚拟内存 320、 虚拟硬盘 330以及客户操作系统 340, 其中虚拟内存 320的逻辑内存页 与物理内存 120的物理内存页之间存在——映射关系,本发明实施例要生成的 内存快照即是针对与该虚拟内存对应的物理内存; 客户操作系统 (Guest
Operation System, Guest OS ) 340是运行在虚拟处理器 310、 虚拟内存 320、 虚拟硬盘 330等虚拟设备之上的操作系统。
需要说明的是,图 9所示虚拟机监视器 VMM200运行在硬件层 100之上, 并无限定的意思, 实际上虚拟机监视器 VMM可以直接运行在硬件层之上; 虚 拟机监视器 VMM也可以直接运行在宿主操作系统(Host Operation System,
Host OS )之上, 相应的, 宿主操作系统可以运行在硬件层之上, 换言之, 虚 拟机监视器 VMM可以间接地运行在硬件层之上。
需要说明的是, 本发明实施例提供的物理主机可以是物理计算机, 具体可 以是个人计算机 PC、 笔记本电脑 laptop, 工作站 Workstation, 服务器 Server, 大型机 Mainframe或者超级计算机 Supercomputer等等。
另外, 本发明实施例七还提供一种物理主机, 参照图 9, 该物理主机除前 述组成设备之外, 在虚拟机监视器 VMM200中还可以包括内存快照恢复模块 230。
该内存快照恢复模块 230用于: 获取并解析该虚拟机的内存快照文件; 当 该内存快照文件中记录的当前第 S 内存页的页类型为非有效数据页时, 在 VMM内存空间中记录当前第 S内存页的页类型为非有效数据页; 当该内存快 照文件中记录的当前第 S内存页的页类型为有效数据页时,在 VMM内存空间 中记录当前第 S内存页的页类型为有效数据页,并将该内存快照文件中记录的 所述当前第 S内存页的页数据对应地拷贝到虚拟机的第 S内存页中。
具体的, 在一种实现方式下, 所述非有效数据包括气球页和需时分配页, 所述有效数据页包括共享页、 交换页和普通页;
相应的, 该内存快照恢复模块 230具体用于:
当内存快照文件中记录的当前第 S内存页的页类型为气球页时,在 VMM 内存空间中记录当前第 S内存页的页类型为气球页;
当内存快照文件中记录的当前第 S 内存页的页类型为需时分配页时, 在 VMM内存空间中记录当前第 S内存页的页类型为需时分配页; 当内存快照文件中记录的当前第 S内存页的页类型为共享页时,在 VMM 内存空间中记录当前第 S内存页的页类型为共享页,将该内存快照文件中记录 的当前第 S内存页的页数据拷贝到虚拟机的第 S内存页中,或者,拷贝到任一 与当前第 S 内存页共享数据的内存页中, 并基于该内存快照文件中记录的页 号,在 VMM内存空间中建立当前第 S内存页与前述页号对应的内存页之间的 共享关系;
当内存快照文件中记录的当前第 S内存页的页类型为交换页时,在 VMM 内存空间中记录当前第 S内存页的页类型为交换页,并将该内存快照文件中记 录的当前第 S内存页的页数据拷贝到新的内存交换文件中; 或者,在 VMM内 存空间中记录当前第 S内存页的页类型为普通页,并将该内存快照文件中记录 的当前第 S内存页的页数据对应地拷贝到虚拟机的第 S内存页中;
当内存快照文件中记录的当前第 S内存页的页类型为普通页时,在 VMM 内存空间中记录当前第 S内存页的页类型为普通页,并将该内存快照文件中记 录的当前第 S内存页的页数据对应地拷贝到虚拟机的第 S内存页中。
或者, 在另一种实现方式下, 所述非有效数据页包括气球页、 需时分配页 和零页; 所述有效数据页包括非零页、 共享页和交换页:
相应的, 该内存快照恢复模块 230具体用于:
当内存快照文件中记录的当前第 S内存页的页类型为气球页时,在 VMM 内存空间中记录当前第 S内存页的页类型为气球页;
当内存快照文件中记录的当前第 S 内存页的页类型为需时分配页时, 在
VMM内存空间中记录当前第 S内存页的页类型为需时分配页;
当内存快照文件中记录的当前第 S内存页的页类型为共享页时,在 VMM 内存空间中记录当前第 S内存页的页类型为共享页,将该内存快照文件中记录 的当前第 S内存页的页数据拷贝到虚拟机的第 S内存页中,或者,拷贝到任一 与当前第 S 内存页共享数据的内存页中, 并基于该内存快照文件中记录的页 号,在 VMM内存空间中建立当前第 S内存页与前述页号对应的内存页之间的 共享关系;
当内存快照文件中记录的当前第 S内存页的页类型为交换页时,在 VMM 内存空间中记录当前第 S内存页的页类型为交换页,并将该内存快照文件中记 录的当前第 S内存页的页数据拷贝到新的内存交换文件中; 或者,在 VMM内 存空间中记录当前第 S内存页的页类型为普通页,并将该内存快照文件中记录 的当前第 S内存页的页数据对应地拷贝到虚拟机的第 S内存页中;
当内存快照文件中记录的当前第 S内存页的页类型为零页时,在 VMM内 存空间中记录当前第 S内存页的页类型为零页,并将虚拟机的第 S内存页内容 置为 0;
当内存快照文件中记录的当前第 S内存页的页类型为非零页时,在 VMM 内存空间中记录当前第 S内存页的页类型为非零页,并将该内存快照文件中记 录的当前第 S内存页的页数据对应地拷贝到虚拟机的第 S内存页中。
综上所述, 以上发明实施例提供的物理主机,通过内存快照生成模块获取 所述虚拟机的当前第 S内存页,然后通过内存页识别模块进行当前第 S内存页 的页类型识别, 当识别出当前第 S内存页为非有效数据页时,在内存快照文件 中记录该当前第 S内存页的页类型;当识别出当前第 S内存页为有效数据页时, 在内存快照文件中记录该当前第 S内存页的页类型和页数据,从而通过以上发 明实施例仅保存有效数据,避免了无效数据的备份, 大大缩短了内存快照的生 成时间, 减小了内存快照对存储资源的占用。
进一步的, 通过内存快照恢复模块获取并解析所述虚拟机的内存快照文 件; 当所述内存快照文件中记录的当前第 S 内存页的页类型为非有效数据页 时,在所述 VMM内存空间中记录所述当前第 S内存页的页类型为非有效数据 页; 当所述内存快照文件中记录的当前第 S内存页的页类型为有效数据页时, 在所述 VMM内存空间中记录所述当前第 S内存页的页类型为有效数据页,并 将所述内存快照文件中记录的所述当前第 S 内存页的页数据对应地拷贝到所 述虚拟机的第 S内存页中,从而通过以上发明实施例仅恢复有效数据,避免了 无效数据的恢复过程, 大大缩短了内存快照的恢复时间。
图 10为本发明实施例八提供的一种计算机系统的逻辑结构图, 该系统包 括: 物理主机 1、 物理主机 2、 以及一个网络存储设备 500, 其中: 物理主机 1 和物理主机 2为本发明实施例六或七中所述的物理主机, 包括硬件层、 VMM 和 VM1到 VMn, 其中 n大于或等于 1 , 换言之, VMM上可以宿主一个或多 个 VM; 网络存储设备 500用于存储物理主机 1或物理主机 2上所宿主的虚拟 机的内存快照文件。
物理主机 1和物理主机 2通过各自的网络接口设备 1和网络接口设备 2 分别与互联网 400相连,然后可以通过互联网 400将虚拟机的内存快照文件存 储到网络存储设备 500上。
需要说明的是,本发明实施例中提供的系统其中的内存快照文件可以只存 储在网络存储设备上,也可以同时存储在网络存储设备和物理主机硬件层的存 储设备中, 不做限定。
图 11为本发明实施九提供的计算机系统的网络拓朴图, 其中物理主机 1 和物理主机 2通过互联网 400与网络存储设备 500相连。
可选的, 所述网络存储设备可以采用中心化存储模式,也可以采用分布式 存储模式。 网络存储设备可以是一个, 采用中心化存储模式; 也可以是多个, 采用单个存储模式或分布式存储模式。所述中心化存储模式指一个内存快照文 件存储在一台网络存储设备里;所述分布式存储模式指一个内存快照文件存储 在多台网络存储设里。后者更适用于物理主机比较多、 内存快照文件产生比较 多的情况下。
综上所述, 本发明实施例提供的虚拟机内存快照生成和恢复的系统中, 通 过识别不同的内存页类型,在内存快照生成过程中,根据不同的内存页类型执 行不同的快照生成处理, 包括: 在当前第 S内存页为非有效数据页时, 在内存 快照文件中仅记录所述当前第 S内存页的页类型;在当前第 S内存页为有效数 据页时,在内存快照文件中记录所述当前第 S内存页的页类型和页数据;以及, 在内存快照恢复过程中,根据不同的内存页类型执行不同的快照恢复处理, 包 括: 当所述内存快照文件中记录的当前第 S 内存页的页类型为非有效数据页 时, 在 VMM内存空间中记录所述当前第 S内存页的页类型为非有效数据页; 当所述内存快照文件中记录的当前第 S内存页的页类型为有效数据页时,在所 述 VMM内存空间中记录所述当前第 S内存页的页类型为有效数据页,并将所 述内存快照文件中记录的所述当前第 S 内存页的页数据对应地拷贝到所述虚 拟机的第 S内存页中,从而通过本发明实施例仅保存有效数据,减少无效数据 的备份和恢复, 大大缩短了内存快照的生成和恢复时间, 减小了内存快照对存 储资源的占用。
举个具体例子, 桌面云环境下的典型 Windows虚拟机, 虚拟机全部内存 为 4G, 在一般业务场景下零页在虚拟机全部内存中平均占比达到 50%左右, 同时气泡页也占虚拟机全部内存的 10%左右,此时若运用本发明实施例提供的 内存快照生成和恢复技术,内存快照的生成和恢复时间能缩短为现有技术实现 方式的 40%左右, 同时, 内存快照文件的大小由原来的 4G减小为 1.61G (内 存快照文件中的除内存页数据之外的其它数据大约为 10M ) 。
进一步的,通过本发明实施例提供的网络存储设备存储内存快照文件,避 免了存在大量内存快照文件时, 本地存取空间不足的问题; 如果同时采用分布 式网络存储模式也可以解决中心化存储模式的存取瓶颈的问题。
本领域普通技术人员可以理解实现前述实施例方法中的全部或部分流程, 是可以通过计算机程序来指令相关的硬件 (如处理器)来完成, 所述的程序可存 储于一计算机可读取存储介质中, 该程序在执行时, 可包括如前述各方法的实 施例的流程。 其中, 所述的存储介质可为磁碟、 光盘、 只读存储记忆体
( Read-Only Memory, ROM )或随机存储记忆体 ( Random Access Memory, RAM )等。
以上所述仅是本发明的具体实施方式,应当指出,对于本技术领域的普通 技术人员来说, 在不脱离本发明原理的前提下, 还可以做出若干改进和润饰, 这些改进和润饰也应视为本发明的保护范围。

Claims

权 利 要 求 书
1、 一种虚拟机内存快照生成方法, 其特征在于, 所述方法包括: 获取所述虚拟机的当前第 S内存页;
识别所述当前第 S内存页的页类型,所述页类型包括非有效数据页和有效 数据页;
当所述当前第 S内存页为非有效数据页时,在内存快照文件中记录所述当 前第 S内存页的页类型; 当所述当前第 S内存页为有效数据页时,在内存快照 文件中记录所述当前第 S内存页的页类型和页数据。
2、 根据权利要求 1所述的方法, 其特征在于, 所述识别所述当前第 S内 存页的页类型, 具体包括:
根据 VMM内存空间中保存的页类型信息,确定所述当前第 S内存页的页 类型, 所述页类型包括气球页、 需时分配页、共享页、 交换页和普通页; 其中, 气球页和需时分配页为非有效数据页,共享页、交换页和普通页为有效数据页。
3、 根据权利要求 2所述的方法, 其特征在于, 所述当所述当前第 S内存 页为非有效数据页时, 在内存快照文件中记录所述当前第 S内存页的页类型; 当所述当前第 S内存页为有效数据页时,在内存快照文件中记录所述当前第 S 内存页的页类型和页数据, 具体包括:
当所述当前第 S内存页为气球页时,在所述内存快照文件中记录当前第 S 内存页的页类型为气球页;
当所述当前第 S内存页为需时分配页时,在所述内存快照文件中记录当前 第 S内存页的页类型为需时分配页;
当所述当前第 S内存页为交换页时,在所述内存快照文件中记录当前第 S 内存页的页类型为交换页,并从内存交换文件中拷贝所述交换页的页数据到所 述内存快照文件中;
当所述当前第 S内存页为共享页时,在所述内存快照文件中记录当前第 S 内存页的页类型为共享页, 拷贝所述共享页的页数据到所述内存快照文件中, 并记录与所述当前第 S内存页共享内存数据的其它内存页的页号; 当所述当前第 S内存页为普通页时,在所述内存快照文件中记录当前第 S 内存页的页类型为普通页, 拷贝所述普通页的页数据到所述内存快照文件中。
4、 根据权利要求 1所述的方法, 其特征在于, 所述识别所述当前第 S内 存页的页类型, 具体包括:
根据 VMM内存空间中保存的页类型信息,确定所述当前第 S内存页的页 类型, 所述页类型包括气球页、 需时分配页、 共享页、 交换页和普通页;
当所述当前第 S内存页的页类型为普通页时,遍历所述当前第 S内存页的 内容,根据遍历结果确定所述当前第 S内存页的页类型为零页或非零页;其中, 气球页、 需时分配页和零页为非有效数据页, 非零页、 共享页和交换页为有效 数据页。
5、 根据权利要求 4所述的方法, 其特征在于, 所述当所述当前第 S内存 页为非有效数据页时, 在内存快照文件中记录所述当前第 S内存页的页类型; 当所述当前第 S内存页为有效数据页时,在内存快照文件中记录所述当前第 S 内存页的页类型和数据, 具体包括:
当所述当前第 S内存页为气球页时,在所述内存快照文件中记录当前第 S 内存页的页类型为气球页;
当所述当前第 S内存页为需时分配页时,在所述内存快照文件中记录当前 第 S内存页的页类型为需时分配页;
当所述当前第 S内存页为零页时,在所述内存快照文件记录当前第 S内存 页的页类型为零页;
当所述当前第 S内存页为非零页时,在所述内存快照文件中记录当前第 S 内存页的页类型为非零页,拷贝所述当前第 S内存页的页数据到所述内存快照 文件中;
当所述当前第 S内存页为交换页时,在所述内存快照文件中记录当前第 S 内存页的页类型为交换页,从内存交换文件中拷贝所述交换页的页数据到所述 内存快照文件中;
当所述当前第 S内存页为共享页时,在所述内存快照文件中记录当前第 S 内存页的页类型为共享页, 拷贝所述共享页的页数据到所述内存快照文件中, 并记录与所述第 S内存页共享内存数据的其它内存页的页号。
6、 一种虚拟机内存快照恢复方法, 其特征在于, 所述方法包括: 获取并解析所述虚拟机的内存快照文件;
当所述内存快照文件中记录的当前第 S 内存页的页类型为非有效数据页 时, 在 VMM内存空间中记录所述当前第 S内存页的页类型为非有效数据页; 当所述内存快照文件中记录的当前第 S内存页的页类型为有效数据页时,在所 述 VMM内存空间中记录所述当前第 S内存页的页类型为有效数据页,并将所 述内存快照文件中记录的所述当前第 S 内存页的页数据对应地拷贝到所述虚 拟机的第 S内存页中。
7、 根据权利要求 6所述的方法, 其特征在于, 在获取并解析所述虚拟机 的的内存快照文件之后, 所述方法还包括:
判断所述内存快照文件是否完整, 若所述内存快照文件不完整,停止内存 恢复操作; 若所述内存快照文件完整,执行所述当所述内存快照文件中记录的 当前第 S内存页的页类型为非有效数据页时,在所述 VMM内存空间中记录所 述当前第 S内存页的页类型为非有效数据页;当所述内存快照文件中记录的当 前第 S内存页的页类型为有效数据页时,在所述 VMM内存空间中记录所述当 前第 S内存页的页类型为有效数据页,并将所述内存快照文件中记录的所述当 前第 S内存页的页数据对应地拷贝到所述虚拟机的第 S内存页中的步骤。
8、 根据权利要求 6或 7所述的方法, 其特征在于, 所述非有效数据页包 括气球页和需时分配页; 所述有效数据页包括共享页、 交换页和普通页。
9、 根据权利要求 8所述的方法, 其特征在于, 所述当所述内存快照文件 中记录的当前第 S内存页的页类型为非有效数据页时,在所述 VMM内存空间 中记录所述当前第 S内存页的页类型为非有效数据页;当所述内存快照文件中 记录的当前第 S内存页的页类型为有效数据页时,在所述 VMM内存空间中记 录所述当前第 S内存页的页类型为有效数据页,并将所述内存快照文件中记录 的所述当前第 S内存页的页数据对应地拷贝到所述虚拟机的第 S内存页中,具 体包括:
当所述内存快照文件中记录的当前第 S内存页的页类型为气球页时,在所 述 VMM内存空间中记录所述当前第 S内存页的页类型为气球页; 当所述内存快照文件中记录的当前第 S内存页的页类型为需时分配页时, 在所述 VMM内存空间中记录所述当前第 S内存页的页类型为需时分配页; 当所述内存快照文件中记录的当前第 S内存页的页类型为共享页时,在所 述 VMM内存空间中记录所述当前第 S内存页的页类型为共享页,将所述内存 快照文件中记录的当前第 S 内存页的页数据拷贝到所述虚拟机的第 S 内存页 中, 或者, 拷贝到任一与所述当前第 S内存页共享数据的内存页中, 并基于所 述内存快照文件中记录的页号, 在所述 VMM 内存空间中建立所述当前第 S 内存页与所述页号对应的内存页之间的共享关系;
当所述内存快照文件中记录的当前第 S内存页的页类型为交换页时,在所 述 VMM内存空间中记录所述当前第 S内存页的页类型为交换页,并将所述内 存快照文件中记录的当前第 S内存页的页数据拷贝到新的内存交换文件中;或 者,在所述 VMM内存空间中记录所述当前第 S内存页的页类型为普通页,并 将所述内存快照文件中记录的当前第 S 内存页的页数据对应地拷贝到所述虚 拟机的第 S内存页中;
当所述内存快照文件中记录的当前第 S内存页的页类型为普通页时,在所 述 VMM内存空间中记录所述当前第 S内存页的页类型为普通页,并将所述内 存快照文件中记录的当前第 S内存页的页数据对应地拷贝到所述虚拟机的第 S 内存页中。
10、 根据权利要求 6或 7所述的方法, 其特征在于, 所述非有效数据页包 括气球页、需时分配页和零页;所述有效数据页包括非零页、共享页和交换页。
11、 根据权利要求 11所述的方法, 其特征在于, 所述当所述内存快照文 件中记录的当前第 S内存页的页类型为非有效数据页时,在所述 VMM内存空 间中记录所述当前第 S内存页的页类型为非有效数据页;当所述内存快照文件 中记录的当前第 S内存页的页类型为有效数据页时,在所述 VMM内存空间中 记录所述当前第 S内存页的页类型为有效数据页,并将所述内存快照文件中记 录的所述当前第 S内存页的页数据对应地拷贝到所述虚拟机的第 S内存页中, 具体包括: 当所述内存快照文件中记录的当前第 S内存页的页类型为气球页时,在所 述 VMM内存空间中记录所述当前第 S内存页的页类型为气球页;
当所述内存快照文件中记录的当前第 S内存页的页类型为需时分配页时, 在 VMM内存空间中记录所述当前第 S内存页的页类型为需时分配页;
当所述内存快照文件中记录的当前第 S内存页的页类型为零页时,在所述
VMM内存空间中记录所述当前第 S内存页的页类型为零页, 并将所述虚拟机 的第 S内存页内容置为 0;
当所述内存快照文件中记录的当前第 S内存页的页类型为非零页时,在所 述 VMM内存空间中记录所述当前第 S内存页的页类型为非零页,并将所述内 存快照文件中记录的所述当前第 S 内存页的页数据对应地拷贝到所述虚拟机 的第 S内存页中;
当所述内存快照文件中记录的当前第 S内存页的页类型为共享页时,在所 述 VMM内存空间中记录所述当前第 S内存页的页类型为共享页,将所述内存 快照文件中记录的当前第 S 内存页的页数据拷贝到所述虚拟机的第 S 内存页 中, 或者, 拷贝到任一与所述当前第 S内存页共享数据的内存页中, 并基于所 述内存快照文件中记录的页号, 在所述 VMM 内存空间中建立所述当前第 S 内存页与所述页号对应的内存页之间的共享关系;
当所述内存快照文件中记录的当前第 S内存页的页类型为交换页时,在所 述 VMM内存空间中记录所述当前第 S内存页的页类型为交换页,并将所述内 存快照文件中记录的当前第 S内存页的页数据拷贝到内存交换文件中; 或者, 在所述 VMM内存空间中记录所述当前第 S内存页的页类型为零页或非零页, 并将所述内存快照文件中记录的当前第 S 内存页的页数据对应地拷贝到所述 虚拟机的第 S内存页中。
12、 一种物理主机, 其特征在于, 所述物理主机包括: 硬件层, 运行在所 述硬件层之上的虚拟机监视器 VMM , 以及运行在所述虚拟机监视器 VMM上 的虚拟机, 所述虚拟机监视器 VMM 包括内存快照生成模块和内存页识别模 块, 其中:
所述内存快照生成模块用于: 获取所述虚拟机的当前第 S内存页; 当所述 内存页识别模块识别所述当前第 S内存页为非有效数据页时,在内存快照文件 中记录所述当前第 S内存页的页类型;当所述内存页识别模块识别所述当前第
S内存页为有效数据页时,在内存快照文件中记录所述当前第 S内存页的页类 型和页数据;
所述内存页识别模块用于:识别所述内存快照生成模块获取的所述当前第
S内存页的页类型, 所述页类型包括非有效数据页和有效数据页。
13、 根据权利要求 12所述的物理主机, 其特征在于, 所述硬件层包括存 储设备, 所述存储设备用于: 存储所述内存快照文件。
14、 根据权利要求 12所述的物理主机, 其特征在于, 所述内存页识别模 块具体用于: 根据 VMM 内存空间中保存的页类型信息, 确定所述当前第 S 内存页的页类型, 所述页类型包括气球页、 需时分配页、 共享页、 交换页和普 通页; 其中, 气球页和需时分配页为非有效数据页, 共享页、 交换页和普通页 为有效数据页。
15、 根据权利要求 12所述的物理主机, 其特征在于, 所述内存页识别模 块具体用于: 根据 VMM 内存空间中保存的页类型信息, 确定所述当前第 S 内存页的页类型, 所述页类型包括气球页、 需时分配页、 共享页、 交换页和普 通页; 当所述当前第 S内存页的页类型为普通页时,遍历所述当前第 S内存页 的内容,根据遍历结果确定所述当前第 S内存页的页类型为零页或非零页; 其 中, 气球页、 需时分配页和零页为非有效数据页, 非零页、 共享页和交换页为 有效数据页。
16、 根据权利要求 12至 15任一项所述的物理主机, 其特征在于, 所述虚 拟机监视器 VMM中还包括内存快照恢复模块, 其中:
所述内存快照恢复模块用于:从所述硬件层中的存储设备中获取并解析所 述虚拟机的内存快照文件;当所述内存快照文件中记录的当前第 S内存页的页 类型为非有效数据页时,在所述 VMM内存空间中中记录所述当前第 S内存页 的页类型为非有效数据页;当所述内存快照文件中记录的当前第 S内存页的页 类型为有效数据页时,在所述 VMM内存空间中中记录所述当前第 S内存页的 页类型为有效数据页,并将所述内存快照文件中记录的所述当前第 S内存页的 页数据对应地拷贝到所述虚拟机的第 S内存页中。
17、 一种计算机系统, 其特征在于, 所述系统包括: 物理主机和网络存储 设备, 其中:
所述物理主机为权利要求 12至 16任一项所述的物理主机;
所述网络存储设备用于存储所述物理主机上所宿主的虚拟机的内存快照 文件。
PCT/CN2012/072887 2011-10-12 2012-03-23 一种虚拟机内存快照生成和恢复方法、装置及系统 WO2012149844A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP12779387.5A EP2755132B1 (en) 2011-10-12 2012-03-23 Virtual machine memory snapshot generating and recovering method, device and system
US14/251,785 US9507672B2 (en) 2011-10-12 2014-04-14 Method, apparatus, and system for generating and recovering memory snapshot of virtual machine

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201110307790.4 2011-10-12
CN201110307790.4A CN102331949B (zh) 2011-10-12 2011-10-12 一种虚拟机内存快照生成和恢复方法、装置及系统

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US14/251,785 Continuation US9507672B2 (en) 2011-10-12 2014-04-14 Method, apparatus, and system for generating and recovering memory snapshot of virtual machine

Publications (1)

Publication Number Publication Date
WO2012149844A1 true WO2012149844A1 (zh) 2012-11-08

Family

ID=45483735

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2012/072887 WO2012149844A1 (zh) 2011-10-12 2012-03-23 一种虚拟机内存快照生成和恢复方法、装置及系统

Country Status (4)

Country Link
US (1) US9507672B2 (zh)
EP (1) EP2755132B1 (zh)
CN (1) CN102331949B (zh)
WO (1) WO2012149844A1 (zh)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9733964B2 (en) 2013-08-27 2017-08-15 Red Hat, Inc. Live snapshot of a virtual machine
US9842032B2 (en) 2013-08-27 2017-12-12 Red Hat, Inc. Memory first live snapshot
CN109460258A (zh) * 2017-08-28 2019-03-12 西安中兴新软件有限责任公司 一种启动电子设备的方法及装置
CN109710377A (zh) * 2018-12-14 2019-05-03 国云科技股份有限公司 一种从故障的分布式存储里恢复kvm虚拟机的方法

Families Citing this family (32)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102331949B (zh) * 2011-10-12 2014-11-05 华为技术有限公司 一种虚拟机内存快照生成和恢复方法、装置及系统
CN103019884B (zh) * 2012-11-21 2015-07-01 北京航空航天大学 基于虚拟机快照的内存页去重方法及装置
US9430333B2 (en) * 2013-03-14 2016-08-30 Microsoft Technology Licensing, Llc Recovery of application from snapshot
CN103425535B (zh) * 2013-06-05 2016-08-10 浙江大学 云环境下的敏捷弹性伸缩方法
CN104572138B (zh) * 2013-10-10 2018-10-30 腾讯科技(深圳)有限公司 应用程序的启动方法及装置
US9459900B2 (en) * 2014-01-13 2016-10-04 Red Hat Israel, Ltd. Hypervisor-based balloon page initialization
CN104102528A (zh) * 2014-07-14 2014-10-15 南京理工大学 快速的虚拟机监视器性能恢复方法
CN105573813B (zh) * 2014-10-10 2018-11-13 北京航空航天大学 虚拟机连续快照方法和装置
CN104268005B (zh) * 2014-10-22 2018-11-30 华为技术有限公司 虚拟机唤醒方法和装置
CN105607962B (zh) * 2015-10-22 2019-03-19 华为技术有限公司 一种虚拟机备份的方法和装置
US20170123657A1 (en) * 2015-11-02 2017-05-04 Dell Products L.P. Systems and methods for back up in scale-out storage area network
CN105260231A (zh) * 2015-11-03 2016-01-20 国云科技股份有限公司 一种降低物理磁盘io读写的方法
CN106201656B (zh) * 2016-06-30 2019-06-07 无锡华云数据技术服务有限公司 一种对kvm虚拟机快照存储空间的统计方法
CN106445732B (zh) * 2016-08-30 2018-04-24 华中科技大学附属中学 一种基于版本控制的在线快照管理方法和系统
CN106775939B (zh) * 2016-12-06 2019-12-31 爱普(福建)科技有限公司 一种工业控制系统中内存快照管理方法
EP3502877B1 (en) 2017-09-29 2021-03-03 Huawei Technologies Co., Ltd. Data loading method and apparatus for virtual machines
CN107832097B (zh) * 2017-09-29 2020-04-28 华为技术有限公司 数据加载方法及装置
CN108334419B (zh) * 2017-12-25 2021-12-28 华为技术有限公司 一种数据恢复的方法和装置
CN110096451B (zh) * 2018-01-29 2023-08-04 华为技术有限公司 一种数据存储方法及装置
US10698716B2 (en) * 2018-03-15 2020-06-30 Nutanix, Inc. Virtual machine state recorder
CN108595308B (zh) * 2018-05-09 2021-12-31 南京思达捷信息科技有限公司 一种基于管理的大数据服务器的处置系统及其方法
CN108717457B (zh) * 2018-05-23 2022-03-22 苏州易康萌思网络科技有限公司 一种电子商务平台大数据处理方法和系统
CN109144776B (zh) * 2018-07-20 2021-04-06 新华三技术有限公司 虚拟机镜像文件处理方法及装置
CN109325022B (zh) * 2018-07-20 2021-04-27 新华三技术有限公司 一种数据处理方法和装置
CN110874473A (zh) * 2018-09-04 2020-03-10 成都华为技术有限公司 病毒检测方法、装置及系统、云服务系统、存储介质
CN109408295A (zh) * 2018-11-13 2019-03-01 郑州云海信息技术有限公司 一种基于分布式存储系统的克隆卷填充方法、装置及设备
US11461121B2 (en) * 2019-07-26 2022-10-04 Red Hat, Inc. Guest-driven virtual machine snapshots
CN111143025B (zh) * 2019-11-22 2023-03-24 中国船舶工业系统工程研究院 一种针对实时虚拟机实例管理的方法
US20210224161A1 (en) 2020-01-21 2021-07-22 Nebulon, Inc. Efficient io processing in a storage system with instant snapshot, xcopy, and unmap capabilities
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
CN112988077B (zh) * 2021-04-27 2021-07-23 云宏信息科技股份有限公司 一种虚拟磁盘复制方法和计算机可读存储介质
CN114138424B (zh) * 2022-02-07 2022-05-20 苏州浪潮智能科技有限公司 一种虚拟机内存快照生成方法、装置及电子设备

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1755673A (zh) * 2004-09-30 2006-04-05 株式会社东芝 具备文件管理功能的文件系统及文件管理方法
CN101063951A (zh) * 2006-04-28 2007-10-31 英业达股份有限公司 采用位映像表算法处理存储设备快照的方法
US20080022032A1 (en) * 2006-07-13 2008-01-24 Microsoft Corporation Concurrent virtual machine snapshots and restore
CN102331949A (zh) * 2011-10-12 2012-01-25 华为技术有限公司 一种虚拟机内存快照生成和恢复方法、装置及系统

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6789156B1 (en) * 2001-05-22 2004-09-07 Vmware, Inc. Content-based, transparent sharing of memory units
CN1955939A (zh) * 2006-10-13 2007-05-02 清华大学 基于虚拟内存盘的备份与恢复方法
US20100070678A1 (en) * 2008-09-12 2010-03-18 Vmware, Inc. Saving and Restoring State Information for Virtualized Computer Systems
CN101436207B (zh) * 2008-12-16 2011-01-19 浪潮通信信息系统有限公司 一种基于日志快照的数据恢复和同步方法
CN102193843B (zh) * 2010-03-19 2013-05-29 复旦大学 虚拟机系统崩溃现场保存的加速方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1755673A (zh) * 2004-09-30 2006-04-05 株式会社东芝 具备文件管理功能的文件系统及文件管理方法
CN101063951A (zh) * 2006-04-28 2007-10-31 英业达股份有限公司 采用位映像表算法处理存储设备快照的方法
US20080022032A1 (en) * 2006-07-13 2008-01-24 Microsoft Corporation Concurrent virtual machine snapshots and restore
CN102331949A (zh) * 2011-10-12 2012-01-25 华为技术有限公司 一种虚拟机内存快照生成和恢复方法、装置及系统

Non-Patent Citations (1)

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

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9733964B2 (en) 2013-08-27 2017-08-15 Red Hat, Inc. Live snapshot of a virtual machine
US9842032B2 (en) 2013-08-27 2017-12-12 Red Hat, Inc. Memory first live snapshot
US11604708B2 (en) 2013-08-27 2023-03-14 Red Hat, Inc. Memory first live snapshot
CN109460258A (zh) * 2017-08-28 2019-03-12 西安中兴新软件有限责任公司 一种启动电子设备的方法及装置
CN109460258B (zh) * 2017-08-28 2024-02-13 西安中兴新软件有限责任公司 一种启动电子设备的方法及装置
CN109710377A (zh) * 2018-12-14 2019-05-03 国云科技股份有限公司 一种从故障的分布式存储里恢复kvm虚拟机的方法
CN109710377B (zh) * 2018-12-14 2023-06-30 国云科技股份有限公司 一种从故障的分布式存储里恢复kvm虚拟机的方法

Also Published As

Publication number Publication date
CN102331949A (zh) 2012-01-25
US20140223126A1 (en) 2014-08-07
EP2755132A4 (en) 2014-08-06
EP2755132B1 (en) 2018-12-26
CN102331949B (zh) 2014-11-05
US9507672B2 (en) 2016-11-29
EP2755132A1 (en) 2014-07-16

Similar Documents

Publication Publication Date Title
WO2012149844A1 (zh) 一种虚拟机内存快照生成和恢复方法、装置及系统
US9823877B2 (en) Virtual machine backup from storage snapshot
US11436091B2 (en) Method and apparatus for generating virtual machine snapshot
US9811369B2 (en) Method and system for physical computer system virtualization
JP5427574B2 (ja) 仮想計算機の移動管理方法、前記移動管理方法を用いた計算機、前記移動管理方法を用いた仮想化機構および前記移動管理方法を用いた計算機システム
US20180285216A1 (en) Virtual Machine Recovery Method and Virtual Machine Management Device
CN110622138B (zh) 一种数据迁移方法及装置
US9600369B2 (en) Operating system recovery method and apparatus, and terminal device
US20150074058A1 (en) Container-based processing method, apparatus, and system
WO2017132872A1 (zh) 虚拟机备份方法、备份装置及宿主机
US9940152B2 (en) Methods and systems for integrating a volume shadow copy service (VSS) requester and/or a VSS provider with virtual volumes (VVOLS)
US8881144B1 (en) Systems and methods for reclaiming storage space from virtual machine disk images
CN110704161B (zh) 虚拟机创建方法、装置及计算机设备
JP2010282468A (ja) 計算機システム及び障害復旧方法
US8972351B1 (en) Systems and methods for creating selective snapshots
US20190250994A1 (en) Backup control method and backup control system
US20220129292A1 (en) Fast virtual machine resume at host upgrade
CN112148532A (zh) 硬盘数据的批量恢复方法、装置、存储介质及电子设备
CN107209727B (zh) 存储系统
US11748145B2 (en) Data processing system using skeleton virtual volumes for improved system startup
CN118170584A (zh) 一种数据备份、变化块记录方法及计算设备
JP2022174793A (ja) 情報処理装置、情報処理プログラム、及び情報処理方法

Legal Events

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

Ref document number: 12779387

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE