Virtual machine snapshot creation method, device, storage medium and computer equipment

By using iterative copying and redirecting virtual machines during virtual machine snapshot creation, the problem of long service interruption time during virtual machine snapshot creation is solved, and more efficient snapshot creation and lower storage space requirements are achieved.

CN111290836BActive Publication Date: 2025-04-29PING AN TECH (SHENZHEN) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010141938.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-03-04
Publication Date
2025-04-29
Estimated Expiration
2040-03-04

AI Technical Summary

Technical Problem

In the prior art, virtual machines interrupt the virtual machine service for a long time during the creation of snapshots, which limits the use of virtual machine snapshots.

Method used

By using iterative copying during the virtual machine snapshot creation process, the virtual machine can be used to sense new memory dirty data in real time when copying online. The virtual machine will not be suspended until the memory dirty data can be saved within a very short period of time, and the virtual machine can be saved in real time by redirecting the virtual machine to reduce storage space utilization.

Benefits of technology

It effectively shortens the time when the virtual machine system is aborted during the virtual machine snapshot creation process, increases the usage scenarios of virtual machine snapshots, and reduces the storage space requirement for saving files in the target snapshot.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111290836B_ABST
    Figure CN111290836B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention provides a virtual machine snapshot creation method, device, storage medium and computer equipment, the method comprising: receiving a command to take a snapshot of a first virtual machine, and cyclically iteratively copying the dirty memory data of the first virtual machine to a transit virtual machine; at the end of each round of iterative copying, estimating the copying time of the currently remaining dirty memory data, if the estimated copying time of the currently remaining dirty memory data is less than or equal to a preset time threshold, pausing the first virtual machine; copying the currently remaining dirty memory data to the transit virtual machine and copying the virtual disk status data of the first virtual machine to the transit virtual machine; saving the dirty memory data and virtual disk status data of the first virtual machine saved in the transit virtual machine to the target snapshot save file. The above method can shorten the virtual machine suspension time to milliseconds during the virtual machine snapshot operation, and improve the availability of the virtual machine when creating a virtual machine snapshot.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of cloud computing, and in particular to a virtual machine snapshot creation method, device, storage medium and computer equipment. Background Art

[0002] In the current cloud computing environment, the snapshot function is an indispensable part: when the system crashes or an abnormality occurs, the virtual machine disk file system and system storage can be restored by restoring to the backed-up snapshot data.

[0003] When creating a snapshot of an existing virtual machine, the virtual machine is usually paused before saving the virtual machine device state and memory state. After the virtual machine device state data and virtual machine memory data are saved to files and all writable virtual disks have completed creating disk snapshots, the virtual machine is restored to a running state.

[0004] Thus, during the entire process of creating a virtual machine snapshot, the virtual machine is in a suspended state, during which the virtual machine system is unavailable, which greatly limits the use scenarios of virtual machine snapshots. Summary of the invention

[0005] The embodiments of the present invention provide a virtual machine snapshot creation method, device, storage medium and computer equipment, which are used to solve the problem in the prior art that the virtual machine service is interrupted for a long time during the process of creating a snapshot.

[0006] In a first aspect, an embodiment of the present invention provides a method for creating a virtual machine snapshot, the method comprising:

[0007] receiving a command for taking a snapshot of the first virtual machine, and creating a target snapshot save file according to the command;

[0008] Copying the dirty data in the memory of the first virtual machine to the transit virtual machine in a circular iterative manner;

[0009] At the end of each round of iterative copying, the copying time of the currently remaining dirty memory data is estimated. If the estimated copying time of the currently remaining dirty memory data is less than or equal to a preset time threshold, the first virtual machine is paused, wherein the round of iterative copying is determined to be completed when all the dirty memory data to be copied in each round of iterative copying is copied to the transit virtual machine;

[0010] The currently remaining dirty memory data is copied to the transit virtual machine, and the virtual disk status data of the first virtual machine is copied to the transit virtual machine; wherein, the data transmission from the first virtual machine to the transit virtual machine is realized through a local interface, and after the transit virtual machine receives the dirty memory data of the first virtual machine, the dirty memory data of the first virtual machine is saved in real time to the memory space of the operating system corresponding to the transit virtual machine;

[0011] The memory dirty data and virtual disk status data of the first virtual machine saved in the transit virtual machine are saved in the target snapshot saving file.

[0012] Optionally, receiving a command to take a snapshot of the first virtual machine, and creating a target snapshot save file according to the command;

[0013] Copying the dirty data in the memory of the first virtual machine to the transit virtual machine in a circular iterative manner;

[0014] At the end of each round of iterative copying, the copying duration of the currently remaining dirty memory data is estimated, and if the estimated copying duration of the currently remaining dirty memory data is less than or equal to a preset time threshold, the first virtual machine is paused;

[0015] The remaining dirty memory data is copied to the transit virtual machine and the virtual disk status data of the first virtual machine is copied to the transit virtual machine; wherein, after the transit virtual machine receives the dirty memory data of the first virtual machine, the dirty memory data of the first virtual machine is saved in the memory space of the operating system corresponding to the transit virtual machine in real time;

[0016] The memory dirty data and virtual disk status data of the first virtual machine saved in the transit virtual machine are saved in the target snapshot saving file.

[0017] Optionally, the method further comprises:

[0018] If at the end of each round of iterative copying, the estimated copying time of the remaining dirty memory data is longer than the preset time threshold, the rate at which new dirty memory data is generated in each round of iterative copying is calculated based on the amount of new dirty memory data generated in each round of iterative copying and the time taken for each round of iterative copying.

