Disclosure of Invention
The invention mainly aims to provide a memory snapshot creating method, a memory snapshot creating device, memory snapshot creating equipment and a readable storage medium, and aims to solve the technical problem that creating a memory snapshot in the prior art is long in time.
In a first aspect, the present invention provides a memory snapshot creating method, where the memory snapshot creating method includes:
acquiring a dirty data page address recorded in a corresponding sub-period at each preset moment in a creation period;
writing the memory content corresponding to the dirty data page address acquired each time into a persistent memory;
and at the end time of the creation period, creating a memory snapshot corresponding to the creation period according to all memory contents written into the persistent memory in the creation period.
Optionally, when the creating period is the first creating period, before the step of obtaining the dirty data page address recorded in the corresponding sub-period at each preset time in the creating period, the method further includes:
applying for a first persistent memory space in a persistent memory, wherein the size of the first persistent memory space is consistent with the size of a virtual machine memory;
and recording the corresponding relation between the memory address of the virtual machine and the address of the first persistent memory space after the first persistent memory space is successfully applied.
Optionally, when the creation cycle is the first creation cycle, the step of writing the memory content corresponding to the dirty data page address obtained each time into the persistent memory includes:
and based on the corresponding relation, overwriting the memory content corresponding to the dirty data page address obtained each time into the storage area corresponding to the dirty data page address obtained each time in the first persistent memory space.
Optionally, when the creation cycle is not the first creation cycle and the depth value of the memory snapshot chain is 1, the step of writing the memory content corresponding to the dirty data page address obtained each time into the persistent memory includes:
and based on the corresponding relation, overwriting the memory content corresponding to the dirty data page address obtained each time into the storage area corresponding to the dirty data page address obtained each time in the first persistent memory space.
Optionally, when the creation cycle is not the first creation cycle, and the memory snapshot chain depth value is N, where N is a positive integer greater than 1, the step of writing the memory content corresponding to the dirty data page address obtained each time into the persistent memory includes:
when the number of the created memory snapshots is less than N, applying for a new persistent memory space in the persistent memory according to the size of the memory content corresponding to the dirty data page address obtained each time, wherein the size of the new persistent memory space is greater than or equal to the size of the memory content corresponding to the dirty data page address obtained each time;
and after a new persistent memory space is successfully applied, writing the memory content corresponding to the dirty data page address acquired each time into the new persistent memory space.
Optionally, the step of writing the memory content corresponding to the dirty data page address obtained each time into the persistent memory further includes:
when the number of the created memory snapshots is equal to N, merging the memory snapshot created earliest and the memory snapshot created second earliest, and releasing all persistent memory spaces applied in the second creation period;
applying for a new persistent memory space in the persistent memory according to the size of the memory content corresponding to the dirty data page address acquired each time, wherein the size of the new persistent memory space is larger than or equal to the size of the memory content corresponding to the dirty data page address acquired each time;
and after a new persistent memory space is successfully applied, writing the memory content corresponding to the dirty data page address acquired each time into the new persistent memory space.
Optionally, the memory snapshot creating method further includes:
when the virtual machine system crashes, the virtual machine is restored by using the created memory snapshots in sequence from back to front according to the creation sequence until the restoration is successful.
In a second aspect, the present invention further provides a memory snapshot creating apparatus, where the memory snapshot creating apparatus includes:
the acquisition module is used for acquiring the dirty data page address recorded in the corresponding sub-period at each preset moment in the creation period;
the write-in module is used for writing the memory content corresponding to the dirty data page address acquired each time into the persistent memory;
and the creating module is used for creating the memory snapshot corresponding to the creating period according to all the memory contents written into the persistent memory in the creating period at the finishing time of the creating period.
In a third aspect, the present invention further provides a memory snapshot creating device, where the memory snapshot creating device includes a processor, a storage, and a memory snapshot creating program that is stored on the storage and can be executed by the processor, where when the memory snapshot creating program is executed by the processor, the steps of the memory snapshot creating method are implemented.
In a fourth aspect, the present invention further provides a readable storage medium, where a memory snapshot creating program is stored on the readable storage medium, where the memory snapshot creating program, when executed by a processor, implements the steps of the memory snapshot creating method described above.
In the invention, dirty data page addresses recorded in corresponding sub-periods are obtained at each preset moment in a creation period; writing the memory content corresponding to the dirty data page address acquired each time into a persistent memory; and at the last moment of the creation period, creating a memory snapshot corresponding to the creation period according to all memory contents written into the persistent memory in the creation period. By the method and the device, time consumption for creating the memory snapshot is reduced, so that the suspension time of the virtual machine when the snapshot of the whole machine is created is shortened, and service interruption on the virtual machine is avoided.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
In a first aspect, an embodiment of the present invention provides a memory snapshot creating apparatus, where the memory snapshot creating apparatus may be an apparatus having a data processing function, such as a Personal Computer (PC), a notebook computer, or a server.
Referring to fig. 1, fig. 1 is a schematic diagram of a hardware structure of a memory snapshot creating device according to an embodiment of the present invention. In this embodiment of the present invention, the memory snapshot creating apparatus may include a processor 1001 (e.g., a Central Processing Unit, CPU), acommunication bus 1002, auser interface 1003, anetwork interface 1004, and astorage 1005. Thecommunication bus 1002 is used for realizing connection communication among the components; theuser interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard); thenetwork interface 1004 may optionally include a standard wired interface, a WIreless interface (e.g., a WI-FI interface, WI-FI interface); thememory 1005 may be a Random Access Memory (RAM) or a non-volatile memory (non-volatile memory), such as a magnetic disk memory, and thememory 1005 may optionally be a storage device independent of theprocessor 1001. Those skilled in the art will appreciate that the hardware configuration depicted in FIG. 1 is not intended to be limiting of the present invention, and may include more or less components than those shown, or some components in combination, or a different arrangement of components.
With continued reference to fig. 1, thememory 1005 of fig. 1, which is a type of computer storage medium, may include an operating system, a network communication module, a user interface module, and a memory snapshot creation program therein. Theprocessor 1001 may call a memory snapshot creating program stored in thestorage 1005, and execute the memory snapshot creating method provided in the embodiment of the present invention.
In a second aspect, an embodiment of the present invention provides a memory snapshot creating method.
In an embodiment, referring to fig. 2, fig. 2 is a flowchart illustrating an embodiment of a memory snapshot creating method according to the present invention. As shown in fig. 2, the memory snapshot creating method includes:
step S10, acquiring dirty data page address recorded in corresponding sub-period at each preset time in the creation period;
in this embodiment, the length of the creation period and the length of the sub-period in the creation period are planned in advance according to a specific use scenario of the virtual machine, for example, a memory specification of a computing node, a CPU performance, a density of the virtual machine, an internal service characteristic of the virtual machine, and the like, and each preset time in the creation period is an end time of each sub-period. For example, the creation period has a length t and the sub-periods have a length t

