Memory adjustment method and device, computer equipment and readable storage medium
By obtaining the miss ratio and status of the virtual machine, combined with the swap status and large page ratio, the memory demand is dynamically adjusted, which solves the problem of inefficient memory adjustment in cloud data centers, realizes fast and efficient memory allocation, avoids page faults and saves memory.
Patent Information
- Application Number
- CN202510824258.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-19
- Publication Date
- 2025-10-10
AI Technical Summary
In cloud data centers, the memory requirements of applications increase and become more complex, resulting in inefficient memory adjustment. Especially when running large working set applications, how to improve memory adjustment efficiency has become an urgent problem to be solved.
By obtaining the miss ratio of the virtual machine, determining the memory status based on the ratio and the preset threshold, and combining the current swap status and large page ratio, dynamically adjusting the memory demand, and allocating memory to the virtual machine through the memory allocation strategy, the dynamic programming algorithm is used to optimize the memory allocation.
It achieves fast and efficient adjustment of virtual machine memory, avoids page fault access, ensures virtual machine performance while saving memory resources.
Smart Images

Figure CN120762885A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of cloud computing virtualization, and in particular to a memory adjustment method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Art
[0002] As applications running in cloud data centers rely on memory in virtualized environments to implement their functions, the number of applications and their complexity increase, and the memory resources required by these applications are also increasing, leading to increasing memory consumption. For example, when running applications with large working sets, since these applications are more sensitive to memory allocation, improving memory adjustment efficiency is a pressing technical issue. Summary of the Invention
[0003] Based on this, it is necessary to provide a memory adjustment method, device, computer equipment, computer-readable storage medium and computer program product that can achieve fast and efficient adjustment of virtual machine memory and improve system performance in response to the above technical problems.
[0004] In a first aspect, the present application provides a memory adjustment method, comprising:
[0005] Obtaining the miss ratio of each virtual machine within a preset time period;
[0006] Determining a memory state of each virtual machine based on a ratio of each virtual machine and a preset ratio threshold, wherein the memory state includes a stable state and an unstable state;
[0007] Determine the memory requirements of each virtual machine based on its memory status, current swap status, and huge page ratio;
[0008] A memory allocation strategy is determined based on the memory requirements of each virtual machine and the total available memory, and memory is allocated to each virtual machine according to the memory allocation strategy.
[0009] In one embodiment, obtaining the ratio of misses of each virtual machine within a preset time period includes:
[0010] Obtaining the number of misses for each virtual machine within a preset time period;
[0011] For each of the virtual machines, an average of the number of occurrences of a target number of miss situations is calculated, and the average is determined as a ratio of the virtual machine.
[0012] In one embodiment, determining the memory status of each virtual machine based on the ratio of each virtual machine and a preset ratio threshold includes:
[0013] If the ratio of the virtual machine is less than or equal to a preset ratio threshold, determining that the memory state of the virtual machine is a stable state; and / or,
[0014] If the ratio of the virtual machine is greater than a preset ratio threshold, it is determined that the memory state of the virtual machine is in an unstable state.
[0015] In one embodiment, determining the memory requirements of each virtual machine based on the memory status, current swap status, and large page ratio of each virtual machine includes:
[0016] If the virtual machine is in a swap state, determining the expected memory of the virtual machine as the sum of the current memory of the virtual machine and the swap memory; or,
[0017] If the virtual machine is not in a swap state, the memory state of the virtual machine is stable, and the huge page ratio in the virtual machine is greater than a preset ratio threshold, the memory requirement of the virtual machine is determined by using a pre-built MRC; or,
[0018] If the virtual machine is not in a swap state, and the memory state of the virtual machine is unstable or the large page ratio in the virtual machine is less than a preset ratio threshold, it is determined that the memory requirement of the virtual machine is to maintain the current memory.
[0019] In one embodiment, determining a memory allocation strategy based on the memory requirements of each virtual machine and the total available memory, and allocating memory to each virtual machine according to the memory allocation strategy, includes:
[0020] Determining a comprehensive expected memory value of the virtual machine based on the memory requirements of each of the virtual machines;
[0021] If the comprehensive expected memory value is less than or equal to the preset total available memory, memory is allocated to each virtual machine according to the expected memory of each virtual machine; or,
[0022] If the comprehensive expected memory value is greater than the preset total available memory, a memory allocation strategy that meets the page fault condition is obtained through a dynamic programming algorithm, and memory is allocated to each of the virtual machines based on the memory allocation strategy.
[0023] In one embodiment, the virtual machine in the swap state is a first virtual machine, and the virtual machine not in the swap state is a second virtual machine; obtaining a memory allocation strategy that satisfies a page fault condition through a dynamic programming algorithm, and allocating memory to each of the virtual machines based on the memory allocation strategy, includes:
[0024] Obtaining memory to be allocated for each first virtual machine by processing, using a dynamic programming algorithm, the total number of the first virtual machines, the amount of memory to be allocated, the memory boundary of each first virtual machine, and the number of page faults when each first virtual machine obtains the first amount of memory;
[0025] Memory is allocated to each of the first virtual machines based on the to-be-allocated memory of each of the first virtual machines, and memory is allocated to each of the second virtual machines based on the expected memory of each of the second virtual machines.
[0026] In a second aspect, the present application further provides a memory adjustment device, comprising:
[0027] A first acquisition module is used to obtain the ratio of miss situations of each virtual machine within a preset time period;
[0028] A first determining module is configured to determine a memory state of each virtual machine based on a ratio of each virtual machine and a preset ratio threshold, wherein the memory state includes a stable state and an unstable state;
[0029] A second determination module is configured to determine the memory requirements of each virtual machine based on the memory status, current swap status, and large page ratio of each virtual machine;
[0030] The third determining module is configured to determine a memory allocation strategy based on the memory requirements of each virtual machine and the total available memory, and allocate memory to each virtual machine according to the memory allocation strategy.
[0031] In a third aspect, the present application further provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps in the embodiments of the present application when executing the computer program.
[0032] In a fourth aspect, the present application further provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps in the embodiments of the present application are implemented.
[0033] In a fifth aspect, the present application also provides a computer program product, including a computer program, which implements the steps in the embodiments of the present application when executed by a processor.
[0034] The memory adjustment method, device, computer device, computer readable storage medium and computer program product, wherein the method comprises: obtaining a ratio corresponding to a miss condition of each virtual machine in a preset time period; determining a memory state of each virtual machine based on the ratio of each virtual machine and a preset ratio threshold, wherein the memory state comprises a stable state and an unstable state; determining a memory requirement of each virtual machine based on the memory state, a current swap state and a large page ratio of each virtual machine; determining a memory allocation strategy based on the memory requirement of each virtual machine and total available memory, and allocating memory for each virtual machine through the memory allocation strategy. By using the method, the memory of the virtual machine can be dynamically and quickly adjusted based on the real-time requirement of each virtual machine, page error access caused by a large number of page downgrades is avoided, and the performance of the virtual machine is ensured while the memory is saved as much as possible. BRIEF DESCRIPTION OF DRAWINGS
[0035] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related art, the drawings needed to be used in the description of the embodiments of the present application or the related art will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other related drawings can be obtained by those skilled in the art without creative effort on the basis of these drawings.
[0036] Figure 1 An application environment diagram of the memory adjustment method in an embodiment;
[0037] Figure 2 A flowchart of the memory adjustment method in an embodiment;
[0038] Figure 3 A flowchart of the step of determining the memory state in an embodiment;
[0039] Figure 4 A flowchart of the step of determining the memory requirement in an embodiment;
[0040] Figure 5 A flowchart of the step of allocating the memory in an embodiment;
[0041] Figure 6 A schematic diagram between the guest operating system and the host operating system in an embodiment;
[0042] Figure 7 An execution flowchart of the memory adjustment method in another embodiment;
[0043] Figure 8 A structural block diagram of the memory adjustment device in an embodiment;
[0044] Figure 9 An internal structure diagram of the computer device in an embodiment. DETAILED DESCRIPTION
[0045] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0046] The memory adjustment method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown, the host operating system 100 (host operating system, Host OS) runs on physical hardware (physical machine, i.e., terminal) and manages hardware resources and schedules virtual machines. The guest operating system 200 (Guest OS) runs in a virtual machine 300 and provides a complete operating system environment for applications through virtualization technology. The Host OS and Guest OS interact through the virtualization layer. The Host OS is responsible for virtual machine creation and resource allocation, while the Guest OS manages the operating system and runs applications within the virtual machine. The Host OS directly manages physical hardware resources, while the Guest OS runs in the virtual machine, with the virtualization layer providing virtualized hardware resources. The Host OS targets the physical hardware and controls the entire virtualized environment; the Guest OS targets the virtual machine and provides operating system functions and services.
[0047] On a physical machine, the host OS is responsible for configuring and managing huge pages to improve system performance and optimize memory usage. By using and configuring the physical machine's huge pages to create a virtual machine, you can then create a guest OS within the virtual machine. Within a virtual machine, the host OS can provide huge page support for the virtual machine, and the guest OS uses huge pages within the virtual machine to improve application performance.
[0048] The host OS configures huge pages on the physical machine, and the guest OS uses these huge pages through the virtualization layer, improving the performance of applications within the virtual machine. The virtualization layer establishes a bridge between the host and guest OSes, enabling the guest OS to utilize the huge page capabilities of the underlying physical machine. The host OS and guest OS work together in a virtualized environment. The host OS manages the entire virtualized environment and underlying hardware resources, while the guest OS provides operating system services within the virtual machine. Huge page configuration optimizes system memory performance and plays a crucial role in both physical and virtual machines. By passing huge page functionality to the guest OS through the host OS and the virtualization layer, the performance and efficiency of the entire virtualized environment are improved.
[0049] Among them, VM (Virtual Machine) refers to a virtual representation or simulation of a physical computer, which uses software instead of hardware to run programs and deploy applications.
[0050] The host operating system (OS) is an operating system installed directly on a physical server or computer. It manages hardware resources and provides a virtualized environment for the guest OS. It runs directly on the physical hardware and is responsible for creating, destroying, scheduling, and allocating resources for virtual machines.
[0051] A guest operating system (OS) is an operating system installed and run in a virtual machine. It is isolated from the host operating system and uses virtualization technology to simulate hardware resources and provide an operating environment for applications. A guest OS can be any operating system, such as Windows and Linux.
[0052] In an exemplary embodiment, Figure 2 As shown, a memory adjustment method is provided, which is applied to Figure 1 The terminal in FIG is taken as an example to illustrate the method, including the following steps 202 to 206. Among them:
[0053] Step 202: Obtain the miss ratio corresponding to each virtual machine within a preset time period.
[0054] The ratio corresponding to the miss situation may be a DTLB MISS (data translation lookaside buffer miss), indicating that when the CPU accesses the memory, the data translation lookaside buffer DTLB fails to find the required mapping relationship between the virtual address and the physical address.
[0055] Specifically, for each virtual machine, the terminal can monitor the DTLB MISS of the virtual machine at intervals of a preset duration. In this way, the terminal can obtain a target number of DTLB MISS of the virtual machine in the most recent time period, calculate an average based on the target number, and determine the ratio of the virtual machine at the current time point based on the average. In other words, the terminal can collect the current DTLB MISS of the virtual machine once every preset time period, and after the preset time period, multiple DTLB MISS can be obtained. In this way, the terminal can obtain k DTLB MISS in the most recent time period, calculate a first average of the DTLB MISS, and determine the first average as the average at the current time point. In this way, the terminal can obtain the first averages corresponding to the k time points, perform average calculation, obtain a second average, and determine the ratio of the first average to the second average as the ratio corresponding to the current time point.
[0056] The target number can be k, and the embodiment does not limit the value of k, which can be determined based on actual application scenarios and actual requirements.
[0057] Optionally, to further reduce noise, the DTLB MISS in the embodiment can be a DTLB MISS greater than a preset value, for example, the preset value can be 5000, etc.
[0058] In step 204, the memory state of each virtual machine is determined based on the ratio of each virtual machine and a preset ratio threshold. The memory state includes a stable state and an unstable state.
[0059] The preset ratio threshold can be determined based on actual business requirements, and the embodiment does not limit it.
[0060] Specifically, for each virtual machine, the terminal can compare the ratio of the virtual machine with the pre-configured ratio threshold to obtain a comparison result. That is, if the ratio of the virtual machine at the current time point is less than or equal to the preset ratio threshold, it is determined that the memory state of the virtual machine is a stable state; if the ratio of the virtual machine at the current time point is greater than the preset ratio threshold, it is determined that the memory state of the virtual machine is an unstable state. That is, the terminal can determine the memory state of the virtual machine to be a stable state or an unstable state through the comparison result of the ratio of the virtual machine at the current time point and the preset ratio threshold.
[0061] In step 206, the memory requirement of each virtual machine is determined based on the memory state of each virtual machine, the current swap state, and the large page ratio.
[0062] The memory state of each virtual machine can include a stable state and an unstable state. The current swap state of the virtual machine refers to whether the data exchange between the memory of the virtual machine and the external storage device (such as a disk) is in progress. For example, the interactive state can refer to the exchange of memory data of the virtual machine to the swap space on the disk, or when the memory used by the application in the virtual machine exceeds the physical memory allocated to the virtual machine, the operating system of the virtual machine will also enable its own exchange mechanism to exchange part of the memory page to the exchange file on the virtual disk of the virtual machine, etc. The large page ratio can be the percentage of large pages in the pages used by the virtual machine, that is, the ratio of the large page memory usage to the total memory usage. The large page is a larger page size in the system.
[0063] Specifically, for each virtual machine, the terminal can determine the memory state of the virtual machine, determine whether the virtual machine is currently in an interactive state, and obtain or determine the huge page ratio of the virtual machine. Based on the memory state, current interactive state, and huge page ratio corresponding to each virtual machine, the memory requirements of each virtual machine are determined accordingly.
[0064] Step 208: Determine a memory allocation strategy based on the memory requirements of each virtual machine and the total available memory, and allocate memory to each virtual machine according to the memory allocation strategy.
[0065] The total available memory can be the pre-allocated total memory available to the multiple virtual machines in the system, or the total amount of memory currently available in the system. The memory requirements of each virtual machine can include the desired memory, the memory to be allocated, and the unchanged memory requirements.
[0066] Specifically, the terminal can obtain the total available memory of the current system and, based on the memory requirements of each virtual machine, determine a memory allocation policy for allocating memory to each virtual machine. This allows the terminal to allocate actual memory to each virtual machine based on the memory allocation policy, enabling fast, efficient, and accurate adjustment of virtual machine memory.
[0067] In the above-mentioned memory adjustment method, the corresponding ratio of misses for each virtual machine within a preset time period is obtained; based on the ratio of each virtual machine and a preset ratio threshold, the memory state of each virtual machine is determined, and the memory state includes a stable state and an unstable state; based on the memory state, current swap state, and large page ratio of each virtual machine, the memory demand of each virtual machine is determined; based on the memory demand of each virtual machine and the total available memory, a memory allocation strategy is determined, and memory is allocated to each virtual machine according to the memory allocation strategy. By adopting this method, the memory of each virtual machine can be dynamically and quickly adjusted based on the real-time needs of each virtual machine, avoiding page fault access caused by a large number of page downgrades, and conserving memory as much as possible while ensuring the performance of the virtual machine.
[0068] In an exemplary embodiment, the specific implementation process of the step of "obtaining the ratio corresponding to the miss situations of each virtual machine within a preset time period" may include:
[0069] Obtain the number of target number misses for each virtual machine within a preset time period. Calculate the average number of target number misses for each virtual machine, and determine the average as the ratio of the virtual machines.
[0070] The ratio corresponding to the miss situation may be a DTLB MISS (data translation lookaside buffer miss), indicating that when the CPU accesses the memory, the data translation lookaside buffer DTLB fails to find the required mapping relationship between the virtual address and the physical address.
[0071] Specifically, for each virtual machine, the terminal can monitor the DTLB MISS of the virtual machine at intervals of a preset duration. In this way, the terminal can obtain a target number of DTLB MISS of the virtual machine in the most recent time period, calculate an average based on the target number, and determine the ratio of the virtual machine at the current time point based on the average. In other words, the terminal can collect the current DTLB MISS of the virtual machine once every preset time period, and after the preset time period, multiple DTLB MISS can be obtained. In this way, the terminal can obtain k DTLB MISS in the most recent time period, calculate a first average of the DTLB MISS, and determine the first average as the average at the current time point. In this way, the terminal can obtain the first averages corresponding to the k time points, perform average calculation, obtain a second average, and determine the ratio of the first average to the second average as the ratio corresponding to the current time point.
[0072] The target number may be k, and this embodiment does not limit the value of k, which may be determined based on actual requirements of actual application scenarios. The preset time period may be a time period containing k time points closest to the current time.
[0073] In this embodiment, the ratio is determined by the average of the number of occurrences of the target number of miss situations, which can improve the accuracy of determining the ratio of each virtual machine and provide a reliable data basis for subsequent memory allocation.
[0074] In an exemplary embodiment, Figure 3 As shown, the specific implementation process of the step of "determining the memory status of each virtual machine based on the ratio of each virtual machine and the preset ratio threshold" may include:
[0075] Step 302: If the ratio of the virtual machine is less than or equal to the preset ratio threshold, the memory state of the virtual machine is determined to be stable. And / or,
[0076] Specifically, for each virtual machine, the terminal may compare the ratio of the virtual machine with a pre-configured ratio threshold to obtain a comparison result. If the comparison result indicates that the ratio of the virtual machine is less than or equal to the preset ratio threshold, the terminal may determine that the memory state of the virtual machine is stable.
[0077] That is, if the terminal determines that the ratio of the virtual machine at the current time point is less than or equal to the preset ratio threshold, the memory state of the virtual machine is determined to be stable; if the ratio of the virtual machine at the current time point is greater than the preset ratio threshold, the memory state of the virtual machine is determined to be unstable. In other words, the terminal can determine whether the memory state of the virtual machine is stable or unstable by comparing the ratio of the virtual machine at the current time point with the preset ratio threshold.
[0078] Step 304: If the ratio of the virtual machine is greater than a preset ratio threshold, it is determined that the memory state of the virtual machine is unstable.
[0079] Specifically, for each virtual machine, the terminal may compare the ratio of the virtual machine with a pre-configured ratio threshold to obtain a comparison result. If the comparison result indicates that the ratio of the virtual machine is greater than the pre-configured ratio threshold, the terminal may determine that the memory state of the virtual machine is unstable.
[0080] That is to say, if the terminal determines that the ratio of the virtual machine at the current time point is greater than the preset ratio threshold, it determines that the memory state of the virtual machine is an unstable state; that is, the terminal can determine whether the memory state of the virtual machine is a stable state or an unstable state by comparing the ratio of the virtual machine at the current time point with the preset ratio threshold.
[0081] It should be noted that the present disclosure does not limit the order of execution of the above steps 302 and 304. The terminal can execute the above steps 302 and 304 simultaneously, or can execute steps 302 and 304 in sequence. Those skilled in the art can make specific decisions based on actual application scenarios.
[0082] In this embodiment, the memory status of the virtual machine is determined by comparing the ratio of each virtual machine with the preset ratio threshold, which can intuitively reflect the memory usage efficiency of the virtual machine, realize early warning of memory failure, improve memory usage efficiency, and avoid waste of memory resources.
[0083] In an exemplary embodiment, Figure 4 As shown, the specific processing of the step of "determining the memory requirements of each virtual machine based on the memory status, current swap status, and large page ratio of each virtual machine" may include:
[0084] Step 402: If the virtual machine is in a swap state, the expected memory of the virtual machine is determined to be the sum of the current memory of the virtual machine and the swap memory. Or,
[0085] Among them, the virtual machine being in the swap state indicates that the virtual machine is currently in a state of exchanging data with other storage devices; other storage devices may be disks on physical machines, etc.; the virtual machine being in the swap state indicates that the memory of the virtual machine is in a seriously insufficient state.
[0086] Specifically, if the terminal determines that the virtual machine is in a swap state, that is, it determines that the virtual machine is in a state of exchanging data between other storage devices, then the terminal performs a summation based on the current memory of the virtual machine and the swapped memory, and determines the obtained sum as the expected memory of the virtual machine. The expected memory is the amount of memory to be allocated and can meet the normal operation of the virtual machine.
[0087] The swapped-out memory may be the amount of memory used by the virtual machine to exchange data with other storage devices.
[0088] Step 404: If the virtual machine is not in a swap state, the memory state of the virtual machine is stable, and the huge page ratio in the virtual machine is greater than a preset ratio threshold, the memory requirement of the virtual machine is determined by using the pre-built MRC. Alternatively,
[0089] The huge page ratio may be the percentage of huge pages in the pages that the virtual machine may use, that is, the ratio of huge page memory usage to total memory usage; a huge page is a larger page size in the system.
[0090] Specifically, for each virtual machine, if the terminal determines that the virtual machine is not currently in a swap state, and the memory state of the virtual machine is in a stable state, and the obtained large page ratio of the virtual machine is greater than the preset ratio threshold, then the terminal can perform memory estimation through the pre-built MRC to determine the memory requirements of the virtual machine, that is, determine the amount of memory required by the virtual machine.
[0091] Step 406: If the virtual machine is not in a swap state, and the memory state of the virtual machine is unstable or the huge page ratio in the virtual machine is less than a preset ratio threshold, it is determined that the memory requirement of the virtual machine is to maintain the current memory.
[0092] Specifically, if the terminal determines that the virtual machine is not currently in a swap state and the memory state of the virtual machine is unstable, the terminal can determine that the current memory demand of the virtual machine is uncertain, but the memory demand can be temporarily met by the memory currently possessed by the virtual machine, that is, the virtual machine does not need more memory, that is, it is determined that the memory demand of the virtual machine remains unchanged.
[0093] Alternatively, if the terminal determines that the virtual machine is not currently in a swap state and the large page ratio of the virtual machine is less than a preset ratio threshold, the terminal can determine that the current memory demand of the virtual machine is uncertain, but the memory demand can be temporarily met by the memory currently available to the virtual machine, that is, the virtual machine does not need more memory, that is, it is determined that the memory demand of the virtual machine remains unchanged.
[0094] It should be noted that the present disclosure does not limit the order of execution of the above steps 402, 404, and 406. The terminal can execute the above steps 402, 404, and 406 simultaneously, or can execute 402, 404, and 406 in sequence. Those skilled in the art can make specific determinations based on actual application scenarios.
[0095] In this embodiment, the memory requirements of each virtual machine are determined by whether the virtual machine is in a swap state, the memory state, and the current huge page ratio, so that the memory requirements of the virtual machine in the huge page environment can be accurately estimated to achieve memory balance among multiple virtual machines.
[0096] In an exemplary embodiment, Figure 5 As shown in FIG, the specific processing of the step of "determining a memory allocation policy based on the memory requirements of each virtual machine and the total available memory, and allocating memory to each virtual machine according to the memory allocation policy" includes:
[0097] Step 502: Determine the comprehensive expected memory value of each virtual machine based on the memory requirements of each virtual machine.
[0098] Specifically, the terminal can obtain the memory requirements of each virtual machine, add up the memory amounts corresponding to the memory requirements of each virtual machine, and determine the resulting sum as the total expected memory value for the system. For example, the memory requirements of a virtual machine may include the expected memory of the virtual machine, the memory requirements of the virtual machine determined by MRC, and the memory requirements that remain unchanged. The memory amounts corresponding to the memory requirements of each virtual machine are added together to obtain the total expected memory value for the system. The memory amount corresponding to the memory requirements that remain unchanged can be 0 or the current memory amount available to the virtual machine.
[0099] Step 504: If the comprehensive expected memory value is less than or equal to the preset total available memory, memory is allocated to each virtual machine according to the expected memory of each virtual machine. Or,
[0100] Specifically, the terminal can obtain the total available memory of the current system and the calculated comprehensive expected memory value, and compare the comprehensive expected memory value with the preset total available memory. If the comprehensive expected memory value is less than or equal to the preset total available memory, it indicates that the current available memory can meet the memory requirements of each virtual machine. In this way, the terminal can allocate the total available memory according to the expected memory of each virtual machine. For example, if the expected memory of the first virtual machine is A, the terminal can allocate memory A from the total available memory to the first virtual machine.
[0101] Optionally, if there is still remaining memory after the terminal allocates the expected memory (expected memory) to each virtual machine, the terminal can evenly allocate the remaining memory to each virtual machine according to the number of virtual machines and the ratio of the expected memory of each virtual machine.
[0102] Step 506: If the comprehensive expected memory value is greater than the preset total available memory, a memory allocation strategy that satisfies the page fault condition is obtained through a dynamic programming algorithm, and memory is allocated to each virtual machine based on the memory allocation strategy.
[0103] Specifically, the terminal can obtain the total available memory of the current system and the calculated comprehensive expected memory value, and compare the comprehensive expected memory value with the preset total available memory. If the comprehensive expected memory value is greater than the preset total available memory, it indicates that the current available memory cannot meet the memory requirements of each virtual machine. In this way, the terminal can use a dynamic programming algorithm to determine the memory allocation strategy that can minimize the total number of error pages and allocate memory to each virtual machine according to this memory allocation.
[0104] It should be noted that the present disclosure does not limit the order of execution of the above steps 502, 504, and 506. The terminal can execute the above steps 502, 504, and 506 simultaneously, or can execute 502, 504, and 506 in sequence. Those skilled in the art can make specific determinations based on actual application scenarios.
[0105] In this embodiment, the memory requirements of each virtual machine are determined by whether the virtual machine is in a swap state, the memory state, and the current huge page ratio, so that the memory requirements of the virtual machine in the huge page environment can be accurately estimated to achieve memory balance among multiple virtual machines.
[0106] In an exemplary embodiment, the virtual machine that is not in a swap state is a first virtual machine, and the virtual machine that is in a swap state is a second virtual machine. The specific processing of the step "obtaining a memory allocation strategy that satisfies a page fault condition through a dynamic programming algorithm, and allocating memory to each virtual machine based on the memory allocation strategy" includes:
[0107] The total number of the first virtual machines, the memory amount to be allocated, the memory boundary of each first virtual machine, and the number of page faults when each first virtual machine obtains the first amount of memory are processed by a dynamic programming algorithm to obtain the memory to be allocated for each first virtual machine. Memory is allocated for each first virtual machine based on the memory to be allocated for each first virtual machine, and memory is allocated for each second virtual machine based on the expected memory of each second virtual machine.
[0108] Specifically, the content of the page fault condition can be to minimize the total number of page faults of the virtual machines; the memory allocation strategy satisfying the page fault condition can be the memory amount allocated for each virtual machine that can minimize the total number of page faults of the virtual machines. The terminal can obtain whether each virtual machine is in the swap state, determine the first virtual machines not in the swap state and the second virtual machines in the swap state, and count the total number of the first virtual machines not in the swap state. The virtual machine i can be any one of the first virtual machines not in the swap state. The memory boundary of the first virtual machine can be the upper boundary and the lower boundary of the memory of the first virtual machine. In this way, the terminal can process the total number of the first virtual machines, the memory amount to be allocated, the memory boundary of each first virtual machine, and the number of page faults when each first virtual machine obtains the first amount of memory by each dynamic programming algorithm to obtain the minimum number corresponding to the total number of virtual machines allocated with jMB, and obtain the memory currently allocated for each first virtual machine, i.e., determine the memory to be allocated for each first virtual machine.
[0109] Optionally, the state transfer function of the dynamic programming algorithm can be represented by the following formula:
[0110] Miss[i,j]=min{Miss[i-1,j-k]+PM i [k]|L i ≤k≤H i};
[0111] wherein Miss[i,j] is the minimum number of page faults when the first i virtual machines are allocated with jMB. Miss[i-1,j-k] is the minimum number of page faults when the first i-1 virtual machines are allocated with (j-k)MB. L i and H i are the lower boundary and the upper boundary of the memory size of the virtual machine i, respectively. PM i [k] is the number of page faults when the virtual machine i obtains kMB, which is determined by the pre-constructed MRC of the virtual machine. i can be the total number of the first virtual machines, and k can be the memory amount to be allocated for the virtual machine i determined based on the memory boundary of the virtual machine. j can be the current available memory.
[0112] In this embodiment, memory is allocated to each virtual machine through a dynamic programming algorithm, which can ensure a balance between the number of page faults and memory usage, and further improve system performance.
[0113] The following describes in detail a specific implementation process of the above memory adjustment method in conjunction with a specific embodiment, which may include:
[0114] The balloon mechanism consists of two main phases: inflation and deflation. Inflation involves the hypervisor sending a request to the guest OS to return a certain amount of memory to the hypervisor. After obtaining the target balloon size, the bolloon driver allocates some physical pages within the virtual machine and pins them. Pinning is implemented through the guest OS interface, ensuring that pinned pages cannot be swapped out to disk under any circumstances. Once the memory is allocated, the balloon driver notifies the hypervisor of the page frame number of the pinned physical memory so that the hypervisor can reclaim the corresponding host physical pages. Deflating involves the hypervisor returning a certain amount of memory to the guest OS, following the same principle.
[0115] In KVM and QEMU, hardware-managed Extended Page Tables (EPTs) are used to translate virtual machine memory addresses. EPT-assisted address translation involves two steps: from virtual machine virtual addresses to virtual machine physical addresses, and from virtual machine physical addresses to host physical addresses. Memory address translation from virtual machine physical addresses to host physical addresses incurs additional overhead.
[0116] The memory adjustment method in this embodiment adjusts the balloon mechanism to support large pages, such as Figure 6The figure below illustrates a schematic diagram of the balloon mechanism, including a guest operating system (Guest OS), a virtio balloon device, and a host operating system (Host OS). The guest OS includes a kernel that performs multiple steps, including balloon inflation, memory page allocation, memory adjustment, and balloon mapping. The host OS may include QEMU. Pages exchanged between the guest balloon driver and the QEMU balloon module are processed sequentially. Specifically, the virtio balloon handles output and the QEMU madvise system call. Specifically, the balloon in QEMU-KVM consists of three parts: the balloon driver in the guest kernel, communication between the guest kernel and host QEMU, and the balloon module in host QEMU. Upon receiving a balloon instruction, QEMU calculates the difference between the given balloon size and the existing balloon size. It then calls the balloon module to inflate or deflate the balloon based on the difference. Pages exchanged between the guest balloon driver and the QEMU balloon module are processed sequentially.
[0117] like Figure 7 As shown, a memory balancing system for a virtual machine may include hardware, a virtual machine manager, a controller, and multiple virtual machines, such as virtual machine 1, virtual machine 2, etc. The hardware may include multiple cores (such as core 1, core 2, etc.) and a power management unit, and the controller may obtain DTLB Miss through the power management unit in the hardware. The controller may estimate WSS through the pre-built RMC in the virtual machine manager (Memory Resource Controller, MRC) to obtain the memory requirements corresponding to each virtual machine. Accordingly, the controller may control multiple virtual machines through a balloon mechanism.
[0118] The specific process of large page-based WSS estimation can be to estimate the WSS of the virtual machine by constructing MRC. The construction of MRC relies on accurately tracking the page access of the workload or virtual machine. However, most memory accesses from the Guest OS are transparent to the virtual machine manager. This embodiment implements tracking memory access in the virtual system by modifying the permission bits of the page table entries of the memory pages. It is also possible to revoke the access rights of the page so that the next access to the page will trigger a page fault, thereby allowing the virtual machine manager to extract the access address and calculate the reuse distance, and determine the memory requirements of each virtual machine based on the distance, that is, the amount of memory required.
[0119] In one embodiment, the memory phase detection metric can be determined by comparing the changing trend of PMU events with memory demand. Because the absolute value of DTLB MISS varies greatly within a short execution period, this embodiment uses data smoothing technology to handle TLB miss changes. The TLB stores a table of virtual to physical address translations. When the virtual machine's memory demand increases, a large number of new virtual-to-physical translation relationships are generated. There are no corresponding entries in the TLB; therefore, the DTLB MISS will increase significantly.
[0120] For example, the preset interval length can be 0.1 seconds, and the terminal can monitor the DTLB MISS counts of each VM every 0.1 seconds. To avoid interference from small TLB MISS counts, this embodiment only considers DTLB MISS counts greater than 5000 within a monitoring window. By saving the average of the most recent k DTLB MISS counts for each VM, the current average is compared with the average of the previous k averages, and the resulting ratio is determined as the ratio for that VM.
[0121] Correspondingly, the virtual machines in this embodiment also include upper and lower memory limits, i.e., the upper and lower memory boundaries, based on which the memory phase is determined. If a virtual machine's memory usage exceeds this range, the virtual machine is considered to have entered a new phase, and the system will send an SSH request to check the virtual machine's memory usage. If a virtual machine is running low on memory, the controller initiates memory tracking and estimates the WSS of all virtual machines.
[0122] VM memory demand prediction. In a large page environment, allocated memory can reach gigabytes, and large page swapping by VMs can significantly degrade performance. To eliminate memory imbalances between VMs, each VM's memory demand needs to be predicted. A VM's memory state can be either stable or unstable. This allows the DTLB MISS to determine the VM's memory state.
[0123] If the ratio does not exceed a threshold (the threshold may be a pre-configured ratio threshold), the memory state of the virtual machine is stable; otherwise, the memory state of the virtual machine is unstable. For each VM, the following three situations may be included:
[0124] Case 1: The VM is in swapping state. Case 2: No swapping, and / or the VM memory state is stable, and / or the huge page ratio is greater than 90%. Case 3: The VM is not in swapping state, but the memory state is unstable or the huge page ratio is less than 90%.
[0125] Since pages in the swap area are regular pages, once a swap occurs, regular pages will remain in the VM until they are released by the program. When the huge page ratio is less than 90%, the accuracy of the WSS estimation based on huge pages drops significantly.
[0126] In the first case, the VM is severely memory-starved and memory swapping occurs; therefore, the expected memory is the sum of the current VM memory and the amount of memory swapped out. In the second case, the VM's WSS is calculated using a pre-built MRC. In the third case, the VM's memory requirements are uncertain, but since no swapping occurs, the memory requirements are temporarily sufficient. Therefore, the VM's predicted memory requirements are determined to be insufficient, and the memory requirements remain unchanged.
[0127] Two scenarios are considered based on whether the total available memory for the VMs is sufficient. If the total memory required by all VMs is less than or equal to the total available memory, memory is allocated as expected. If there is still remaining memory, it is evenly distributed to each VM in proportion to the expected memory. If the host cannot meet the memory requirements of all VMs, a dynamic programming algorithm is used to generate a memory allocation policy that minimizes the total number of page faults, and memory is allocated to each VM based on this allocation.
[0128] The goal of the dynamic programming algorithm is to achieve the best overall performance, that is, to minimize the number of error pages in multiple virtual machines. The state transfer function of the dynamic programming algorithm is:
[0129] Miss[i,j]=min{Miss[i-1,jk]+PMi[k]|Li≤k≤Hi};
[0130] Where Miss[i,j] is the minimum number of page faults when the first i virtual machines are allocated jMB in total. Miss[i-1,jk] is the minimum number of page faults when the first i-1 virtual machines are allocated (jk)MB in total. i and H i are the lower and upper bounds of the memory size of virtual machine i. i [k] is the number of page faults when virtual machine i obtains kMB, determined by the pre-built MRC of the virtual machine. i can be the total number of first virtual machines, k can be the amount of unallocated memory allocated for virtual machine i based on the virtual machine's memory boundaries, and j can be the current available memory.
[0131] The memory allocation method provided in this embodiment can be based on the balloon mechanism of large memory pages, allowing virtual machine memory adjustment without large-scale page degradation; establishing a large memory page total number estimation mechanism in the virtual execution environment to achieve memory balance between virtual machines; combining the balloon mechanism and the accessed large page total number estimation mechanism in the virtual execution environment, and proposing a memory balancing method based on dynamic programming to achieve memory balance between multiple virtual machines.
[0132] It should be understood that, although the various steps in the flowcharts involved in the various embodiments described above are displayed in sequence according to the instructions of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowcharts involved in the various embodiments described above can include multiple steps or multiple stages, and these steps or stages are not necessarily executed and completed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of steps or stages in other steps.
[0133] Based on the same inventive concept, embodiments of the present application also provide a memory adjustment device for implementing the aforementioned memory adjustment method. The solution provided by this device is similar to the solution described in the aforementioned method. Therefore, the specific limitations of one or more memory adjustment device embodiments provided below can be found in the limitations of the memory adjustment method described above and will not be further elaborated here.
[0134] In an exemplary embodiment, Figure 8 As shown, a memory adjustment device 800 is provided, comprising:
[0135] A first acquisition module 802 is configured to acquire a miss ratio corresponding to each virtual machine within a preset time period;
[0136] A first determining module 804 is configured to determine a memory state of each virtual machine based on a ratio of each virtual machine and a preset ratio threshold, where the memory state includes a stable state and an unstable state;
[0137] A second determination module 806 is configured to determine the memory requirements of each virtual machine based on the memory status, current swap status, and large page ratio of each virtual machine;
[0138] The third determining module 808 is configured to determine a memory allocation strategy based on the memory requirements of each virtual machine and the total available memory, and allocate memory to each virtual machine according to the memory allocation strategy.
[0139] In one embodiment, the first acquisition module is specifically configured to:
[0140] Obtaining the number of misses for each virtual machine within a preset time period;
[0141] For each of the virtual machines, an average of the number of occurrences of a target number of miss situations is calculated, and the average is determined as a ratio of the virtual machine.
[0142] In one embodiment, the first determining module is specifically configured to:
[0143] If the ratio of the virtual machine is less than or equal to a preset ratio threshold, determining that the memory state of the virtual machine is a stable state; and / or,
[0144] If the ratio of the virtual machine is greater than a preset ratio threshold, it is determined that the memory state of the virtual machine is in an unstable state.
[0145] In one embodiment, the second determining module is specifically configured to include:
[0146] If the virtual machine is in a swap state, determining the expected memory of the virtual machine as the sum of the current memory of the virtual machine and the swap memory; or,
[0147] If the virtual machine is not in a swap state, the memory state of the virtual machine is stable, and the huge page ratio in the virtual machine is greater than a preset ratio threshold, the memory requirement of the virtual machine is determined by using a pre-built MRC; or,
[0148] If the virtual machine is not in a swap state, and the memory state of the virtual machine is unstable or the large page ratio in the virtual machine is less than a preset ratio threshold, it is determined that the memory requirement of the virtual machine is to maintain the current memory.
[0149] In one embodiment, the third determining module is specifically configured to:
[0150] Determining a comprehensive expected memory value of the virtual machine based on the memory requirements of each of the virtual machines;
[0151] If the comprehensive expected memory value is less than or equal to the preset total available memory, memory is allocated to each virtual machine according to the expected memory of each virtual machine; or,
[0152] If the comprehensive expected memory value is greater than the preset total available memory, a memory allocation strategy that meets the page fault condition is obtained through a dynamic programming algorithm, and memory is allocated to each of the virtual machines based on the memory allocation strategy.
[0153] In one embodiment, the virtual machine in the swap state is a first virtual machine, and the virtual machine not in the swap state is a second virtual machine; the third determining module is specifically configured to:
[0154] Obtaining memory to be allocated for each first virtual machine by processing, using a dynamic programming algorithm, the total number of the first virtual machines, the amount of memory to be allocated, the memory boundary of each first virtual machine, and the number of page faults when each first virtual machine obtains the first amount of memory;
[0155] Memory is allocated to each of the first virtual machines based on the to-be-allocated memory of each of the first virtual machines, and memory is allocated to each of the second virtual machines based on the expected memory of each of the second virtual machines.
[0156] Each module in the aforementioned memory adjustment device can be implemented in whole or in part through software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in the computer device in the form of software, so that the processor can call and execute the corresponding operations of each module.
[0157] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Figure 9 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, abbreviated as I / O) and a communication interface. The processor, memory and input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The database of the computer device is used to store memory data of the virtual machine. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a memory adjustment method is implemented.
[0158] Those skilled in the art will understand that Figure 9 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0159] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the embodiments of the present application when executing the computer program.
[0160] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the embodiments of the present application are performed.
[0161] In one embodiment, a computer program product is provided, including a computer program, and the computer program is executed by a processor to perform the steps in the embodiments of the present application.
[0162] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0163] Those skilled in the art will understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. In particular, any reference to memory, database, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The databases involved in the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the various embodiments provided herein may be, but are not limited to, general-purpose processors, central processing units (CPUs), graphics processing units (GPUs), digital signal processors (DSPs), programmable logic devices (PLDs), quantum computing-based data processing logic devices, artificial intelligence (AI) processors, and the like.
[0164] The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0165] The above-described embodiments are merely illustrative of several embodiments of the present application, and the description is relatively specific and detailed, but should not be understood as a limitation on the scope of the patent. It should be noted that for those skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are all within the scope of the present application. Therefore, the scope of protection of the present application should be subject to the appended claims.
Claims
1. A memory adjustment method, characterized in that: The method comprises: Obtaining the miss ratio of each virtual machine within a preset time period; Determining a memory state of each virtual machine based on a ratio of each virtual machine and a preset ratio threshold, wherein the memory state includes a stable state and an unstable state; Determine the memory requirements of each virtual machine based on its memory status, current swap status, and huge page ratio; A memory allocation strategy is determined based on the memory requirements of each virtual machine and the total available memory, and memory is allocated to each virtual machine according to the memory allocation strategy.
2. The method according to claim 1, characterized in that The obtaining of the ratio corresponding to the miss situation of each virtual machine within the preset time period includes: Obtaining the number of misses for each virtual machine within a preset time period; For each of the virtual machines, an average of the number of occurrences of a target number of misses is calculated, and the average is determined as a ratio of the virtual machine.
3. The method according to claim 1, characterized in that The determining the memory status of each virtual machine based on the ratio of each virtual machine and a preset ratio threshold includes: If the ratio of the virtual machine is less than or equal to a preset ratio threshold, determining that the memory state of the virtual machine is a stable state; and / or, If the ratio of the virtual machine is greater than a preset ratio threshold, it is determined that the memory state of the virtual machine is in an unstable state.
4. The method according to claim 1, wherein Determining the memory requirements of each virtual machine based on the memory status, current swap status, and large page ratio of each virtual machine includes: If the virtual machine is in a swap state, determining the expected memory of the virtual machine as the sum of the current memory of the virtual machine and the swap memory; or, If the virtual machine is not in a swap state, the memory state of the virtual machine is stable, and the huge page ratio in the virtual machine is greater than a preset ratio threshold, the memory requirement of the virtual machine is determined by using a pre-built MRC; or, If the virtual machine is not in a swap state, and the memory state of the virtual machine is unstable or the large page ratio in the virtual machine is less than a preset ratio threshold, it is determined that the memory requirement of the virtual machine is to maintain the current memory.
5. The method according to claim 1, wherein The determining of a memory allocation strategy based on the memory requirements of each virtual machine and the total available memory, and allocating memory to each virtual machine according to the memory allocation strategy, includes: Determining a comprehensive expected memory value of the virtual machine based on the memory requirements of each of the virtual machines; If the comprehensive expected memory value is less than or equal to the preset total available memory, memory is allocated to each virtual machine according to the expected memory of each virtual machine; or, If the comprehensive expected memory value is greater than the preset total available memory, a memory allocation strategy that meets the page fault condition is obtained through a dynamic programming algorithm, and memory is allocated to each of the virtual machines based on the memory allocation strategy.
6. The method according to claim 5, characterized in that The virtual machine in the swap state is a first virtual machine, and the virtual machine not in the swap state is a second virtual machine; obtaining a memory allocation strategy that satisfies a page fault condition through a dynamic programming algorithm, and allocating memory to each of the virtual machines based on the memory allocation strategy, includes: Obtaining memory to be allocated for each first virtual machine by processing, using a dynamic programming algorithm, the total number of the first virtual machines, the amount of memory to be allocated, the memory boundary of each first virtual machine, and the number of page faults when each first virtual machine obtains the first amount of memory; Memory is allocated to each of the first virtual machines based on the to-be-allocated memory of each of the first virtual machines, and memory is allocated to each of the second virtual machines based on the expected memory of each of the second virtual machines.
7. A memory adjustment device, characterized in that: The device comprises: A first acquisition module is used to obtain the ratio of miss situations of each virtual machine within a preset time period; A first determining module is configured to determine a memory state of each virtual machine based on a ratio of each virtual machine and a preset ratio threshold, wherein the memory state includes a stable state and an unstable state; A second determination module is configured to determine the memory requirements of each virtual machine based on the memory status, current swap status, and large page ratio of each virtual machine; The third determining module is configured to determine a memory allocation strategy based on the memory requirements of each virtual machine and the total available memory, and allocate memory to each virtual machine according to the memory allocation strategy.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.