[0019] The sleep time ratio of the first virtual machine in the next round of iterative copying is determined according to the ratio between the generation rate of new memory dirty data in each round of iterative copying and the copy rate of each round of iterative copying, and the sleep time ratio of the first virtual machine is controlled according to the sleep time ratio, where the sleep time ratio is the proportion of the sleep time within a preset time length.

[0020] Optionally, copying the virtual disk state data of the first virtual machine to the transit virtual machine includes:

[0021] Determine whether the virtual disk of the first virtual machine still has IO events being processed;

[0022] If not, blocking the newly generated IO events of the virtual disk of the first virtual machine, and inserting the newly generated IO events of the virtual disk into the blocking queue during the blocking process;

[0023] Copying the virtual disk state data of the first virtual machine to the transit virtual machine;

[0024] The newly generated IO event blocked in the blocking queue is awakened to execute the newly generated IO event blocked in the blocking queue.

[0025] Optionally, the command includes a first virtual machine identifier and a snapshot identifier to be created, and the step of creating a target snapshot save file according to the command includes:

[0026] querying, according to the first virtual machine identifier and the snapshot identifier to be created, whether the first virtual machine identifier and the snapshot identifier corresponding to the command exist;

[0027] If the first virtual machine identifier corresponding to the command exists and the snapshot identifier does not exist, determining that the first virtual machine supports creating an internal snapshot;

[0028] A file path for saving memory dirty data and virtual disk status data of the first virtual machine is determined based on the snapshot name, and the target snapshot save file is created based on the file path.

[0029] In a second aspect, an embodiment of the present invention provides a virtual machine snapshot creation device, comprising:

[0030] A receiving module, configured to receive a command for taking a snapshot of the first virtual machine, and create a target snapshot save file according to the command;

[0031] A first copy module, used for cyclically iteratively copying the dirty data in the memory of the first virtual machine to the transit virtual machine;

[0032] A first computing module is used to estimate the copying time of the currently remaining dirty memory data at the end of each round of iterative copying, and if the estimated copying time of the currently remaining dirty memory data is less than or equal to a preset time threshold, pausing the first virtual machine, wherein when all the dirty memory data to be copied in each round of iterative copying is copied to the transit virtual machine, it is determined that the round of iterative copying is completed;

[0033] a second copy module, used to copy the currently remaining dirty memory data to the transit virtual machine and to copy the virtual disk status data of the first virtual machine to the transit virtual machine; wherein, the data transmission from the first virtual machine to the transit virtual machine is implemented through a local interface, and after the transit virtual machine receives the dirty memory data of the first virtual machine, the dirty memory data of the first virtual machine is saved in real time to the memory space of the operating system corresponding to the transit virtual machine; and

[0034] The saving module is used to save the memory dirty data and virtual disk status data of the first virtual machine saved in the transit virtual machine to the target snapshot saving file.

[0035] Optionally, the first calculation module includes:

[0036] A first calculation unit, used to calculate the copy rate of each round of iterative copying according to the amount of memory dirty data copied in each round of iterative copying and the time taken for each round of iterative copying;

[0037] A first determining unit is used to determine the amount of currently remaining dirty memory data, wherein the currently remaining dirty memory data is newly generated dirty memory data within the duration of each round of iterative copying; and

[0038] The second calculation unit is used to estimate the copying time of the currently remaining dirty memory data according to the amount of new dirty memory data generated within the time used for each round of iterative copying and the copying rate of each round of iterative copying.

[0039] Optionally, the virtual machine snapshot creation device further includes:

[0040] A second calculation module is configured to calculate a generation rate of new memory dirty data in each round of iterative copying according to the amount of memory dirty data newly generated in each round of iterative copying and the duration of each round of iterative copying if, at the end of each round of iterative copying, the estimated copying duration of the currently remaining memory dirty data is greater than a preset time threshold; and

[0041] The first determination module is used to determine the sleep time ratio of the first virtual machine in the next round of iterative copying according to the ratio between the generation rate of new memory dirty data in each round of iterative copying and the copy rate of each round of iterative copying, and to control the sleep time of the first virtual machine according to the sleep time ratio, where the sleep time ratio is the proportion of the sleep time within a preset time length.

[0042] In a third aspect, an embodiment of the present invention provides a storage medium, wherein the storage medium includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the above method.

[0043] In a fourth aspect, an embodiment of the present invention provides a computer device, comprising a memory and a processor, wherein the memory is used to store information including program instructions, and the processor is used to control the execution of the program instructions, and the program instructions implement the steps of the above method when loaded and executed by the processor.

[0044] It can be understood that the virtual machine copy method provided in the embodiment of the present invention adopts an iterative copying method when copying the virtual machine, and utilizes the characteristic that the new memory dirty data can be perceived in real time when the virtual machine is copied online. When the virtual machine snapshot is created to save the memory state, the new memory dirty data is saved in real time, and the virtual machine is not paused until the memory dirty data can be saved in a very short time. Therefore, the problem of the virtual machine service being interrupted for a long time in the process of creating a snapshot in the prior art is solved, and the use scenarios of the virtual machine snapshot are increased. At the same time, the embodiment of the present invention provides the setting of a transit virtual machine, and the memory dirty data received by the transit virtual machine is loaded into the memory space of the operating system of the physical machine, and then sent to the target snapshot to save the file. Since the data migration from the first virtual machine to the transit virtual machine can perform memory operations through the local interface, the suspension stage of the first virtual machine can be reached more quickly, and the virtual machine snapshot operation can be successfully completed with a higher probability. At the same time, since the transit virtual machine can load data into the memory address space of the corresponding physical machine operating system in real time, multiple modifications to the same memory area during the copying process will ultimately present the latest data in the transit virtual machine. Since the transit virtual machine only serves as a transit and does not run, the amount of data finally saved to the target snapshot save file is smaller than that of the current solution, thereby significantly reducing the utilization of the storage space of the target snapshot save file. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] The present invention is further described below in conjunction with the accompanying drawings and embodiments.

