Virtual machine hot migration method, device, electronic device and computer storage medium
By setting up the main backup page table in the virtual machine and switching to the small page table according to the switch trigger instruction for hot migration of virtual machines, the problem of high bandwidth consumption and performance damage of hot migration of virtual machines is solved, and more efficient hot migration is achieved and better performance.
Patent Information
- Application Number
- CN201910715884.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-08-05
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2039-08-05
AI Technical Summary
In the prior art, the virtual machine hot migration consumes a high bandwidth, resulting in increased migration difficulty, and may cause page-migration exceptions of the virtual client during the migration process, damaging its performance.
By setting the first page table and the second page table in the first physical machine, the physical memory page size indicated by the last page table of the first page table is greater than the set size (i.e., "big page"), while the second page table is The physical memory page size indicated by the last page table satisfies the set size (i.e., "small page"). According to the switch trigger command, switch the first page table to the second page table, and use the second page table to perform hot migration of the virtual machine.
In this way, the bandwidth consumption of virtual machine hot migration is reduced, the success rate and performance of virtual clients are improved, and the adverse impact of page table size changes on the operation of virtual clients is reduced.
Smart Images

Figure CN112328354B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of data processing technology, and in particular to a virtual machine hot migration method, device, electronic device and computer storage medium. Background Art
[0002] Virtual machine hot migration is a key technology in cloud computing operations. Through virtual machine hot migration, a virtual client can be migrated from one physical machine to another while ensuring the normal operation of the virtual client, so as to realize dynamic scheduling of computing resources and physical machine fault repair.
[0003] Specifically, the process of hot migration of a virtual machine is to copy the memory of the virtual client from one physical machine to another physical machine in an iterative manner, and the memory content of each copy is determined according to the memory paging of the virtual client.
[0004] Traditional virtual clients generally use a 4k BYTES memory paging method, that is, the memory page size indicated by the last-level page table is 4k. Now, in order to improve the performance of virtual clients, "large pages" are generally used for paging, such as a 2MBYTES or 1G BYTES memory paging method. However, the change in the memory paging method increases the bandwidth consumption of virtual machine hot migration, making the hot migration of virtual machines more difficult. In the prior art, in order to reduce the consumption of bandwidth, the original 2M or 1G "large page" will be directly deleted before hot migration, and then the 4K page table will be rebuilt through the page fault exception. However, this method will cause a large number of page fault exceptions in the virtual client, which will impair the performance of the virtual client.
[0005] In view of this, a technical problem that needs to be solved urgently in the prior art is how to provide another virtual machine hot migration method with lower difficulty. Summary of the invention
[0006] In view of this, an embodiment of the present invention provides a virtual machine hot migration method, device, electronic device and computer storage medium to solve the above problems.
[0007] According to a first aspect of an embodiment of the present invention, a method for hot migration of a virtual machine is provided, comprising: switching a first page table in a first physical machine for indicating a mapping relationship between a virtual client memory address and a host machine physical address to a second page table according to a switching trigger instruction; hot migrating the virtual client from the first physical machine to a second physical machine according to the second page table; wherein the size of a physical memory page indicated by a last-level page table of the second page table satisfies a set size, and the size of a physical memory page indicated by a last-level page table of the first page table is greater than the set size.
[0008] According to a second aspect of an embodiment of the present invention, a virtual machine hot migration device is provided, comprising: a switching module, for switching a first page table in a first physical machine, used to indicate a mapping relationship between a virtual client memory address and a host machine physical address, to a second page table according to a switching trigger instruction; a hot migration module, for hot migrating the virtual client from the first physical machine to a second physical machine according to the second page table; wherein the size of the physical memory page indicated by the last-level page table of the second page table satisfies a set size, and the size of the physical memory page indicated by the last-level page table of the first page table is greater than the set size.
[0009] According to a third aspect of an embodiment of the present invention, there is provided an electronic device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform operations corresponding to the virtual machine hot migration method as described above.
[0010] According to a fourth aspect of an embodiment of the present invention, there is provided a computer storage medium on which a computer program is stored. When the program is executed by a processor, the method for hot migration of a virtual machine as described above is implemented.
[0011] According to the solution provided by the embodiment of the present invention, a first page table and a second page table are set in the first physical machine, and the first and second page tables are used to indicate the mapping relationship between the virtual client memory address and the host machine physical address to form the master-slave setting of the mapping relationship. The difference is that the size of the physical memory page indicated by the last-level page table of the second page table meets the set size, such as the conventionally used 4K BYTES size, while the size of the physical memory page indicated by the last-level page table of the first page table is larger than the set size, that is, the so-called "large page". Therefore, virtual machine hot migration can be achieved according to the second page table. On the one hand, because the size of the physical memory page corresponding to the second page table meets the set size, that is, the size requirements of the hot migration for the physical memory page are met, the virtual client and its hot migration success rate and performance are improved; on the other hand, through the master-slave setting and reasonable switching of the first page table and the second page table, in the process of converting the physical memory page size to the page size required for hot migration, the virtual machine will not be suspended or other problems that affect the performance of the virtual machine will not be introduced, which greatly reduces the adverse effects of the hot migration page table size change on the virtual client operation. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the embodiments of the present invention. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.
[0013] Figure 1 A flowchart of a method for hot migration of a virtual machine according to a first embodiment of the present invention;
[0014] Figure 2 This is a flowchart of the steps of a virtual machine hot migration method according to the second embodiment of the present invention;
[0015] Figure 3 This is a flowchart of a method for hot migration of a virtual machine according to the third embodiment of the present invention;
[0016] Figure 4 This is a flowchart of a method for hot migration of a virtual machine according to a fourth embodiment of the present invention;
[0017] Figure 5 for Figure 4 A schematic diagram of a first page table and a second page table in the illustrated embodiment;
[0018] Figure 6 This is a structural block diagram of a virtual machine hot migration device according to a fifth embodiment of the present invention;
[0019] Figure 7 This is a structural block diagram of a virtual machine hot migration device according to Embodiment 6 of the present invention;
[0020] Figure 8 This is a schematic diagram of the structure of an electronic device according to Embodiment 7 of the present invention. DETAILED DESCRIPTION
[0021] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in the field based on the embodiments in the embodiments of the present invention should fall within the scope of protection of the embodiments of the present invention.
[0022] The specific implementation of the embodiment of the present invention is further described below in conjunction with the accompanying drawings of the embodiment of the present invention.
[0023] Embodiment 1
[0024] Reference Figure 1 , shows a flowchart of the steps of a virtual machine hot migration method according to embodiment 1 of the present invention.
[0025] The virtual machine hot migration method of this embodiment includes the following steps:
[0026] Step S102: according to the switching trigger instruction, the first page table for indicating the mapping relationship between the virtual client memory address and the host machine physical address in the first physical machine is switched to the second page table.
[0027] In a virtual machine system, a physical machine can be virtualized into multiple virtual machines, which are virtual clients. The physical machine can be considered as the host of multiple virtual machines. Multiple virtual clients use the actual physical resources of the host through a page table that indicates the mapping relationship between the virtual client memory address and the host physical address. For example, in various virtual machine systems such as the KVM (Kernel-based Virtual Machine) virtual machine system and the XEN virtual machine system, the EPT (Extended Page Tables) page table is used to implement the mapping between the virtual client memory address and the host physical address.
[0028] In an embodiment of the present invention, when implementing hot migration of a virtual machine under a virtual machine system, a first page table and a second page table are set, and both the first page table and the second page table are page tables for indicating the mapping relationship between the virtual client memory address and the host physical address. The switching operation of the first page table and the second page table is indicated by a switching trigger instruction, and then the hot migration of the virtual machine is performed based on the switching operation of the first page table and the second page table. Among them, the switching trigger instruction can be any appropriate instruction, or an instruction triggered by any appropriate trigger operation. After the switch, the first page table can be marked as read-only, and if a write error exception occurs during the hot migration, the second page table can also be used for processing.
[0029] In addition, in the present embodiment, both the first page table and the second page table are multi-level page tables, the size of the physical memory page indicated by the last-level page table of the second page table satisfies the set size, and the size of the physical memory page indicated by the last-level page table of the first page table is larger than the set size. Among them, the set size can be set by a person skilled in the art according to the memory paging size required for the memory copy iteration of hot migration, for example, it can be set to 4K BYTES. A physical memory page that meets the set size can be called a "small page", and accordingly, a physical memory page that is larger than the set size can be called a "large page", such as a physical memory page of 2M BYTES or 1G BYTES in size.
[0030] The second page table can be generated after further processing based on the information in the first page table, such as dividing the "large page" in the first page table into "small pages" and creating corresponding page table entries to save generation costs and improve generation efficiency. However, the second page table can also be generated in a conventional way of generating page tables, such as the same way as the first page table (such as the way of generating an EPT page table).
[0031] It should be noted that, in the embodiments of the present invention, unless otherwise specified, "multi-level", "multiple", and other numbers related to "multiple" all mean two or more. In addition, "first" and "second" are only used to distinguish different page tables, and do not mean that there is a necessary order or timing relationship between the two page tables.
[0032] Step S104: hot-migrating the virtual client from the first physical machine to the second physical machine according to the second page table.
[0033] Because the size of the physical memory page indicated by the last-level page table of the second page table meets the set size, that is, the memory paging size required for the memory copy iteration of the virtual machine hot migration, the virtual client can be hot migrated from the first physical machine to the second physical machine based on the second page table.
[0034] Through this embodiment, a first page table and a second page table are set in the first physical machine, and the first and second page tables are used to indicate the mapping relationship between the virtual client memory address and the host machine physical address to form the master-slave setting of the mapping relationship. The difference is that the size of the physical memory page indicated by the last-level page table of the second page table meets the set size, such as the conventionally used 4K BYTES size, while the size of the physical memory page indicated by the last-level page table of the first page table is larger than the set size, that is, the so-called "large page". Therefore, virtual machine hot migration can be achieved according to the second page table. On the one hand, because the size of the physical memory page corresponding to the second page table meets the set size, that is, the size requirements of the hot migration for the physical memory page are met, the virtual client and its hot migration success rate and performance are improved; on the other hand, through the master-slave setting and reasonable switching of the first and second page tables, in the process of converting the physical memory page size to the page size required for hot migration, the virtual machine will not be suspended or other problems that affect the performance of the virtual machine will not be introduced, which greatly reduces the adverse effects of the hot migration page table size change on the virtual client operation.
[0035] The virtual machine hot migration method of this embodiment can be executed by any appropriate electronic device with data processing capabilities, including but not limited to: a server, a mobile terminal (such as a tablet computer, a mobile phone, etc.) and a PC.
[0036] Embodiment 2
[0037] Reference Figure 2 , shows a flow chart of the steps of a virtual machine hot migration method according to Embodiment 2 of the present invention.
[0038] The virtual machine hot migration method of this embodiment includes the following steps:
[0039] Step S202: according to the switching trigger instruction, the first page table for indicating the mapping relationship between the virtual client memory address and the host machine physical address in the first physical machine is switched to the second page table.
[0040] Among them, the size of the physical memory page indicated by the last-level page table of the second page table meets the set size, and the size of the physical memory page indicated by the last-level page table of the first page table is larger than the set size. The set size is as described in Example 1, and can be set by a person skilled in the art according to the memory paging size required for the memory copy iteration of hot migration, for example, it can be set to 4K BYTES. In various virtual machine systems such as the KVM virtual machine system and the XEN virtual machine system, both the first page table and the second page table can be in the form of EPT (Extended Page Tables) page tables.
[0041] In one feasible method, this step can be implemented as follows: according to a switching trigger instruction, the currently used virtual machine active page table is switched from the first page table to the second page table; and an indication signal for indicating reloading the page table is sent to all virtual clients in the first physical machine to instruct each virtual client to switch the page table node in the currently used first page table to the corresponding page table node in the second page table.
[0042] The virtual client needs to use the host machine's memory resources through an active page table. In order to implement hot migration of virtual machines in the case of "large pages", the embodiment of the present invention provides a first page table and a second page table, wherein the first page table can be considered as a page table pointing to the "large page", and the second page table can be considered as a page table pointing to the "small page". Based on this, when performing hot migration of virtual machines, it is necessary to switch the currently used virtual machine active page table from the first page table to the second page table, and then send an indication signal for instructing to reload the page table to all virtual clients in the first physical machine, and perform page table switching on a virtual client basis to reduce the performance impact of page table switching on the virtual client.
[0043] Optionally, page table switching can be performed in units of virtual processors (VCPUs), and further page table switching reduces the performance impact on virtual clients. In this case, the sending of an indication signal for instructing to reload the page table to all virtual clients in the first physical machine to instruct each virtual client to switch the page table node in the first page table currently in use to the corresponding page table node in the second page table includes: sending an indication signal for instructing to reload the page table to the virtual processors corresponding to all virtual clients in the first physical machine to instruct each virtual processor to switch the page table node in the first page table currently in use to the corresponding page table node in the second page table.
[0044] When the currently used virtual machine active page table is switched from the first page table to the second page table according to the switching trigger instruction, in a feasible solution, after receiving the switching trigger instruction, the second page table can be created according to the first page table; after the second page table is successfully created, the currently used virtual machine active page table is switched from the first page table to the second page table. However, it is not limited to this. The second page table can also be created in advance, and then it can be directly switched after receiving the switching trigger instruction. The method of creating the second page table according to the first page table after receiving the switching trigger instruction, on the one hand, creates the second page table according to the switching trigger instruction, that is, creates it only after it is determined that hot migration is to be performed, which effectively ensures that the second page table will be used, avoiding the waste of data and resources caused by the second page table may not be used later under the advance creation method; on the other hand, the creation of the second page table based on the first page table improves the creation efficiency and also ensures the smooth transition of the switch and the performance of the virtual machine.
[0045] In order to reduce the cost of page table switching and improve the efficiency of page table switching, an embodiment of the present invention further provides a method for implementing page table switching through variables. In this method, when the currently used virtual machine active page table is switched from the first page table to the second page table, the variable value corresponding to the first variable pointing to the root page table of the virtual machine active page table is first determined, and the currently used virtual machine active page table is determined to be the first page table according to the variable value; then the first variable is reassigned to a set value, the first page table is deactivated according to the set value, and the second page table is activated as the virtual machine active page table. Among them, the set value can be appropriately set by those skilled in the art according to actual conditions, and can be a number, a letter, a symbol, or a combination of the above. For example, taking active_page as the first variable, when active_page is 1, it indicates that the currently used virtual machine active page table is the first page table, and when active_page is 0, it indicates that the currently used virtual machine active page table is the second page table. Then, by changing the variable value of active_page, the switching indication of the page table can be realized.
[0046] In the KVM virtual machine system, the first variable can be a memory management unit node MMU_NODE variable. If the MMU lock is set to protect the MMU resources, the memory management unit MMU corresponding to the first variable can also be locked before the first variable is reassigned to the set value; and after activating the second page table as the virtual machine active page table, the MMU is unlocked. In this way, exclusive use of MMU resources is guaranteed. The use of the MMU_NODE variable facilitates the subsequent rapid switching of the first page table and the second page table by changing the value of NODE, and can be compatible with the existing code logic to the greatest extent possible. However, as mentioned above, other variable forms are also applicable.
[0047] In addition, based on the setting of the first variable, when the aforementioned method of sending an indication signal for indicating reloading the page table to the virtual processors corresponding to all virtual clients in the first physical machine is adopted to instruct each virtual processor to switch the page table node in the first page table currently used to the corresponding page table node in the second page table, each virtual processor can switch the page table node in the first page table currently used to the corresponding page table node in the second page table in the following manner, including: each virtual processor checks whether the variable value of the second variable pointing to the root page table currently used by each virtual processor is consistent with the variable value of the first variable according to the indication signal; if not, the variable value of the second variable is replaced with the variable value of the first variable. By replacing the variable value, the switching of the page table nodes used by the virtual processor can be realized simply and quickly, thereby improving the switching efficiency.
[0048] It can be seen that through the above process, the switching between the first page table and the second page table is effectively achieved. Based on this, the following step S204 can be performed.
[0049] Step S204: hot-migrating the virtual client from the first physical machine to the second physical machine according to the second page table.
[0050] The size of the physical memory page indicated by the last-level page table of the second page table meets the set size, such as 4K BYTES, which can effectively meet the memory paging size requirements of virtual machine hot migration. Through the second page table, all virtual client memory page table updates can be completed at one time, reducing the impact of hot migration on virtual machine performance and users.
[0051] Step S206: Determine whether the hot migration is successful; if successful, execute step S208; otherwise, execute step S210.
[0052] The judgment on whether the hot migration of the virtual machine is successful can be implemented in a conventional manner, such as whether the virtual client runs normally, whether the data is complete, etc., which is not limited in the embodiment of the present invention.
[0053] Step S208: If the hot migration is successful, the first page table and the second page table in the first physical machine are released, and this process ends.
[0054] After the hot migration is successful, the memory data of the virtual client is successfully copied from the first physical machine to the second physical machine. The virtual client after the hot migration can use the corresponding data and mechanisms in the second physical machine to work normally. In this case, the first page table and the second page table in the first physical machine can be released, including the release of data related to the page tables and occupied resources.
[0055] Step S210: If the hot migration fails, then failure processing is performed.
[0056] In one case, after the hot migration operation is performed, the virtual client cannot work normally on the second physical machine, that is, although the hot migration is performed, the hot migration is not successful and a rollback operation is triggered. For this kind of hot migration failure, the second page table can be switched back to the first page table, and the second page table in the first physical machine can be released. That is, by switching the second page table back to the first page table, the virtual client can work normally in the cloud according to the first page table, and the second page table is released. In this case, the hot migration failure may be caused by reasons such as non-convergence of migration. Therefore, it is possible to switch back to the first page table and perform a hot migration rollback operation to ensure that the virtual client works in the original state, continue to use the first page table, improve the performance of the virtual machine, and avoid affecting user use.
[0057] In another case, if a hot migration anomaly occurs during the hot migration process (such as abnormal exit or shutdown of the virtual client), the second page table can be released first, and then the currently used virtual machine active page table is switched back to the first page table, and then the first page table is released. That is, the hot migration has not been completed, and an anomaly occurs during the hot migration process. At this time, the relevant data and occupied resources of the first and second page tables need to be released.
[0058] It should be noted that in actual applications, the first and second page tables can also be released at the same time. However, the method of releasing the second page table first and then switching the currently used virtual machine active page table back to the first page table before releasing it is more in line with the actual code logic of the solution implementation.
[0059] Through steps S206-S210, the unsuccessful hot migration situation is effectively handled, ensuring the reliability and safety of the hot migration.
[0060] Through this embodiment, a first page table and a second page table are set in the first physical machine, and the first and second page tables are used to indicate the mapping relationship between the virtual client memory address and the host machine physical address to form the master-slave setting of the mapping relationship. The difference is that the size of the physical memory page indicated by the last-level page table of the second page table meets the set size, such as the conventionally used 4K BYTES size, while the size of the physical memory page indicated by the last-level page table of the first page table is larger than the set size, that is, the so-called "large page". Therefore, virtual machine hot migration can be achieved according to the second page table. On the one hand, because the size of the physical memory page corresponding to the second page table meets the set size, that is, the size requirements of the hot migration for the physical memory page are met, the virtual client and its hot migration success rate and performance are improved; on the other hand, through the master-slave setting and reasonable switching of the first and second page tables, in the process of converting the physical memory page size to the page size required for hot migration, the virtual machine will not be suspended or other problems that affect the performance of the virtual machine will not be introduced, which greatly reduces the adverse effects of the hot migration page table size change on the virtual client operation.
[0061] The virtual machine hot migration method of this embodiment can be executed by any appropriate electronic device with data processing capabilities, including but not limited to: a server, a mobile terminal (such as a tablet computer, a mobile phone, etc.) and a PC.
[0062] Embodiment 3
[0063] Reference Figure 3 , shows a flowchart of the steps of a virtual machine hot migration method according to embodiment three of the present invention.
[0064] This embodiment focuses on how to create a second page table and describes the virtual machine hot migration solution provided by the embodiment of the present invention.
[0065] The virtual machine hot migration method of this embodiment includes the following steps:
[0066] Step S302: after receiving the switching trigger instruction, create a second page table according to the first page table.
[0067] The size of the physical memory page indicated by the last-level page table of the second page table satisfies the set size, and the size of the physical memory page indicated by the last-level page table of the first page table is larger than the set size. The set size is as described in the first embodiment, and can be set by those skilled in the art according to the memory paging size required for the memory copy iteration of the hot migration, for example, it can be set to 4K BYTES.
[0068] In one feasible manner, the memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table can be traversed, and the second page table can be created according to the traversal result. In this way, the second page table can be quickly created. In another feasible manner, the first page table can be directly traversed, and then the second page table can be created based on the traversal result and the corresponding "small page segmentation" result.
[0069] The memory reverse mapping table records the mapping relationship between the physical memory address of the host machine and its corresponding virtual address. Whenever a physical memory page is mapped to a new virtual address space (here, the virtual client physical address), the last-level page table entry corresponding to the physical memory page will be recorded in the memory reverse mapping table. The memory of the virtual client is composed of multiple virtual memory slots memslot, and each memslot does not overlap. That is, by traversing the memory reverse mapping table corresponding to each virtual memory slot memslot, the mapping relationship between the memory address of the virtual client and the corresponding physical memory address can be obtained. Based on this, data and information for creating a second page table can be obtained. Because the size of the physical memory page indicated by the last-level page table of the second page table needs to meet the set size, it is necessary to further process according to the traversal result of the corresponding memory reverse mapping table, such as dividing the page whose traversed physical memory page size is larger than the set size according to the set size, and generating the corresponding table entry in the second page table.
[0070] For example, creating a second page table according to the traversal result may include: generating a last-level page table entry in the second page table according to the copy of each last-level page table entry traversed, and marking the generated last-level page table entry with a set identifier; determining whether the size of the physical memory page pointed to by the generated last-level page table entry is greater than the set size; if greater, deleting the set identifier corresponding to the last-level page table entry, and establishing at least one level of sub-page table entry for the last-level page table entry according to the size of the physical memory page pointed to by the last-level page table entry, wherein the size of the physical memory page pointed to by the last-level page table entry in the at least one level of sub-page table entry is the set size. The set identifier can be appropriately set by those skilled in the art according to actual needs, and the embodiment of the present invention does not limit this; the set size is as described above and will not be repeated here.
[0071] If the size of the physical memory page is larger than the set size, indicating that it is a "large page" and does not meet the requirements of the last-level page table entry of the second page table, the set identifier used to indicate the last-level page table entry needs to be deleted, and the "large page" is processed as a "small page". From "large page" to "small page" may require one or more levels of processing. For example, if the "large page" is 2M, it can be processed into 512 "small pages" of 4KBYTES, and then the next level of sub-page table entries is established under the current table entry level of the second page table, and each sub-page table entry points to a physical memory page of 4K BYTES. If the "large page" is 1G, it needs to be processed into 512 2M pages first, and then each 2M page is processed into 512 "small pages" of 4K BYTES, and then the second-level sub-page table entries are established under the current table entry level of the second page table, and the first-level sub-page table entries point to the second-level sub-page table entries, and each second-level sub-page table entry points to a physical memory page of 4K BYTES.
[0072] If the size of the physical memory page pointed to by the generated last-level page table entry is not greater than the set size, it indicates that it points to a "small page" and can be directly copied and used.
[0073] In addition, for each generated final page table entry, it can also be determined whether the upper-level page table corresponding to the generated final page table entry exists; if not, a corresponding upper-level page table is generated for the final page table entry and saved in the second page table. In this way, the second page table is improved and generated.
[0074] In some cases, a physical memory page of a host machine may be mapped to multiple memory pages of a virtual client. In this case, a corresponding linked list of multiple last-level page table entries pointing to the physical memory page is stored in the memory reverse mapping table. In this case, the memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table is traversed, and a second page table is created according to the traversal result, including: obtaining the memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table; traversing the table items of the memory reverse mapping table one by one to determine whether the linked list is stored in the current table item; if the linked list is stored, traversing each last-level page table item in the linked list, and copying the information of the multiple last-level page table items corresponding to the linked list and the content of each traversed last-level page table item to the second page table; if the linked list is not stored, copying the content of the current table item to the second page table. In this way, the problem of generating page table entries corresponding to a physical memory page being mapped to multiple virtual client memory pages is effectively solved.
[0075] Step S304: after the second page table is successfully created, the currently used virtual machine active page table is switched from the first page table to the second page table.
[0076] The specific implementation of switching the currently used virtual machine active page table from the first page table to the second page table may refer to the description of step S202 in the second embodiment, which will not be described in detail here.
[0077] Step S306: hot-migrating the virtual client from the first physical machine to the second physical machine according to the second page table.
[0078] Through this embodiment, a first page table and a second page table are set in the first physical machine, and the first and second page tables are used to indicate the mapping relationship between the virtual client memory address and the host machine physical address to form the master-slave setting of the mapping relationship. The difference is that the size of the physical memory page indicated by the last-level page table of the second page table meets the set size, such as the conventionally used 4K BYTES size, while the size of the physical memory page indicated by the last-level page table of the first page table is larger than the set size, that is, the so-called "large page". Therefore, virtual machine hot migration can be achieved according to the second page table. On the one hand, because the size of the physical memory page corresponding to the second page table meets the set size, that is, the size requirements of the hot migration for the physical memory page are met, the virtual client and its hot migration success rate and performance are improved; on the other hand, through the master-slave setting and reasonable switching of the first and second page tables, in the process of converting the physical memory page size to the page size required for hot migration, the virtual machine will not be suspended or other problems that affect the performance of the virtual machine will not be introduced, which greatly reduces the adverse effects of the hot migration page table size change on the virtual client operation.
[0079] The virtual machine hot migration method of this embodiment can be executed by any appropriate electronic device with data processing capabilities, including but not limited to: a server, a mobile terminal (such as a tablet computer, a mobile phone, etc.) and a PC.
[0080] Embodiment 4
[0081] Reference Figure 4 , shows a step flow chart of a virtual machine hot migration method according to embodiment 4 of the present invention.
[0082] This embodiment takes the KVM virtual machine system as an example to illustrate the virtual machine hot migration method provided by the embodiment of the present invention. KVM is a virtualization technology based on CPU hardware support, which can be implemented as a module of Linux, namely, a KVM module. After Linux loads the KVM module, it can further create virtual machines through other tools. However, the user cannot directly control the operating system kernel to operate only through the KVM module, and it is also necessary to control the user space of KVM through corresponding user space tools such as Qemu, that is, to work in the user mode of the operating system through Qemu.
[0083] In addition, in KVM, in order to realize memory virtualization and let the virtual client use an isolated, zero-based and continuous memory space, KVM introduces the guest physical address space (GPA). GPA is not a real physical address space, it is just a mapping of the host virtual address space (HVA) in the virtual client address space. For the virtual client, GPA is a continuous address space starting from zero, but for the host, the physical address space of the virtual client is not necessarily continuous, and the virtual client physical address space may be mapped to several discontinuous host address intervals.
[0084] Since the virtual client is essentially a process on the host machine, in virtualization mode, the virtual client is in non-root mode and cannot directly access the memory on the host machine in root mode. At this time, the intervention of VMM (virtual client monitor) is required to intercept the memory access instructions of the virtual client through VMM, and then virtualize the memory on the host machine, which is equivalent to VMM adding a layer between the virtual address space (GVA) of the virtual client and the virtual address space (HVA) of the host machine, namely GPA.
[0085] It can be seen that memory virtualization is to convert the virtual address of the virtual client (Guest Virtual Address, GVA) into the physical address of the host (Host Physical Address, HPA), which must go through the conversion of the virtual machine's physical address (Guest Physical Address, GPA) and the host virtual address (Host Virtual Address, HVA), that is: GVA→GPA→HVA→HPA. Through the above conversion, a memory mapping relationship is established between the virtual client and the host, thereby realizing the virtual client's use of the host's physical memory resources. In the hot migration of virtual machines, page table generation, hot migration and other operations are also required based on the above memory mapping relationship.
[0086] Based on this, the virtual machine hot migration method of this embodiment includes the following steps:
[0087] Step S402: before performing hot migration of the virtual machine, the Qemu thread generates a switch trigger instruction through an IOCTL call trigger to indicate preparation for switching the main and backup page tables.
[0088] In this embodiment, the main page table is the aforementioned first page table, and the standby page table (also called the standby page table) is the aforementioned second page table.
[0089] It should be noted that, in this embodiment, only the IOCTL call triggering generation of the switching trigger instruction is taken as an example, but in actual applications, those skilled in the art can also set other appropriate trigger operations or trigger conditions according to actual needs to generate the switching trigger instruction.
[0090] Step S404: creating a standby page table according to the main page table according to the switch trigger instruction.
[0091] In KVM, the physical memory of the virtual client is divided into several memslots, each of which does not overlap. In this embodiment, a method of traversing all memslots in sequence and completing the copying and reconstruction of the page table entries of the physical memory corresponding to each memslot in sequence is adopted to create a standby page table. Specifically, a method of traversing the table entries of the memory reverse mapping rmap table of the current memslot is adopted to create the standby page table.
[0092] The memory reverse map rmap is a data structure that records the correspondence between the physical memory address and its virtual address. It records the association between each physical memory page and its page table. In practical applications, the EPT page table associated with the physical memory page can be found through the page frame number (gfn) of the guest physical memory page, that is, rmap[gfn].
[0093] Whenever a host machine's physical memory page is mapped to a new virtual address space (here, the virtual machine's physical address), the address of the last-level page table entry corresponding to the physical memory page will be recorded in rmap[gfn]. When a host machine's physical memory page is mapped to multiple new virtual address spaces at the same time, rmap[gfn] will record the first address of a pte linked list, and all last-level page table entries associated with the physical memory page will be recorded in the pte linked list.
[0094] The multiple physical memory pages included in the physical memory of the virtual client can be determined according to the memory allocation information of the virtual machine, and the determined physical memory page can be represented by the page frame number (gfn) of the physical memory page. The physical memory of the virtual client is composed of multiple memslots, each memslot has a basegfn, and the basegfn records the starting offset of the memslot in the entire virtual client physical address space. The gfn corresponding to each physical memory page in the memslot is calculated by the basegfn of the memslot and the offset of the physical memory page in the memslot. In order to traverse the entire gfn, each memslot needs to be traversed once.
[0095] For each rmap[gfn], if it corresponds to multiple virtual address spaces, it is necessary to traverse each last-level page table entry in the pte linked list entry corresponding to rmap[gfn]. After all the last-level page table entries are traversed, continue to traverse the next gfn.
[0096] For each last-level page table entry obtained through traversal, copy it to the backup page table, i.e., the backup EPT page table. Specifically, it may include: (a) if the parent page table corresponding to the last-level page table entry currently copied does not exist in the backup page table, then establish a corresponding parent page table for the last-level page table entry and add it to the backup page table (such as using the same establishment method as the first page table (such as EPT)); (b) determine whether the page pointed to by the last-level page table entry currently copied is a "large page". If it is not a "large page", return to (a) after the copy is completed to continue traversing the next page table entry; if it is a "large page", delete the flag indicating that the page table entry is the last-level page table entry, and then, sequentially establish all the sub-page table entries corresponding to the page table entry pointing to the "large page".
[0097] Among them, the above-mentioned establishment of all sub-page table entries corresponding to the page table entry pointing to the "large page" includes: first, from the page table entry pointing to the "large page", querying the physical page frame number gfn of the virtual client associated with the page table entry and its real physical page frame number pfn in the host machine; judging whether the memory cache pool resources required for creating the page table entry are sufficient, if not, adding cache resources to the cache pool; if sufficient, for all the "small page" physical memories covered by the "large page" physical memory, sequentially creating corresponding multi-level "small page" page tables (for example, for a "large page" of 2M BYTES, it is necessary to create page tables at the 2M BYTES and 4K BYTES levels respectively; for a "large page" of 1G BYTES, it is necessary to create three-level page tables of 1G BYTES, 2M BYTES and 4K BYTES respectively. Specifically for the EPT page table, it is necessary to create the second, third, and fourth level page tables for the physical memory of 1G BYTES, and the third and fourth level page tables for the physical memory of 2MBYTES).
[0098] Then, the table entries of the backup page table are filled, including: for non-last-level page tables (page tables other than the fourth-level page table), query the first-level page table corresponding to the gfn to check whether the corresponding next-level page table exists; if not, apply for a page table for the next-level page table, and fill the first-level page table with the physical address and other information of the newly applied page table memory. Repeat the above process until the last-level page table, that is, the fourth-level page table. For the last-level page table (fourth-level page table), fill the last-level page table with the corresponding gfn and pfn information according to the memory attributes. Among them, for the dirtybit of the memory attribute, the flag bit is set to 0 so that it can be tracked using pml later. In addition, the last-level page table is added to the rmap structure corresponding to the gfn. If there are multiple gfns, the last-level page table entry needs to be added to the corresponding rmap linked list. After all physical memory traversals are completed, the creation of the backup page table is completed.
[0099] A comparison between a created backup page table (i.e., the second page table) and a main page table (i.e., the first page table) is as follows: Figure 5 shown. Figure 5 In the main page table and backup page table, the EPT page table is used as an example, and the meaning of each node is the same as that of the regular EPT page table. Figure 5 In the main EPT page table shown in , high-level page table entries such as PDE or PDPTE are used directly to point to a physical "large page". For example, PDE (third-level page table) points to a physical memory page of 2M BYTES ( Figure 5 The backup EPT page table is created from the main EPT page table. Figure 5 As can be seen, the EPT page table uses PTE (fourth-level page table) to point to the physical memory page of 4K BYTES ( Figure 5 As shown in the dashed box, PTE serves as the last-level page table of the backup EPT page table to complete the entire physical memory mapping.
[0100] Step S406: Switch the active page table node of the KVM indicating the current virtual client to the backup page table node.
[0101] In this embodiment, in order to avoid the overall switching of the page table affecting the performance of the virtual client, the switching process of the primary and standby page tables is disassembled to the vcpu granularity for implementation. To this end, this embodiment introduces two new variables kvm->mmu_node and vcpu->mmu_node, where kvm->mmu_node represents the root page table pointed to by the current KVM, and vcpu->mmu_node represents the root page table used by the current vcpu.
[0102] Based on the above variables, the switching of the primary and backup EPT page tables can be completed by kvm->mmu_node=kvm->mmu_node^1. Among them, "^1" represents the operation of 1->0 (from 1 to 0) or 0->1 (from 0 to 1). For example, if "1" indicates the primary EPT page table and "0" indicates the backup EPT page table, assuming that it is necessary to switch from the primary EPT page table to the backup EPT page table, it can be achieved by, for example: kvm->mmu_node=kvm->mmu_node-1.
[0103] In addition, in this embodiment, mmu_node is protected by mmu lock, so it is necessary to obtain mmu lock before changing mmu_node, so as to be mutually exclusive with memory hot plug operation during the creation and switching process of the backup page table.
[0104] Step S408: Send mmu_reload signal to all vcpus.
[0105] The mmu_reload signal will be called by all vCPUs before the next enter guest mode to reload the page table.
[0106] Step S410: vcpu finds the mmu_reload signal and checks whether the mmu_node currently used by the vcpu is consistent with the active mmu_node specified by the KVM. If they are consistent, the mmu_reload signal is triggered by other reasons and is not processed. If they are inconsistent, step S412 is executed.
[0107] Step S412: If the vcpu finds that the mmu_node used is inconsistent with the active mmu_node specified by the KVM, the mmu_node currently used by the vcpu is replaced with the mmu_node specified by the KVM.
[0108] At the same time, the ept root table used by the vcpu is switched to the ept root table of the standby page table.
[0109] Step S414: When the mmu_node of all vcpus is consistent with the mmu_node specified by KVM, the switching is completed.
[0110] Step S416: Refresh the TLB cache corresponding to the VM to ensure that the newly loaded page table takes effect; at the same time, enable PML to start monitoring of memory changes.
[0111] TLB (Translation Lookaside Buffer) is a memory management unit and a cache used to improve the speed of virtual address to physical address translation. Each row in TLB stores a block consisting of a single PTE (Page Table Entry). With TLB, there is no need to access the memory twice each time to read data (i.e., look up the page table to obtain the physical address and read the data), and you can read directly from TLB. The CPU provides a TLB refresh instruction, which is used to refresh the TLB through the instruction and the VPID information corresponding to the VM.
[0112] PML is a feature of the CPU. When this feature is enabled, the CPU will record the physical memory page information that has been rewritten by the CPU. Hot migration needs to record this rewrite information to ensure that the VM data on the source and destination ends are consistent.
[0113] Step S418: Perform hot migration of the virtual machine.
[0114] That is, the virtual client on the first physical machine is hot migrated to the second physical machine according to the switched backup EPT page table.
[0115] Step S420: Perform post-processing of virtual machine hot migration.
[0116] If the hot migration of the virtual machine succeeds, the home page table and the backup page table can be released; if the hot migration of the virtual machine fails, the virtual client needs to continue to work on the first physical machine, and steps S406-S416 can be repeated to switch the backup EPT page table back to the main EPT page table, thereby ensuring that the virtual client can use the main EPT page table, thereby improving the performance of the virtual client. After switching back to the main EPT page table, the backup EPT page table can be released.
[0117] In KVM, active_mmu_pages records the address microcosm of all page table entries used by the current virtual client. There is one active_mmu_pages for each primary and standby page table. After the hot migration of the virtual machine, the corresponding page table can be released by traversing the active_mmu_pages corresponding to the corresponding page table.
[0118] Taking the release of the standby page table as an example, the release process of the standby page table includes: traversing each item in active_mmu_pages one by one; judging whether the current table item is active and whether there are still page table child nodes; if there are page table child nodes, traversing all child nodes and recording all child nodes in the invalid list; releasing all page table items in the invalid list, and thereby releasing all page table memory.
[0119] In the above, the page table release process is described by taking the standby page table as an example. The home page table is released in the same manner as the standby page table. Those skilled in the art can implement the release of the home page table according to the above description, which will not be repeated here.
[0120] Through this embodiment, in view of the problem that the page fault exception caused by the hot migration of the virtual machine causes a great jitter to the virtual machine performance when the page table is organized in the "large page" manner in the prior art, the solution provided by this embodiment actively analyzes the memory mapping relationship of the virtual client's rmap before the hot migration of the virtual machine, and backs up and rebuilds the EPT page table of the virtual client, and then reloads the root directory item root table of the backup EPT page table for each vcpu in turn, and switches the page table of the virtual client from the main EPT page table to the backup EPT page table at one time, thereby switching the memory of the virtual client to the standard 4K BYTES mode, effectively improving the performance of the virtual machine and reducing the impact of the hot migration of the virtual machine on the user.
[0121] The virtual machine hot migration method of this embodiment can be executed by any appropriate electronic device with data processing capabilities, including but not limited to: a server, a mobile terminal (such as a tablet computer, a mobile phone, etc.) and a PC.
[0122] Embodiment 5
[0123] Reference Figure 6 , shows a structural block diagram of a virtual machine hot migration device according to Embodiment 5 of the present invention.
[0124] The virtual machine hot migration device of this embodiment includes: a switching module 502, which is used to switch the first page table indicating the mapping relationship between the virtual client memory address and the host machine physical address in the first physical machine to the second page table according to the switching trigger instruction; a hot migration module 504, which is used to hot migrate the virtual client from the first physical machine to the second physical machine according to the second page table; wherein the size of the physical memory page indicated by the last-level page table of the second page table meets the set size, and the size of the physical memory page indicated by the last-level page table of the first page table is greater than the set size.
[0125] The virtual machine hot migration device of this embodiment is used to implement the corresponding virtual machine hot migration method in the aforementioned multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here. In addition, the functional implementation of each module in the virtual machine hot migration device of this embodiment can refer to the description of the corresponding part in the aforementioned method embodiments, which will not be repeated here.
[0126] Embodiment 6
[0127] Reference Figure 7, shows a structural block diagram of a virtual machine hot migration device according to embodiment 6 of the present invention.
[0128] The virtual machine hot migration device of this embodiment includes: a switching module 602, which is used to switch the first page table indicating the mapping relationship between the virtual client memory address and the host machine physical address in the first physical machine to the second page table according to the switching trigger instruction; a hot migration module 604, which is used to hot migrate the virtual client from the first physical machine to the second physical machine according to the second page table; wherein the size of the physical memory page indicated by the last-level page table of the second page table meets the set size, and the size of the physical memory page indicated by the last-level page table of the first page table is greater than the set size.
[0129] Optionally, the switching module 602 includes: an active page table switching sub-module 6022, used to switch the currently used virtual machine active page table from the first page table to the second page table according to a switching trigger instruction; an indication sub-module 6024, used to send an indication signal for indicating reloading the page table to all virtual clients in the first physical machine, so as to instruct each virtual client to switch the page table node in the currently used first page table to the corresponding page table node in the second page table.
[0130] Optionally, the active page table switching submodule 6022 includes: a creation unit 60222, which is used to create the second page table according to the first page table after receiving a switching trigger instruction; and a post-creation switching unit 60224, which is used to switch the currently used virtual machine active page table from the first page table to the second page table after the second page table is successfully created.
[0131] Optionally, the post-creation switching unit 60224 is used to determine the variable value corresponding to the first variable of the root page table pointing to the virtual machine active page table after the second page table is successfully created, and determine that the currently used virtual machine active page table is the first page table according to the variable value; reassign the first variable to a set value, deactivate the first page table according to the set value, and activate the second page table as the virtual machine active page table.
[0132] Optionally, the first variable is a memory management unit node MMU_NODE variable; the post-creation switching unit 60224 is also used to lock the memory management unit MMU corresponding to the first variable before reassigning the first variable to a set value; and, after activating the second page table as the active page table of the virtual machine, unlock the MMU.
[0133] Optionally, the indication submodule 6024 is used to send an indication signal for instructing reloading the page table to the virtual processors corresponding to all virtual clients in the first physical machine, so as to instruct each virtual processor to switch the page table node in the currently used first page table to the corresponding page table node in the second page table.
[0134] Optionally, each virtual processor switches the page table node in the currently used first page table to the corresponding page table node in the second page table in the following manner: each virtual processor checks, based on the indication signal, whether the variable value of the second variable pointing to the root page table currently used by each virtual processor is consistent with the variable value of the first variable; if they are inconsistent, the variable value of the first variable is used to replace the variable value of the second variable.
[0135] Optionally, the virtual machine hot migration device of this embodiment also includes: a first hot migration processing module 606, used to determine whether the hot migration is successful; if the hot migration is successful, releasing the first page table and the second page table in the first physical machine; if the hot migration fails, switching the second page table back to the first page table, and releasing the second page table in the first physical machine.
[0136] Optionally, the creation unit 60222 is used to traverse the memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table after receiving the switching trigger instruction, and create the second page table according to the traversal result.
[0137] Optionally, the creation unit 60222 is used to traverse the memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table after receiving the switching trigger instruction; generate the last-level page table entry in the second page table based on the copies of each last-level page table entry traversed, and mark the generated last-level page table entry with a set identifier; determine whether the size of the physical memory page pointed to by the generated last-level page table entry is greater than the set size; if greater, delete the set identifier corresponding to the last-level page table entry, and establish at least one level of sub-page table entry for the last-level page table entry based on the size of the physical memory page pointed to by the last-level page table entry, wherein the size of the physical memory page pointed to by the last-level page table entry in the at least one level of sub-page table entry is the set size.
[0138] Optionally, the creation unit 60222 is further used to determine whether the upper-level page table corresponding to the generated last-level page table entry exists; if not, generate a corresponding upper-level page table for the last-level page table entry and save it to the second page table.
[0139] Optionally, when a physical memory page of the host machine is mapped to multiple virtual client memory pages, the memory reverse mapping table stores a corresponding linked list of multiple last-level page table entries pointing to the physical memory page.
[0140] Optionally, when the creation unit 60222 traverses the memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table and creates the second page table according to the traversal result: obtains the memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table; traverses the table items of the memory reverse mapping table one by one to determine whether the linked list is stored in the current table item; if the linked list is stored, traverses each last-level page table item in the linked list, and copies the information of the multiple last-level page table items corresponding to the linked list and the content of each traversed last-level page table item to the second page table; if the linked list is not stored, copies the content of the current table item to the second page table.
[0141] Optionally, the virtual machine hot migration device of this embodiment also includes: a second hot migration processing module 608, which is used to release the second page table first, switch the currently used virtual machine active page table back to the first page table, and then release the first page table if a hot migration exception occurs during the hot migration process.
[0142] The virtual machine hot migration device of this embodiment is used to implement the corresponding virtual machine hot migration method in the aforementioned multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here. In addition, the functional implementation of each module in the virtual machine hot migration device of this embodiment can refer to the description of the corresponding part in the aforementioned method embodiments, which will not be repeated here.
[0143] Embodiment 7
[0144] An electronic device comprises: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform operations corresponding to the virtual machine hot migration method described above.
[0145] Specifically, refer to Figure 8 , shows a schematic diagram of the structure of an electronic device according to Embodiment 7 of the present invention. The specific embodiment of the present invention does not limit the specific implementation of the electronic device.
[0146] like Figure 8 As shown, the electronic device may include: a processor (processor) 702 , a communication interface (Communications Interface) 704 , a memory (memory) 706 , and a communication bus 708 .
[0147] in:
[0148] The processor 702 , the communication interface 704 , and the memory 706 communicate with each other via a communication bus 708 .
[0149] The communication interface 704 is used to communicate with other electronic devices or servers.
[0150] The processor 702 is used to execute the program 710, and specifically can execute the relevant steps in the above-mentioned virtual machine hot migration method embodiment.
[0151] Specifically, the program 710 may include program codes, which include computer operation instructions.
[0152] The processor 702 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention. The one or more processors included in the electronic device may be processors of the same type, such as one or more CPUs; or processors of different types, such as one or more CPUs and one or more ASICs.
[0153] The memory 706 is used to store the program 710. The memory 706 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0154] Program 710 can be specifically used to enable the processor 702 to perform the following operations: according to a switching trigger instruction, switch the first page table in the first physical machine for indicating the mapping relationship between the virtual client memory address and the host machine physical address to the second page table; according to the second page table, hot migrate the virtual client from the first physical machine to the second physical machine; wherein the size of the physical memory page indicated by the last-level page table of the second page table meets the set size, and the size of the physical memory page indicated by the last-level page table of the first page table is greater than the set size.
[0155] In an optional embodiment, the program 710 is also used to enable the processor 702 to switch the first page table used to indicate the mapping relationship between the virtual client memory address and the host machine physical address in the first physical machine to the second page table according to a switching trigger instruction: according to the switching trigger instruction, switch the currently used virtual machine active page table from the first page table to the second page table; and send an indication signal for indicating the reloading of the page table to all virtual clients in the first physical machine, so as to instruct each virtual client to switch the page table node in the currently used first page table to the corresponding page table node in the second page table.
[0156] In an optional embodiment, program 710 is also used to enable the processor 702 to switch the currently used virtual machine active page table from the first page table to the second page table according to a switching trigger instruction: after receiving the switching trigger instruction, create the second page table according to the first page table; after the second page table is successfully created, switch the currently used virtual machine active page table from the first page table to the second page table.
[0157] In an optional embodiment, program 710 is also used to enable the processor 702 to switch the currently used virtual machine active page table from the first page table to the second page table: determine the variable value corresponding to the first variable of the root page table pointing to the virtual machine active page table, and determine that the currently used virtual machine active page table is the first page table based on the variable value; reassign the first variable to a set value, deactivate the first page table based on the set value, and activate the second page table as the virtual machine active page table.
[0158] In an optional embodiment, the first variable is a memory management unit node MMU_NODE variable; the program 710 is also used to enable the processor 702 to lock the memory management unit MMU corresponding to the first variable before reassigning the first variable to a set value; and, after activating the second page table as the virtual machine active page table, unlock the MMU.
[0159] In an optional embodiment, program 710 is also used to enable processor 702 to send an indication signal for instructing reloading of page tables to all virtual clients in the first physical machine to instruct each virtual client to switch a page table node in the first page table currently in use to a corresponding page table node in the second page table: send an indication signal for instructing reloading of page tables to virtual processors corresponding to all virtual clients in the first physical machine to instruct each virtual processor to switch a page table node in the first page table currently in use to a corresponding page table node in the second page table.
[0160] In an optional embodiment, each virtual processor switches the page table node in the currently used first page table to the corresponding page table node in the second page table in the following manner: each virtual processor checks, based on the indication signal, whether the variable value of the second variable pointing to the root page table currently used by each virtual processor is consistent with the variable value of the first variable; if they are inconsistent, the variable value of the first variable is used to replace the variable value of the second variable.
[0161] In an optional embodiment, program 710 is also used to enable processor 702 to determine whether the hot migration is successful; if the hot migration is successful, the first page table and the second page table in the first physical machine are released; if the hot migration fails, the second page table is switched back to the first page table, and the second page table in the first physical machine is released.
[0162] In an optional embodiment, the program 710 is also used to enable the processor 702 to traverse the memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table when creating the second page table according to the first page table, and create the second page table according to the traversal result.
[0163] In an optional embodiment, the program 710 is also used to enable the processor 702 to create the second page table according to the traversal results: generate the last-level page table entry in the second page table according to the copies of each last-level page table entry traversed, and mark the generated last-level page table entry with a set identifier; determine whether the size of the physical memory page pointed to by the generated last-level page table entry is greater than the set size; if greater, delete the set identifier corresponding to the last-level page table entry, and establish at least one level of sub-page table entry for the last-level page table entry according to the size of the physical memory page pointed to by the last-level page table entry, wherein the size of the physical memory page pointed to by the last-level page table entry in the at least one level of sub-page table entry is the set size.
[0164] In an optional implementation, the program 710 is also used to enable the processor 702 to determine whether the upper-level page table corresponding to the generated last-level page table entry exists; if not, a corresponding upper-level page table is generated for the last-level page table entry and saved to the second page table.
[0165] In an optional implementation, when a physical memory page of the host machine is mapped to multiple virtual client memory pages, the memory reverse mapping table stores a corresponding linked list of multiple last-level page table entries pointing to the physical memory page.
[0166] In an optional embodiment, the program 710 is also used to enable the processor 702 to traverse the memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table, and create the second page table according to the traversal result: obtain the memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table; traverse the table items of the memory reverse mapping table one by one to determine whether the linked list is stored in the current table item; if the linked list is stored, traverse each last-level page table item in the linked list, and copy the information of the multiple last-level page table items corresponding to the linked list and the content of each traversed last-level page table item to the second page table; if the linked list is not stored, copy the content of the current table item to the second page table.
[0167] In an optional embodiment, the program 710 is also used to enable the processor 702 to first release the second page table if a hot migration exception occurs during the hot migration process, and then switch the currently used virtual machine active page table back to the first page table, and then release the first page table.
[0168] The specific implementation of each step in program 710 can refer to the corresponding description of the corresponding steps and units in the above-mentioned virtual machine hot migration method embodiment, which will not be repeated here. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the above-described devices and modules can refer to the corresponding process description in the above-mentioned method embodiment, which will not be repeated here.
[0169] The electronic device of this embodiment is provided with a first page table and a second page table in the first physical machine, and the first and second page tables are used to indicate the mapping relationship between the virtual client memory address and the host machine physical address to form the master-slave setting of the mapping relationship. The difference is that the size of the physical memory page indicated by the last-level page table of the second page table meets the set size, such as the conventionally used 4K BYTES size, while the size of the physical memory page indicated by the last-level page table of the first page table is larger than the set size, that is, the so-called "large page". Thus, virtual machine hot migration can be realized according to the second page table. On the one hand, because the size of the physical memory page corresponding to the second page table meets the set size, that is, the size requirements of the hot migration for the physical memory page are met, the virtual client and its hot migration success rate and performance are improved; on the other hand, through the master-slave setting and reasonable switching of the first and second page tables, in the process of converting the physical memory page size to the page size required for hot migration, the virtual machine will not be suspended or other problems that affect the performance of the virtual machine will not be introduced, which greatly reduces the adverse effects of the hot migration page table size change on the virtual client operation.
[0170] It should be pointed out that, according to the needs of implementation, the various components / steps described in the embodiments of the present invention can be split into more components / steps, or two or more components / steps or partial operations of components / steps can be combined into new components / steps to achieve the purpose of the embodiments of the present invention.
[0171] The above-described method according to an embodiment of the present invention may be implemented in hardware, firmware, or may be implemented as software or computer code that may be stored in a recording medium (such as a CD ROM, RAM, floppy disk, hard disk, or magneto-optical disk), or may be implemented as computer code that is originally stored in a remote recording medium or a non-temporary machine-readable medium downloaded through a network and will be stored in a local recording medium, so that the method described herein may be stored in such software processing on a recording medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware (such as an ASIC or FPGA). It is understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component (e.g., RAM, ROM, flash memory, etc.) that may store or receive software or computer code, and when the software or computer code is accessed and executed by a computer, a processor, or hardware, the virtual machine hot migration method described herein is implemented. In addition, when a general-purpose computer accesses code for implementing the virtual machine hot migration method shown herein, the execution of the code converts the general-purpose computer into a dedicated computer for executing the virtual machine hot migration method shown herein.
[0172] Those of ordinary skill in the art will appreciate that the units and method steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the embodiments of the present invention.
[0173] The above implementation methods are only used to illustrate the embodiments of the present invention, and are not limitations of the embodiments of the present invention. Ordinary technicians in the relevant technical field may make various changes and modifications without departing from the spirit and scope of the embodiments of the present invention. Therefore, all equivalent technical solutions also belong to the scope of the embodiments of the present invention. The patent protection scope of the embodiments of the present invention should be defined by the claims.
Claims
1. A virtual machine hot migration method, characterized in that: include: According to the switching trigger instruction, a first page table in the first physical machine for indicating a mapping relationship between a virtual client memory address and a host machine physical address is switched to a second page table; hot migrating the virtual client from the first physical machine to the second physical machine according to the second page table; Among them, the size of the physical memory page indicated by the last-level page table of the second page table meets the set size, and the size of the physical memory page indicated by the last-level page table of the first page table is larger than the set size.
2. The method according to claim 1, characterized in that The method of switching a first page table in the first physical machine for indicating a mapping relationship between a virtual client memory address and a host machine physical address to a second page table according to the switching trigger instruction includes: According to the switching trigger instruction, the currently used virtual machine active page table is switched from the first page table to the second page table; And an indication signal for instructing to reload the page table is sent to all virtual clients in the first physical machine, so as to instruct each virtual client to switch the page table node in the first page table currently being used to the corresponding page table node in the second page table.
3. The method according to claim 2, characterized in that The step of switching the currently used virtual machine active page table from the first page table to the second page table according to the switching trigger instruction includes: After receiving the switching trigger instruction, creating the second page table according to the first page table; After the second page table is successfully created, the currently used virtual machine active page table is switched from the first page table to the second page table.
4. The method according to claim 3, characterized in that The switching the currently used virtual machine active page table from the first page table to the second page table includes: Determine a variable value corresponding to a first variable of a root page table pointing to the virtual machine active page table, and determine, according to the variable value, that the currently used virtual machine active page table is the first page table; The first variable is reassigned to a set value, the first page table is deactivated according to the set value, and the second page table is activated as an active page table of the virtual machine.
5. The method according to claim 4, characterized in that The first variable is a memory management unit node MMU_NODE variable; Before reassigning the first variable to a set value, the method further includes: locking a memory management unit MMU corresponding to the first variable; After activating the second page table as the virtual machine active page table, the method further includes: unlocking the MMU.
6. The method according to claim 4, characterized in that The sending an indication signal for indicating to reload the page table to all virtual clients in the first physical machine, so as to instruct each virtual client to switch a page table node in the first page table currently used to a corresponding page table node in the second page table, includes: An indication signal for instructing to reload the page table is sent to the virtual processors corresponding to all virtual clients in the first physical machine, so as to instruct each virtual processor to switch the page table node in the currently used first page table to the corresponding page table node in the second page table.
7. The method according to claim 6, characterized in that Each virtual processor switches the currently used page table node in the first page table to the corresponding page table node in the second page table in the following manner: Each virtual processor checks, according to the indication signal, whether the variable value of the second variable pointing to the root page table currently used by each virtual processor is consistent with the variable value of the first variable; If they are inconsistent, the variable value of the first variable is used to replace the variable value of the second variable.
8. The method according to any one of claims 1 to 7, characterized in that: The method further comprises: Determining whether the thermal migration is successful; If the hot migration is successful, releasing the first page table and the second page table in the first physical machine; If the hot migration fails, the second page table is switched back to the first page table, and the second page table in the first physical machine is released.
9. The method according to any one of claims 3 to 7, characterized in that: The step of creating the second page table according to the first page table includes: The memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table is traversed, and the second page table is created according to the traversal result.
10. The method according to claim 9, characterized in that The step of creating the second page table according to the traversal result includes: Generate a last-level page table entry in the second page table according to the copies of each last-level page table entry traversed, and mark the generated last-level page table entry with a set identifier; Determine whether the size of the physical memory page pointed to by the generated last-level page table entry is greater than the set size; If it is greater, delete the set identifier corresponding to the last-level page table entry, and establish at least one level of sub-page table entry for the last-level page table entry according to the size of the physical memory page pointed to by the last-level page table entry, wherein the size of the physical memory page pointed to by the last-level page table entry in the at least one level of sub-page table entry is the set size.
11. The method according to claim 9, characterized in that The method further comprises: Determine whether the upper-level page table corresponding to the generated last-level page table entry exists; If it does not exist, a corresponding upper-level page table is generated for the last-level page table entry and saved in the second page table.
12. The method according to claim 9, characterized in that When a physical memory page of the host machine is mapped to multiple virtual client memory pages, the memory reverse mapping table stores a corresponding linked list of multiple last-level page table entries pointing to the physical memory page.
13. The method according to claim 12, characterized in that The traversing the memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table, and creating the second page table according to the traversal result, comprises: Obtaining a memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table; Traversing the table entries of the memory reverse mapping table one by one to determine whether the linked list is stored in the current table entry; If the linked list is stored, traverse each last-level page table entry in the linked list, and copy information of multiple last-level page table entries corresponding to the linked list and content of each traversed last-level page table entry to the second page table; If the linked list is not stored, the content of the current entry is copied to the second page table.
14. The method according to any one of claims 1 to 7, characterized in that: The method further comprises: If a hot migration exception occurs during the hot migration process, the second page table is released first, and then the currently used virtual machine active page table is switched back to the first page table, and then the first page table is released.
15. A virtual machine hot migration device, characterized in that: include: A switching module, configured to switch a first page table in the first physical machine, which is used to indicate a mapping relationship between a virtual client memory address and a host machine physical address, to a second page table according to a switching trigger instruction; a hot migration module, configured to hot migrate the virtual client from the first physical machine to the second physical machine according to the second page table; Among them, the size of the physical memory page indicated by the last-level page table of the second page table meets the set size, and the size of the physical memory page indicated by the last-level page table of the first page table is larger than the set size.
16. The device according to claim 15, characterized in that The switching module comprises: An active page table switching submodule, used to switch the currently used virtual machine active page table from the first page table to the second page table according to a switching trigger instruction; The indication submodule is used to send an indication signal for indicating reloading the page table to all virtual clients in the first physical machine, so as to instruct each virtual client to switch the page table node in the first page table currently used to the corresponding page table node in the second page table.
17. The device according to claim 16, characterized in that The active page table switching submodule includes: a creating unit, configured to create the second page table according to the first page table after receiving a switching trigger instruction; The post-creation switching unit is used to switch the currently used virtual machine active page table from the first page table to the second page table after the second page table is successfully created.
18. The device according to claim 17, characterized in that The post-creation switching unit is used to determine, after the second page table is successfully created, a variable value corresponding to a first variable of a root page table pointing to the virtual machine active page table, and determine, according to the variable value, that the currently used virtual machine active page table is the first page table; The first variable is reassigned to a set value, the first page table is deactivated according to the set value, and the second page table is activated as an active page table of the virtual machine.
19. The device according to claim 18, characterized in that The first variable is a memory management unit node MMU_NODE variable; The post-creation switching unit is further used to lock the memory management unit MMU corresponding to the first variable before reassigning the first variable to a set value; and unlock the MMU after activating the second page table as the active page table of the virtual machine.
20. The device according to claim 18, characterized in that The indication submodule is used to send an indication signal for indicating reloading the page table to the virtual processors corresponding to all virtual clients in the first physical machine, so as to instruct each virtual processor to switch the page table node in the currently used first page table to the corresponding page table node in the second page table.
21. The device according to claim 20, characterized in that Each virtual processor switches the currently used page table node in the first page table to the corresponding page table node in the second page table in the following manner: Each virtual processor checks, according to the indication signal, whether the variable value of the second variable pointing to the root page table currently used by each virtual processor is consistent with the variable value of the first variable; If they are inconsistent, the variable value of the first variable is used to replace the variable value of the second variable.
22. The device according to any one of claims 15 to 21, characterized in that The device also includes: The first hot migration processing module is used to determine whether the hot migration is successful; if the hot migration is successful, the first page table and the second page table in the first physical machine are released; if the hot migration fails, the second page table is switched back to the first page table and the second page table in the first physical machine is released.
23. The device according to any one of claims 17 to 21, characterized in that: The creation unit is used to traverse the memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table after receiving the switching trigger instruction, and create the second page table according to the traversal result.
24. The device according to claim 23, characterized in that The creation unit is used to traverse the memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table after receiving the switching trigger instruction; generate the last-level page table entry in the second page table according to the copy of each last-level page table entry traversed, and mark the generated last-level page table entry with a set identifier; determine whether the size of the physical memory page pointed to by the generated last-level page table entry is greater than the set size; if greater, delete the set identifier corresponding to the last-level page table entry, and establish at least one level of sub-page table entry for the last-level page table entry according to the size of the physical memory page pointed to by the last-level page table entry, wherein the size of the physical memory page pointed to by the last-level page table entry in the at least one level of sub-page table entry is the set size.
25. The device according to claim 23, characterized in that The creation unit is further used to determine whether the upper-level page table corresponding to the generated last-level page table entry exists; if not, generate the corresponding upper-level page table for the last-level page table entry and save it to the second page table.
26. The device according to claim 23, characterized in that When a physical memory page of the host machine is mapped to multiple virtual client memory pages, the memory reverse mapping table stores a corresponding linked list of multiple last-level page table entries pointing to the physical memory page.
27. The device according to claim 26, characterized in that When the creating unit traverses the memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table and creates the second page table according to the traversal result: Obtaining a memory reverse mapping table corresponding to the virtual memory slot pointed to by the first page table; Traversing the table entries of the memory reverse mapping table one by one to determine whether the linked list is stored in the current table entry; If the linked list is stored, traverse each last-level page table entry in the linked list, and copy information of multiple last-level page table entries corresponding to the linked list and content of each traversed last-level page table entry to the second page table; If the linked list is not stored, the content of the current entry is copied to the second page table.
28. The device according to any one of claims 15 to 21, characterized in that The device also includes: The second hot migration processing module is used to release the second page table first, switch the currently used virtual machine active page table back to the first page table, and then release the first page table if a hot migration exception occurs during the hot migration process.
29. An electronic device comprising: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform an operation corresponding to the virtual machine hot migration method according to any one of claims 1-14.
30. A computer storage medium having a computer program stored thereon, wherein when the program is executed by a processor, the method for hot migration of a virtual machine as claimed in any one of claims 1 to 14 is implemented.
Citation Information
Patent Citations
KVM (Kernel-based Virtual Machine)-based on-line virtual-to-virtual migration method and device
CN104598303A