Memory pressure detection method, device, equipment and storage medium for virtual machines
By running the memory monitoring process and virtualization monitoring unit in the host, and obtaining the memory statistics of the virtual machine, the problem of the virtual machine's memory pressure detection program being shut down is solved, and stable and reliable memory pressure detection is achieved.
Patent Information
- Application Number
- CN202410804949.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-20
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2044-06-20
AI Technical Summary
In cloud computing and virtualization scenarios, when the memory pressure of the virtual machine is too high, the system's memory recovery mechanism may cause the memory detection program to be shut down, and the memory pressure of the virtual machine cannot be detected, causing system lag and memory jitter.
By running the memory monitoring process in the host, sending trigger instructions to the virtualization monitoring unit, generating interrupt signals, calling the kernel-state driver of the virtual machine to be monitored, obtaining memory statistics, and determining the memory pressure category based on these data.
It realizes the memory pressure of the virtual machine outside the virtual machine, avoids the memory detection program shutdown problem caused by the memory recovery mechanism, and improves the stability and reliability of the virtual machine memory detection.
Smart Images

Figure CN118747104B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to the field of cloud computing technology, and in particular to a memory pressure detection method, device, equipment and storage medium for a virtual machine. Background Art
[0002] In cloud computing and virtualization scenarios, when the memory pressure of a virtual machine is too high, the system's memory recycling mechanism will be triggered to reduce the memory pressure of the virtual machine. However, at the same time, when the memory recycling process is too intense, it will cause system freezes, that is, memory jitter (bumping).
[0003] In the prior art, in view of the uncontrollable nature of the memory recycling process, a dedicated memory monitoring program is usually deployed in the virtual machine to monitor the memory usage of the virtual machine to avoid the above-mentioned memory jitter problem.
[0004] However, in actual application, after the memory recycling mechanism of the system is triggered, the system may also shut down the memory detection program running in the virtual machine, thereby causing the problem of being unable to detect the memory pressure of the virtual machine. Summary of the invention
[0005] The embodiments of the present disclosure provide a method, apparatus, device and storage medium for detecting memory pressure of a virtual machine, so as to overcome the problem that the memory pressure of the virtual machine cannot be detected due to system memory recycling.
[0006] In a first aspect, an embodiment of the present disclosure provides a memory pressure detection method for a virtual machine, comprising:
[0007] A trigger instruction is sent to a virtualization monitoring unit through a memory monitoring process running in a host machine, wherein the virtualization monitoring unit corresponds one-to-one to the virtual machine to be monitored created by the host machine and is used to generate a corresponding interrupt signal in response to the trigger instruction; memory statistics data of the virtual machine to be monitored are obtained by responding to the interrupt signal output by the virtualization monitoring unit through the kernel state driver of the virtual machine to be monitored, and the memory statistics data represent statistical indicators of a memory recovery process for the virtual machine to be monitored; and a memory pressure category is obtained based on the memory statistics data of the virtual machine to be monitored.
[0008] In a second aspect, an embodiment of the present disclosure provides a memory pressure detection device for a virtual machine, comprising:
[0009] A trigger module, used for sending a trigger instruction to a virtualization monitoring unit through a memory monitoring process running in the host machine, wherein the virtualization monitoring unit corresponds one-to-one to the virtual machine to be monitored created by the host machine, and is used for generating a corresponding interrupt signal in response to the trigger instruction;
[0010] A detection module, configured to respond to an interrupt signal output by the virtualization monitoring unit through a kernel state driver of the virtual machine to be monitored, to obtain memory statistical data of the virtual machine to be monitored, wherein the memory statistical data represents a statistical indicator of a memory recycling process for the virtual machine to be monitored;
[0011] The processing module is used to obtain a memory pressure category according to the memory statistics data of the virtual machine to be monitored.
[0012] In a third aspect, an embodiment of the present disclosure provides an electronic device, including: a processor and a memory;
[0013] The memory stores computer-executable instructions;
[0014] The processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the memory pressure detection method for the virtual machine as described in the first aspect and various possible designs of the first aspect.
[0015] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, in which computer execution instructions are stored. When a processor executes the computer execution instructions, the memory pressure detection method for a virtual machine as described in the first aspect and various possible designs of the first aspect is implemented.
[0016] In a fifth aspect, an embodiment of the present disclosure provides a computer program product, including a computer program, which, when executed by a processor, implements the memory pressure detection method for a virtual machine as described in the first aspect and various possible designs of the first aspect.
[0017] The memory pressure detection method, device, equipment and storage medium for virtual machines provided in this embodiment send a trigger instruction to a virtualization monitoring unit through a memory monitoring process running in a host machine, wherein the virtualization monitoring unit corresponds one-to-one to the virtual machine to be monitored created by the host machine, and is used to generate a corresponding interrupt signal in response to the trigger instruction; the kernel state driver of the virtual machine to be monitored responds to the interrupt signal output by the virtualization monitoring unit to obtain memory statistics of the virtual machine to be monitored, and the memory statistics represent statistical indicators of the memory recovery process for the virtual machine to be monitored; according to the memory statistics of the virtual machine to be monitored, the memory pressure category is obtained. By setting a virtualization monitoring unit corresponding one-to-one to the virtual machine to be monitored in the host machine, and sending an interrupt signal to the kernel state driver of the virtual machine to be monitored through the virtualization monitoring unit, the memory statistics are obtained, and then the memory pressure category is obtained based on the memory statistics, so as to realize the detection of memory pressure. Since the above steps are executed outside the virtual machine, the memory pressure detection is not performed by relying on the memory detection program running inside the virtual machine, so that the problem of being unable to detect the memory pressure of the virtual machine due to the memory recovery mechanism causing the memory detection program to be closed can be avoided, and the stability and reliability of the virtual machine memory detection can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the embodiments of the present disclosure 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 some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0019] Figure 1 An application scenario diagram of the memory pressure detection method for a virtual machine provided in an embodiment of the present disclosure;
[0020] Figure 2 A flow chart of a memory pressure detection method for a virtual machine provided in an embodiment of the present disclosure Figure 1 ;
[0021] Figure 3 A schematic diagram of a process for a host machine to obtain memory statistics data provided by an embodiment of the present disclosure;
[0022] Figure 4 for Figure 2 A flowchart of a specific implementation method of step S102 in the illustrated embodiment;
[0023] Figure 5 for Figure 2 A flowchart of a specific implementation method of step S103 in the illustrated embodiment;
[0024] Figure 6 for Figure 2 A flowchart of another specific implementation of step S103 in the illustrated embodiment;
[0025] Figure 7 for Figure 2 A flowchart of another specific implementation of step S103 in the illustrated embodiment;
[0026] Figure 8 A flow chart of a memory pressure detection method for a virtual machine provided in an embodiment of the present disclosure Figure 2 ;
[0027] Fig. 9 A structural block diagram of a memory pressure detection device for a virtual machine provided in an embodiment of the present disclosure;
[0028] Fig.10 A schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure;
[0029] Fig.11 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0031] 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 disclosure 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 the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0032] The application scenarios of the embodiments of the present disclosure are explained below:
[0033] The memory pressure detection method for a virtual machine provided in the embodiment of the present disclosure can be applied to the application scenario of memory monitoring of a virtual machine. The execution subject of this embodiment can be a host machine (Host) that creates a virtual machine (Guest), or other electronic devices that perform similar functions. Among them, in some embodiments, the server can implement the memory pressure detection method for a virtual machine provided in the embodiment of the present application by running various computer executable instructions or computer programs. For example, a computer executable instruction may be a program-level command, machine instruction, or software instruction. The computer program may be a native program or software module in the operating system; it may be a local application, that is, a program that needs to be installed in the operating system to run. In summary, the above-mentioned computer executable instructions may be instructions in any form, and the above-mentioned computer program may be an application, module, or plug-in in any form, and the specific implementation form may be configured as needed. Furthermore, in some embodiments, the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud storage, cloud communications, cloud databases, cloud computing, cloud functions, network services, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms, among which cloud services can be interactive processing services for terminal devices to call.
[0034] Figure 1 An application scenario diagram of the memory pressure detection method for a virtual machine provided in the embodiment of the present disclosure, referring to Figure 1 As shown in , the host machine creates, configures, and manages multiple independent virtual machines by running a virtual machine monitor (Virtual Machine Monitor, VMM), and provides them with corresponding physical resources, such as CPU resources, memory resources, etc. On each virtual machine, a corresponding operating system runs independently. The operating system has the function of memory management, that is, it allocates and recycles memory according to the programs and services currently running on the virtual machine, thereby ensuring the normal operation of the programs on the virtual machine. At the same time, the operating system will provide a corresponding memory monitoring interface (API_1) to the outside, and other terminal devices (such as terminal devices used by users who use or maintain the virtual machine) can monitor the memory pressure of the virtual machine by calling this monitoring interface.
[0035] In the prior art, when the memory pressure of a virtual machine is too high, the memory recycling mechanism of the operating system will be triggered to reduce the memory pressure of the virtual machine. However, the memory recycling mechanism of the operating system is somewhat uncontrollable. In some cases, the memory recycling mechanism of the operating system will also shut down the memory detection program running in the virtual machine, thereby causing the external terminal device to be unable to obtain the current memory status of the virtual machine through, for example, the above-mentioned memory monitoring interface, thereby causing the problem of being unable to detect the memory pressure of the virtual machine, affecting the operating stability and performance of the virtual machine.
[0036] The disclosed embodiment provides a memory pressure detection method for a virtual machine to solve the above problem.
[0037] refer to Figure 2 , Figure 2 A flow chart of a memory pressure detection method for a virtual machine provided in an embodiment of the present disclosure Figure 1 The method of this embodiment can be applied in a host machine. The memory pressure detection method for a virtual machine includes:
[0038] Step S101: sending a trigger instruction to a virtualization monitoring unit through a memory monitoring process running in a host machine, wherein the virtualization monitoring unit is deployed in the host machine and corresponds one-to-one to a virtual machine to be monitored created by the host machine.
[0039] Step S102: the virtualization monitoring unit responds to the trigger instruction, calls the kernel state driver of the corresponding virtual machine to be monitored, and obtains memory statistics data of the virtual machine to be monitored, where the memory statistics data represent statistical indicators of the memory recycling process for the virtual machine to be monitored.
[0040] For example, reference Figure 1 As shown in the schematic diagram of the application scenario, the host machine creates one or more virtual machines by running a virtual machine monitoring program in a manner that shares hardware resources, and allocates corresponding computing resources to each virtual machine. The principle and specific process of creating a virtual machine are prior arts known to those skilled in the art and will not be repeated here. After the virtual machine is created, a process for monitoring the memory pressure of each virtual machine, namely the memory monitoring process, runs in the host machine. The memory monitoring process can be started after the host machine is initialized and maintained at all times, thereby triggering the virtualization detection unit corresponding to each virtual machine created by it by polling or the like, thereby achieving the purpose of obtaining the memory pressure corresponding to each virtual machine.
[0041] Specifically, the memory monitoring process corresponds to the memory monitoring program preset in the host machine, and a process is created to execute the memory monitoring program, thereby achieving the purpose of sending a trigger instruction to the virtualization monitoring unit. According to the specific program logic of the memory monitoring program preset in the host machine corresponding to the memory monitoring process, the memory monitoring process can send a trigger instruction to each virtualization monitoring unit based on a fixed cycle, or can send a trigger instruction to each virtualization monitoring unit based on other trigger conditions, and there is no restriction at this time.
[0042] Furthermore, the virtualization monitoring unit is a functional module deployed in the virtual machine, which is used to obtain the memory pressure of the virtual machine and can be maintained in the memory of the host machine through a specific process. Among them, the virtualization monitoring unit corresponds one-to-one to the virtual machine created by the host machine. For example, if the host machine creates 100 virtual machines, then correspondingly, 100 virtualization monitoring units are deployed in the host machine. When the virtualization monitoring unit receives the trigger instruction sent by the memory monitoring process, the virtualization monitoring unit will call the kernel state driver of the corresponding virtual machine to obtain the memory statistics of the virtual machine to be monitored. Among them, the kernel state driver of the virtual machine refers to the driver program running in the kernel state of the virtual machine, which has a high-level authority for the virtual machine, that is, through the driver program, the memory statistics of the virtual machine can be obtained.
[0043] More specifically, the kernel-mode driver of the virtual machine to be monitored can respond to a request sent by the virtualization monitoring unit, such as an interrupt request, to obtain memory statistics of the virtual machine, and send the memory statistics to the virtualization monitoring unit. Figure 3 A schematic diagram of a process for a host machine to obtain memory statistics data provided by an embodiment of the present disclosure, such as Figure 3 As shown, exemplarily, first, the memory monitoring process in the host machine sends a trigger instruction for the virtual machine G1 to the virtualization monitoring unit D1. After receiving the trigger instruction, the virtualization monitoring unit D1 calls the kernel state driver of the virtual machine G1 by sending an interrupt signal to obtain the memory statistics corresponding to the virtual machine G1. After that, the memory statistics are sent back to the virtualization monitoring unit D1, and the virtualization monitoring unit D1 completes the subsequent steps of calculating the memory pressure category. Furthermore, when it is necessary to push the memory pressure category calculated subsequently to an external terminal device, it can also be implemented through the virtualization monitoring unit in the host machine. For example, the terminal device obtains the memory pressure category corresponding to the virtual machine G1 by accessing the interface API_1 provided by the virtualization monitoring unit D1 in the figure, or pushes the memory pressure category corresponding to the virtual machine G1 to the terminal device through the interface API_1 provided by the virtualization monitoring unit D1.
[0044] Based on the introduction of the above embodiment, after obtaining memory statistics data, the virtualization monitoring unit processes the memory statistics data outside the virtual machine to obtain the memory pressure category and complete the goal of memory pressure detection. This process is completed outside the virtual machine, and there is no need to maintain a monitoring process inside the virtual machine to perform memory pressure detection, thus avoiding the problem of the memory pressure detection process in the virtual machine being closed during the memory recovery process.
[0045] In a possible implementation, before obtaining the memory statistics of the virtual machine to be monitored by calling the kernel state driver of the corresponding virtual machine to be monitored, the step of initializing the kernel state driver is further included, specifically including:
[0046] Step S100A: Initialize the kernel-mode driver of the virtual machine to be monitored, and generate program parameters corresponding to the virtual machine to be monitored, wherein the program parameters are used to indicate the category of the statistical indicator corresponding to the memory statistical data.
[0047] Step S100B: Create a monitoring program object and a communication program object according to the program parameters.
[0048] Correspondingly, such as Figure 4 As shown, after executing the above steps, the specific implementation of step S102 includes:
[0049] Step S1021: The virtualization monitoring unit responds to the trigger instruction and sends an interrupt signal to the monitoring program object to obtain memory statistics of the virtual machine to be monitored.
[0050] Step S1022: Send memory statistics data to the memory monitoring process through the communication program object.
[0051] Exemplarily, the kernel-state driver serves as the driver program of the virtual machine to be monitored and needs to be initialized before use. For example, in the process of creating the above-mentioned virtual machine to be monitored, its kernel-state driver is initialized, which includes generating program parameters corresponding to the virtual machine to be monitored, and the program parameters are used to indicate the category of statistical indicators corresponding to the memory statistical data. Specifically, program parameters are parameters related to the virtual machine. During the process of creating a virtual machine, the virtual machine will be configured according to its purpose, which will cause its kernel-state driver to have corresponding and possibly different program parameters after initialization. Different program parameters indicate the category of statistical indicators corresponding to the memory statistical data, that is, the specific implementation of the statistical indicators in the memory recovery process. For example, for virtual machine G1, after its kernel-state driver is initialized according to its configuration information, program parameter para_1 is generated, and accordingly, according to the program parameter, the memory statistical data composed of statistical indicators A, statistical indicators B, and statistical indicators C in the memory recovery process of the virtual machine are subsequently detected; and for virtual machine G2, after its kernel-state driver is initialized according to its configuration information, program parameter para_2 is generated, and accordingly, according to the program parameter, the memory statistical data composed of statistical indicators B, statistical indicators C, and statistical indicators E in the memory recovery process of the virtual machine are subsequently detected.
[0052] Furthermore, after generating the program parameters corresponding to the virtual machine to be monitored, a monitoring program object and / or a communication program object are created based on the program parameters, wherein the monitoring program object is used to obtain memory statistics, and the communication program object is used to transmit the above memory statistics. Afterwards, when calling the kernel state driver of the corresponding virtual machine to be monitored, the virtualization monitoring unit sends an interrupt signal to the monitoring program object. After receiving the interrupt signal, the monitoring program object obtains the memory statistics corresponding to the virtual machine to be monitored according to the program parameters used when creating the monitoring program object (i.e., different program parameters create corresponding monitoring program objects, thereby obtaining corresponding memory statistics). Afterwards, the memory statistics are returned to the virtualization monitoring unit through the communication program object.
[0053] It can be understood that the above-mentioned communication program object and monitoring program object are two specific implementation methods for obtaining memory statistical data and returning memory statistical data, and there may be other implementation methods for obtaining memory statistical data and returning memory statistical data. Therefore, the above-mentioned steps of creating communication program objects and monitoring program objects can be executed one by one as needed, or they can be executed simultaneously, and there is no restriction this time.
[0054] Furthermore, the memory statistics data involved in the above-mentioned embodiment steps are further introduced below. The memory statistics data refers to the statistical indicators of the operating system of the monitored virtual machine in the process of data in the memory and memory resource recycling based on the memory recycling mechanism. For example, it includes any one or more of the following:
[0055] The first event number, the second event number, the third event number, the first scanned page number, the second scanned page number, the first recycled page number, and the second recycled page number.
[0056] Among them, the first event number represents the number of Out of Memory (OOM) events; the second event number represents the number of page fault events; the third event number represents the number of direct memory recovery events; the first scan page number represents the number of memory pages scanned by the recovery thread in the background memory recovery event; the second scan page number represents the number of memory pages scanned by the recovery thread in the direct memory recovery event; the first recovery page number represents the number of memory pages recovered in the background memory recovery event; the second recovery page number represents the number of memory pages recovered in the direct memory recovery event. The above-mentioned statistical indicators of the virtual machine during the memory recovery process can be used as features to represent the current memory operation status of the virtual machine. By processing the above-mentioned statistical indicators, the purpose of predicting the memory pressure category can be achieved.
[0057] Step S103: Obtain a memory pressure category according to memory statistics of the virtual machine to be monitored.
[0058] Exemplarily, after obtaining the above-mentioned memory statistics, the memory statistics of the virtual machine to be monitored are analyzed outside the virtual machine, so as to classify the current memory pressure of the virtual machine to be monitored, thereby obtaining the memory pressure category. This arrangement can be executed by the virtualization monitoring unit, or by calling other functional units to be executed by the memory monitoring process. The specific arrangement can be set as needed and will not be repeated here. Since the execution process is executed by an independent functional unit in the host machine, rather than by the monitoring program inside the virtual machine, the problem of being unable to detect the memory pressure of the virtual machine due to the memory monitoring program being mistakenly closed when the memory pressure of the virtual machine is high can be avoided. .
[0059] Exemplarily, the following is a detailed introduction to the process of obtaining memory pressure categories in combination with the implementation of the memory statistics data introduced above. For example, when the change in the number of the first event is greater than 0, it means that the number of insufficient memory events has increased, that is, insufficient memory events have occurred recently, which can be regarded as a very serious (high level) memory pressure category; for another example, when the change in the number of the third event is greater than a specific threshold, it means that a relatively serious memory shortage has occurred, which will affect the performance of the virtual machine, and it can be regarded as a relatively serious (medium to high level) memory pressure category. By analogy, different memory pressure categories can be obtained by analyzing the above statistical indicators.
[0060] In one possible implementation, Figure 5 As shown, the memory statistical data includes the number of first events, and the specific implementation of step S103 includes:
[0061] Step S103A-1: Obtain the event change amount of the first event quantity within the detection period.
[0062] Step S103A-2: Obtain a memory pressure category according to the event change amount of the first event quantity.
[0063] Exemplarily, the event change amount of the first event quantity is the change amount of the number of insufficient memory events. Specifically, the memory monitoring process sends a trigger instruction to the virtualization monitoring unit through a specific detection cycle, and the event change amount can be obtained by counting the number of insufficient memory events that have occurred in each detection cycle and comparing it with the number of insufficient memory events that have occurred in the previous detection cycle. For example, according to the first event quantity, within the t(1) period, the number of insufficient memory events recorded by the system is N. If within the t(2) period, the number of insufficient memory events recorded by the system is still N, the event change is 0, indicating that no insufficient memory event occurred within the t(2) period; if within the t(2) period, the number of insufficient memory events recorded by the system is M (M>N), the event change is greater than or equal to 1. At this time, it is indicated that an insufficient memory event occurred within the t(2) period. Then, the corresponding memory pressure category can be determined based on whether an insufficient memory event has occurred or based on the number of insufficient memory events (i.e., the event change). For example, within a certain value range, the larger the event change, the greater the memory pressure and the more severe the corresponding memory pressure category.
[0064] Further, illustratively, the specific implementation of step S103A-2 includes:
[0065] Step S103A-21: if the event change amount of the first event quantity is greater than the first threshold, a first level of pressure category is obtained;
[0066] Step S103A-22: If the event change amount of the first event quantity is less than the first threshold, the event change amount of the third event quantity is obtained, and if the event change amount of the third event quantity is greater than the second threshold, the second level pressure category is obtained.
[0067] In the case corresponding to step S103A-21, when the first threshold value is equal to 0, it can also be other values greater than 0 in consideration of errors and other incidental situations. This situation has been introduced in the previous part and will not be repeated here. For the case corresponding to step S103A-22, when the event change amount of the first event number is less than the first threshold value, that is, when no out-of-memory event occurs (or only a very small number of out-of-memory events occur), it can be further judged by obtaining the event change amount of the third event number, that is, if the event change amount of the third event number is greater than the second threshold value, the second-level stress category is obtained. Among them, the third event represents the number of direct memory recovery events that occur, and the second-level stress category can be, for example, a more serious stress category (that is, a category that is lighter than the first-level stress category and more serious than the third-level stress category). Among them, the second threshold value can be a pre-configured threshold value that matches the performance specifications of the virtual machine, and its specific data can be set as needed.
[0068] In another possible implementation, Figure 6 As shown, the memory statistics data includes the first recycled page quantity and the second recycled page quantity. The specific implementation of step S103 includes:
[0069] Step S103B-1: Obtain a first recycled page variation corresponding to the first recycled page quantity and a second recycled page variation corresponding to the second recycled page quantity.
[0070] Step S103B-2: Obtain the disk memory page change amount according to the sum of the first recycled page change amount and the second recycled page change amount.
[0071] Step S103B-3: Obtain the memory pressure category according to the disk memory page change amount.
[0072] Exemplarily, in this embodiment, the memory statistics data include the first number of recycled pages and the second number of recycled pages, wherein the first number of recycled pages represents the number of memory pages recycled in the background memory recycling event, and the second number of recycled pages represents the number of memory pages recycled in the direct memory recycling event. Specifically, in the Linux system, the background memory recycling event corresponds to the memory recycling event performed by the kswapd thread, and the first number of recycled pages is the number of memory pages (pages) scanned during the memory recycling process performed by the kswapd thread. The direct memory recycling (direct reclaim) event is a memory recycling event that is triggered when the recycling rate of the kswapd thread is lower than the rate at which the user process allocates memory, or when the amount of available memory is lower than the minimum memory watermark. The above two memory recycling methods are both prior arts known to those skilled in the art, and will not be described in detail here. After the above background memory recycling event and direct memory recycling event occur in the virtual machine, the system will record the corresponding statistical data, namely the first number of recycled pages and the second number of recycled pages. After obtaining the above number of recycled pages and the second number of recycled pages, the host machine calculates the corresponding changes, namely the first recycling page change corresponding to the first recycling page number and the second recycling page change corresponding to the second recycling page number. The calculation method of the change amount has been introduced in the previous embodiment, and the calculation method of the event change amount of the first event number can be referred to, which will not be repeated here. Afterwards, the disk memory page change amount is calculated based on the sum of the first recycling page change amount and the second recycling page change amount. Finally, according to the disk memory page change amount, the corresponding memory pressure category is determined based on the preset mapping table.
[0073] Furthermore, in a possible implementation, a specific implementation of step S103B-3 includes:
[0074] Step S103B-31: Obtain the recovered disk bandwidth according to the disk memory page change amount and the disk memory page size.
[0075] Step S103B-32: If the ratio of the recovered disk bandwidth to the system disk bandwidth is greater than the third threshold, a third level of pressure category is obtained.
[0076] Exemplarily, the disk memory page size (pagesize) is the memory space occupied by each memory page. The product of the disk memory page change and the disk memory page size is calculated to obtain the total memory recovery amount, that is, the recovered disk bandwidth. Then, according to the ratio of the recovered disk bandwidth to the system disk bandwidth, a ratio value of the recovered bandwidth is obtained. The ratio value represents the recovery volatility, that is, the larger the ratio of the recovered disk bandwidth to the system disk bandwidth, the greater the memory volatility caused by memory recovery, and vice versa. Finally, by comparing the ratio of the recovered disk bandwidth to the system disk bandwidth with the size of the preset third threshold, if the ratio of the recovered disk bandwidth to the system disk bandwidth is greater than or equal to the third threshold, the memory pressure level is determined to be the third level pressure category.
[0077] In another possible implementation, the memory statistics data includes the number of first scanned pages and the number of second scanned pages, such as Figure 7 As shown, the memory statistics data includes the first recycled page quantity and the second recycled page quantity. The specific implementation of step S103 includes:
[0078] Step S103C-1: obtaining a first scan page change amount corresponding to the first scan page quantity and a second scan page change amount corresponding to the second scan page quantity within a detection period;
[0079] Step S103C-2: If the sum of the first scan page change amount and the second scan page change amount is greater than a fourth threshold, a fourth level of pressure category is obtained.
[0080] Exemplarily, the steps of this embodiment provide another implementation scheme for determining the memory pressure category. Specifically, the first scan page change amount and the second scan page number respectively represent the number of memory pages scanned by the recovery thread in the background memory recovery event, and the number of memory pages scanned by the recovery thread in the direct memory recovery event. In the previous embodiment, the concepts of background memory recovery events and direct memory recovery events have been introduced. In the steps of this embodiment, by obtaining the number of memory pages scanned by the thread in the background memory recovery event and the number of memory pages scanned by the thread in the direct memory recovery event, and calculating the sum of the two, a total scan page change amount is obtained. The total scan page change amount represents the number of memory pages scanned during the memory recovery process. The larger the total scan page change amount, the more intense the memory recovery process is, and the more severe the performance fluctuation of the virtual machine is. When the total scan page change amount is greater than the fourth threshold, the corresponding memory pressure category is determined to be the fourth pressure category.
[0081] Furthermore, in another possible implementation, the memory statistics data includes a second event number, and the second event number represents the number of major page fault events. Similarly, the number of page fault events is determined by obtaining a third event number and calculating a corresponding event change. The higher the event change of the third event number, the more serious the memory resource shortage. Therefore, if the event change of the second event number is greater than the fifth threshold, it can be determined that a serious memory resource shortage has occurred recently, and the memory pressure category is determined as the fifth level pressure category.
[0082] In this embodiment, a trigger instruction is sent to a virtualization monitoring unit through a memory monitoring process running in a host machine, wherein the virtualization monitoring unit corresponds one-to-one to the virtual machine to be monitored created by the host machine, and is used to generate a corresponding interrupt signal in response to the trigger instruction; the kernel state driver of the virtual machine to be monitored responds to the interrupt signal output by the virtualization monitoring unit to obtain memory statistics of the virtual machine to be monitored, and the memory statistics represent statistical indicators of the memory recovery process for the virtual machine to be monitored; according to the memory statistics of the virtual machine to be monitored, the memory pressure category is obtained. By setting a virtualization monitoring unit corresponding one-to-one to the virtual machine to be monitored in the host machine, and sending an interrupt signal to the kernel state driver of the virtual machine to be monitored through the virtualization monitoring unit, the memory statistics are obtained, and then the memory pressure category is obtained based on the memory statistics, so as to realize the detection of memory pressure. Since the above steps are executed outside the virtual machine, the memory pressure detection is not performed by relying on the memory detection program running inside the virtual machine, so that the problem of being unable to detect the memory pressure of the virtual machine due to the memory recovery mechanism causing the memory detection program to be closed can be avoided, and the stability and reliability of the virtual machine memory detection can be improved.
[0083] refer to Figure 8 , Figure 8 A flow chart of a memory pressure detection method for a virtual machine provided in an embodiment of the present disclosure Figure 2 In this embodiment Figure 2 On the basis of the illustrated embodiment, step S103 is further refined, and the memory pressure detection method for a virtual machine includes:
[0084] Step S201: periodically sending a trigger instruction to a virtualization monitoring unit based on a dynamic detection cycle through a memory monitoring process.
[0085] Step S202: The virtualization monitoring unit responds to the trigger instruction, calls the kernel state driver of the corresponding virtual machine to be monitored, and obtains memory statistics data of the virtual machine to be monitored. The memory statistics data represent statistical indicators of the memory recycling process for the virtual machine to be monitored.
[0086] Step S203: Obtain the event change amount of the first event quantity within the detection period.
[0087] Step S204: If the event change amount of the first event quantity is greater than the first threshold, a first level of pressure category is obtained.
[0088] Step S205: If the event change amount of the first event quantity is less than the first threshold, the event change amount of the third event quantity is obtained.
[0089] Step S206: If the event change amount of the third event quantity is greater than the second threshold, a second level of pressure category is obtained.
[0090] Step S207: If the event change amount of the third event quantity is less than the second threshold, obtain the first recycled page change amount corresponding to the first recycled page quantity and the second recycled page change amount corresponding to the second recycled page quantity, and obtain the disk memory page change amount based on the sum of the first recycled page change amount and the second recycled page change amount.
[0091] Step S208: Obtain the recovered disk bandwidth according to the disk memory page change amount and the disk memory page size.
[0092] Step S209: If the ratio of the recovered disk bandwidth to the system disk bandwidth is greater than the third threshold, a third level of pressure category is obtained.
[0093] Step S210: If the ratio of the recovered disk bandwidth to the system disk bandwidth is less than the third threshold, obtain the first scan page change corresponding to the first scan page quantity and the second scan page change corresponding to the second scan page quantity within the detection period.
[0094] Step S211: If the sum of the first scan page change amount and the second scan page change amount is greater than a fourth threshold, a fourth level of pressure category is obtained.
[0095] Step S212: if the sum of the first scan page change amount and the second scan page change amount is less than a fourth threshold, then acquiring the event change amount of the second event quantity.
[0096] Step S213: If the event change amount of the second event quantity is greater than the fifth threshold, a fifth level of pressure category is obtained.
[0097] Step S214: Otherwise, the zeroth level pressure category is obtained.
[0098] Exemplarily, this embodiment provides a scheme for performing memory pressure detection based on memory pressure priority, wherein, after obtaining memory statistical data through a virtualization monitoring unit, judgments are made in sequence according to the priority of each statistical indicator in the memory statistical data of the virtual machine to be monitored, so as to accurately obtain the memory pressure category. Specifically, first, judgment is made according to the statistical indicator with the highest priority in the memory statistical data, that is, the number of first events that characterize the number of insufficient memory events. If the conditions of the first-level pressure category are met according to the first event number, the memory pressure category is determined as the first-level pressure category, and the memory pressure detection of this cycle is terminated. Afterwards, if the conditions of the first-level pressure category are met, the memory pressure category is detected according to the statistical indicator of the next priority, and so on, until a specific memory pressure category is determined. Through the above scheme of this embodiment, that is, based on the priority of each statistical indicator in the memory statistical data, the memory pressure category is judged in sequence, and in the case of severe memory pressure, the memory detection process will be terminated in advance, and the corresponding memory pressure category will be output, which can improve the efficiency and timeliness of memory pressure detection.
[0099] The specific implementation process of determining the first to fifth level pressure categories in the above steps is as follows: Figure 2 The detailed introduction has been made in the illustrated embodiment and will not be repeated here. The zero-level pressure category can indicate a situation in which there is relatively slight memory pressure in the current detection cycle, and no processing or intervention is required. At the same time, it should be noted that in the present embodiment, in the process of comparing the thresholds (the first threshold to the fifth threshold) to determine the corresponding memory pressure category, the boundary judgment condition (the situation of being equal) can be flexibly set as needed. For example, when the event change amount of the first event quantity is equal to the first threshold, the step of obtaining the first-level pressure category in step S204 can be executed, or the step of obtaining the event change amount of the third event quantity in step S205 can be executed. The situation of the boundary points will not be repeated one by one by giving examples here.
[0100] Optionally, after obtaining the specific memory pressure category, that is, for example, after executing any one of steps S204, S206, S208, S210, and S212, the method further includes:
[0101] Step S215: Generate a corresponding dynamic detection cycle according to the memory pressure category, where the dynamic detection cycle is used to control the frequency at which the memory monitoring process sends a trigger instruction to the virtualization monitoring unit.
[0102] Exemplarily, after executing any one of steps S204, S206, S208, S210, and S212, a corresponding dynamic detection cycle can be further generated according to the obtained memory pressure category, and then the process returns to step S201, and based on the dynamic detection cycle, the memory pressure of the virtual machine is continuously detected. Since the detection cycle is related to resource overhead, the shorter the detection cycle is, the shorter the resource overhead of the host machine for the above-mentioned memory pressure detection process is. Therefore, in this embodiment, according to the memory pressure detection result of this round, the corresponding detection cycle is adjusted in real time to obtain a dynamic detection cycle, and the frequency of the memory monitoring process sending a trigger instruction to the virtualization monitoring unit is controlled according to the dynamic detection cycle. After that, the next round of memory monitoring is performed based on the dynamic detection cycle. When the memory pressure is small, the detection cycle is delayed (the frequency is reduced), and when the memory pressure is large, the detection cycle is shortened (the frequency is increased), thereby improving the computing resource utilization efficiency of the memory detection process.
[0103] In this embodiment, the implementation method of step S201-step S202 is the same as that of the present disclosure. Figure 2 The implementation methods of step S101 and step S102 in the illustrated embodiment are the same and will not be described in detail here.
[0104] Corresponding to the memory pressure detection method for a virtual machine in the above embodiment, Fig. 9 A structural block diagram of a memory pressure detection device for a virtual machine provided in an embodiment of the present disclosure. The method described in the above embodiment can be executed by the memory pressure detection device for a virtual machine, which can be implemented by software and / or hardware, and can be integrated in an electronic device with certain data processing functions. The electronic device may include but is not limited to a mobile terminal with big data processing capabilities, as well as a fixed terminal with big data processing capabilities such as a desktop computer and a supercomputer.
[0105] For the sake of convenience, only the parts related to the embodiments of the present disclosure are shown. Fig. 9 , the memory pressure detection device 3 for the virtual machine includes:
[0106] A trigger module 31, used to send a trigger instruction to a virtualization monitoring unit through a memory monitoring process running in the host machine, wherein the virtualization monitoring unit corresponds one-to-one to the virtual machine to be monitored created by the host machine, and is used to generate a corresponding interrupt signal in response to the trigger instruction;
[0107] The detection module 32 is used to respond to the interrupt signal output by the virtualization monitoring unit through the kernel state driver of the virtual machine to be monitored, and obtain the memory statistical data of the virtual machine to be monitored, where the memory statistical data represents the statistical indicators of the memory recycling process for the virtual machine to be monitored;
[0108] The processing module 33 is used to obtain a memory pressure category according to the memory statistics of the virtual machine to be monitored.
[0109] According to one or more embodiments of the present disclosure, after obtaining the memory pressure category based on the memory statistics of the virtual machine to be monitored, the trigger module 31 is also used to: generate a corresponding dynamic detection cycle based on the memory pressure category, and the dynamic detection cycle is used to control the frequency of the memory monitoring process sending trigger instructions to the virtualization monitoring unit; the trigger module 31 is specifically used to: periodically send trigger instructions to the virtualization monitoring unit based on the dynamic detection cycle through the memory monitoring process.
[0110] According to one or more embodiments of the present disclosure, before the virtualization monitoring unit responds to the trigger instruction, calls the kernel state driver of the corresponding virtual machine to be monitored, and obtains the memory statistics data of the virtual machine to be monitored, the detection module 32 is also used to: initialize the kernel state driver of the virtual machine to be monitored, and generate program parameters corresponding to the virtual machine to be monitored, wherein the program parameters are used to indicate the category of the statistical indicator corresponding to the memory statistics data; create a monitoring program object and a communication program object according to the program parameters; the detection module 32 is specifically used for at least one of the following: respond to the trigger instruction through the virtualization monitoring unit, send an interrupt signal to the monitoring program object to obtain the memory statistics data of the virtual machine to be monitored; send the memory statistics data to the memory monitoring process through the communication program object.
[0111] According to one or more embodiments of the present disclosure, memory statistics data include at least one of the following: a first event number, a second event number, a third event number, a first scan page number, a second scan page number, a first reclaimed page number, and a second reclaimed page number; wherein the first event number represents the number of out-of-memory events that occur; the second event number represents the number of page fault events that occur; the third event number represents the number of direct memory reclaim events that occur; the first scan page number represents the number of memory pages scanned by the reclaiming thread in the background memory reclaiming event; the second scan page number represents the number of memory pages scanned by the reclaiming thread in the direct memory reclaiming event; the first reclaimed page number represents the number of memory pages reclaimed in the background memory reclaiming event; the second reclaimed page number represents the number of memory pages reclaimed in the direct memory reclaiming event.
[0112] According to one or more embodiments of the present disclosure, memory statistics include a first event quantity, and a processing module 33 is specifically used to: obtain an event change amount of the first event quantity within a detection period; and obtain a memory pressure category based on the event change amount of the first event quantity.
[0113] According to one or more embodiments of the present disclosure, the memory statistics data also includes a third event number. When the processing module 33 obtains the memory pressure category based on the event change amount of the first event number, it is specifically used to: if the event change amount of the first event number is greater than the first threshold, obtain the first-level pressure category; if the event change amount of the first event number is less than the first threshold, obtain the event change amount of the third event number, and if the event change amount of the third event number is greater than the second threshold, obtain the second-level pressure category.
[0114] According to one or more embodiments of the present disclosure, memory statistics data include the first recycled page number and the second recycled page number, and the processing module 33 is specifically used to: obtain the first recycled page change amount corresponding to the first recycled page number and the second recycled page change amount corresponding to the second recycled page number; obtain the disk memory page change amount according to the sum of the first recycled page change amount and the second recycled page change amount; obtain the memory pressure category according to the disk memory page change amount.
[0115] According to one or more embodiments of the present disclosure, when the processing module 33 obtains the memory pressure category based on the disk memory page change amount, it is specifically used to: obtain the recovered disk bandwidth based on the disk memory page change amount and the disk memory page size; if the ratio of the recovered disk bandwidth to the system disk bandwidth is greater than the third threshold, then a third level pressure category is obtained.
[0116] According to one or more embodiments of the present disclosure, the memory statistical data includes the number of first scan pages and the number of second scan pages, and the processing module 33 is specifically used to: obtain the first scan page change corresponding to the first scan page number and the second scan page change corresponding to the second scan page number within the detection period; if the sum of the first scan page change and the second scan page change is greater than a fourth threshold value, a fourth level pressure category is obtained.
[0117] According to one or more embodiments of the present disclosure, the memory statistical data includes the second event quantity, and the processing module 33 is specifically used to: if the event change amount of the second event quantity is greater than a fifth threshold, obtain a fifth level of pressure category.
[0118] The trigger module 31, the detection module 32 and the processing module 33 are connected in sequence. The memory pressure detection device 3 for a virtual machine provided in this embodiment can implement the technical solution of the above method embodiment, and its implementation principle and technical effect are similar, which will not be repeated in this embodiment.
[0119] Fig.10 A schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure is shown in FIG. Fig.10 As shown, the electronic device 4 includes:
[0120] A processor 41, and a memory 42 communicatively connected to the processor 41;
[0121] The memory 42 stores computer executable instructions;
[0122] The processor 41 executes the computer execution instructions stored in the memory 42 to implement the following Figure 2-Figure 8 The memory pressure detection method for a virtual machine in the illustrated embodiment.
[0123] Optionally, the processor 41 and the memory 42 are connected via a bus 43 .
[0124] For related instructions, please refer to Figure 2-Figure 8 The relevant descriptions and effects corresponding to the steps in the corresponding embodiments can be understood, and no further elaboration is made here.
[0125] The present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, which are used to implement the present invention when executed by a processor. Figure 2-Figure 8 A memory pressure detection method for a virtual machine is provided in any one of the corresponding embodiments.
[0126] The present invention provides a computer program product, including a computer program. When the computer program is executed by a processor, the present invention is realized. Figure 2-Figure 8 A memory pressure detection method for a virtual machine is provided in any one of the corresponding embodiments.
[0127] In order to implement the above embodiment, the embodiment of the present disclosure also provides an electronic device.
[0128] refer to Fig.11 , which shows a schematic diagram of the structure of an electronic device 900 suitable for implementing the embodiment of the present disclosure, and the electronic device 900 may be a terminal device or a server. The terminal device may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, personal digital assistants (PDAs), tablet computers (Portable Android Devices, PADs), portable multimedia players (PMPs), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig.11 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0129] like Fig.11As shown, the electronic device 900 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage device 908 to a random access memory (RAM) 903. Various programs and data required for the operation of the electronic device 900 are also stored in the RAM 903. The processing device 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0130] Typically, the following devices may be connected to the I / O interface 905: input devices 906 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 907 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 908 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 909. The communication device 909 may allow the electronic device 900 to communicate with other devices wirelessly or by wire to exchange data. Although Fig.11 The electronic device 900 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0131] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 909, or installed from a storage device 908, or installed from a ROM 902. When the computer program is executed by the processing device 901, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0132] It should be noted that the computer-readable medium mentioned above in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. Computer readable signal media may also be any computer readable medium other than computer readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0133] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0134] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device executes the method shown in the above embodiment.
[0135] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0136] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0137] The units or modules involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the name of a unit or module does not, in some cases, constitute a limitation on the unit itself.
[0138] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0139] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0140] In a first aspect, according to one or more embodiments of the present disclosure, a method for detecting memory pressure for a virtual machine is provided, comprising: sending a trigger instruction to a virtualization monitoring unit through a memory monitoring process running in a host machine, wherein the virtualization monitoring unit is deployed in the host machine and corresponds one-to-one to the virtual machine to be monitored created by the host machine; the virtualization monitoring unit responds to the trigger instruction, calls the kernel state driver of the corresponding virtual machine to be monitored, and obtains memory statistical data of the virtual machine to be monitored, wherein the memory statistical data represents statistical indicators of a memory recovery process for the virtual machine to be monitored; and obtains a memory pressure category based on the memory statistical data of the virtual machine to be monitored.
[0141] According to one or more embodiments of the present disclosure, after obtaining the memory pressure category based on the memory statistics of the virtual machine to be monitored, it also includes: generating a corresponding dynamic detection cycle based on the memory pressure category, and the dynamic detection cycle is used to control the frequency of the memory monitoring process sending trigger instructions to the virtualization monitoring unit; sending trigger instructions to the virtualization monitoring unit through the memory monitoring process running in the host machine includes: periodically sending trigger instructions to the virtualization monitoring unit based on the dynamic detection cycle through the memory monitoring process.
[0142] According to one or more embodiments of the present disclosure, before the virtualization monitoring unit responds to the trigger instruction, calls the kernel state driver of the corresponding virtual machine to be monitored, and obtains the memory statistics data of the virtual machine to be monitored, it also includes: initializing the kernel state driver of the virtual machine to be monitored, and generating program parameters corresponding to the virtual machine to be monitored, wherein the program parameters are used to indicate the category of the statistical indicator corresponding to the memory statistics data; creating a monitoring program object and a communication program object according to the program parameters; the virtualization monitoring unit responds to the trigger instruction, calls the kernel state driver of the corresponding virtual machine to be monitored, and obtains the memory statistics data of the virtual machine to be monitored, including at least one of the following: the virtualization monitoring unit responds to the trigger instruction, sends an interrupt signal to the monitoring program object to obtain the memory statistics data of the virtual machine to be monitored; sends the memory statistics data to the memory monitoring process through the communication program object.
[0143] According to one or more embodiments of the present disclosure, the memory statistical data includes at least one of the following: a first event number, a second event number, a third event number, a first scan page number, a second scan page number, a first recycled page number, and a second recycled page number; wherein the first event number represents the number of out-of-memory events that occur; the second event number represents the number of page fault events that occur; the third event number represents the number of direct memory recycling events that occur; the first scan page number represents the number of memory pages scanned by the recycling thread in background memory recycling events; the second scan page number represents the number of memory pages scanned by the recycling thread in direct memory recycling events; the first recycled page number represents the number of memory pages recycled in background memory recycling events; the second recycled page number represents the number of memory pages recycled in direct memory recycling events.
[0144] According to one or more embodiments of the present disclosure, the memory statistical data includes a first event quantity, and the memory pressure category is obtained based on the memory statistical data of the virtual machine to be monitored, including: obtaining the event change amount of the first event quantity within a detection cycle; obtaining the event change amount of the first event quantity within a target detection cycle; obtaining the event change amount of the first event quantity within a target detection cycle; and obtaining the memory pressure category based on the event change amount of the first event quantity.
[0145] According to one or more embodiments of the present disclosure, the memory statistical data also includes a third event number, and the memory pressure category is obtained based on the event change amount of the first event number, including: if the event change amount of the first event number is greater than a first threshold, a first-level pressure category is obtained; if the event change amount of the first event number is less than the first threshold, the event change amount of the third event number is obtained, and if the event change amount of the third event number is greater than a second threshold, a second-level pressure category is obtained.
[0146] According to one or more embodiments of the present disclosure, the memory statistical data includes a first recycled page number and a second recycled page number, and the memory pressure category is obtained based on the memory statistical data of the virtual machine to be monitored, including: obtaining a first recycled page change corresponding to the first recycled page number within a detection period; obtaining a first recycled page change corresponding to the first recycled page number and a second recycled page change corresponding to the second recycled page number within a detection period; obtaining a disk memory page change based on the sum of the first recycled page change and the second recycled page change; and obtaining the memory pressure category based on the disk memory page change.
[0147] According to one or more embodiments of the present disclosure, the memory pressure category is obtained according to the disk memory page change amount, including: obtaining the reclaimed disk bandwidth according to the disk memory page change amount and the disk memory page size; if the ratio of the reclaimed disk bandwidth to the system disk bandwidth is greater than a third threshold, a third level pressure category is obtained.
[0148] According to one or more embodiments of the present disclosure, the memory statistical data include a first scan page number and a second scan page number, and the memory pressure category is obtained based on the memory statistical data of the virtual machine to be monitored, including: obtaining the first scan page change amount corresponding to the first scan page number and the second scan page change amount corresponding to the second scan page number within a detection period; if the sum of the first scan page change amount and the second scan page change amount is greater than a fourth threshold value, a fourth level pressure category is obtained.
[0149] According to one or more embodiments of the present disclosure, the memory statistics data include a second event quantity, and the memory pressure category is obtained based on the memory statistics data of the virtual machine to be monitored, including: if the event change amount of the second event quantity is greater than a fifth threshold, a fifth level pressure category is obtained.
[0150] In a second aspect, according to one or more embodiments of the present disclosure, a memory pressure detection device for a virtual machine is provided, comprising:
[0151] A trigger module, used for sending a trigger instruction to a virtualization monitoring unit through a memory monitoring process running in the host machine, wherein the virtualization monitoring unit corresponds one-to-one to the virtual machine to be monitored created by the host machine, and is used for generating a corresponding interrupt signal in response to the trigger instruction;
[0152] A detection module, configured to respond to an interrupt signal output by the virtualization monitoring unit through a kernel state driver of the virtual machine to be monitored, to obtain memory statistical data of the virtual machine to be monitored, wherein the memory statistical data represents a statistical indicator of a memory recycling process for the virtual machine to be monitored;
[0153] The processing module is used to obtain a memory pressure category according to the memory statistics data of the virtual machine to be monitored.
[0154] According to one or more embodiments of the present disclosure, after obtaining the memory pressure category based on the memory statistics of the virtual machine to be monitored, the trigger module is further used to: generate a corresponding dynamic detection cycle based on the memory pressure category, and the dynamic detection cycle is used to control the frequency of the memory monitoring process sending trigger instructions to the virtualization monitoring unit; the trigger module is specifically used to: periodically send trigger instructions to the virtualization monitoring unit through the memory monitoring process based on the dynamic detection cycle.
[0155] According to one or more embodiments of the present disclosure, before the virtualization monitoring unit responds to the trigger instruction, calls the kernel state driver of the corresponding virtual machine to be monitored, and obtains the memory statistics data of the virtual machine to be monitored, the detection module is also used to: initialize the kernel state driver of the virtual machine to be monitored, and generate program parameters corresponding to the virtual machine to be monitored, wherein the program parameters are used to indicate the category of the statistical indicator corresponding to the memory statistics data; create a monitoring program object and a communication program object according to the program parameters; the detection module is specifically used for at least one of the following: respond to the trigger instruction through the virtualization monitoring unit, send an interrupt signal to the monitoring program object to obtain the memory statistics data of the virtual machine to be monitored; send the memory statistics data to the memory monitoring process through the communication program object.
[0156] According to one or more embodiments of the present disclosure, the memory statistical data includes at least one of the following: a first event number, a second event number, a third event number, a first scan page number, a second scan page number, a first recycled page number, and a second recycled page number; wherein the first event number represents the number of out-of-memory events that occur; the second event number represents the number of page fault events that occur; the third event number represents the number of direct memory recycling events that occur; the first scan page number represents the number of memory pages scanned by the recycling thread in background memory recycling events; the second scan page number represents the number of memory pages scanned by the recycling thread in direct memory recycling events; the first recycled page number represents the number of memory pages recycled in background memory recycling events; the second recycled page number represents the number of memory pages recycled in direct memory recycling events.
[0157] According to one or more embodiments of the present disclosure, the memory statistical data includes a first event quantity, and the processing module is specifically used to: obtain the event change amount of the first event quantity within a detection cycle; obtain the event change amount of the first event quantity within a target detection cycle; obtain the event change amount of the first event quantity within the target detection cycle; and obtain the memory pressure category according to the event change amount of the first event quantity.
[0158] According to one or more embodiments of the present disclosure, the memory statistical data also includes a third event number. When the processing module obtains the memory pressure category based on the event change amount of the first event number, it is specifically used to: if the event change amount of the first event number is greater than a first threshold, obtain a first-level pressure category; if the event change amount of the first event number is less than the first threshold, obtain the event change amount of the third event number, and if the event change amount of the third event number is greater than the second threshold, obtain a second-level pressure category.
[0159] According to one or more embodiments of the present disclosure, the memory statistical data includes a first recycled page number and a second recycled page number, and the processing module is specifically used to: obtain a first recycled page change amount corresponding to the first recycled page number within a detection cycle; obtain a first recycled page change amount corresponding to the first recycled page number and a second recycled page change amount corresponding to the second recycled page number within a detection cycle; obtain a disk memory page change amount based on the sum of the first recycled page change amount and the second recycled page change amount; and obtain the memory pressure category based on the disk memory page change amount.
[0160] According to one or more embodiments of the present disclosure, when the processing module obtains the memory pressure category based on the disk memory page change amount, it is specifically used to: obtain the recovered disk bandwidth based on the disk memory page change amount and the disk memory page size; if the ratio of the recovered disk bandwidth to the system disk bandwidth is greater than a third threshold, then obtain a third level pressure category.
[0161] According to one or more embodiments of the present disclosure, the memory statistical data includes the number of first scan pages and the number of second scan pages, and the processing module is specifically used to: obtain the first scan page change corresponding to the first scan page number and the second scan page change corresponding to the second scan page number within the detection period; if the sum of the first scan page change and the second scan page change is greater than a fourth threshold value, a fourth level pressure category is obtained.
[0162] According to one or more embodiments of the present disclosure, the memory statistical data includes a second event quantity, and the processing module is specifically used to obtain a fifth level of stress category if the event change amount of the second event quantity is greater than a fifth threshold.
[0163] In a third aspect, according to one or more embodiments of the present disclosure, there is provided an electronic device, comprising: at least one processor and a memory;
[0164] The memory stores computer-executable instructions;
[0165] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the memory pressure detection method for the virtual machine as described in the first aspect and various possible designs of the first aspect.
[0166] In a fourth aspect, according to one or more embodiments of the present disclosure, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer execution instructions. When a processor executes the computer execution instructions, the memory pressure detection method for a virtual machine as described in the first aspect and various possible designs of the first aspect is implemented.
[0167] In a fifth aspect, according to one or more embodiments of the present disclosure, a computer program product is provided, including a computer program, which, when executed by a processor, implements the memory pressure detection method for a virtual machine as described in the first aspect and various possible designs of the first aspect.
[0168] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0169] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0170] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
Claims
1. A memory pressure detection method for a virtual machine, characterized in that: include: Sending a trigger instruction to a virtualization monitoring unit through a memory monitoring process running in the host machine, wherein the virtualization monitoring unit is deployed in the host machine and corresponds one-to-one to the virtual machine to be monitored created by the host machine; The virtualization monitoring unit responds to the trigger instruction and calls the kernel state driver of the corresponding virtual machine to be monitored to obtain memory statistical data of the virtual machine to be monitored, wherein the memory statistical data represents statistical indicators of the memory recycling process for the virtual machine to be monitored; Obtaining a memory pressure category according to memory statistics of the virtual machine to be monitored; The memory statistical data includes a first event number, where the first event number represents the number of insufficient memory events that occur; and obtaining a memory pressure category according to the memory statistical data of the virtual machine to be monitored includes: Obtain an event change amount of the first event quantity within a detection period; obtain the memory pressure category according to the event change amount of the first event quantity; wherein the event change amount is positively correlated with the memory pressure corresponding to the memory pressure category.
2. The method according to claim 1, characterized in that: After obtaining the memory pressure category according to the memory statistics of the virtual machine to be monitored, the method further includes: A corresponding dynamic detection cycle is generated according to the memory pressure category, and the dynamic detection cycle is used to control the frequency at which the memory monitoring process sends a trigger instruction to the virtualization monitoring unit.
3. The method according to claim 1, characterized in that Before the virtualization monitoring unit responds to the trigger instruction, calls the kernel state driver of the corresponding virtual machine to be monitored, and obtains the memory statistics data of the virtual machine to be monitored, the method further includes: Initializing the kernel state driver of the virtual machine to be monitored, generating a program parameter corresponding to the virtual machine to be monitored, wherein the program parameter is used to indicate the category of the statistical indicator corresponding to the memory statistical data; According to the program parameters, create a monitoring program object and a communication program object; The step of responding to the trigger instruction by the virtualization monitoring unit to call the kernel state driver of the corresponding virtual machine to be monitored to obtain memory statistics of the virtual machine to be monitored includes at least one of the following: In response to the trigger instruction, the virtualization monitoring unit sends an interrupt signal to the monitoring program object to obtain memory statistics of the virtual machine to be monitored; The memory statistics are sent to the memory monitoring process via the communication program object.
4. The method according to claim 1, characterized in that: The memory statistics data also include at least one of the following: the second event number, the third event number, the first scanned page number, the second scanned page number, the first recycled page number, and the second recycled page number; The second event quantity represents the number of page fault events that occur; The third event quantity represents the number of direct memory reclaim events that occur; The first scanned page quantity represents the number of memory pages scanned by the recycling thread in the background memory recycling event; The second number of scanned pages represents the number of memory pages scanned by the recycling thread in a direct memory recycling event; The first number of reclaimed pages represents the number of memory pages reclaimed in a background memory reclaim event; The second number of reclaimed pages represents the number of memory pages reclaimed in a direct memory reclaim event.
5. The method according to claim 1, characterized in that The memory statistical data further includes a third event quantity, and obtaining the memory pressure category according to the event change amount of the first event quantity includes: If the event change amount of the first event quantity is greater than a first threshold, a first level of stress category is obtained; If the event change amount of the first event quantity is less than a first threshold, the event change amount of the third event quantity is obtained, and if the event change amount of the third event quantity is greater than a second threshold, a second level of pressure category is obtained.
6. The method according to claim 4, characterized in that The memory statistics data include the first recycled page quantity and the second recycled page quantity, and the memory pressure category is obtained according to the memory statistics data of the virtual machine to be monitored, including: Acquire a first recycled page change amount corresponding to the first recycled page quantity and a second recycled page change amount corresponding to the second recycled page quantity within a detection period; Obtaining a disk memory page change amount according to the sum of the first recycled page change amount and the second recycled page change amount; The memory pressure category is obtained according to the disk memory page change amount.
7. The method according to claim 6, characterized in that The memory pressure category is obtained according to the disk memory page change amount, including: Obtaining a recovered disk bandwidth according to the disk memory page change amount and the disk memory page size, wherein the disk memory page size represents the memory space occupied by each memory page, and the recovered disk bandwidth is the product of the disk memory page change amount and the disk memory page size; If the ratio of the reclaimed disk bandwidth to the system disk bandwidth is greater than a third threshold, a third level of pressure category is obtained.
8. The method according to claim 4, characterized in that The memory statistical data includes the number of first scanned pages and the number of second scanned pages, and the memory pressure category is obtained according to the memory statistical data of the virtual machine to be monitored, including: Acquire a first scan page change amount corresponding to the first scan page quantity and a second scan page change amount corresponding to the second scan page quantity within a detection period; If the sum of the first scan page change amount and the second scan page change amount is greater than a fourth threshold, a fourth level of pressure category is obtained.
9. The method according to claim 4, characterized in that The memory statistical data includes the second event quantity, and obtaining the memory pressure category according to the memory statistical data of the virtual machine to be monitored includes: If the event change amount of the second event quantity is greater than a fifth threshold, a fifth level of stress category is obtained.
10. A memory pressure detection device for a virtual machine, characterized in that: include: A trigger module, used for sending a trigger instruction to a virtualization monitoring unit through a memory monitoring process running in the host machine, wherein the virtualization monitoring unit corresponds one-to-one to the virtual machine to be monitored created by the host machine, and is used for generating a corresponding interrupt signal in response to the trigger instruction; A detection module, configured to respond to an interrupt signal output by the virtualization monitoring unit through a kernel state driver of the virtual machine to be monitored, to obtain memory statistical data of the virtual machine to be monitored, wherein the memory statistical data represents a statistical indicator of a memory recycling process for the virtual machine to be monitored; A processing module, used for obtaining a memory pressure category according to memory statistics of the virtual machine to be monitored; The memory statistical data includes a first event number, and the first event number represents the number of insufficient memory events that occur; the processing module is specifically used to: obtain the event change amount of the first event number within a detection period; obtain the memory pressure category based on the event change amount of the first event number; wherein the event change amount is positively correlated with the memory pressure corresponding to the memory pressure category.
11. An electronic device, characterized in that: include: Processor and memory; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the processor executes the memory pressure detection method for a virtual machine according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions. When the processor executes the computer-executable instructions, the memory pressure detection method for a virtual machine as described in any one of claims 1 to 9 is implemented.
13. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the memory pressure detection method for a virtual machine as described in any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Driving separation system inside virtual machine and method
CN102938035A
Memory management method, system, computer equipment and storage medium
CN111679914A
Data processing method and system
CN114490273A