[0046] Figure 1 A flowchart of a method for creating a virtual machine snapshot provided by an embodiment of the present invention;

[0047] Figure 2 A schematic block diagram of a virtual machine snapshot creation device provided by an embodiment of the present invention;

[0048] Figure 3 A schematic block diagram of a computer device provided by an embodiment of the present invention. Specific embodiments

[0049] In order to better understand the technical solution of the present invention, the embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0050] It should be clear that the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0051] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.

[0052] It should be understood that the term "and / or" used in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0053] In the existing virtual machine snapshot creation method, before saving the virtual machine device state and memory state, the virtual machine is first suspended, and after the virtual machine device state and virtual machine memory state are saved to files and all writable virtual disks have completed disk snapshot creation, the virtual machine is restored to a running state. In this way, the virtual machine is in a suspended state during the entire virtual machine snapshot creation process, and the virtual machine system is unavailable during this period, which greatly limits the use scenarios of virtual machine snapshots.

[0054] The virtual machine snapshot creation method provided in the embodiment of the present invention adopts an iterative copying method when copying the virtual machine, and utilizes the fact that the virtual machine can perceive new memory dirty data in real time when copying online. When the virtual machine snapshot is created to save the memory dirty data, the new memory dirty data is saved in real time, and the virtual machine is not paused until the memory dirty data can be saved in a very short time. Therefore, the problem of the virtual machine service being interrupted for a long time during the snapshot creation process in the prior art is solved, and the use scenarios of the virtual machine snapshot are increased.

[0055] Please see attached Figure 1 The embodiment of the present invention provides a virtual machine snapshot creation method, which is applied to a virtual machine snapshot creation device. The virtual machine snapshot creation device may include but is not limited to a personal computer, a server computer, a handheld device or a portable device, a tablet device, etc.

[0056] The handheld device or portable device includes, but is not limited to, other portable devices such as mobile phones, laptop computers, or tablet computers with touch-sensitive surfaces (e.g., touch screen displays and / or touch pads). The virtual machine snapshot creation method includes:

[0057] Step S01: receiving a command for taking a snapshot of a first virtual machine, and creating a target snapshot save file according to the command.

[0058] Step S02: cyclically iteratively copy the dirty data in the memory of the first virtual machine to the transit virtual machine.

[0059] Step S03: At the end of each round of iterative copying, the copying duration of the currently remaining dirty memory data is estimated. If the estimated copying duration of the currently remaining dirty memory data is less than or equal to the preset time threshold, the virtual machine is paused. When all the dirty memory data to be copied in each round of iterative copying is copied to the transit virtual machine, it is determined that the round of iterative copying is completed.

[0060] Step S04: copy the currently remaining dirty memory data to the transit virtual machine and copy the virtual disk status data of the first virtual machine to the transit virtual machine; wherein, the data transmission from the first virtual machine to the transit virtual machine is realized through a local interface, and after the transit virtual machine receives the dirty memory data of the first virtual machine, it saves the dirty memory data of the first virtual machine in real time to the memory space of the operating system corresponding to the transit virtual machine.

[0061] Step S05: Save the dirty memory data and virtual disk status data of the first virtual machine stored in the transit virtual machine into the target snapshot save file.

[0062] It can be understood that the virtual machine copy method provided in the embodiment of the present invention adopts an iterative copying method when copying the virtual machine, and utilizes the characteristic that the new memory dirty data can be perceived in real time when the virtual machine is copied online. When the virtual machine snapshot is created to save the memory state, the new memory dirty data is saved in real time, and the virtual machine is not paused until the memory dirty data can be saved in a very short time. Therefore, the problem of the virtual machine service interruption time for a long time in the process of creating a snapshot in the prior art is solved, and the use scenarios of the virtual machine snapshot are increased. At the same time, the embodiment of the present invention provides the setting of a transit virtual machine, and the memory dirty data received by the transit virtual machine is loaded into the memory space of the operating system of the physical machine, and then sent to the target snapshot to save the file. Since the data transmission from the first virtual machine to the transit virtual machine can be performed through the local interface for memory operation, the suspension stage of the first virtual machine can be reached more quickly, and the virtual machine snapshot operation can be successfully completed with a higher probability. At the same time, since the transit virtual machine can load data into the memory address space of the corresponding physical machine operating system in real time, multiple modifications to the same memory area during the copying process will ultimately present the latest data in the transit virtual machine. Since the transit virtual machine only serves as a transit and does not run, the amount of data finally saved to the target snapshot save file is smaller than that of the current solution, thereby significantly reducing the utilization of the storage space of the target snapshot save file.

[0063] Next, combine the attached Figure 1 The specific technical solution of the virtual machine snapshot creation method provided in this embodiment is described in detail.

[0064] With respect to step S01: receiving a command for taking a snapshot of a first virtual machine, and creating a target snapshot save file according to the command.

[0065] In actual applications, the command for taking a snapshot of the first virtual machine may be issued by a relevant operator, or may be issued autonomously by a virtual machine snapshot creation device according to a certain policy. The command includes the first virtual machine identifier and the snapshot identifier to be created.

