A hot plug method and related equipment
By hot-plugging memory in virtual machines in batches and determining the upper limit of memory based on actual memory and required memory, the problem of insufficient virtual machine memory is solved, memory is increased from small to large, and hot-plug efficiency is improved.
Patent Information
- Application Number
- CN202010986451.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-18
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2040-09-18
AI Technical Summary
During the operation of the virtual machine, the memory is limited, which leads to the problem of insufficient memory. It is difficult to hot-plug a larger memory at one time with the existing technology, so the virtual machine cannot directly increase the initial memory to the larger required memory.
After receiving the memory hot plug request, the upper limit memory is determined based on the actual memory of the virtual machine, and the target memory is hot inserted into the virtual machine in batches to ensure that the sum of the target memory and the actual memory does not exceed the upper limit memory, thereby gradually increasing the virtual machine's memory capacity. Memory.
It realizes the gradual increase of the memory of the virtual machine from the small initial memory to the larger required memory, overcomes the defect that the initial memory is small and cannot be hot-plugged at one time, and improves the efficiency of memory hot-plugging.
Smart Images

Figure CN112114935B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a hot plug method and related equipment. Background Art
[0002] Hot plugging applied to a virtual machine refers to adding or removing memory, etc. to a virtual machine while the virtual machine is in operation. In addition, the hot plugging may include two processes: hot plugging and hot unplugging. Among them, hot plugging refers to adding memory, etc. to a virtual machine while the virtual machine is in operation; hot unplugging refers to removing memory, etc. from a virtual machine while the virtual machine is in operation.
[0003] In addition, since the memory of the virtual machine is limited, the virtual machine may encounter a problem of insufficient memory during operation. At this time, new memory can be hot-plugged into the virtual machine to solve this problem. However, how to hot-plug new memory into the virtual machine is still a technical problem that needs to be solved urgently. Summary of the invention
[0004] In order to solve the above technical problems existing in the prior art, the present application provides a hot plug method and related equipment, which can realize hot plugging of new memory into a virtual machine.
[0005] In order to achieve the above purpose, the technical solutions provided by the embodiments of the present application are as follows:
[0006] The present application provides a hot plug method, which is applied to a virtual machine. The method includes:
[0007] After receiving the memory hot-plug request, determine the upper limit memory according to the actual memory of the virtual machine at the current moment; wherein the upper limit memory is used to represent the maximum memory that the virtual machine with the actual memory is allowed to reach by hot-plugging;
[0008] When it is determined that the required memory of the virtual machine is higher than the upper limit memory, the target memory is determined according to the upper limit memory, the target memory is hot-plugged into the virtual machine, and the step of determining the upper limit memory according to the actual memory of the virtual machine at the current moment and subsequent steps are continued; wherein the sum of the target memory and the actual memory of the virtual machine at the current moment is not higher than the upper limit memory.
[0009] Optionally, the method further includes:
[0010] When it is determined that the required memory of the virtual machine is not higher than the upper memory limit, the required memory of the virtual machine is subtracted from the actual memory of the virtual machine at the current moment to obtain the remaining memory, and the remaining memory is hot-plugged into the virtual machine.
[0011] Optionally, determining the upper limit memory according to the actual memory of the virtual machine at the current moment includes:
[0012] The product of the actual memory of the virtual machine at the current moment and the memory stability coefficient is determined as the upper limit memory.
[0013] Optionally, determining the target memory according to the upper limit memory includes:
[0014] Determine a candidate memory range according to the upper limit memory, and determine a target memory from the candidate memory range;
[0015] or,
[0016] The target memory is obtained by subtracting the upper limit memory from the actual memory of the virtual machine at the current moment.
[0017] Optionally, the method further includes:
[0018] After receiving a CPU hot-plug request, determine an upper limit number of cores according to the actual memory of the virtual machine at the current moment, where the upper limit number of cores is used to represent the maximum number of CPU cores that the virtual machine with the actual memory is allowed to hot-plug;
[0019] When it is determined that the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is lower than the required number of CPU cores of the virtual machine, determine the target number of cores according to the upper limit number of cores, hot-plug the CPUs of the target number of cores into the virtual machine, and continue to perform the process of determining the upper limit number of cores according to the actual memory of the virtual machine at the current moment and subsequent processes; wherein the target number of cores is not higher than the upper limit number of cores;
[0020] When it is determined that the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is not less than the required number of CPU cores of the virtual machine, the required number of CPU cores of the virtual machine is subtracted from the actual number of CPU cores of the virtual machine at the current moment to obtain the remaining number of cores, and the CPUs with the remaining number of cores are hot-plugged into the virtual machine.
[0021] Optionally, determining the upper limit number of cores according to the actual memory of the virtual machine at the current moment includes:
[0022] Determine the product of the actual memory of the virtual machine at the current moment and the preset conversion coefficient as the first intermediate value;
[0023] Convert the first intermediate value according to the target memory unit to obtain a second intermediate value;
[0024] When it is determined that the integer part of the second intermediate value is less than 1, 1 is determined as the upper limit number of cores;
[0025] When it is determined that the integer part of the second intermediate value is not less than 1, the integer part of the second intermediate value is determined as the upper limit core number.
[0026] Optionally, determining the target number of cores according to the upper limit number of cores includes:
[0027] Determine a range of candidate core numbers according to the upper limit core number, and determine a target core number from the range of candidate core numbers;
[0028] or,
[0029] The upper limit number of cores is determined as the target number of cores.
[0030] Optionally, the method further includes:
[0031] Determine whether the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is lower than the required number of CPU cores of the virtual machine;
[0032] The continuing to execute the determining of the upper limit number of cores according to the actual memory of the virtual machine at the current moment and the subsequent process includes:
[0033] When it is determined that the actual memory has changed, continue to execute the process of determining the upper limit number of cores according to the actual memory of the virtual machine at the current moment and its subsequent processes;
[0034] When it is determined that the actual memory has not changed, continue to execute the process of determining whether the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is lower than the required number of CPU cores of the virtual machine and subsequent processes.
[0035] The embodiment of the present application also provides a hot plug device, the device comprising:
[0036] A first determining unit is used to determine an upper limit memory according to the actual memory of the virtual machine at the current moment after receiving the memory hot plug request; wherein the upper limit memory is used to represent the maximum memory that the virtual machine with the actual memory is allowed to reach by hot plugging;
[0037] The first hot-plug unit is used to determine the target memory according to the upper limit memory when it is determined that the required memory of the virtual machine is higher than the upper limit memory, hot-plug the target memory to the virtual machine, and return to the first determination unit to execute the determination of the upper limit memory according to the actual memory of the virtual machine at the current moment; wherein the sum of the target memory and the actual memory of the virtual machine at the current moment is not higher than the upper limit memory.
[0038] The present application also provides a device, the device comprising a processor and a memory:
[0039] The memory is used to store computer programs;
[0040] The processor is used to execute any implementation of the hot plug method provided in the embodiments of the present application according to the computer program.
[0041] The embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, and the computer program is used to execute any implementation of the hot plug method provided in the embodiment of the present application.
[0042] Compared with the prior art, the embodiments of the present application have at least the following advantages:
[0043] In the hot-plug method provided in the embodiment of the present application, after receiving a memory hot-plug request, the upper limit memory is determined according to the actual memory of the virtual machine at the current moment, so that when it is determined that the required memory of the virtual machine is higher than the upper limit memory, the target memory is first determined according to the upper limit memory, so that the sum of the target memory and the above-mentioned actual memory is not higher than the upper limit memory, and then the target memory is hot-plugged to the virtual machine, and the above-mentioned determination of the upper limit memory according to the actual memory of the virtual machine at the current moment and its subsequent steps are continued to be executed, so that the new memory can be hot-plugged to the virtual machine in batches.
[0044] Among them, because the upper limit memory is the maximum memory that the virtual machine with the above actual memory is allowed to hot-plug, the sum of the target memory determined based on the upper limit memory and the above actual memory is not higher than the maximum memory that the virtual machine with the actual memory is allowed to hot-plug, so that the virtual machine at the current moment can definitely meet the memory overhead when the target memory is hot-plugged to the virtual machine, so that the actual memory of the virtual machine can be gradually increased from a smaller initial memory to a larger required memory (for example, from 512M to 27G), overcoming the defect that the virtual machine cannot directly perform memory hot-plug (especially one-time memory hot-plug) due to the small initial memory of the virtual machine. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the embodiments of the present application 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 present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0046] Figure 1 A flowchart of a hot-swap method provided in an embodiment of the present application;
[0047] Figure 2 A schematic diagram of a CPU hot-plug process provided in an embodiment of the present application;
[0048] Figure 3 A flow chart of a possible implementation of the hot swap method provided in the embodiment of the present application;
[0049] Figure 4 A flow chart of another possible implementation of the hot swap method provided in the embodiment of the present application;
[0050] Figure 5 A flow chart of another possible implementation of the hot-swap method provided in the embodiment of the present application;
[0051] Figure 6 A schematic diagram of the structure of a hot-swap device provided in an embodiment of the present application;
[0052] Figure 7 A schematic diagram of the device structure provided in an embodiment of the present application. DETAILED DESCRIPTION
[0053] The inventor found the following problem in the research of technical problems in the background technology part: when hot-plugging new memory into a virtual machine, the existing memory of the virtual machine needs to be consumed, and if the new memory that is hot-plugged at one time is larger, the virtual machine needs to consume more existing memory to support the hot-plugging process of the new memory, so that the virtual machine with a smaller initial memory cannot support the hot-plugging process of hot-plugging a larger memory at one time, and thus the memory of the virtual machine cannot be directly increased from the smaller initial memory to the larger required memory through the one-time hot-plugging process. For example, when the initial memory of the virtual machine is 512M, but the required memory of the virtual machine is 27G, if you want to hot-plug the memory of the virtual machine from 512M to 27G at one time, the 512M existing memory of the virtual machine cannot support the hot-plugging process, which causes the failure of the memory hot-plugging.
[0054] In order to solve the above technical problems, an embodiment of the present application provides a hot plug method, which includes: after receiving a memory hot plug request, determining the upper limit memory according to the actual memory of the virtual machine at the current moment, so that when it is determined that the required memory of the virtual machine is higher than the upper limit memory, first determine the target memory according to the upper limit memory, so that the sum of the target memory and the above actual memory is not higher than the upper limit memory, and then hot plug the target memory to the virtual machine, and return to continue to execute the above determination of the upper limit memory according to the actual memory of the virtual machine at the current moment and its subsequent steps, so that the new memory can be hot plugged into the virtual machine in batches.
[0055] Among them, because the upper limit memory is the maximum memory that the virtual machine with the above actual memory is allowed to hot-plug, the sum of the target memory determined based on the upper limit memory and the above actual memory is not higher than the maximum memory that the virtual machine with the actual memory is allowed to hot-plug, so that the virtual machine at the current moment can definitely meet the memory consumption requirement when the target memory is hot-plugged to the virtual machine, so that the actual memory of the virtual machine can be gradually increased from a smaller initial memory to a larger required memory (for example, from 512M to 27G), overcoming the defect that the virtual machine cannot directly perform memory hot-plug (especially one-time memory hot-plug) due to the small initial memory of the virtual machine.
[0056] In addition, the hot-swap method provided in the embodiment of the present application can be applied to virtual machines, and the embodiment of the present application is not limited to virtual machines. For example, when the hot-swap method provided in the embodiment of the present application is applied to a lightweight virtualization system built by Kubernetes and kata, the virtual machine may refer to the virtual machine corresponding to each Pod.
[0057] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0058] Method Example 1
[0059] See also Figure 1 , which is a flow chart of a hot plug method provided in an embodiment of the present application.
[0060] The hot swap method provided in the embodiment of the present application includes S101-S105:
[0061] S101: receiving a memory hot plug request.
[0062] The memory hot plug request is used to request to add new memory to the virtual machine by using the hot plug method when the virtual machine is in the running state.
[0063] In addition, the embodiment of the present application does not limit the triggering method of the memory hot plug request, and any existing or future triggering method that can trigger the memory hot plug request can be adopted.
[0064] S102: Determine the upper limit memory according to the actual memory of the virtual machine at the current moment.
[0065] The "actual memory of the virtual machine at the current moment" in S102 refers to the actual memory of the virtual machine when S102 is executed, that is, the actual memory of the virtual machine in the current round of memory hot plug process. It should be noted that a round of memory hot plug process refers to the process of adding memory to the virtual machine once according to S102-S105.
[0066] In addition, the actual memory of the virtual machine will change as the memory hot plug process is executed. Specifically, for two adjacent rounds of memory hot plug processes, the actual memory of the virtual machine in the previous round of memory hot plug process is lower than the actual memory of the virtual machine in the next round of memory hot plug process.
[0067] It can be seen that for the actual memory of the virtual machine, when the memory hot-plug request is just received, the actual memory of the virtual machine should be the initial memory of the virtual machine because the memory hot-plug has not been performed on the virtual machine. That is, in the first round of memory hot-plug process, the actual memory M1 of the virtual machine is the initial memory M0 of the virtual machine; however, in the Nth round of memory hot-plug process, the actual memory M N is the sum of the total amount of memory added to the virtual machine during the first N-1 rounds of memory hot-plugging and the initial memory S0 of the virtual machine, that is, Among them, M N Indicates the actual memory of the virtual machine during the Nth round of memory hot plugging, m i Indicates the memory added to the virtual machine during the i-th round of memory hot plugging, where N is a positive integer.
[0068] The upper limit memory is used to characterize the maximum memory that a virtual machine with actual memory is allowed to reach through hot plugging. That is, the upper limit memory refers to the maximum memory that a virtual machine can increase during the current round of memory hot plugging.
[0069] In addition, the embodiment of the present application also provides a possible implementation method for determining the upper limit memory, which is specifically: multiplying the actual memory of the virtual machine at the current moment by the memory stability coefficient to determine the upper limit memory.
[0070] The memory stability coefficient refers to the ratio between the maximum memory that the virtual machine can stably hot-plug and the existing memory of the virtual machine, and the memory stability coefficient can be set in advance according to the application scenario. For example, the memory stability coefficient is 8.
[0071] Based on the above content, it can be known that in the jth round of memory hot plugging, the actual memory M of the virtual machine can be used. j Determine the upper limit memory of the virtual machine, which is specifically: the upper limit memory E determined in the jth round of memory hot plugging process j =α×M j , where α is the memory stability coefficient (such as α = 8). In this way, the upper limit memory E in the jth round of memory hot plugging can be used to calculate the memory stability coefficient.j , to execute the subsequent steps in the jth round of memory hot-plugging process. Wherein, j is a positive integer, and j≤J, and J is the total number of cycles of the memory hot-plugging process.
[0072] S103: Determine whether the required memory of the virtual machine is higher than the upper memory limit. If so, execute S104; if not, execute S105.
[0073] The required memory is used to represent the actual memory requirement of the virtual machine. In addition, the embodiment of the present application does not limit the method of obtaining the required memory of the virtual machine. For example, the required memory of the virtual machine can be carried in the memory hot plug request.
[0074] In the embodiment of the present application, after obtaining the upper limit memory E in the jth round of memory hot plugging process, j After that, it can be determined whether the virtual machine's required memory Q is higher than the upper limit memory E during the jth round of memory hot plugging. j ; if it is higher (that is, Q>E j ), it is determined that in the jth round of memory hot-plugging, the existing memory of the virtual machine cannot support the one-time hot-plugging of the virtual machine to the required memory Q of the virtual machine, so the virtual machine can continue to be hot-plugged from the existing memory M to the required memory Q of the virtual machine through multiple rounds of memory hot-plugging including the jth round of memory hot-plugging. j Gradually add to the virtual machine's required memory Q; if it is not higher (that is, Q ≤ E j ), it is determined that in the jth round of memory hot-plugging, the existing memory of the virtual machine can support the one-time hot-plugging of the virtual machine to the required memory Q of the virtual machine, so the virtual machine can be hot-plugged from the existing memory M to the required memory Q of the virtual machine in the jth round of memory hot-plugging. j The required memory Q is directly added to the virtual machine through a one-time memory hot plug method. Wherein, j is a positive integer, and j≤J, and J is the total number of cycles of the memory hot plug process.
[0075] S104: Determine the target memory according to the upper limit memory, hot-plug the target memory into the virtual machine, and return to execute S102.
[0076] The target memory refers to the memory to be hot-plugged into the virtual machine, and the sum of the target memory and the actual memory of the virtual machine at the current moment is not higher than the upper limit memory. For example, for the jth round of memory hot-plugging, the target memory R j The actual memory M of the virtual machine j The sum of the values is not higher than the upper memory limit E j , that is, R j +M j ≤E j It can be seen that the target memory can be comprehensively determined based on the upper limit memory and the actual memory at the current moment, so that the determined target memory does not exceed the difference between the upper limit memory and the actual memory at the current moment.
[0077] In addition, the embodiments of the present application also provide two possible implementation methods for determining the target memory, which are introduced below respectively.
[0078] In a possible implementation, the process of determining the target memory may be: determining a candidate memory range according to the upper limit memory, and determining the target memory from the candidate memory range.
[0079] The candidate memory range refers to the range from 0 to the difference between the upper limit memory and the actual memory of the virtual machine at the current moment. That is, for the jth round of memory hot plugging process, according to the upper limit memory E j The actual memory M of the virtual machine j The difference between j -M j , determine the candidate memory range is [0, E j -M j ]. Wherein, j is a positive integer and j≤J, and J is the total number of cycles of the memory hot-plug process.
[0080] Based on the above content, it can be known that for the jth round of memory hot plugging process, after determining the upper limit memory E in the jth round of memory hot plugging process, j After that, you can first set the upper limit memory E j The actual memory M of the virtual machine j Difference E j -M j , and then according to the difference E j -M j and 0 determine the candidate memory range in the jth round of memory hot plugging as [0, E j -M j ], and select the candidate memory range [0, E j -M j ], select any memory value as the target memory R j , so that R j ∈[0,E j -M j ], so that the target memory R j The actual memory M of the virtual machine during the jth round of memory hot plugging j The sum of is not higher than the upper limit memory E in the jth round of memory hot plugging process j , so as to ensure the stable and smooth implementation of the jth round of memory hot-plugging process. Wherein, j is a positive integer, and j≤J, and J is the total number of cycles of the memory hot-plugging process.
[0081] In another possible implementation, the target memory may be determined by subtracting the upper limit memory from the actual memory of the virtual machine at the current moment to obtain the target memory.
[0082] It can be seen that for the jth round of memory hot plugging process, after determining the upper limit memory E in the jth round of memory hot plugging process, j Afterwards, the upper limit memory E in the jth round of memory hot plugging can be j The actual memory M of the virtual machine during the jth round of memory hot plugging j Subtract and get the target memory R j =e j -M j , to achieve the target memory R j The actual memory M of the virtual machine during the jth round of memory hot plugging j The sum of is not higher than the upper limit memory E in the jth round of memory hot plugging process j The purpose is to increase the memory value of the virtual machine as much as possible while ensuring the stable and smooth execution of the jth round of memory hot plugging process, thereby reducing the number of cycles of the memory hot plugging process required to add the virtual machine from the initial memory to the required memory, thereby improving the efficiency of memory hot plugging. Where j is a positive integer, and j≤J, and J is the total number of cycles of the memory hot plugging process.
[0083] Based on the above S104, it can be known that in the embodiment of the present application, after determining that the required memory of the virtual machine is higher than the upper limit memory, the target memory can be determined according to the online memory and the actual memory of the virtual machine at the current moment, and then the target memory can be hot-plugged into the virtual machine. It can be seen that for the jth round of memory hot-plugging process, after determining that the required memory Q of the virtual machine is higher than the upper limit memory E of the jth round of memory hot-plugging process, j After that, you can first use the upper limit memory E j The actual memory M of the virtual machine j Difference E j -M j , determine the target memory R in the jth round of memory hot plugging j , so that the target memory R j Not higher than the virtual machine's required memory Q and the upper limit memory E during the jth round of memory hot plugging j The difference between the target memory R j When hot-plugging into a virtual machine, the virtual machine's existing memory M j Can meet the hot plug target memory R j The memory overhead at that time can ensure that the target memory R is smoothly inserted into the jth round of memory hot plugging. j Hot plug into the virtual machine. Where j is a positive integer, j≤J, and J is the total number of cycles of the memory hot plug process.
[0084] In addition, after the target memory is hot-plugged into the virtual machine, the actual memory of the virtual machine will be updated. Specifically, for the jth round of memory hot-plugging, after the target memory R j After hot-plugging into a virtual machine, the actual memory in the virtual machine will be increased from M j Increase to M j +R j , so that the actual memory M of the virtual machine in the j+1th round of memory hot plugging j+1 M j +R j , so that in the j+1th round of memory hot plugging, the actual memory M of the virtual machine can continue to be used. j+1 Determine the upper memory limit E j+1 , and based on the upper memory limit E j+1 Execute the subsequent process of the j+1th round of memory hot-plugging process, where j is a positive integer and j≤J, and J is the total number of cycles of the memory hot-plugging process.
[0085] It should be noted that, in the embodiment of the present application, the target memory R j Can be used as m in S102 above j Wherein, j is a positive integer and j≤J, and J is the total number of cycles of the memory hot-plug process.
[0086] S105: Subtract the required memory of the virtual machine from the actual memory of the virtual machine at the current moment to obtain the remaining memory, and hot-plug the remaining memory into the virtual machine.
[0087] In the embodiment of the present application, for the jth round of memory hot plugging process, after determining that the required memory Q of the virtual machine is not higher than the upper limit memory E of the jth round of memory hot plugging process, j After that, the virtual machine's required memory Q can be directly compared with the virtual machine's actual memory M j Subtract and get the remaining memory D = QM j , and directly hot-plug the remaining memory D to the virtual machine, thus achieving the purpose of adding the virtual machine's memory to the required memory Q. Among them, the remaining memory D is the required memory Q of the virtual machine and the actual memory M of the virtual machine during the jth round of memory hot-plugging. j The difference between the remaining memory D and the actual memory M of the virtual machine during the jth round of memory hot plugging j The sum of does not exceed the upper limit memory E in the jth round of memory hot plugging process j , so that when the remaining memory D is hot-plugged into the virtual machine, the existing memory M of the virtual machine j The memory overhead when hot-plugging the remaining memory D can be met, thereby ensuring that the remaining memory D can be hot-plugged into the virtual machine smoothly and stably during the jth round of memory hot-plugging.
[0088] Based on the relevant contents of S101 to S105 above, it can be known that in the hot-plug method provided in the embodiment of the present application, after receiving a memory hot-plug request, the upper limit memory is determined according to the actual memory of the virtual machine at the current moment, so that when it is determined that the required memory of the virtual machine is higher than the upper limit memory, the target memory is first determined according to the upper limit memory, so that the sum of the target memory and the above actual memory is not higher than the upper limit memory, and then the target memory is hot-plugged to the virtual machine, and the above step of determining the upper limit memory according to the actual memory of the virtual machine at the current moment and its subsequent steps are returned to continue to execute, so that the new memory can be hot-plugged to the virtual machine in batches.
[0089] Among them, because the upper limit memory is the maximum memory that the virtual machine with the above actual memory is allowed to hot-plug, the sum of the target memory determined based on the upper limit memory and the above actual memory is not higher than the maximum memory that the virtual machine with the actual memory is allowed to hot-plug, so that the virtual machine at the current moment can definitely meet the memory consumption requirement when the target memory is hot-plugged to the virtual machine, so that the actual memory of the virtual machine can be gradually increased from a smaller initial memory to a larger required memory (for example, from 512M to 27G), overcoming the defect that the virtual machine cannot directly perform memory hot-plug (especially one-time memory hot-plug) due to the small initial memory of the virtual machine.
[0090] Method Example 2
[0091] In some cases, it is necessary not only to hot-plug the memory in the virtual machine, but also to hot-plug the central processing unit (CPU) in the virtual machine so as to meet the demand of the virtual machine for the CPU. Based on this, the embodiment of the present application also provides a possible implementation of the hot-plug method, in which, in addition to all or part of the above steps, S106-S111 (such as Figure 2 shown):
[0092] S106: Receive a CPU hot plug request.
[0093] The CPU hot plug request is used to request to add a new CPU to the virtual machine by hot plugging when the virtual machine is in the running state.
[0094] In addition, the embodiment of the present application does not limit the triggering method of the CPU hot plug request, and any existing or future triggering method that can trigger the CPU hot plug request can be used.
[0095] S107: Determine the upper limit of the number of cores according to the actual memory of the virtual machine at the current moment.
[0096] The "actual memory of the virtual machine at the current moment" in S107 refers to the actual memory of the virtual machine when S107 is executed, that is, the actual memory of the virtual machine in the current round of CPU hot plug process. It should be noted that a round of CPU hot plug process refers to the process of adding a CPU to the virtual machine once according to S107-S111.
[0097] In addition, in the present application, the actual memory of the virtual machine in different rounds of CPU hot plugging may be the same or different, which is specifically: if the actual memory of the virtual machine changes during the execution of the yth round of CPU hot plugging (e.g., the memory increases), then the actual memory of the virtual machine during the y+1th round of CPU hot plugging is the changed actual memory (e.g., the increased memory), so that the actual memory of the virtual machine during the y+1th round of CPU hot plugging is different from the actual memory of the virtual machine during the yth round of CPU hot plugging; if the actual memory of the virtual machine does not change during the execution of the yth round of CPU hot plugging, then the actual memory of the virtual machine during the y+1th round of CPU hot plugging is the actual memory of the virtual machine during the yth round of CPU hot plugging. Wherein, y is a positive integer, y≤Y, and Y is the total number of cycles of the CPU hot plugging process.
[0098] The upper limit core number is used to characterize the maximum number of CPU cores that a virtual machine with actual memory is allowed to hot-plug. That is, the upper limit memory refers to the maximum number of CPU cores that can be hot-plugged into the virtual machine at one time that can be satisfied by the existing memory of the virtual machine during the current round of CPU hot-plugging.
[0099] In addition, the present application embodiment also provides a possible implementation method for determining the upper limit number of cores, which specifically includes the following three steps:
[0100] Step 1: The product of the actual memory of the virtual machine at the current moment and the preset conversion coefficient is determined as a first intermediate value. The preset conversion coefficient can be preset according to the application scenario, for example, the preset conversion coefficient can be 4.
[0101] Step 2: Convert the first intermediate value according to the target memory unit to obtain a second intermediate value.
[0102] The target memory unit may be preset, for example, the target memory unit may be G.
[0103] Step 3: Determine whether the integer part of the second intermediate value is less than 1. If so, determine 1 as the upper limit number of cores; if not, determine the integer part of the second intermediate value as the upper limit number of cores. The integer part of the second intermediate value refers to the value before the decimal point in the second intermediate value.
[0104] Based on the above steps 1-3, it can be known that after obtaining the actual memory M of the virtual machine in the yth round of CPU hot plugging, yAfter that, you can first use the actual memory M y Multiply by the preset conversion coefficient β to obtain the first intermediate value And the first intermediate value Convert the target memory unit to get the second intermediate value Get the second intermediate value The integer part of And determine the integer part Is it lower than 1? If it is lower than 1, the upper limit number of cores C is directly increased. y Set to 1; if it is higher than or equal to 1, the integer part is directly Determined as the upper limit of core number C y . Wherein, F() is a function that converts according to the target memory unit. Wherein, y is a positive integer, y≤Y, and Y is the total number of cycles of the CPU hot plug process.
[0105] S108: Determine whether the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is lower than the required number of CPU cores of the virtual machine. If so, execute S109; if not, execute S111.
[0106] The required number of CPU cores is used to characterize the actual CPU requirement of the virtual machine. In addition, the embodiment of the present application does not limit the method for obtaining the required number of CPU cores of the virtual machine. For example, the required number of CPU cores of the virtual machine can be carried in the CPU hot plug request.
[0107] The actual number of CPU cores of the virtual machine at the current moment refers to the number of CPU cores of the virtual machine when S108 is executed, that is, the number of CPU cores of the virtual machine in the current round of CPU hot plugging.
[0108] In addition, the actual number of CPU cores of the virtual machine will change as the CPU hot plug process is executed. Specifically, for two adjacent rounds of CPU hot plug processes, the actual memory of the virtual machine in the previous round of CPU hot plug process is lower than the actual memory of the virtual machine in the next round of CPU hot plug process.
[0109] It can be seen that for the actual number of CPU cores of the virtual machine, when the CPU hot plug request is just received, because the CPU hot plug has not been performed on the virtual machine, the actual number of CPU cores of the virtual machine should be the initial number of CPU cores of the virtual machine, that is, the actual number of CPU cores of the virtual machine in the first round of CPU hot plug process S 1 S is the initial number of CPU cores of the virtual machine 0 However, in the Tth round of CPU hot plugging, the actual CPU of the virtual machine is the sum of the total number of CPU cores added to the virtual machine in the previous T-1 rounds of CPU hot plugging and the initial number of CPU cores of the virtual machine S 0 The sum of, that is, Among them, ST represents the actual number of CPU cores of the virtual machine during the T-th round of CPU hot plugging, s x represents the number of CPU cores added to the virtual machine during the x-th round of CPU hot plugging, where T is a positive integer.
[0110] Based on the above, it can be known that in the embodiment of the present application, for the y-th round of CPU hot plugging process, after obtaining the upper limit number of cores C in the y-th round of CPU hot plugging process y first, add the upper limit number of cores C y to the actual number of CPU cores S of the virtual machine during the y-th round of CPU hot plugging process y to obtain the maximum number of cores A in the y-th round of CPU hot plugging process y = C y + S y ; then determine whether the maximum number of cores A y is lower than the required number of CPU cores H of the virtual machine; if A y < H, it is determined that during the y-th round of CPU hot plugging process, the existing memory M of the virtual machine y cannot support the virtual machine to reach the required number of CPU cores H in one-time CPU hot plugging, so the virtual machine can be gradually added from the existing number of CPU cores S y to the required number of CPU cores H through multiple rounds of CPU hot plugging processes including the y-th round of CPU hot plugging process; if A y ≥ H, it is determined that during the y-th round of CPU hot plugging process, the existing memory M of the virtual machine y can support the virtual machine to reach the required number of CPU cores H in one-time CPU hot plugging, so the virtual machine can be added from the existing number of CPU cores S y to the required number of CPU cores H in one-time CPU hot plugging manner during the y-th round of CPU hot plugging process. Wherein, y is a positive integer, y ≤ Y, and Y is the total number of cycles of the CPU hot plugging process.
[0111] S109: Determine the target number of cores according to the upper limit number of cores, and hot plug the CPU with the target number of cores into the virtual machine.
[0112] Wherein, the target number of cores refers to the number of CPU cores to be hot plugged into the virtual machine, and the target number of cores is not higher than the upper limit number of cores.
[0113] In addition, the embodiment of the present application also provides two possible implementation manners for determining the target number of cores, which are introduced respectively below.
[0114] In a possible implementation manner, the determination process of the target number of cores can be: determine the range of alternative cores according to the upper limit number of cores, and determine the target number of cores from the range of alternative cores.
[0115] The candidate core number range refers to the range of positive integers from 0 to the upper limit core number. That is, for the yth round of CPU hot plugging process, according to the upper limit core number C y Determine the range of candidate core numbers [0,C y ] PI Among them, [0,C y ] PI It refers to the range of positive integers from 0 to the upper limit of the number of cores; y is a positive integer, y≤Y, and Y is the total number of cycles of the CPU hot plug process.
[0116] Based on the above content, it can be known that for the yth round of CPU hot plugging process, when determining the upper limit number of cores C in the yth round of CPU hot plugging process y After that, we can first calculate the upper limit of the number of cores C y Determine the range of candidate core numbers [0,C y ] PI , and then select the candidate core number range [0,C y ] PI Select any positive integer as the target number of cores B y , so that B y ∈[0,C y ] PI , so as to ensure the target number of cores B y Not higher than the upper limit of the number of cores C during the yth round of CPU hot plugging y , so as to ensure the stable and smooth implementation of the yth round of CPU hot plugging process. Wherein, y is a positive integer, y≤Y, and Y is the total number of cycles of the CPU hot plugging process.
[0117] In another possible implementation, the process of determining the target number of CPU cores may be: determining an upper limit number of cores as the target number of cores.
[0118] It can be seen that for the yth round of CPU hot plugging, when determining the upper limit number of cores C in the yth round of CPU hot plugging, y After that, you can directly set the upper limit number of cores C y Determine the target number of cores B y , so that the target number of cores B y Not higher than the upper limit of the number of cores C during the yth round of CPU hot plugging y , so that the number of CPU cores hot-plugged into the virtual machine can be increased as much as possible under the premise of ensuring the stable and smooth execution of the yth round of CPU hot-plugging process, thereby reducing the number of CPU hot-plugging process cycles required to add the virtual machine from the initial number of CPU cores to the required number of CPU cores, thus improving the CPU hot-plugging efficiency. Where y is a positive integer, y≤Y, and Y is the total number of CPU hot-plugging process cycles.
[0119] Based on the above S109, it can be seen that in the embodiment of the present application, after determining that the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is lower than the required number of CPU cores of the virtual machine, the target number of cores can be determined based on the upper limit number of cores, and then the CPU with the target number of cores can be hot-plugged into the virtual machine. It can be seen that for the yth round of CPU hot-plugging process, after determining the upper limit number of cores C in the yth round of CPU hot-plugging process, the target number of cores can be hot-plugged into the virtual machine. y The actual number of CPU cores S of the virtual machine during the yth round of CPU hot plugging y The sum of C y +S y After the number of CPU cores required by the virtual machine is lower than H, you can first use the upper limit of the number of cores C y Determine the target number of cores B during the yth round of CPU hot plugging y , so that the target number of cores B y Not higher than the upper limit of the number of cores C during the yth round of CPU hot plugging y , so that when the target number of cores B y When you hot-plug a CPU into a virtual machine, the virtual machine's existing memory M y Able to meet the hot-plug target core count B y The memory overhead of the CPU during the yth round of CPU hot plugging can be guaranteed to smoothly and stably transfer the target core number B y The CPU is hot-plugged into the virtual machine. Where y is a positive integer, y≤Y, and Y is the total number of cycles of the CPU hot-plug process.
[0120] In addition, after the CPU with the target number of cores is hot-plugged into the virtual machine, the actual number of CPU cores of the virtual machine will be updated. Specifically, for the yth round of CPU hot-plugging, after the target number of cores B is hot-plugged into the virtual machine, the actual number of CPU cores of the virtual machine will be updated. y After hot-plugging the CPU to the virtual machine, the number of CPU cores in the virtual machine can be increased from S y Increase to S y +B y , so that the actual number of CPU cores of the virtual machine during the y+1th round of CPU hot plugging is S y+1 For S y +B y , so that in the y+1th round of CPU hot plugging, the actual number of CPU cores S of the virtual machine can continue to be y+1 Proceed to the next steps of the CPU hot-plug process.
[0121] S110: Determine whether the actual memory has changed, if so, return to S107; if not, return to S108.
[0122] The “actual memory” in S110 refers to the actual memory of the virtual machine when S110 is executed.
[0123] In the embodiment of the present application, for the yth round of CPU hot plugging process, when the target number of cores B is set y After the CPU is hot-plugged into the virtual machine, it is necessary to first determine whether the actual memory of the virtual machine when executing S110 is the same as the actual memory of the virtual machine when executing S107. If they are the same, it is determined that the actual memory of the virtual machine has not changed during the execution of the yth round of CPU hot-plugging process, thereby determining that the upper limit number of cores corresponding to the actual memory has not changed. Therefore, in order to improve efficiency, the step of executing S107 can be omitted, and S108 can be directly returned to start the execution of the y+1th round of CPU hot-plugging process; if they are different, it is determined that the actual memory of the virtual machine has changed during the execution of the yth round of CPU hot-plugging process, thereby determining that the upper limit number of cores corresponding to the actual memory has also changed. Therefore, in order to improve the hot-plugging stability, S107 can be returned to start the execution of the y+1th round of CPU hot-plugging process. Wherein, y is a positive integer, y≤Y, and Y is the total number of cycles of the CPU hot-plugging process.
[0124] S111: Subtract the required number of CPU cores of the virtual machine from the actual number of CPU cores of the virtual machine at the current moment to obtain the number of remaining cores, and hot-plug the CPUs with the remaining number of cores into the virtual machine.
[0125] In the embodiment of the present application, for the yth round of CPU hot plugging process, after determining the upper limit number of cores C y The actual number of CPU cores S of the virtual machine y After the sum of is not less than the required CPU core number H of the virtual machine, the required CPU core number H of the virtual machine can be divided by the actual CPU core number S of the virtual machine. y Subtract and we get the number of remaining cores Z = HS y , and hot-plug the CPUs with the remaining cores Z into the virtual machine, thus achieving the purpose of adding the CPUs of the virtual machine to the required CPU cores. Among them, because the remaining cores Z are not higher than the upper limit cores C y , so that when the CPU with the remaining cores Z is hot-plugged into the virtual machine, the actual memory M of the virtual machine y The memory overhead of hot-plugging the remaining Z CPU cores can be met, thereby ensuring that the remaining Z CPU cores can be hot-plugged into the virtual machine smoothly and stably during the yth round of CPU hot-plugging.
[0126] Based on the relevant contents of S106 to S111 above, it can be known that the embodiment of the present application can gradually increase the CPU of the virtual machine from the initial number of CPU cores to the required number of CPU cores by batch hot plugging, thereby overcoming the defect that the virtual machine cannot directly perform CPU hot plugging (especially one-time CPU hot plugging) due to the small actual memory of the virtual machine.
[0127] In some cases, when the virtual machine's memory and CPU need to be hot-plugged at the same time, the embodiment of the present application does not limit the execution order of the above memory hot-plug process and the CPU memory hot-plug process.
[0128] Example 1: The memory hot-plug process and the CPU memory hot-plug process can be executed serially in the following two process serial modes.
[0129] The first process serial method is: Figure 3 As shown in S301-S309 in the figure, the memory hot-plugging process can be performed first, and after the virtual machine's memory is hot-plugged to the required memory, the CPU memory hot-plugging process can be performed. Among them, because S306 is performed after the actual memory of the virtual machine has been hot-plugged to the required memory, the actual memory of the virtual machine in S206 will not change, so that the actual memory of the virtual machine will always remain the required memory of the virtual machine during the execution of the CPU memory hot-plugging process. Therefore, in the first process serial mode, the CPU memory hot-plugging process can be performed according to Figure 3 The process shown in S306-S309 is implemented.
[0130] Based on the relevant content of the first process serial method mentioned above, it can be known that the CPU memory hot-plugging process can be executed after completing the memory hot-plugging process of hot-plugging the virtual machine's memory into the required memory in batches. Among them, because the actual memory of the virtual machine can be expanded to the larger required memory after the memory hot-plugging process is completed, the upper limit of the number of cores determined based on the required memory is also relatively large, so that in each round of CPU memory hot-plugging process, a CPU with a larger number of cores can be hot-plugged into the virtual machine, thereby reducing the number of cycles of the CPU memory hot-plugging process, thereby improving the CPU hot-plugging efficiency.
[0131] The second process serial method is: Figure 4 As shown in S401-S409 in the figure, the CPU memory hot plug process can be executed first, and after the CPU of the virtual machine is hot plugged to the required number of CPU cores, the memory hot plug process can be executed. Among them, because the CPU memory hot plug process is executed when the actual memory of the virtual machine is still the initial memory of the virtual machine, and the actual memory of the virtual machine will not change during the execution of the CPU memory hot plug process, so that the actual memory of the virtual machine remains the initial memory of the virtual machine during the execution of the CPU memory hot plug process, the CPU memory hot plug process can be executed according to the second serial method. Figure 4 The process shown in S402-S405 is implemented.
[0132] Based on the relevant content of the above-mentioned second process serial method, it can be known that the CPU memory hot plug process can be executed before the memory hot plug process is executed, thereby realizing a serial hot plug process of first hot plugging the CPU in the virtual machine to the required number of CPU cores, and then hot plugging the memory in the virtual machine to the required memory.
[0133] Example 2: The memory hot plug process and the CPU memory hot plug process can be executed in parallel (eg Figure 5 ), the process is specifically as follows: while executing the j-th round of memory hot-plugging process, the j-th round of CPU hot-plugging process is also executed, so that when it is determined that the j-th round of memory hot-plugging process is completed and the j-th round of CPU hot-plugging process is also completed, the j+1-th round of memory hot-plugging process and the j+1-th round of CPU hot-plugging process are started, so that the actual memory of the virtual machine in the j-th round of memory hot-plugging process is the same as the actual memory of the virtual machine in the j-th round of CPU hot-plugging process, so that before the memory hot-plugging process is completed (that is, the memory of the virtual machine is hot-plugged to the required memory), for two adjacent rounds of CPU hot-plugging process, the actual memory of the virtual machine in the previous round of CPU hot-plugging process is smaller than the actual memory of the virtual machine in the next round of CPU hot-plugging process.
[0134] Based on the hot-swap method provided in the above method embodiment, the embodiment of the present application also provides a hot-swap device, which is explained and illustrated below in conjunction with the accompanying drawings.
[0135] Device Embodiment
[0136] For technical details of the hot-swap device provided in the device embodiment, please refer to the above method embodiment.
[0137] See also Figure 6 , which is a structural schematic diagram of a hot-swap device provided in an embodiment of the present application.
[0138] The hot-swap device 600 provided in the embodiment of the present application includes:
[0139] The first determining unit 601 is used to determine the upper limit memory according to the actual memory of the virtual machine at the current moment after receiving the memory hot plug request; wherein the upper limit memory is used to represent the maximum memory that the virtual machine with the actual memory is allowed to reach by hot plugging;
[0140] The first hot-plug unit 602 is used to determine the target memory according to the upper limit memory when it is determined that the required memory of the virtual machine is higher than the upper limit memory, hot-plug the target memory to the virtual machine, and return to the first determination unit to execute the determination of the upper limit memory according to the actual memory of the virtual machine at the current moment; wherein the sum of the target memory and the actual memory of the virtual machine at the current moment is not higher than the upper limit memory.
[0141] In a possible implementation manner, the hot swap device 600 further includes:
[0142] The second hot-plug unit, when determining that the required memory of the virtual machine is not higher than the upper memory limit, subtracts the required memory of the virtual machine from the actual memory of the virtual machine at the current moment to obtain the remaining memory, and hot-plugs the remaining memory into the virtual machine.
[0143] In a possible implementation manner, the first determining unit 601 is specifically configured to:
[0144] After receiving the memory hot plug request, the product of the actual memory of the virtual machine at the current moment and the memory stability coefficient is determined as the upper limit memory.
[0145] In a possible implementation manner, the first hot plug unit 602 includes:
[0146] A first determining subunit is used to determine a candidate memory range according to the upper limit memory, and determine a target memory from the candidate memory range;
[0147] or,
[0148] The second determining subunit is used to obtain a target memory by subtracting the upper limit memory from the actual memory of the virtual machine at the current moment.
[0149] In a possible implementation manner, the hot swap device 600 further includes:
[0150] A second determining unit is used to determine an upper limit number of cores according to the actual memory of the virtual machine at the current moment after receiving a central processing unit CPU hot plug request, wherein the upper limit number of cores is used to represent the maximum number of CPU cores allowed to be hot plugged by the virtual machine with the actual memory;
[0151] A third hot-plug unit is used to determine a target number of cores according to the upper limit number of cores, hot-plug the CPUs of the target number of cores into the virtual machine, and continue to perform the process of determining the upper limit number of cores according to the actual memory of the virtual machine at the current moment and subsequent processes thereof when it is determined that the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is lower than the required number of CPU cores of the virtual machine.
[0152] The fourth hot-plug unit is used to, when it is determined that the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is not less than the required number of CPU cores of the virtual machine, subtract the required number of CPU cores of the virtual machine from the actual number of CPU cores of the virtual machine at the current moment to obtain the remaining number of cores, and hot-plug the CPUs of the remaining number of cores into the virtual machine.
[0153] In a possible implementation manner, the second determining unit is specifically configured to:
[0154] After receiving a CPU hot-plug request, the product of the actual memory of the virtual machine at the current moment and the preset conversion coefficient is determined as a first intermediate value; the first intermediate value is converted according to the target memory unit to obtain a second intermediate value; when it is determined that the integer part of the second intermediate value is less than 1, 1 is determined as the upper limit number of cores; when it is determined that the integer part of the second intermediate value is not less than 1, the integer part of the second intermediate value is determined as the upper limit number of cores.
[0155] In a possible implementation manner, the third hot plug unit includes:
[0156] A third determining subunit is used to determine a range of candidate core numbers according to the upper limit core number, and determine a target core number from the range of candidate core numbers;
[0157] or,
[0158] The fourth determining subunit is configured to determine the upper limit number of cores as the target number of cores.
[0159] In a possible implementation manner, the hot swap device 600 further includes:
[0160] A judging unit, configured to judge whether a sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at a current moment is lower than the required number of CPU cores of the virtual machine;
[0161] The third hot plug unit comprises:
[0162] A first loop sub-unit is used for returning to the second determination unit to execute the determination of the upper limit number of cores according to the actual memory of the virtual machine at the current moment when it is determined that the actual memory has changed;
[0163] The second loop sub-unit is used to return to the judgment unit to execute the judgment whether the sum of the upper limit core number and the actual CPU core number of the virtual machine at the current moment is lower than the required CPU core number of the virtual machine when it is determined that the actual memory has not changed.
[0164] Based on the relevant content of the above-mentioned hot-swap device 600, it can be known that in an embodiment of the present application, after receiving a memory hot-swap request, the hot-swap device 600 determines the upper limit memory according to the actual memory of the virtual machine at the current moment, so that when it is determined that the required memory of the virtual machine is higher than the upper limit memory, the target memory is first determined according to the upper limit memory, so that the sum of the target memory and the above-mentioned actual memory is not higher than the upper limit memory, and then the target memory is hot-plugged to the virtual machine, and returns to continue to execute the above-mentioned determination of the upper limit memory according to the actual memory of the virtual machine at the current moment and its subsequent steps, so that the new memory can be hot-plugged to the virtual machine in batches.
[0165] Among them, because the upper limit memory is the maximum memory that the virtual machine with actual memory is allowed to hot-plug, the sum of the target memory determined based on the upper limit memory and the above actual memory is not higher than the maximum memory that the virtual machine with actual memory is allowed to hot-plug, so that the virtual machine at the current moment can definitely meet the memory overhead when the target memory is hot-plugged to the virtual machine, so that the actual memory of the virtual machine can be gradually increased from a smaller initial memory to a larger required memory (for example, from 512M to 27G), overcoming the defect that the virtual machine cannot directly perform memory hot-plug due to the small initial memory of the virtual machine.
[0166] Based on the hot-swap method provided in the above method embodiment, the embodiment of the present application also provides a device, which is explained and illustrated below in conjunction with the accompanying drawings.
[0167] Device Embodiment
[0168] For technical details of the device provided in the device embodiment, please refer to the above method embodiment.
[0169] See also Figure 7 , which is a schematic diagram of the device structure provided in an embodiment of the present application.
[0170] The device 700 provided in the embodiment of the present application includes: a processor 701 and a memory 702;
[0171] The memory 702 is used to store computer programs;
[0172] The processor 701 is used to execute any implementation of the hot-swap method provided in the above method embodiment according to the computer program. That is, the processor 701 is used to execute the following steps:
[0173] After receiving the memory hot-plug request, determine the upper limit memory according to the actual memory of the virtual machine at the current moment; wherein the upper limit memory is used to represent the maximum memory that the virtual machine with the actual memory is allowed to reach by hot-plugging;
[0174] When it is determined that the required memory of the virtual machine is higher than the upper limit memory, the target memory is determined according to the upper limit memory, the target memory is hot-plugged into the virtual machine, and the step of determining the upper limit memory according to the actual memory of the virtual machine at the current moment and subsequent steps are continued; wherein the sum of the target memory and the actual memory of the virtual machine at the current moment is not higher than the upper limit memory.
[0175] Optionally, also include:
[0176] When it is determined that the required memory of the virtual machine is not higher than the upper memory limit, the required memory of the virtual machine is subtracted from the actual memory of the virtual machine at the current moment to obtain the remaining memory, and the remaining memory is hot-plugged into the virtual machine.
[0177] Optionally, determining the upper limit memory according to the actual memory of the virtual machine at the current moment includes:
[0178] The product of the actual memory of the virtual machine at the current moment and the memory stability coefficient is determined as the upper limit memory.
[0179] Optionally, determining the target memory according to the upper limit memory includes:
[0180] Determine a candidate memory range according to the upper limit memory, and determine a target memory from the candidate memory range;
[0181] or,
[0182] The target memory is obtained by subtracting the upper limit memory from the actual memory of the virtual machine at the current moment.
[0183] Optionally, also include:
[0184] After receiving a CPU hot-plug request, determine an upper limit number of cores according to the actual memory of the virtual machine at the current moment, where the upper limit number of cores is used to represent the maximum number of CPU cores that the virtual machine with the actual memory is allowed to hot-plug;
[0185] When it is determined that the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is lower than the required number of CPU cores of the virtual machine, determine the target number of cores according to the upper limit number of cores, hot-plug the CPUs of the target number of cores into the virtual machine, and continue to perform the process of determining the upper limit number of cores according to the actual memory of the virtual machine at the current moment and subsequent processes; wherein the target number of cores is not higher than the upper limit number of cores;
[0186] When it is determined that the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is not less than the required number of CPU cores of the virtual machine, the required number of CPU cores of the virtual machine is subtracted from the actual number of CPU cores of the virtual machine at the current moment to obtain the remaining number of cores, and the CPUs with the remaining number of cores are hot-plugged into the virtual machine.
[0187] Optionally, determining the upper limit number of cores according to the actual memory of the virtual machine at the current moment includes:
[0188] Determine the product of the actual memory of the virtual machine at the current moment and the preset conversion coefficient as the first intermediate value;
[0189] Convert the first intermediate value according to the target memory unit to obtain a second intermediate value;
[0190] When it is determined that the integer part of the second intermediate value is less than 1, 1 is determined as the upper limit number of cores;
[0191] When it is determined that the integer part of the second intermediate value is not less than 1, the integer part of the second intermediate value is determined as the upper limit core number.
[0192] Optionally, determining the target number of cores according to the upper limit number of cores includes:
[0193] Determine a range of candidate core numbers according to the upper limit core number, and determine a target core number from the range of candidate core numbers;
[0194] or,
[0195] The upper limit number of cores is determined as the target number of cores.
[0196] Optionally, also include:
[0197] Determine whether the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is lower than the required number of CPU cores of the virtual machine;
[0198] The continuing to execute the determining of the upper limit number of cores according to the actual memory of the virtual machine at the current moment and the subsequent process includes:
[0199] When it is determined that the actual memory has changed, continue to execute the process of determining the upper limit number of cores according to the actual memory of the virtual machine at the current moment and its subsequent processes;
[0200] When it is determined that the actual memory has not changed, continue to execute the process of determining whether the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is lower than the required number of CPU cores of the virtual machine and subsequent processes.
[0201] The above is the relevant content of the device 700 provided in the embodiment of the present application.
[0202] Based on the hot-swap method provided by the above method embodiment, the embodiment of the present application also provides a computer-readable storage medium.
[0203] Medium Embodiment
[0204] For technical details of the computer-readable storage medium provided by the medium embodiment, please refer to the method embodiment.
[0205] The embodiment of the present application provides a computer-readable storage medium, which is used to store a computer program, and the computer program is used to execute any implementation of the hot plug method provided in the above method embodiment. In other words, the computer program is used to execute the following steps:
[0206] After receiving the memory hot-plug request, determine the upper limit memory according to the actual memory of the virtual machine at the current moment; wherein the upper limit memory is used to represent the maximum memory that the virtual machine with the actual memory is allowed to reach by hot-plugging;
[0207] When it is determined that the required memory of the virtual machine is higher than the upper limit memory, the target memory is determined according to the upper limit memory, the target memory is hot-plugged into the virtual machine, and the step of determining the upper limit memory according to the actual memory of the virtual machine at the current moment and subsequent steps are continued; wherein the sum of the target memory and the actual memory of the virtual machine at the current moment is not higher than the upper limit memory.
[0208] Optionally, also include:
[0209] When it is determined that the required memory of the virtual machine is not higher than the upper memory limit, the required memory of the virtual machine is subtracted from the actual memory of the virtual machine at the current moment to obtain the remaining memory, and the remaining memory is hot-plugged into the virtual machine.
[0210] Optionally, determining the upper limit memory according to the actual memory of the virtual machine at the current moment includes:
[0211] The product of the actual memory of the virtual machine at the current moment and the memory stability coefficient is determined as the upper limit memory.
[0212] Optionally, determining the target memory according to the upper limit memory includes:
[0213] Determine a candidate memory range according to the upper limit memory, and determine a target memory from the candidate memory range;
[0214] or,
[0215] The target memory is obtained by subtracting the upper limit memory from the actual memory of the virtual machine at the current moment.
[0216] Optionally, also include:
[0217] After receiving a CPU hot-plug request, determine an upper limit number of cores according to the actual memory of the virtual machine at the current moment, where the upper limit number of cores is used to represent the maximum number of CPU cores that the virtual machine with the actual memory is allowed to hot-plug;
[0218] When it is determined that the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is lower than the required number of CPU cores of the virtual machine, determine the target number of cores according to the upper limit number of cores, hot-plug the CPUs of the target number of cores into the virtual machine, and continue to perform the process of determining the upper limit number of cores according to the actual memory of the virtual machine at the current moment and subsequent processes; wherein the target number of cores is not higher than the upper limit number of cores;
[0219] When it is determined that the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is not less than the required number of CPU cores of the virtual machine, the required number of CPU cores of the virtual machine is subtracted from the actual number of CPU cores of the virtual machine at the current moment to obtain the remaining number of cores, and the CPUs with the remaining number of cores are hot-plugged into the virtual machine.
[0220] Optionally, determining the upper limit number of cores according to the actual memory of the virtual machine at the current moment includes:
[0221] Determine the product of the actual memory of the virtual machine at the current moment and the preset conversion coefficient as the first intermediate value;
[0222] Convert the first intermediate value according to the target memory unit to obtain a second intermediate value;
[0223] When it is determined that the integer part of the second intermediate value is less than 1, 1 is determined as the upper limit number of cores;
[0224] When it is determined that the integer part of the second intermediate value is not less than 1, the integer part of the second intermediate value is determined as the upper limit core number.
[0225] Optionally, determining the target number of cores according to the upper limit number of cores includes:
[0226] Determine a range of candidate core numbers according to the upper limit core number, and determine a target core number from the range of candidate core numbers;
[0227] or,
[0228] The upper limit number of cores is determined as the target number of cores.
[0229] Optionally, also include:
[0230] Determine whether the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is lower than the required number of CPU cores of the virtual machine;
[0231] The continuing to execute the determining of the upper limit number of cores according to the actual memory of the virtual machine at the current moment and the subsequent process includes:
[0232] When it is determined that the actual memory has changed, continue to execute the process of determining the upper limit number of cores according to the actual memory of the virtual machine at the current moment and its subsequent processes;
[0233] When it is determined that the actual memory has not changed, continue to execute the process of determining whether the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is lower than the required number of CPU cores of the virtual machine and subsequent processes.
[0234] The above is the relevant content of the computer-readable storage medium provided in the embodiments of the present application.
[0235] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0236] The above is only a preferred embodiment of the present invention and does not limit the present invention in any form. Although the present invention has been disclosed as above in the preferred embodiment, it is not used to limit the present invention. Any technician familiar with the art can make many possible changes and modifications to the technical solution of the present invention by using the methods and technical contents disclosed above without departing from the scope of the technical solution of the present invention, or modify it into an equivalent embodiment of equivalent changes. Therefore, any simple modification, equivalent change and modification made to the above embodiments according to the technical essence of the present invention without departing from the content of the technical solution of the present invention still falls within the scope of protection of the technical solution of the present invention.
Claims
1. A hot-swap method, characterized in that: Applied to a virtual machine, the method comprises: After receiving the memory hot-plug request, determine the upper limit memory according to the actual memory of the virtual machine at the current moment; wherein the upper limit memory is used to represent the maximum memory that the virtual machine with the actual memory is allowed to reach by hot-plugging; When it is determined that the required memory of the virtual machine is higher than the upper limit memory, a target memory is determined according to the upper limit memory, the target memory is hot-plugged into the virtual machine, and the step of determining the upper limit memory according to the actual memory of the virtual machine at the current moment and subsequent steps are continued; wherein the sum of the target memory and the actual memory of the virtual machine at the current moment is not higher than the upper limit memory; The determining the upper limit memory according to the actual memory of the virtual machine at the current moment includes: The product of the actual memory of the virtual machine at the current moment and the memory stability coefficient is determined as the upper limit memory; The determining the target memory according to the upper limit memory includes: Determine a candidate memory range according to the upper limit memory, and determine a target memory from the candidate memory range; or, The target memory is obtained by subtracting the upper limit memory from the actual memory of the virtual machine at the current moment.
2. The method according to claim 1, characterized in that: The method further comprises: When it is determined that the required memory of the virtual machine is not higher than the upper memory limit, the required memory of the virtual machine is subtracted from the actual memory of the virtual machine at the current moment to obtain the remaining memory, and the remaining memory is hot-plugged into the virtual machine.
3. The method according to claim 1, characterized in that The method further comprises: After receiving a CPU hot-plug request, determine an upper limit number of cores according to the actual memory of the virtual machine at the current moment, where the upper limit number of cores is used to represent the maximum number of CPU cores that the virtual machine with the actual memory is allowed to hot-plug; When it is determined that the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is lower than the required number of CPU cores of the virtual machine, determine the target number of cores according to the upper limit number of cores, hot-plug the CPUs of the target number of cores into the virtual machine, and continue to perform the process of determining the upper limit number of cores according to the actual memory of the virtual machine at the current moment and subsequent processes; wherein the target number of cores is not higher than the upper limit number of cores; When it is determined that the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is not less than the required number of CPU cores of the virtual machine, the required number of CPU cores of the virtual machine is subtracted from the actual number of CPU cores of the virtual machine at the current moment to obtain the remaining number of cores, and hot-plug the CPUs of the remaining number of cores into the virtual machine; The determining the upper limit number of cores according to the actual memory of the virtual machine at the current moment includes: Determine the product of the actual memory of the virtual machine at the current moment and the preset conversion coefficient as the first intermediate value; Convert the first intermediate value according to the target memory unit to obtain a second intermediate value; When it is determined that the integer part of the second intermediate value is less than 1, 1 is determined as the upper limit number of cores; When it is determined that the integer part of the second intermediate value is not less than 1, determining the integer part of the second intermediate value as the upper limit number of cores; The determining the target number of cores according to the upper limit number of cores includes: Determine a range of candidate core numbers according to the upper limit core number, and determine a target core number from the range of candidate core numbers; or, The upper limit number of cores is determined as the target number of cores.
4. The method according to claim 3, characterized in that The method further comprises: Determine whether the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is lower than the required number of CPU cores of the virtual machine; The continuing to execute the determining of the upper limit number of cores according to the actual memory of the virtual machine at the current moment and the subsequent process includes: When it is determined that the actual memory has changed, continue to execute the process of determining the upper limit number of cores according to the actual memory of the virtual machine at the current moment and its subsequent processes; When it is determined that the actual memory of the virtual machine has not changed, continue to execute the process of determining whether the sum of the upper limit number of cores and the actual number of CPU cores of the virtual machine at the current moment is lower than the required number of CPU cores of the virtual machine and subsequent processes.
5. A hot-swap device, characterized in that: The device comprises: A first determining unit is used to determine an upper limit memory according to the actual memory of the virtual machine at the current moment after receiving the memory hot plug request; wherein the upper limit memory is used to represent the maximum memory that the virtual machine with the actual memory is allowed to reach by hot plugging; A first hot-plug unit is used to determine a target memory according to the upper limit memory when it is determined that the required memory of the virtual machine is higher than the upper limit memory, hot-plug the target memory to the virtual machine, and return to the first determination unit to execute the determination of the upper limit memory according to the actual memory of the virtual machine at the current moment; wherein the sum of the target memory and the actual memory of the virtual machine at the current moment is not higher than the upper limit memory; The first determining unit is specifically configured to: The product of the actual memory of the virtual machine at the current moment and the memory stability coefficient is determined as the upper limit memory; The first hot plug unit comprises: A first determining subunit is used to determine a candidate memory range according to the upper limit memory, and determine a target memory from the candidate memory range; or, The second determining subunit is used to obtain a target memory by subtracting the upper limit memory from the actual memory of the virtual machine at the current moment.
6. A device, characterized in that: The device comprises a processor and a memory: The memory is used to store computer programs; The processor is configured to execute the method according to any one of claims 1 to 4 according to the computer program.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store a computer program, and the computer program is used to execute the method according to any one of claims 1 to 4.