If there are 3 sub-periods in a creation period, the ending time of each sub-period is each preset time, and there are 3 preset times in total, then in a creation period, the dirty data page address recorded in the first sub-period is obtained at the first preset time, the dirty data page address recorded in the second sub-period is obtained at the second preset time, and the dirty data page address recorded in the third sub-period is obtained at the third preset time. It should be noted that, this is only an illustrative example, and the ratio between the length of the sub-period and the length of the creation period is set according to actual needs, and is not limited herein. The dirty data page address is an address of a memory with changed contents in the memory of the virtual machine.
Step S20, writing the memory content corresponding to the dirty data page address acquired each time into a persistent memory;
in this embodiment, the length of the creation period is t, and the length of the sub-period is t

For example, after the dirty data page address recorded in the first sub-cycle is obtained at the first preset time in one cycle, the memory content corresponding to the dirty data page address is written into the persistent memory, and so on, the dirty data page address pair obtained at each preset time is pairedAnd writing the corresponding memory content into the persistent memory. The persistent memory is PMEM (persistent memory), and PMEM has the performance advantage of short read-write time consumption. Referring to fig. 3, fig. 3 is a schematic diagram illustrating writing data into a persistent memory according to an embodiment of the memory snapshot creating method of the present invention. As shown in fig. 3, when a physical memory is allocated to a virtual machine, a PMEM memory of the same specification is applied, the physical memory corresponding to the virtual machine is written in the running process of the virtual machine, dirty data page addresses are periodically written into a bitmap according to a sub-period, the dirty data page addresses in the bitmap are periodically read, memory contents corresponding to the dirty data page addresses are written into the PMEM memory, and records in the bitmap are cleared when the sub-period is over.
Step S30, at the end of the creation cycle, creating a memory snapshot corresponding to the creation cycle according to all memory contents written into the persistent memory in the creation cycle.
In this embodiment, at the end of the creation period, the memory snapshot corresponding to the creation period may be created according to all the memory contents written in the persistent memory in the creation period.
In this embodiment, the memory snapshot mainly stores contents that change in a memory of a Virtual Machine, a common storage method is to store the contents into a hard disk of a computing node or a file on an internal disk of the Virtual Machine, and discovery of an intermediate time consumption based on a principle of Virtual Machine memory management by a VMM (Virtual Machine Monitor) is mainly to read a memory to be stored and write the memory to the disk.
In the embodiment, a dirty data page address recorded in a corresponding sub-period is acquired at each preset time in a creation period; writing the memory content corresponding to the dirty data page address acquired each time into a persistent memory; and at the last moment of the creation period, creating a memory snapshot corresponding to the creation period according to all memory contents written into the persistent memory in the creation period. Through the embodiment, the time consumption for creating the memory snapshot is reduced, so that the suspension time of the virtual machine when the snapshot of the whole machine is created is shortened, and the service interruption on the virtual machine is avoided.
Further, in an embodiment, when the creation cycle is the first creation cycle, before step S10, the method further includes:
step S01, applying for a first persistent memory space in the persistent memory, where the size of the first persistent memory space is consistent with the size of the virtual machine memory;
in this embodiment, after the virtual machine is created or started, when the VMM allocates an HPA (Host physical address) memory to the virtual machine, a first persistent memory space may be applied in the persistent memory, where a size of the first persistent memory space is consistent with a size of a memory of the virtual machine. For example, the size of the memory of the virtual machine is 2G, the VMM allocates a 2G physical memory HPA to the virtual machine to directly store the content of the memory of the virtual machine, and at this stage, the storage space with the size of 2G is applied in the persistent memory, that is, the first persistent memory space is applied.
Step S02, after applying for the first persistent memory space successfully, record the corresponding relationship between the virtual machine memory address and the first persistent memory space address.
In this embodiment, after the first persistent memory space is successfully applied, the corresponding relationship between the memory address of the virtual machine and the address of the first persistent memory space is recorded. For example, the virtual machine memory addresses are denoted as X1, X2, X3... Xm, the first persistent memory space addresses are denoted as C1, C2, C3... Cm, and the recorded correspondence relationship is that X1 corresponds to C1, X2 corresponds to C2, and X3 corresponds to C3... Xm corresponds to Cm. Subsequently, in the first creation cycle, if the dirty data page addresses are X3 and X7, the memory contents corresponding to X3 and X7 may be written into C3 and C7 in the first persistent memory space, respectively.
Further, in an embodiment, based on the previous embodiment, when the creation cycle is the first creation cycle, step S20 includes:
and based on the corresponding relation, overwriting the memory content corresponding to the dirty data page address obtained each time into the storage area corresponding to the dirty data page address obtained each time in the first persistent memory space.
In this embodiment, the length of the creation period is t, and the length of the sub-period is t