[0066] After receiving a command for taking a snapshot of the first virtual machine, the command is firstly checked for parameter validity to determine whether the first virtual machine corresponding to the command supports creating an internal snapshot; specifically, the command parameter validity check includes:

[0067] Step S011: querying whether the first virtual machine identifier and the snapshot identifier to be created corresponding to the command exist according to the first virtual machine identifier and the snapshot identifier to be created;

[0068] Step S012: If the first virtual machine identifier corresponding to the command exists and the snapshot identifier does not exist, it is determined that the first virtual machine supports the creation of internal snapshots; based on the snapshot name, a file path for saving the memory dirty data and virtual disk status data of the first virtual machine is determined, and a target snapshot save file is created based on the file path.

[0069] Step S013: determining a file path for saving memory dirty data and virtual disk status data of the first virtual machine based on the snapshot name, and creating a target snapshot save file based on the file path.

[0070] On the contrary, if the first virtual machine identifier corresponding to the command does not exist or the snapshot identifier exists, it is determined that the first virtual machine does not support the creation of an internal snapshot, and an error message is sent to the user.

[0071] The virtual machine identifier may be a UUID (Universally Unique Identifier), as long as it can uniquely identify a virtual machine in the current physical host. The target save file may be a local file, a network file, or a shared block device, such as rbd, iscsi block device, etc.

[0072] With respect to step S02: the dirty data in the memory of the first virtual machine is copied to the transit virtual machine in a cyclic and iterative manner.

[0073] After receiving the command to take a snapshot of the first virtual machine, all current memory data in the first virtual machine is used as memory dirty data, and a first round of iterative copying is performed to copy all current memory dirty data of the first virtual machine to the transit virtual machine.

[0074] Since the first virtual machine does not pause but continues to run during the time taken to copy the dirty memory data, new dirty memory data will be generated when there is a write operation in the memory of the first virtual machine. Therefore, the newly generated dirty memory data needs to be copied to the transit virtual machine in the next round of iterative copying process, and the first virtual machine will not be paused until it is determined that the remaining dirty memory data can be saved in a very short time. At this time, the first virtual machine will no longer generate new dirty memory data. After the first virtual machine is paused, the first virtual machine will copy the remaining dirty memory data to the transit virtual machine, and then the iteration can be jumped out.

[0075] Before performing iterative copying, initialization is required. The initialization process includes marking the memory page storing the memory data of the first virtual machine as a dirty page, wherein the memory data corresponding to the dirty page is the memory dirty data. Specifically, the memory dirty page bitmap is initialized, the dirty bits represented by all memory pages corresponding to the first virtual machine in the memory dirty bitmap are set to true, and the memory dirty page flag is set to true.

[0076] For step S03: at the end of each round of iterative copying, the copying duration of the currently remaining dirty memory data is estimated, and if the estimated copying duration of the currently remaining dirty memory data is less than or equal to the preset time threshold, the first virtual machine is paused, wherein when all the dirty memory data to be copied in each round of iterative copying is copied to the transit virtual machine, it is determined that the round of iterative copying is completed;

[0077] Specifically, at the end of each round of iterative copying, the estimated copying time of the remaining dirty memory data includes:

[0078] Step S021: Calculate the copy rate of each round of iterative copying according to the amount of dirty memory data copied in each round of iterative copying and the time taken for each round of iterative copying;

[0079] The formula used to calculate the copy rate of the iterative copy is:

[0080] C(i)=M(i) / t(i), where C(i) is the copy rate of dirty data in memory during the i-th round of iterative copying, M(i) is the amount of dirty data in memory during the i-th round of iterative copying, and t(i) is the copy duration of the i-th round of iterative copying.

[0081] Step S022: determining the amount of currently remaining dirty memory data, wherein the currently remaining dirty memory data is the newly generated dirty memory data within the duration of each round of iterative copying;

[0082] Step S023: Estimate the remaining copying time of the dirty memory data according to the amount of new dirty memory data generated during each round of iterative copying and the copying rate of each round of iterative copying.

[0083] Among them, the formula used to estimate the copying time of the currently remaining dirty memory data is: t(i+1)=S(i+1) / C(i), wherein t(i+1) is the copying time of the i+1th round of iterative copying, S(i+1) is the amount of dirty memory data during the i+1th round of iterative copying, that is, the amount of dirty memory data remaining after the i-th round of iterative copying (that is, the amount of new memory data generated by the i-th round of iterative copying); C(i) is the copying rate of dirty memory data during the i-th round of iterative copying.

[0084] Furthermore, in some scenarios, if the current first virtual machine processes internal business of the virtual machine frequently, the internal CPU (Central Processing Unit / Processor) writes memory frequently, resulting in a high rate of dirty memory data generation, and the current rate of copying dirty memory data is slow, that is, when the copy rate of dirty memory data is low, the iterative copy process of the first virtual machine will be difficult to pause, and it will continue to migrate iteratively, and it will be difficult to end. For example, when the rate at which the virtual machine generates dirty memory data is high (such as greater than 2GB / s) and the copy rate of dirty memory data is low (such as less than 1GB / s), the first virtual machine will be in the process of iterative copying all the time, and it will be difficult to stop or difficult to stop in a short time.

[0085] In order to prevent the first virtual machine from being in the process of iterative copying and being difficult to end or difficult to end in a short time, an embodiment of the present invention provides a mechanism for controlling the first virtual machine to sleep. The mechanism controls the first virtual machine to sleep for part of the time. Since the internal CPU does not work when the virtual machine is in sleep state, the first virtual machine will not generate new dirty memory data during the sleep time. The rate at which the first virtual machine generates dirty memory data can be reduced, so as to achieve the purpose of ending the migration process of the first virtual machine.

[0086] Specifically, creating a virtual machine snapshot also includes:

[0087] Step S050: if at the end of each round of iterative copying, the estimated copying time of the currently remaining dirty memory data is greater than the preset time threshold, the generation rate of new dirty memory data in each round of iterative copying is calculated according to the amount of new dirty memory data generated in each round of iterative copying and the time taken for each round of iterative copying;

[0088] The formula used to calculate the rate at which new dirty memory data is generated is: O(i)=L(i) / t(i), where O(i) is the rate at which new dirty memory data is generated in the i-th round of iterative copying, L(i) is the amount of new memory data generated in the i-th round of iterative copying (i.e., the amount of dirty memory data remaining after the i-th round of iterative copying), and t(i) is the copying duration of the i-th round of iterative copying.

[0089] Step S060: Determine the sleep time ratio of the first virtual machine in the next round of iterative copying according to the ratio between the generation rate of new memory dirty data in each round of iterative copying and the copy rate of each round of iterative copying, and control the sleep time of the first virtual machine according to the sleep time ratio, where the sleep time ratio is the proportion of the sleep time within a preset time length.

[0090] In a specific implementation, the corresponding relationship between the ratio between the generation rate of new dirty memory data and the copy rate and the sleep time ratio can be preset. Generally, the higher the ratio between the generation rate of new dirty memory data and the copy rate, the higher the sleep time ratio. Of course, a threshold value (for example, 0.8 or other values ​​less than 1) can also be set. When the ratio between the generation rate of new dirty memory data and the copy rate is less than or equal to the threshold, the sleep time ratio is 0 (the first virtual machine does not need to sleep); when the ratio between the generation rate of new dirty memory data and the copy rate is greater than the threshold, the sleep time ratio increases step by step, for example, by 0.1, 0.2, 0.3, etc. It should be noted that in order to prevent the first virtual machine from having difficulty working for a long time, an upper limit value can be set for the sleep time ratio, for example, 0.6, so as to control the generation rate of new dirty memory data within a reasonable range.

[0091] In practical applications, the sleep time ratio is the ratio of the sleep time in a preset duration. The preset duration is usually in milliseconds. For example, assuming the preset duration is 100ms, when the sleep time ratio is 0.3, it means that the first virtual machine sleeps for 30ms in each preset duration of 100ms.

[0092] It can be understood that the embodiment of the present invention calculates the generation rate of new memory dirty data in each round of iterative copying by the amount of memory dirty data newly generated in each round of iterative copying and the time taken for each round of iterative copying after each round of iterative copying is completed, and then calculates the generation rate of new memory dirty data in each round of iterative copying according to the amount of memory dirty data newly generated in each round of iterative copying and the time taken for each round of iterative copying. The sleep time ratio of the first virtual machine in the next round of iterative copying is determined according to the ratio between the generation rate of new memory dirty data in each round of iterative copying and the copy rate of each round of iterative copying, so that the virtual machine determines the sleep time according to the sleep time ratio, and then sleeps according to the sleep time. Compared with the prior art, when the first virtual machine is under different business loads, by controlling the first virtual machine to sleep according to the determined sleep time, the ratio of the current generation rate of memory dirty data of the first virtual machine and the copy rate of memory dirty data can be controlled within a reasonable range, avoiding the problem that the iterative copying process is difficult to end, and at the same time, it can also prevent the business from being interrupted for a long time due to a long sleep time, which is more flexible and practical.

[0093] For step S04: copy the currently remaining dirty memory data to the transit virtual machine and copy the virtual disk state data of the first virtual machine to the transit virtual machine; wherein the data transmission from the first virtual machine to the transit virtual machine is realized through a local interface, and after the transit virtual machine receives the dirty memory data of the first virtual machine, the dirty memory data of the first virtual machine is saved in real time to the memory space of the operating system corresponding to the transit virtual machine, wherein the transit virtual machine and the first virtual machine are located in the same physical host;

[0094] Specifically, the embodiment of the present invention can execute the steps of copying the currently remaining dirty memory data to the transit virtual machine and the step of copying the virtual disk status data of the first virtual machine to the transit virtual machine simultaneously or sequentially. If they are performed sequentially, the embodiment of the present invention does not limit the sequence.

[0095] Specifically, after the transit virtual machine receives the memory dirty data of the first virtual machine, it saves the memory dirty data of the first virtual machine in real time to the memory space of the operating system corresponding to the transit virtual machine. At the same time, after the transit virtual machine receives the virtual disk status data of the first virtual machine, it also saves the virtual disk status data of the first virtual machine in real time to the virtual disk device status cache space corresponding to the transit virtual machine.

[0096] Since the data migration from the first virtual machine to the transit virtual machine can be performed through the local interface memory operation, the suspension stage of the first virtual machine can be reached more quickly, and the virtual machine snapshot operation can be successfully completed with a higher probability. At the same time, since the transit virtual machine can load data into the memory address space of the corresponding physical machine operating system in real time, the multiple modifications to the same memory area during the copying process must be the last data presented in the transit virtual machine. Since the transit virtual machine only acts as a transit and does not run, the amount of data finally saved to the target snapshot save file is smaller than that of the current solution, so the use of the storage space of the target snapshot save file can be greatly reduced.

[0097] Optionally, copying the virtual disk state data of the first virtual machine to the transit virtual machine includes:

[0098] Step S041: determining whether the virtual disk of the first virtual machine still has an IO event being processed;

[0099] Step S042: if not, blocking the newly generated IO events of the virtual disk of the first virtual machine, and inserting the newly generated IO events of the virtual disk during the blocking process into the blocking queue;