For example. In a first creation cycle, if the address of the dirty data page acquired for the first time is X2, writing the content in X2 into C2 in a first persistent memory space; if the dirty data page addresses obtained for the second time are X1 and X3, writing the contents in X1 and X3 into C1 and C3 in the first persistent memory space respectively; if the dirty data page address obtained for the third time is X2, the content in X2 at this time is written into C2 in the first persistent memory space, i.e., the content in X2 which is written into C2 for the first time is overwritten. When the memory content corresponding to the acquired dirty data page address is written into the corresponding storage area in the first persistent memory space, if the storage area has no data, the data is directly written, and if the storage area has data, the original data is covered while the data is written.
Further, in an embodiment, based on the previous embodiment, when the creation cycle is not the first creation cycle and the memory snapshot chain depth value is 1, step S20 includes:
and based on the corresponding relation, overwriting the memory content corresponding to the dirty data page address obtained each time into the storage area corresponding to the dirty data page address obtained each time in the first persistent memory space.
In this embodiment, the depth value of the memory snapshot chain is determined in advance according to a specific use scenario of the virtual machine, for example, a memory specification of a compute node, a CPU performance, a density of the virtual machine, and an internal service characteristic of the virtual machine.
When the creation cycle is not the first creation cycle and the memory snapshot chain depth value is 1, for example, in the 2 nd creation cycle, each time the memory content corresponding to the acquired dirty data page address is written into the corresponding storage area in the first persistent memory space, if the storage area has no data, the data is directly written, and if the storage area has data, the original data is overwritten while the data is written.
Further, in an embodiment, when the creation cycle is not the first creation cycle, and the memory snapshot chain depth value is N, where N is a positive integer greater than 1, step S20 includes:
step S201, when the number of created memory snapshots is less than N, applying for a new persistent memory space in the persistent memory according to the size of the memory content corresponding to the dirty data page address obtained each time, where the size of the new persistent memory space is greater than or equal to the size of the memory content corresponding to the dirty data page address obtained each time;
in this embodiment, when the creation cycle is not the first creation cycle, and the memory snapshot chain depth value is N, N is a positive integer greater than 1, for example, N is set to 5. Referring to fig. 4, fig. 4 is a schematic diagram illustrating a persistent memory space application in an embodiment of a memory snapshot creating method according to the present invention. As shown in fig. 4, after acquiring the dirty data page address recorded in the corresponding sub-period at the first preset time in the 3 rd creation period, detecting that the number of the currently created memory snapshots is 2 (the memory snapshot corresponding to the first creation period and the memory snapshot corresponding to the second creation period), applying for a new persistent memory space in the persistent memory according to the size of the memory content corresponding to the dirty data page address recorded in the corresponding sub-period acquired at the first preset time, for example, applying for a new persistent memory space with a size of 3 × 128M in the persistent memory when the size of the memory content corresponding to the dirty data page address recorded in the corresponding sub-period acquired at the first preset time is 300M; similarly, if the size of the memory content corresponding to the dirty data page address recorded in the corresponding sub-period is acquired at the second preset time is 500M, applying for a new persistent memory space with a size of 4 × 128M in the persistent memory, and so on, that is, the size of the new persistent memory space applied each time is a multiple of 128M and is larger than the size of the memory content to be written.
Step S202, after applying for a new persistent memory space successfully, writing the memory content corresponding to the dirty data page address obtained each time into the new persistent memory space.
In this embodiment, if the size of the memory content corresponding to the dirty data page address recorded in the corresponding sub-period is 300M at the first preset time, a new persistent memory space with a size of 3 × 128M is applied in the persistent memory, and after the application is successful, the memory content of 300M is written into the new persistent memory space with a size of 3 × 128M; similarly, if the size of the memory content corresponding to the dirty data page address recorded in the corresponding sub-period is acquired at the second preset time and is 500M, a new persistent memory space with the size of 4 × 128M is applied in the persistent memory, and after the application is successful, the memory content of 500M is written into the new persistent memory space with the size of 4 × 128M, and so on.
Further, in an embodiment, based on the previous embodiment, step S20 further includes:
step S203, merging the memory snapshot created earliest and the memory snapshot created second earliest when the number of the created memory snapshots is equal to N, and releasing all persistent memory spaces applied in the second creation period;
in this embodiment, when the creation cycle is not the first creation cycle, and the memory snapshot chain depth value is N, N is a positive integer greater than 1, for example, N is set to 5. Referring to fig. 5, fig. 5 is a schematic diagram illustrating a persistent memory space application in another embodiment of the memory snapshot creation method of the present invention. As shown in fig. 5, in the 6 th creation cycle, after obtaining the dirty data page address recorded in the corresponding sub-cycle at the first preset time, it is detected that the number of the currently created memory snapshots is 5 (the memory snapshot corresponding to the first creation cycle, the memory snapshot corresponding to the second creation cycle, the memory snapshot corresponding to the third creation cycle, the memory snapshot corresponding to the fourth creation cycle, and the memory snapshot corresponding to the fifth creation cycle), at this time, the earliest created memory snapshot is merged with the second earliest created memory snapshot in a specific manner of writing data in all persistent memory spaces (i.e., the second persistent memory space) applied in the second creation cycle into the first persistent memory space, and releasing all persistent memory spaces applied in the second creation cycle.
Step S204, applying for a new persistent memory space in the persistent memory according to the size of the memory content corresponding to the dirty data page address acquired each time, wherein the size of the new persistent memory space is larger than or equal to the size of the memory content corresponding to the dirty data page address acquired each time;
step S205, after applying for a new persistent memory space successfully, writing the memory content corresponding to the dirty data page address obtained each time into the new persistent memory space.
In this embodiment, the specific embodiment of steps S204 to S205 is similar to that of steps S201 and S202, and is not described herein again.
By the embodiment, the quantity of the memory snapshots is controlled as required.
Further, in an embodiment, the memory snapshot creating method further includes:
when the virtual machine system crashes, the virtual machine is restored by using the created memory snapshots in sequence from back to front according to the creation sequence until the restoration is successful.
In this embodiment, when the virtual machine system crashes, the virtual machine is first restored through the last created memory snapshot, if the restoration is unsuccessful, the virtual machine is restored through the penultimate created memory snapshot, and so on until the virtual machine is successfully restored.
In the prior art, due to the fact that time consumption for creating the content snapshot is long, due to the fact that the virtual machine service interruption time is long, the memory snapshot cannot be created frequently in actual operation, the difference between the service state of the virtual machine recovered through the memory snapshot and the service state before the virtual machine system crashes is large, and the time consumption for creating the content snapshot is shortened in the embodiment, so that the creating period can be shorter than the period for creating the memory snapshot in the prior art, namely the memory snapshot can be created at a higher frequency compared with the embodiment in the prior art, the virtual machine can be recovered to the state close to the system crash by using the memory snapshot generated at a later time, and the service interruption time of the virtual machine is reduced to the maximum extent.
In a third aspect, an embodiment of the present invention further provides a memory snapshot creating apparatus.
Referring to fig. 6, fig. 6 is a functional module schematic diagram of a memory snapshot creating apparatus according to an embodiment of the present invention.
In one embodiment, the memory snapshot creating apparatus includes:
an obtainingmodule 10, configured to obtain, at each preset time in a creation cycle, a dirty data page address recorded in a corresponding sub-cycle;
a write-in module 20, configured to write memory content corresponding to the dirty data page address obtained each time into a persistent memory;
a creatingmodule 30, configured to create, at the end of the creating period, a memory snapshot corresponding to the creating period according to all memory contents written in the persistent memory in the creating period.
Further, in an embodiment, when the creation cycle is the first creation cycle, the memory snapshot creation apparatus further includes an application module configured to:
applying for a first persistent memory space in a persistent memory, wherein the size of the first persistent memory space is consistent with the size of a virtual machine memory;
and recording the corresponding relation between the memory address of the virtual machine and the address of the first persistent memory space after the first persistent memory space is successfully applied.
Further, in an embodiment, when the creation cycle is the first creation cycle, thewriting module 20 is configured to:
and based on the corresponding relation, overwriting the memory content corresponding to the dirty data page address obtained each time into the storage area corresponding to the dirty data page address obtained each time in the first persistent memory space.
Further, in an embodiment, when the creation cycle is not the first creation cycle and the memory snapshot chain depth value is 1, thewriting module 20 is configured to:
and based on the corresponding relation, overwriting the memory content corresponding to the dirty data page address obtained each time into the storage area corresponding to the dirty data page address obtained each time in the first persistent memory space.
Further, in an embodiment, when the creation cycle is not the first creation cycle, and the memory snapshot chain depth value is N, where N is a positive integer greater than 1, thewriting module 20 is configured to:
when the number of the created memory snapshots is less than N, applying for a new persistent memory space in the persistent memory according to the size of the memory content corresponding to the dirty data page address obtained each time, wherein the size of the new persistent memory space is greater than or equal to the size of the memory content corresponding to the dirty data page address obtained each time;
and after a new persistent memory space is successfully applied, writing the memory content corresponding to the dirty data page address acquired each time into the new persistent memory space.
Further, in an embodiment, thewriting module 20 is configured to:
when the number of the created memory snapshots is equal to N, merging the memory snapshot created earliest and the memory snapshot created second earliest, and releasing all persistent memory spaces applied in the second creation period;
applying for a new persistent memory space in the persistent memory according to the size of the memory content corresponding to the dirty data page address acquired each time, wherein the size of the new persistent memory space is larger than or equal to the size of the memory content corresponding to the dirty data page address acquired each time;
and after a new persistent memory space is successfully applied, writing the memory content corresponding to the dirty data page address acquired each time into the new persistent memory space.
Further, in an embodiment, the memory snapshot creating apparatus further includes a recovery module, configured to:
when the virtual machine system crashes, the virtual machine is restored by using the created memory snapshots in sequence from back to front according to the creation sequence until the restoration is successful.
The function implementation of each module in the memory snapshot creation apparatus corresponds to each step in the memory snapshot creation method embodiment, and the function and implementation process thereof are not described in detail here.
In a fourth aspect, the embodiment of the present invention further provides a readable storage medium.
The readable storage medium of the present invention stores a memory snapshot creating program, wherein when the memory snapshot creating program is executed by a processor, the steps of the memory snapshot creating method are implemented.
The method implemented when the memory snapshot creating program is executed may refer to each embodiment of the memory snapshot creating method of the present invention, and details are not described here.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for causing a terminal device to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.