[0100] Step S043: copying the virtual disk state data of the first virtual machine to the transit virtual machine;

[0101] Step S044: Wake up the newly generated IO event blocked in the blocking queue to execute the newly generated IO event blocked in the blocking queue.

[0102] It can be understood that, since the traditional virtual machine only supports synchronous implementation when taking snapshots of virtual disks, that is, after receiving the command to create an internal snapshot from the external from the monitoring interface, the virtual machine will first poll whether there are any IO events being processed in the current virtual disk. If there are, the polling will continue until all IO event operations of the currently processed virtual disks are completed; when there are no IO events being processed, the virtual disk internal program is created. When creating the virtual disk internal snapshot according to the virtual disk internal program, it is necessary to read and write the metadata of the virtual disk to realize the backup of the data inside the virtual disk. Since the virtual machine internal snapshot program is in the main thread instead of in the environment when the virtual machine coroutine is running, during the entire virtual disk internal snapshot creation process, for each read and write IO request event of the external instruction, the main process of the running virtual machine cannot respond, nor can it respond to the user's out-of-band operation on the virtual machine, such as IO events from the virtual machine system to the block device, network device IO events, etc. The embodiment of the present invention blocks the IO events of the virtual disk of the first virtual machine, and when taking a snapshot of the virtual disk, the IO blocking flag is changed to true, and the corresponding IO blocking queue is initialized to empty. If the virtual machine system or user out-of-band operation generates a new IO event for the virtual disk, the IO event will be blocked and saved in the IO blocking queue. When the internal snapshot is completed, the IO blocking flag will be reset to false, and the IO events blocked by the snapshot creation in the IO blocking queue will be woken up in turn to execute the blocked IO events in the blocking queue. This enables the function of responding to IO events or user out-of-band operations while creating an internal snapshot of the virtual disk, significantly improving the work efficiency of the virtual machine.

[0103] With respect to step S05: the memory dirty data and virtual disk status data of the first virtual machine stored in the transit virtual machine are saved in the target snapshot saving file.

[0104] Specifically, the memory dirty data in the memory space of the operating system corresponding to the transit virtual machine is saved in the target snapshot save file, and the virtual disk state data saved in the virtual disk device state cache space corresponding to the first virtual machine is saved in the target snapshot save file.

[0105] Next, the flag of the memory dirty page that has completed migration is changed to false, the memory dirty page bitmap is released, and the first virtual machine is restored to a running state, thereby completing the creation of a snapshot of the first virtual machine.

[0106] Please see attached Figure 2The embodiment of the present invention provides a virtual machine snapshot creation device 1, comprising:

[0107] The receiving module 11 is used to receive a command for taking a snapshot of the first virtual machine, and create a target snapshot save file according to the command;

[0108] A first copy module 12, used for cyclically iteratively copying the dirty data in the memory of the first virtual machine to the transit virtual machine;

[0109] The first calculation module 13 is used to estimate the copying time of the currently remaining dirty memory data at the end of each round of iterative copying, and if the estimated copying time of the currently remaining dirty memory data is less than or equal to a preset time threshold, the first virtual machine is suspended, wherein the round of iterative copying is determined to be completed when all the dirty memory data to be copied in each round of iterative copying is copied to the transit virtual machine;

[0110] The second copy module 14 is used to copy the currently remaining dirty memory data to the transit virtual machine and to copy the virtual disk state data of the first virtual machine to the transit virtual machine; wherein the data transmission from the first virtual machine to the transit virtual machine is realized through a local interface, and after the transit virtual machine receives the dirty memory data of the first virtual machine, it saves the dirty memory data of the first virtual machine to the memory space of the operating system corresponding to the transit virtual machine in real time; and

[0111] The saving module 15 is used to save the dirty memory data and virtual disk status data of the first virtual machine saved in the transit virtual machine to the target snapshot saving file.

[0112] Optionally, the first calculation module 13 includes:

[0113] A first calculation unit, used to calculate the copy rate of each round of iterative copying according to the amount of memory dirty data copied in each round of iterative copying and the time taken for each round of iterative copying;

[0114] A first determining unit is used to determine the amount of currently remaining dirty memory data, wherein the currently remaining dirty memory data is newly generated dirty memory data within the duration of each round of iterative copying; and

[0115] The second calculation unit is used to estimate the copying time of the currently remaining dirty memory data according to the amount of new dirty memory data generated within the time used for each round of iterative copying and the copying rate of each round of iterative copying.

[0116] Optionally, the virtual machine snapshot creation device 1 further includes:

[0117] A second calculation module is configured to calculate a generation rate of new memory dirty data in each round of iterative copying according to the amount of memory dirty data newly generated in each round of iterative copying and the duration of each round of iterative copying if, at the end of each round of iterative copying, the estimated copying duration of the currently remaining memory dirty data is greater than a preset time threshold; and

[0118] The first determination module is used to determine the sleep time ratio of the first virtual machine in the next round of iterative copying according to the ratio between the generation rate of new memory dirty data in each round of iterative copying and the copy rate of each round of iterative copying, and to control the sleep time of the first virtual machine according to the sleep time ratio, where the sleep time ratio is the proportion of the sleep time within a preset time length.

[0119] Optionally, the second copy module 14 further includes:

[0120] A determination unit, used to determine whether the virtual disk of the first virtual machine still has an IO event being processed;

[0121] A blocking unit, configured to block newly generated IO events of the virtual disk of the first virtual machine if there is no IO event being processed by the virtual disk of the first virtual machine, and insert the newly generated IO events of the virtual disk during the blocking process into a blocking queue;

[0122] A first copy unit, configured to copy the virtual disk state data of the first virtual machine to the transit virtual machine; and

[0123] The wake-up unit is used to wake up the newly generated IO event blocked in the blocking queue to execute the newly generated IO event blocked in the blocking queue.

[0124] Optionally, the receiving module 11 further includes:

[0125] A query unit, configured to query whether the first virtual machine identifier and the snapshot identifier corresponding to the command exist according to the first virtual machine identifier and the snapshot identifier to be created;

[0126] a determining unit, configured to determine that the first virtual machine supports creation of an internal snapshot if the first virtual machine identifier corresponding to the command exists and the snapshot identifier does not exist; and

[0127] The creation unit is used to determine a file path for saving memory dirty data and virtual disk status data of the first virtual machine based on the snapshot name, and to create a target snapshot saving file based on the file path.

[0128] It can be understood that the embodiment of the present invention utilizes the feature that new dirty memory data can be perceived in real time during online migration of the virtual machine, and performs cyclic iterative copying of the memory data of the first virtual machine to the transit virtual machine. In the process of cyclic iterative copying, the new dirty memory data is saved in real time, and the virtual machine is not paused until the remaining dirty memory data can be saved in a very short time. Therefore, the time when the virtual machine system is suspended during the process of creating a snapshot of the virtual machine can be minimized. Combined with the feature that the virtual disk supports snapshots, internal snapshots are taken of all virtual disks at this time to save the virtual disk status. Therefore, the suspension time of the first virtual machine when the virtual machine performs a snapshot operation can be shortened to milliseconds, greatly improving the availability of the virtual machine when creating a virtual machine snapshot.

[0129] At the same time, an embodiment of the present invention provides for setting up a transit virtual machine, and the dirty memory data received by the transit virtual machine is loaded into the memory space of the physical machine operating system, and then sent to the target snapshot save file. Since the data migration from the first virtual machine to the transit virtual machine can perform memory operations through the local interface, the pause stage of the first virtual machine can be reached more quickly, and the virtual machine snapshot operation can be successfully completed with a higher probability. At the same time, since the transit virtual machine can load data into the memory address space of the corresponding physical machine operating system in real time, multiple modifications to the same memory area during the copying process must be the last data that is finally presented in the transit virtual machine. Since the transit virtual machine only serves as a transit and does not run, the amount of data finally saved in the target snapshot save file is smaller than that of the current solution, so the utilization of the storage space of the target snapshot save file can be greatly reduced.

[0130] It should be understood that, to avoid repetition, other implementations or further specific details of the virtual machine snapshot creation device provided in the embodiment of the present invention may refer to other embodiments of the present invention, such as corresponding contents of the method embodiment.

[0131] An embodiment of the present invention provides a storage medium, which includes a stored program, wherein when the program is running, a device where the storage medium is located is controlled to execute a method for creating a virtual machine snapshot in the embodiment.

[0132] It should be understood that, to avoid repetition, other implementations or further specific details of the storage medium provided in the embodiments of the present invention may refer to other embodiments of the present invention, such as corresponding contents of the method embodiments.

[0133] Please see attached Figure 3, an embodiment of the present invention provides a computer device, the computer device 50 of the embodiment includes: a processor 51, a memory 52, and a computer program 53 stored in the memory 52 and executable on the processor 51, the computer program 53 when executed by the processor 51 implements the virtual machine snapshot creation method in the embodiment, to avoid repetition, it is not described one by one here. Alternatively, when the computer program is executed by the processor 51, the functions of each model / unit in the virtual machine snapshot creation device 1 in the embodiment are implemented, to avoid repetition, it is not described one by one here.

[0134] The computer device 50 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The computer device 50 may include, but is not limited to, a processor 51 and a memory 52. ​​Those skilled in the art will appreciate that Figure 3 This is only an example of the computer device 50 and does not constitute a limitation of the computer device 50. The computer device 50 may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the computer device may also include input and output devices, network access devices, buses, etc.

[0135] The processor 51 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0136] The memory 52 may be an internal storage unit of the computer device 50, such as a hard disk or memory of the computer device 50. The memory 52 may also be an external storage device of the computer device 50, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the computer device 50. Further, the memory 52 may also include both an internal storage unit of the computer device 50 and an external storage device. The memory 52 is used to store computer programs and other programs and data required by the computer device. The memory 52 may also be used to temporarily store data that has been output or is to be output.

[0137] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0138] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of units is only a logical function division, and there may be other division methods in actual implementation, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0139] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0140] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional units.

[0141] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (Processor) to perform some steps of the methods of various embodiments of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program codes.

[0142] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for creating a virtual machine snapshot, characterized in that: The method comprises: receiving a command for taking a snapshot of the first virtual machine, and creating a target snapshot save file according to the command; cyclically iteratively copying the dirty data in the memory of the first virtual machine to the transit virtual machine; At the end of each round of iterative copying, the copying time of the currently remaining dirty memory data is estimated. If the estimated copying time of the currently remaining dirty memory data is less than or equal to a preset time threshold, the first virtual machine is paused, wherein the round of iterative copying is determined to be completed when all the dirty memory data to be copied in each round of iterative copying is copied to the transit virtual machine; The currently remaining dirty memory data is copied to the transit virtual machine, and the virtual disk state data of the first virtual machine is copied to the transit virtual machine; wherein, the data transmission from the first virtual machine to the transit virtual machine implements memory operation through a local interface, and after the transit virtual machine receives the dirty memory data of the first virtual machine, the dirty memory data of the first virtual machine is saved in real time to the memory space of the operating system corresponding to the transit virtual machine, and the transit virtual machine and the first virtual machine are located in the same physical host; The memory dirty data and virtual disk status data of the first virtual machine saved in the transit virtual machine are saved in the target snapshot saving file.

2. The method according to claim 1, characterized in that The estimated copy duration of the remaining dirty memory data at the end of each round of iterative copying includes: The copy rate of each round of iterative copying is calculated based on the amount of dirty memory data copied in each round of iterative copying and the time taken for each round of iterative copying; Determine the amount of currently remaining dirty memory data, wherein the currently remaining dirty memory data is newly generated dirty memory data within the duration of each round of iterative copying; The remaining memory dirty data copying time is estimated based on the amount of new memory dirty data generated during each round of iterative copying and the copying rate of each round of iterative copying.

3. The method according to claim 2, characterized in that The method further comprises: If at the end of each round of iterative copying, the estimated copying time of the remaining dirty memory data is longer than the preset time threshold, the rate at which new dirty memory data is generated in each round of iterative copying is calculated based on the amount of new dirty memory data generated in each round of iterative copying and the time taken for each round of iterative copying. The sleep time ratio of the first virtual machine in the next round of iterative copying is determined according to the ratio between the generation rate of new memory dirty data in each round of iterative copying and the copy rate of each round of iterative copying, and the sleep time ratio of the first virtual machine is controlled according to the sleep time ratio, where the sleep time ratio is the proportion of the sleep time within a preset time length.

4. The method according to claim 1, characterized in that The step of copying the virtual disk state data of the first virtual machine to the transit virtual machine includes: Determine whether the virtual disk of the first virtual machine still has IO events being processed; If not, blocking the newly generated IO events of the virtual disk of the first virtual machine, and inserting the newly generated IO events of the virtual disk during the blocking process into the blocking queue; Copying the virtual disk state data of the first virtual machine to the transit virtual machine; The newly generated IO event blocked in the blocking queue is awakened to execute the newly generated IO event blocked in the blocking queue.

5. The method according to claim 1, characterized in that The command includes a first virtual machine identifier and a snapshot identifier to be created, and the step of creating a target snapshot save file according to the command includes: querying, according to the first virtual machine identifier and the snapshot identifier to be created, whether the first virtual machine identifier and the snapshot identifier corresponding to the command exist; If the first virtual machine identifier corresponding to the command exists and the snapshot identifier does not exist, determining that the first virtual machine supports creating an internal snapshot; A file path for saving memory dirty data and virtual disk status data of the first virtual machine is determined based on the snapshot name, and the target snapshot save file is created based on the file path.

6. A virtual machine snapshot creation device, characterized in that: include: A receiving module, configured to receive a command for taking a snapshot of the first virtual machine, and create a target snapshot save file according to the command; A first copy module, used for cyclically iteratively copying the dirty data in the memory of the first virtual machine to the transit virtual machine; A first computing module is used to estimate the copying time of the currently remaining dirty memory data at the end of each round of iterative copying, and if the estimated copying time of the currently remaining dirty memory data is less than or equal to a preset time threshold, pausing the first virtual machine, wherein when all the dirty memory data to be copied in each round of iterative copying is copied to the transit virtual machine, it is determined that the round of iterative copying is completed; a second copy module, used to copy the currently remaining dirty memory data to the transit virtual machine and to copy the virtual disk status data of the first virtual machine to the transit virtual machine; wherein, the data transmission from the first virtual machine to the transit virtual machine implements memory operations through a local interface, and after the transit virtual machine receives the dirty memory data of the first virtual machine, the dirty memory data of the first virtual machine is saved in real time to the memory space of the operating system corresponding to the transit virtual machine, and the transit virtual machine and the first virtual machine are located in the same physical host; and The saving module is used to save the memory dirty data and virtual disk status data of the first virtual machine saved in the transit virtual machine to the target snapshot saving file.

7. The device according to claim 6, characterized in that The first calculation module includes: A first calculation unit, used to calculate the copy rate of each round of iterative copying according to the amount of memory dirty data copied in each round of iterative copying and the time taken for each round of iterative copying; A first determining unit is used to determine the amount of currently remaining dirty memory data, wherein the currently remaining dirty memory data is newly generated dirty memory data within the duration of each round of iterative copying; and The second calculation unit is used to estimate the copying time of the currently remaining dirty memory data according to the amount of new dirty memory data generated within the time used for each round of iterative copying and the copying rate of each round of iterative copying.

8. The device according to claim 7, characterized in that Also includes: The second calculation module is used to calculate the generation rate of new memory dirty data in each round of iterative copying according to the amount of memory dirty data newly generated in each round of iterative copying and the duration of each round of iterative copying if the estimated copying time of the currently remaining memory dirty data is longer than a preset time threshold at the end of each round of iterative copying; and The first determination module is used to determine the sleep time ratio of the first virtual machine in the next round of iterative copying according to the ratio between the generation rate of new memory dirty data in each round of iterative copying and the copy rate of each round of iterative copying, and to control the sleep time of the first virtual machine according to the sleep time ratio, where the sleep time ratio is the proportion of the sleep time within a preset time length.

9. A storage medium, characterized in that: The storage medium includes a stored program, wherein when the program is executed, the device where the storage medium is located is controlled to execute the method according to any one of claims 1 to 5.

10. A computer device comprising a memory and a processor, wherein the memory is used to store information including program instructions, and the processor is used to control the execution of the program instructions, characterized in that: When the program instructions are loaded and executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Method for virtual machine to dynamically save snapshots

    CN104572248A