Method and related device for determining memory reclamation threshold
By dynamically adjusting the memory reclamation threshold, the problem of improper memory utilization caused by a fixed memory reclamation threshold is solved, and system performance and memory utilization efficiency are improved.
Patent Information
- Application Number
- CN202010948414.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-10
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2040-09-10
AI Technical Summary
In the prior art, the memory recycling threshold is fixed, which results in the memory recycling mechanism being unable to fully exert its advantages, or causing the system performance to degrade due to frequent triggering.
By obtaining memory usage parameters and processor operating parameters, the memory recycling threshold is dynamically adjusted, including adjusting the usage rate of the first partition and the second partition, free memory, and the processor occupancy of the memory recycling thread, so as to flexibly adjust the memory recycling threshold.
The flexibility of memory reclamation thresholds is achieved, which avoids improper triggering of the memory reclamation mechanism and improves system performance and memory utilization efficiency.
Smart Images

Figure CN114168490B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a method for determining a memory reclaim threshold and related devices. Background Art
[0002] To address the problem of insufficient memory in a computer device, a compressed partition is created within the computer device's memory. Thus, the computer device's original memory includes a system partition and a compressed partition. The system partition is used to store data originally stored in the memory, and the compressed partition is used to store data compressed from the system partition's data. Furthermore, a memory reclamation threshold is preconfigured, comprising a low threshold and a high threshold. When the remaining capacity of the system partition falls below the low threshold, some data is obtained from the system partition, compressed, and placed in the compressed partition until the remaining capacity of the system partition exceeds the high threshold, thereby reclaiming the memory in the system partition.
[0003] In related art, the low and high thresholds of memory reclamation thresholds are derived from the minimum number of free bytes (min-free-kbytes) preset in a computer device. Because the minimum number of free bytes in a computer device is fixed, the determined memory reclamation threshold is also fixed. Therefore, memory reclamation based on this threshold cannot fully utilize the advantages of memory reclamation technology. Summary of the Invention
[0004] The present invention provides a method and related devices for determining a memory reclamation threshold, which can improve the flexibility of determining the memory reclamation threshold. The technical solution is as follows:
[0005] In a first aspect, a method for determining a memory reclamation threshold is provided. The method is applied to a computer device, wherein the computer device's memory includes a first partition and a second partition, the first partition being used to store data read or written by a processor, and the second partition being used to store compressed data migrated from the first partition. In this method, a memory usage parameter or a processor operating parameter is obtained, the memory usage parameter indicating the usage of the first partition or the second partition in the memory, and the processor operating parameter indicating the operating status of the processor; and the memory reclamation threshold is adjusted based on the memory usage parameter or the processor operating parameter.
[0006] In an embodiment of the present application, the memory reclamation threshold can be adjusted based on memory usage parameters or processor operating parameters in the computer device. It can be seen that the embodiment of the present application provides a method for flexibly adjusting the memory reclamation threshold, thereby avoiding the problem that the memory reclamation threshold is usually fixed in memory reclamation mechanisms such as ZRAM technology. In addition, because the memory reclamation threshold can be flexibly adjusted, it can not only avoid the problem that a low memory reclamation threshold cannot fully utilize the advantages of memory reclamation technology, but also avoid the problem of low system performance caused by a high memory reclamation threshold.
[0007] Based on the method provided in the first aspect, in one possible implementation, the memory usage parameter includes a usage rate of the second partition, and the processor operating parameter includes a memory reclamation operation indication parameter, where the memory reclamation operation indication parameter indicates whether the processor is performing a memory reclamation operation. In this scenario, adjusting the memory reclamation threshold based on the memory usage parameter or the processor operating parameter can be implemented by lowering the memory reclamation threshold if it is determined that the usage rate of the second partition exceeds the usage rate threshold and the memory reclamation operation indication parameter indicates that the processor is performing a memory reclamation operation.
[0008] In this embodiment of the present application, if the usage rate of the second partition exceeds the usage rate threshold, it indicates that the available capacity of the second partition is currently low, and a memory reclamation operation is not appropriate at this time. However, if it is determined that the processor is currently performing a memory reclamation operation, the memory reclamation threshold can be lowered to minimize the subsequent triggering of a memory reclamation operation and to terminate the currently ongoing memory reclamation operation as quickly as possible.
[0009] Based on the method provided in the first aspect, in one possible implementation, the memory usage parameter includes the free memory of the first partition, the memory reclamation threshold includes a first memory reclamation threshold and a second memory reclamation threshold, the first memory reclamation threshold is greater than the second memory reclamation threshold, the first memory reclamation threshold is used to indicate the critical value for ending the memory reclamation operation, and the second memory reclamation threshold is used to indicate the critical value for starting the memory reclamation operation. In this scenario, the above-mentioned implementation method for adjusting the memory reclamation threshold based on the memory usage parameter or the processor operation parameter can be: adjusting the first memory reclamation threshold or the second memory reclamation threshold based on the size relationship between the free memory of the first partition and the first memory reclamation threshold or the second memory reclamation threshold.
[0010] In an embodiment of the present application, the free memory of the first partition can be considered. If it is determined that the free memory of the first partition is relatively large, in this case, assuming that the memory reclamation threshold is not adjusted, the operating system may no longer perform the memory reclamation operation, which may easily cause a waste of space in the second partition. If it is determined that the free memory in the first partition is relatively small, in this case, assuming that the memory reclamation threshold is not adjusted, the operating system may always trigger the memory reclamation operation, resulting in the free space in the second partition being easily insufficient. Therefore, in this scenario, the first memory reclamation threshold and the second memory reclamation threshold can be adjusted based on the size relationship between the free memory of the first partition and the first memory reclamation threshold or the second memory reclamation threshold.
[0011] Based on the method provided in the first aspect, in one possible implementation method, according to the size relationship between the free memory and the first memory recycling threshold or the second memory recycling threshold, the implementation method of adjusting the first memory recycling threshold or the second memory recycling threshold can be: if it is determined that the number of times the free memory exceeds the first memory recycling threshold is greater than or equal to the first reference number, then the second memory recycling threshold is raised.
[0012] Based on the method provided in the first aspect, in one possible implementation, adjusting the first memory reclamation threshold or the second memory reclamation threshold based on the relationship between the free memory of the first partition and the first memory reclamation threshold or the second memory reclamation threshold may be implemented by lowering the first memory reclamation threshold if the number of times the free memory falls below the second memory reclamation threshold is greater than or equal to a second reference number. Optionally, the first memory reclamation threshold may be adjusted if the free memory falls below the minimum memory reclamation threshold obtained by converting the minimum number of free bytes configured in the computer device.
[0013] Based on the method provided in the first aspect, in one possible implementation, the processor operating parameters include a memory reclamation operation indication parameter, and the memory reclamation operation indication parameter indicates whether the processor is performing a memory reclamation operation. In this scenario, based on the relationship between the free memory of the first partition and the first memory reclamation threshold or the second memory reclamation threshold, the first memory reclamation threshold or the second memory reclamation threshold can be adjusted by: if it is determined that the free memory exceeds the second memory reclamation threshold but is lower than the first memory reclamation threshold, and the memory reclamation operation indication parameter indicates that the processor is performing a memory reclamation operation, then the first memory reclamation threshold is lowered.
[0014] In the embodiment of the present application, the memory reclamation threshold can be adjusted to different degrees based on the different size relationships between the free memory of the first partition and the first memory reclamation threshold or the second memory reclamation threshold, thereby improving the flexibility of adjusting the memory reclamation threshold.
[0015] Based on the method provided in the first aspect, in one possible implementation, a memory reclamation thread is configured in a computer device, and a processor performs a memory reclamation operation based on the memory reclamation thread. The memory reclamation operation indication parameter is the processor occupancy rate of the memory reclamation thread. When the processor occupancy rate of the memory reclamation thread exceeds a preset value, it indicates that the processor is performing a memory reclamation operation; when the processor occupancy rate of the memory reclamation thread is below the preset value, it indicates that the processor is not performing a memory reclamation operation.
[0016] In an embodiment of the present application, whether the processor is performing a memory reclamation operation can be determined by the processor occupancy of the memory reclamation thread, thereby improving the efficiency of the method provided in the embodiment of the present application when adjusting the memory reclamation threshold.
[0017] Based on the method provided in the first aspect, in a possible implementation, the computer device also includes multiple non-uniform memory access NMUA nodes, the memory of each NUMA node in the multiple NUMA nodes includes a first partition and a second partition, and adjusting the memory recovery threshold refers to adjusting the memory recovery threshold of any NMUA node in the multiple NUMA nodes, and the memory recovery threshold of each NUMA node in the multiple NUMA nodes is independent of each other.
[0018] The method provided in the embodiments of the present application can be applied to a computer device comprising multiple NUMA nodes. Because the local memory of each NUMA node is independent of each other, the memory reclamation threshold of each NUMA node in the multiple NUMA nodes is also independent of each other. In this scenario, in the embodiments of the present application, adjusting the memory reclamation threshold in the computer device can be adjusting the memory reclamation threshold in any NUMA node. This increases the application flexibility of the method provided in the embodiments of the present application.
[0019] Based on the method provided in the first aspect, in one possible implementation, a watermark control file is configured in the computer device, and the watermark control file is used to store a parameter indicating a memory reclamation threshold. In this scenario, in the method, the value of the parameter in the watermark control file is modified based on the adjusted memory reclamation threshold.
[0020] Since the memory recovery threshold provided in the embodiment of the present application can be flexibly adjusted, the embodiment of the present application also configures a waterline control file in the computer device to facilitate the storage of the adjusted memory recovery threshold, thereby correspondingly improving the efficiency of subsequent memory recovery operations based on the adjusted memory recovery threshold.
[0021] Optionally, in this method, a configuration interface can also be displayed, which includes a waterline adjustment control; in response to a selection operation on the waterline adjustment control, a waterline adjustment rule is obtained; wherein the waterline adjustment rule includes the amplitude of increasing the memory recovery threshold, or the amplitude of decreasing the memory recovery threshold, or the usage threshold for the second partition.
[0022] In the embodiment of the present application, some rules in the waterline adjustment process can also be configured through human-computer interaction, thereby improving the flexibility of the method provided in the embodiment of the present application.
[0023] In a second aspect, a computer device is provided, which has the function of implementing the method for determining a memory reclamation threshold in the first aspect. The computer device includes at least one module, which is used to implement the method for determining a memory reclamation threshold in the first aspect.
[0024] In a third aspect, a computer device is provided, the structure of which includes a processor and a memory, the memory is used to store program code, and the processor is used to execute the program code to implement the method described in any aspect of the first aspect.
[0025] In a fourth aspect, a computer-readable storage medium is provided, wherein instructions are stored in the computer-readable storage medium, and when the computer-readable storage medium is run on a computer, the computer executes the method described in any one of the first aspects above.
[0026] In a fifth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the method described in any one of the first aspects above.
[0027] The technical effects obtained in the above-mentioned second, third, fourth and fifth aspects are similar to those obtained by the corresponding technical means in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 This is a schematic diagram of a software system architecture of a computer device provided in an embodiment of the present application;
[0029] Figure 2 This is a schematic diagram of the hardware architecture of a computer device in a UMA mechanism provided in an embodiment of the present application;
[0030] Figure 3 This is a schematic diagram of the hardware architecture of a computer device in a NUMA mechanism provided by an embodiment of the present application;
[0031] Figure 4 This is a flow chart of a method for determining a memory recycling threshold provided by an embodiment of the present application;
[0032] Figure 5 This is a flow chart of another method for determining a memory recycling threshold provided by an embodiment of the present application;
[0033] Figure 6 It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0034] In order to make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0035] Before explaining the embodiments of the present application in detail, the application scenarios of the embodiments of the present application are first described.
[0036] Currently, regardless of the amount of memory configured for a computer device, the operating system of the computer device may always run out of memory. When this happens, the operating system needs to take various measures to prevent abnormal operation. In one possible implementation, the operating system can reclaim a portion of currently used memory to meet new memory needs. In Linux systems, this memory reclaiming method is also called "page reclaim."
[0037] The following uses compressed random access memory (ZRAM) technology as an example to illustrate the specific process of memory reclamation. It should be noted that ZRAM technology is only one possible implementation of memory reclamation. The method for determining the memory reclamation threshold provided in the embodiments of the present application is not limited to application in ZRAM technology and can also be applied to other types of memory reclamation technologies.
[0038] ZRAM technology is a memory optimization mechanism in Linux systems. In ZRAM technology, a portion of memory is pre-allocated to create a ZRAM block device, which is then used as a compressed partition. This compressed partition is also called a swap area. The remaining space in memory is used as the system partition, which stores data originally stored in memory and read or written by the processor. When the remaining capacity in the system partition is insufficient, inactive memory pages in the system partition can be compressed and stored in the compressed partition, and these inactive memory pages in the system partition can be deleted, thereby increasing the available capacity of the system partition.
[0039] Compared to swap partitions based on disk space, ZRAM technology uses memory-based compressed partitions. Therefore, when compressed data is needed again, it can be read directly from the memory-based compressed partition, resulting in faster read speeds. Therefore, this memory reclamation mechanism offers superior performance compared to disk-based memory reclamation mechanisms.
[0040] The method for determining the memory recovery threshold provided in the embodiment of the present application can be applied to the above-mentioned ZRAM technology, and can also be applied to other memory recovery technologies that can adjust the memory recovery threshold. The embodiment of the present application does not specifically limit this. For the convenience of subsequent explanation, the aforementioned system partition is referred to as the first partition, and the compressed partition is referred to as the second partition. That is, the first partition involved in the subsequent embodiments refers to the partition in the memory of the computer device for storing data read or written by the processor, and the second partition refers to the memory of the computer device for storing data migrated from the first partition and compressed. Among them, the data migrated from the first partition and compressed means: deleting the data in the first partition from the first partition, and then compressing this part of the deleted data and putting it into the second partition.
[0041] Currently, in memory reclamation mechanisms like ZRAM, the memory reclamation thresholds are typically fixed. Typically, a minimum watermark (pages_min) is determined by converting the minimum free space in the computer device (min-free-kbytes) through unit conversion. A low watermark (pages_low) and a high watermark (pages_high) are then determined based on the minimum watermark. These low and high watermarks become the two memory reclamation thresholds. These two parameters are then used to determine when to initiate and terminate memory reclamation operations.
[0042] The low waterline and high waterline are obtained by enlarging the minimum waterline by a certain proportion. For example, enlarging the minimum waterline by 15% to get the low waterline, and enlarging the minimum waterline by 30% to get the high waterline.
[0043] If the minimum number of bytes of space preset in the computer device remains unchanged, the above low watermark and high watermark are also fixed values. This may lead to the following two technical problems:
[0044] (1) If the minimum number of bytes of memory preset in the computer device is too small, the low watermark and high watermark determined by this are also relatively small. A small low watermark makes it difficult to trigger the ZRAM mechanism for memory reclamation, and a small high watermark causes the memory reclamation mechanism to end quickly, thus failing to fully utilize the ZRAM mechanism.
[0045] (2) If the minimum number of free bytes preset in the computer device is large, the low watermark and high watermark determined in this way will be relatively large. A large high watermark will result in excessive memory being reserved in the system memory, reducing the actual available memory. A large low watermark will also cause the memory recycling mechanism to be triggered frequently, resulting in reduced system performance.
[0046] Based on the above technical problems, an embodiment of the present application provides a method for dynamically adjusting a memory recycling mechanism, the purpose of which is to provide a method that can flexibly adjust the memory recycling threshold according to demand, so as to give full play to the advantages of the memory recycling mechanism.
[0047] The current memory recycling operation is implemented by the operating system in the computer device. For the convenience of subsequent description, the software system architecture of the computer device involved in the embodiment of the present application is briefly described below.
[0048] Figure 1 This is a schematic diagram of the software system architecture of a computer device provided in an embodiment of the present application. Figure 1 As shown, the computer device 100 includes an application layer (applications) 101 and an operating system 102. The operating system 102 provides a unified middle layer for applications 101 to access the hardware in the computer device. The application layer 101 includes various applications installed on the computer device. Applications can also be referred to as clients, applications, etc. The operating system 102 manages the computer device's hardware resources, such as the CPU, memory, and disk, to provide hardware resources to applications in the application layer 101.
[0049] In addition, if Figure 1 As shown, the operating system 102 includes a user space 1021 and a kernel space 1022. The user space 1021 is a space for application execution. The kernel space is deployed with the kernel of the operating system, and the kernel space also provides a system call interface for the user space to connect to the kernel. By dividing the user space 1021 and the kernel space 1022, it is possible to limit the access rights of different applications to resources in the computer device. As to how to limit the access rights of different applications to resources in the computer device, the embodiments of the present application will not be described in detail.
[0050] like Figure 1 As shown, a memory recycling thread (the kernel swap daemon, kswapd) and a memory allocator are deployed in the kernel state space 1022. The memory recycling thread is used to perform memory recycling operations. The memory allocator is used to manage memory.
[0051] It should be noted that with the development of computer equipment technology, a computer device may include multiple CPUs, and there are two access mechanisms for these multiple CPUs to access memory. One is the uniform memory access (UMA) mechanism. In the UMA mechanism, all processors share a unified memory. In this case, the above-mentioned memory recovery thread is used to reclaim the unified memory. The other is the non-uniform memory access (NUMA) mechanism. In NUMA, one or more processors and the local memory of these one or more processors are called a NUMA node. The processors in a NUMA node give priority to accessing local memory, and can also access the memory in other NMUA nodes through the bus between NUMA nodes. At this time, each NUMA node corresponds to one of the above-mentioned memory recovery threads, and each memory recovery thread is used to reclaim the memory in the corresponding NMUA node.
[0052] The following combination Figure 2 and Figure 3 The two memory access mechanisms mentioned above are briefly explained.
[0053] Figure 2 This is a schematic diagram of the hardware architecture of a computer device in a UMA mechanism provided by an embodiment of the present application. Figure 2 As shown, the computer device includes multiple central processing units (CPUs), and any CPU can access shared memory through a bus. The shared memory can be a total memory space composed of the local memory of each CPU, or it can be a unified memory space provided by other storage devices.
[0054] In the UMA mechanism, the bus ensures consistent memory access across all CPUs, meaning each processor shares the same memory address space. However, as the number of CPUs increases, this architecture poses challenges to bus bandwidth and can cause conflicts when different processors access the same memory block.
[0055] Figure 3 This is a schematic diagram of the hardware architecture of a computer device in a NUMA mechanism provided by an embodiment of the present application. Figure 3 As shown, the computer device includes multiple NUMA nodes. Each NMUA node includes one or more CPUs and local memory for these one or more CPUs. The processors within any NUMA node can access local memory via an internal bus. Processors on different NMUA nodes can access each other's memory via an external bus.
[0056] exist Figure 3The memory of each of the multiple NUMA nodes shown includes a first partition and a second partition. In this embodiment of the present application, adjusting the memory reclamation threshold refers to adjusting the memory reclamation threshold of any NUMA node in the multiple NUMA nodes.
[0057] The method for determining the memory recycling threshold provided in the embodiment of the present application can be applied to Figure 2 The computer device shown can also be used in Figure 3 The computer device shown in the figure is not specifically limited in the present embodiment.
[0058] In order to enable the operating system to dynamically adjust the memory recovery threshold, Figure 1 The configuration of the operating system in the computer device shown is expanded. The specific expansion content is as follows:
[0059] 1. Configure the waterline adjustment thread in the user space of the operating system, such as Figure 1 shown.
[0060] The watermark adjustment thread is used to implement the method provided in the embodiment of the present application to adjust the memory reclaim threshold. When an application or operating system in the application layer triggers the watermark adjustment thread, the processor in the computer device can adjust the memory reclaim threshold based on the method provided in the embodiment of the present application.
[0061] The above-mentioned waterline adjustment thread can be automatically triggered periodically by the application program of the application layer or the operating system. The period for triggering the waterline adjustment thread can be pre-configured. Optionally, the above-mentioned waterline adjustment thread can be triggered by the application program of the application layer based on the user's operation. For example, in one possible implementation, when the computer device determines that the conditions for triggering the waterline adjustment thread are currently met, a prompt message can be displayed on the current display interface, and the prompt message is used to prompt the user whether to trigger the waterline adjustment thread. When the user's confirmation instruction based on the prompt message is detected, the waterline adjustment thread is triggered. The aforementioned conditions for triggering the waterline adjustment thread can also be pre-configured, and the embodiments of the present application do not limit this.
[0062] It should be noted that to facilitate users to trigger the watermark adjustment thread based on applications in the application layer, the watermark adjustment thread is configured in the user space of the operating system. Optionally, the watermark adjustment thread can also be configured in the kernel space, in which case only applications with kernel access rights can trigger the memory reclaim thread.
[0063] Furthermore, in an embodiment of the present application, watermark adjustment rules can be obtained through human-computer interaction. The watermark adjustment rules may include rules such as the magnitude of increasing or decreasing the memory reclamation threshold, or the threshold value for the usage rate of the second partition. This allows the watermark adjustment thread to adjust the memory reclamation threshold based on these watermark adjustment rules.
[0064] Therefore, in one possible implementation, the computer device may further display a configuration interface that includes a waterline adjustment control. In response to a selection operation on the waterline adjustment control, the computer device retrieves the waterline adjustment rule. The selection operation may be triggered by the user through voice, click, or touch. When the computer device detects the selection operation, the waterline adjustment rule may be retrieved based on the information input by the user.
[0065] The above-mentioned waterline adjustment rules can be set arbitrarily by the user based on needs, and the embodiment of the present application does not limit the specific content of the waterline adjustment rules.
[0066] 2. Configure the waterline control file in the kernel space of the operating system, such as Figure 1 shown.
[0067] The waterline control file is used to store parameters indicating the memory recycling threshold. Figure 3 In the NUMA mechanism shown in Figure 1, the waterline control file is used to store parameters indicating the memory reclamation threshold corresponding to each NMUA node. Figure 2 In the UMA mechanism shown, the watermark control file is used to store parameters indicating the memory reclamation threshold corresponding to the entire computer device.
[0068] Figure 1 When the memory recovery thread in the memory recovery process performs a memory recovery operation, it reads the value of the parameter indicating the memory recovery threshold from the waterline control file, thereby obtaining the memory recovery threshold. The memory recovery thread performs a memory recovery operation based on the obtained memory recovery threshold. The memory recovery threshold includes a first memory recovery threshold and a second memory recovery threshold, and the second memory recovery threshold is less than the first memory recovery threshold. The memory recovery thread performs a memory recovery operation based on the obtained memory recovery threshold, which specifically means that when the remaining capacity of the first partition in the memory is lower than the second memory recovery threshold, part of the data in the first partition is compressed and recovered to the second partition in the memory until the remaining capacity of the first partition exceeds the first memory recovery threshold. It can be seen that the first memory recovery threshold is used to indicate the critical value for ending the memory recovery operation, and the second memory recovery threshold is used to indicate the critical value for starting the memory recovery operation.
[0069] In addition, since memory reclamation operations are currently implemented by the memory reclamation thread in the kernel space, the watermark control file is also configured in the kernel space to prevent the memory reclamation threshold from being arbitrarily modified by malicious applications. Optionally, the watermark control file can also be adaptively configured in the user space based on demand, which is not limited in the embodiments of the present application.
[0070] 3. Added the function of modifying waterline control files by memory allocator.
[0071] When the waterline automatic thread is deployed in the user state space, after the waterline adjustment thread adjusts the memory recovery threshold, since the waterline adjustment thread cannot access the information in the kernel state space, in the embodiment of the present application, the memory allocator will update the adjusted memory recovery threshold to the waterline control file, so that the memory recovery thread can perform memory recovery operations based on the adjusted memory recovery threshold.
[0072] For example, in Figure 3 In the NUMA mechanism shown, if the waterline adjustment thread currently adjusts the memory reclamation threshold of any NMUA node, the memory allocator can modify the memory reclamation threshold of the NUMA node in the waterline control file according to the adjusted memory reclamation threshold.
[0073] Based on the above configuration of the operating system, the waterline adjustment thread in the operating system can implement the method for determining the memory reclaim threshold provided in the embodiment of the present application through the following embodiments.
[0074] Figure 4 This is a flow chart of a method for determining a memory recycling threshold provided by an embodiment of the present application. Figure 4 As shown, the method includes the following steps.
[0075] Step 401: Obtain a memory usage parameter or a processor operation parameter, wherein the memory usage parameter indicates the usage of the first partition or the second partition in the memory, and the processor operation parameter indicates the operation status of the processor.
[0076] It should be noted that obtaining memory usage parameters or processor operating parameters in step 401 includes three situations. One is to obtain only memory usage parameters, one is to obtain only processor operating parameters, and the other is to obtain both memory usage parameters and processor operating parameters. In addition, the memory usage parameters indicating the usage of the first partition or the second partition in the memory also include three situations. One is that the memory usage parameters indicate the usage of the first partition in the memory, one is that the memory usage parameters indicate the usage of the second partition in the memory, and the other is that the memory usage parameters indicate the usage of the first partition and the second partition in the memory. That is, in an embodiment of the present application, A or B may include three situations, one is A, one is B, and the other is A and B.
[0077] In one possible implementation, the memory usage parameters in step 401 may include parameters such as the free memory of the first partition. Among them, the free memory of the first partition can indicate the usage of the first partition. The more free memory the first partition has, the less likely it is that the first partition is currently using it. In this case, there is no need to perform a memory recovery operation at present. The less free memory the first partition has, the more likely it is that the first partition is currently using it. In this case, a memory recovery operation may be required at present. Therefore, the usage of the first partition can indicate whether it is currently necessary to perform a memory recovery operation. Therefore, in an embodiment of the present application, the memory recovery threshold can be adjusted based on the usage of the first partition.
[0078] It should be noted that the free memory of the first partition is only one possible parameter indicating the usage of the first partition. The usage of the first partition can also be represented by other references, such as the used capacity of the first partition, the idle rate of the first partition, or the utilization rate of the first partition. The idle rate of the first partition refers to the ratio of the free memory of the first partition to the total capacity of the first partition, and the utilization rate of the first partition refers to the ratio of the used capacity of the first partition to the total capacity of the first partition.
[0079] In addition, the memory usage parameters in step 401 may also include parameters such as the usage rate of the second partition. The usage rate of the second partition can indicate the usage of the second partition. The greater the usage rate of the second partition, the more data is stored in the second partition, and the smaller the remaining space of the second partition. The smaller the usage rate of the second partition, the less data is stored in the second partition, and the larger the remaining space of the second partition. Among them, the usage of the second partition can indicate the amount of memory allowed to be recycled. Therefore, in an embodiment of the present application, the memory recycling threshold can be adjusted according to the usage of the second partition to achieve flexible adjustment of the memory recycling threshold based on actual conditions.
[0080] It should also be noted that the utilization rate of the second partition is only one possible parameter indicating the utilization of the second partition. The utilization of the second partition can also be characterized by other references, such as the used capacity of the second partition, the idle rate of the second partition, or the utilization rate of the second partition. For explanations of the used capacity, idle rate, or utilization rate of the second partition, please refer to the corresponding concepts in the first partition and will not be repeated here.
[0081] In addition, the above-mentioned processor operating parameters may include a memory reclamation operation indication parameter, and the memory reclamation operation indication parameter indicates whether the processor is performing a memory reclamation operation.
[0082] In one possible implementation, based on Figure 1 It can be seen from the software system architecture shown that the operating system is configured with a memory recovery thread (kswapd), and the processor performs memory recovery operations based on the memory recovery thread. Therefore, the above-mentioned memory recovery operation indication parameter can specifically refer to the processor occupancy of the memory recovery thread. At this time, the implementation method for judging whether the processor is performing a memory recovery operation can be: if the processor occupancy of the memory recovery thread exceeds a preset value, it is determined that the processor is performing a memory recovery operation. Correspondingly, if the processor occupancy of the memory recovery thread is lower than the preset value, it is determined that the processor is not performing a memory recovery operation. The aforementioned preset value is a pre-configured value, which can be 0 or a value close to 0.
[0083] Among them, the processor occupancy rate of each thread in the operating system can be directly obtained from the parameters related to the operating state of the processor, and the embodiments of the present application do not explain this in detail. Optionally, the memory recovery operation indication parameter can also be characterized by other indicators. For example, the memory recovery operation indication parameter can be characterized by the startup and shutdown status of the memory recovery thread, and the embodiments of the present application do not limit this.
[0084] Furthermore, the aforementioned memory reclamation operation indication parameter is merely one possible way to indicate the processor's operating status. Optionally, the processor's operating status may also include parameters such as the processor's current memory reclamation capability. In this case, the processor's current memory reclamation capability may also be taken into account when subsequently adjusting the memory reclamation threshold. This will not be further explained.
[0085] Step 402: Adjust the memory reclaim threshold according to the memory usage parameter or the processor operation parameter.
[0086] In step 402, the memory reclamation threshold may be adjusted by performing different adjustment actions based on the different usage rates of the second partition. Therefore, step 402 may be explained through the following scenarios.
[0087] Scenario 1: The usage of the second partition exceeds the usage threshold.
[0088] In scenario 1, the usage of the second partition exceeds the usage threshold, indicating that the available capacity of the second partition is currently low and that memory reclamation is not appropriate. However, if the processor is currently performing a memory reclamation operation, the memory reclamation threshold can be lowered to minimize subsequent triggering of memory reclamation operations and to quickly terminate the ongoing memory reclamation operation. If the processor is not currently performing a memory reclamation operation, since it is uncertain whether the usage threshold will change in the future, the memory reclamation threshold can be maintained unchanged.
[0089] Therefore, in one possible implementation, if the usage rate of the second partition exceeds the usage rate threshold and the memory reclamation operation indication parameter indicates that the processor is performing a memory reclamation operation, the memory reclamation threshold is lowered. Correspondingly, if the usage rate of the second partition exceeds the usage rate threshold and the memory reclamation operation indication parameter indicates that the processor is not performing a memory reclamation operation, the memory reclamation threshold is maintained unchanged.
[0090] The above usage rate threshold is a pre-configured threshold, which can be set based on demand. For example, the usage rate threshold can be 90%.
[0091] Lowering the memory reclamation threshold may mean lowering both the first and second memory reclamation thresholds simultaneously. For example, the first and second memory reclamation thresholds may be lowered at the same ratio, or at different ratios. This is not specifically limited in the present embodiments.
[0092] In addition, in the embodiments of the present application, "exceed" can be greater than or greater than or equal to. "lower than" can be less than or less than or equal to. When "exceed" means greater than, "lower than" means less than or equal to. When "exceed" means greater than or equal to, "lower than" means less than.
[0093] Scenario 2: The usage of the second partition is lower than the usage threshold.
[0094] In scenario 2, the usage of the second partition is lower than the usage threshold, indicating that there is currently sufficient free capacity in the second partition, making it suitable for memory reclamation. In this scenario, you can directly increase the memory reclamation threshold to trigger memory reclamation as soon as possible.
[0095] Optionally, in this scenario, the free memory in the first partition can be further considered. If the first partition has a lot of free memory, then if the memory reclamation threshold is not adjusted, the operating system may not perform memory reclamation operations, which can easily waste space in the second partition. If the first partition has less free memory, then if the memory reclamation threshold is not adjusted, the operating system may continuously trigger memory reclamation operations, which can easily lead to insufficient free space in the second partition.
[0096] Therefore, in one possible implementation, if the usage rate of the second partition is lower than the usage threshold, the first memory recycling threshold and the second memory recycling threshold are flexibly adjusted according to the size relationship between the free memory of the first partition and the first memory recycling threshold or the second memory recycling threshold.
[0097] Adjusting the first memory reclamation threshold and the second memory reclamation threshold based on the relationship between the free memory of the first partition and the first memory reclamation threshold or the second memory reclamation threshold is specifically divided into the following three situations:
[0098] (1) If the number of times that the free memory exceeds the first memory reclamation threshold is greater than or equal to a first reference number, the second memory reclamation threshold is increased so that the second lower memory reclamation threshold exceeds the free memory.
[0099] If the number of times that the free memory exceeds the first memory reclamation threshold is greater than or equal to the first reference number, it means that the free memory continues to exceed the first memory reclamation threshold, indicating that the processor will not trigger a memory reclamation operation for a long period of time. This is not conducive to leveraging the advantages of the memory reclamation mechanism. Therefore, in this scenario, the intensity of the memory reclamation operation can be increased. Specifically, the second memory reclamation threshold can be increased so that the second lower memory reclamation threshold exceeds the free memory. The purpose is to quickly trigger the memory reclamation operation and minimize the termination of the memory reclamation operation.
[0100] In addition, the above-mentioned increase in the second memory reclamation threshold value may not set a goal of "making the second lowest memory reclamation threshold value exceed the free memory", and may simply be increased.
[0101] After the second memory reclamation threshold is increased, the free memory can be less than the second memory reclamation threshold, thereby triggering a memory reclamation operation when the free memory is relatively large.
[0102] Furthermore, while increasing the second memory reclamation threshold, the first memory reclamation threshold can also be increased. In one possible implementation, the first and second memory reclamation thresholds can be increased in the same proportion. For example, each of the first and second memory reclamation thresholds can be increased to 110% of their original values.
[0103] In addition, the number of times that the space memory of the first partition exceeds the first memory recycling threshold is greater than or equal to the first reference number may mean that: when periodically detecting whether the space memory of the first partition exceeds the first memory recycling threshold, the space memory of the first partition exceeds the first memory recycling threshold more than the first reference number of times. The first reference number may be three times or other times. In addition, the period of the aforementioned periodic detection may also be pre-configured, which will not be described in detail here.
[0104] Furthermore, if the space memory of the first partition exceeds the first memory reclamation threshold over a longer first reference time period, the memory reclamation threshold can be adjusted in the same manner as described above. The specific adjustment method is the same as the implementation method for increasing the second memory reclamation threshold described above and will not be further described here. The first reference time period can be pre-configured, and this embodiment of the present application does not limit this.
[0105] (2) If the number of times that the free memory is lower than the second memory recycling threshold is greater than or equal to the second reference number, lower the first memory recycling threshold so that the first memory recycling threshold is lower than the free memory.
[0106] If the number of times the free memory is within the second memory recycling threshold is greater than or equal to the second reference number, it is equivalent to the free memory being continuously lower than the second memory recycling threshold, indicating that after multiple memory recycling operations are performed according to the existing memory recycling threshold, the free memory is still lower than the second memory recycling threshold. At this time, under the existing memory recycling threshold, there is no need to perform memory recycling operations. Therefore, the first memory recycling threshold can be lowered. After lowering the first memory recycling threshold, it can be achieved that the free memory is larger than the first memory recycling threshold, thereby stopping the memory recycling operation.
[0107] Similar to Scenario 1, the aforementioned lowering of the first memory reclamation threshold can be performed without setting the goal of "making the first memory reclamation threshold lower than the free memory," and can simply be performed downward. The aforementioned second reference time period can be the same as or different from the first reference time period in Scenario 1. Furthermore, the multiple consecutive times in Scenario 2 can be the same number of times as the multiple consecutive times in Scenario 1, or they can be different numbers of times.
[0108] Furthermore, while lowering the first memory reclamation threshold, the second memory reclamation threshold can also be lowered. In one possible implementation, the first and second memory reclamation thresholds can be lowered in the same proportion. For example, each of the first and second memory reclamation thresholds can be lowered to 95% of their original values.
[0109] Furthermore, the number of times that the second memory reclamation threshold value exists within the space of the first partition is greater than or equal to the second reference number may mean that after the processor performs memory reclamation read operations more than the second reference number of times, the memory space of the first partition remains below the second memory reclamation threshold value. The second reference number of times may be three or another number, which is not specifically limited herein.
[0110] Furthermore, if the memory usage of the first partition remains below the second memory reclamation threshold over a longer second reference time period, the memory reclamation threshold can be adjusted in the same manner as described above. The specific adjustment method is the same as the aforementioned implementation method for lowering the first memory reclamation threshold and is not further described here. The second reference time period can be preconfigured, and this is not limited in this embodiment of the present application.
[0111] The first reference number and the second reference number in the above cases (1) and (2) may be the same or different. The first reference time period and the second reference time period in the above cases (1) and (2) may be the same or different.
[0112] Furthermore, if the free memory of the first partition is lower than the minimum memory reclamation threshold obtained by converting the minimum number of free bytes configured in the computer device, the first memory reclamation threshold can be directly lowered without waiting for this situation to continue to occur. Alternatively, the first memory reclamation threshold can be lowered after waiting for this situation to continue to occur.
[0113] (3) If the free memory exceeds the second memory reclamation threshold but is lower than the first memory reclamation threshold, and the memory reclamation operation indication parameter indicates that the processor is performing a memory reclamation operation, lower the first memory reclamation threshold so that the first memory reclamation threshold among the memory reclamation thresholds is lower than the free memory. Correspondingly, if the free memory exceeds the second lower memory reclamation threshold but is lower than the first memory reclamation threshold, and the memory reclamation operation indication parameter indicates that the processor is not performing a memory reclamation operation, maintain the first memory reclamation threshold unchanged.
[0114] When the free memory exceeds the second memory reclamation threshold but is lower than the first memory reclamation threshold, you can continue to refer to the processor's operating status to determine whether the memory reclamation threshold needs to be adjusted. If the free memory exceeds the second memory reclamation threshold but is lower than the first memory reclamation threshold, it indicates that there is no strong demand for memory reclamation at present. In this scenario, if the memory reclamation operation indication parameter indicates that the processor is performing a memory reclamation operation, the first memory reclamation threshold can be lowered. After lowering the first memory reclamation threshold, it can be achieved that the free memory is larger than the first memory reclamation threshold, so that the processor stops the currently ongoing memory reclamation operation.
[0115] Optionally, when the free memory exceeds the second memory reclamation threshold but is lower than the first memory reclamation threshold, the memory reclamation threshold may be maintained unchanged without considering other factors, which is not limited in this embodiment of the present application.
[0116] It should be noted that the above scenario 1 and scenario 2, as well as the three situations in scenario 2, have no particular order and can be implemented in parallel.
[0117] In addition, the above three situations of adjusting the first memory recycling threshold and the second memory recycling threshold according to the size relationship between the free memory of the first partition and the first memory recycling threshold or the second memory recycling threshold are implemented in a scenario where the usage rate of the second partition is lower than the usage threshold. Optionally, the first memory recycling threshold and the second memory recycling threshold can be adjusted according to the size relationship between the free memory of the first partition and the first memory recycling threshold or the second memory recycling threshold, regardless of whether the usage rate of the second partition is lower than the usage threshold. The embodiments of the present application are not limited to this.
[0118] It should be noted that step 402 is described above using the usage rate of the second partition or the free memory of the first partition as an example parameter indicating memory usage. Alternatively, if other parameters of the second partition or other parameters of the first partition are selected to indicate memory usage, the specific process for adjusting memory recycling can also refer to step 402 above. The principles are essentially the same, only the parameters used are different.
[0119] In summary, in an embodiment of the present application, the memory reclamation threshold can be adjusted based on memory usage parameters or processor operating parameters in a computer device. It can be seen from this that an embodiment of the present application provides a method for flexibly adjusting the memory reclamation threshold, thereby avoiding the problem that the memory reclamation threshold is usually fixed in memory reclamation mechanisms such as ZRAM technology. In addition, because the memory reclamation threshold can be flexibly adjusted, it can not only avoid the problem that a low memory reclamation threshold does not fully utilize the advantages of memory reclamation technology, but also avoid the problem of low system performance caused by a high memory reclamation threshold.
[0120] The following combination Figure 5 The method provided in the embodiment of the present application is further explained. It should be noted that, Figure 5 The embodiment shown is only the aforementioned Figure 4 Some optional technical solutions in the illustrated embodiments do not constitute a limitation on the method for adjusting the memory reclaim threshold provided in the embodiments of the present application.
[0121] like Figure 5 As shown, the method for adjusting the memory recycling threshold includes the following steps:
[0122] 1. Initialize a first memory reclamation threshold and a second memory reclamation threshold. The initialized first memory reclamation threshold and the second memory reclamation threshold may be converted based on the minimum number of free bytes (min-free-kbytes) configured in the computer device. For details on the specific implementation, see the aforementioned embodiment.
[0123] 2. Adjust the memory reclaim threshold based on the CPU usage of kswapd, the usage of the second partition, and the free memory of the second partition.
[0124] Specifically, taking the usage threshold of 90% as an example, when the usage of the second partition exceeds the usage threshold of 90%:
[0125] If the CPU usage of kswapd is the preset value 0 and the usage of the second partition exceeds the usage threshold of 90%, the memory reclaim threshold remains unchanged.
[0126] If the CPU usage of kswapd is greater than the preset value of 0 and the usage of the second partition exceeds the usage threshold of 90%, the memory reclaim threshold is lowered.
[0127] When the usage of the second partition is lower than the usage threshold of 90%:
[0128] If the number of times that the free memory exceeds the first memory reclamation threshold (also known as the high watermark) is greater than or equal to 3 times, it indicates that the free memory continues to exceed the first memory reclamation threshold, and the values of the first memory reclamation threshold and the second memory reclamation threshold are increased, thereby triggering memory compression. Figure 4 The first reference number in the embodiment is an example of an illustration and does not constitute a Figure 4 Definition of the first reference number in the embodiment.
[0129] If the number of times that the free memory is lower than the second memory reclamation threshold (also known as the low watermark) is less than or equal to 3 times, indicating that the free memory is continuously lower than the second memory reclamation threshold, the values of the first memory reclamation threshold and the second memory reclamation threshold are lowered, thereby stopping memory compression. Figure 4 The second reference number in the embodiment is an example of an illustration and does not constitute a Figure 4 Alternatively, if the free memory is lower than the minimum watermark obtained by converting the minimum number of free bytes (min-free-kbytes), the values of the first memory reclamation threshold and the second memory reclamation threshold are lowered, thereby stopping memory compression.
[0130] If the free memory is between the first and second memory reclamation thresholds and the CPU usage of kswapd is greater than the preset value 0, the first and second memory reclamation thresholds are lowered to stop memory compression.
[0131] about Figure 5 The detailed implementation of the embodiment shown can be referred to Figure 4 The embodiments shown will not be described in detail here.
[0132] It should be noted that the aforementioned usage threshold of 90% and the preset value of 0 corresponding to the kswapd CPU usage are for illustration purposes only. The present embodiment does not limit the specific values of the usage threshold and the preset value. Furthermore, the operations for adjusting the memory reclaim threshold in each of the aforementioned scenarios are not sequential and can be performed in parallel.
[0133] Figure 6 This is a computer device provided in an embodiment of the present application. Figure 6 As shown, the computer device 600 includes:
[0134] An acquisition module 601 is configured to acquire a memory usage parameter or a processor operation parameter, wherein the memory usage parameter indicates a usage of the first partition or the second partition in the memory, and the processor operation parameter indicates an operation status of the processor;
[0135] The adjustment module 602 is configured to adjust the memory reclaim threshold according to memory usage parameters or processor operation parameters.
[0136] Optionally, the memory usage parameter includes a usage rate of the second partition, and the processor operation parameter includes a memory recycling operation indication parameter, and the memory recycling operation indication parameter indicates whether the processor is performing a memory recycling operation;
[0137] The adjustment module is used to:
[0138] It is determined that the usage rate of the second partition exceeds the usage rate threshold, and the memory reclamation operation indication parameter indicates that the processor is performing a memory reclamation operation, and the memory reclamation threshold is lowered.
[0139] Optionally, the memory usage parameter includes free memory of the first partition, the memory reclamation threshold includes a first memory reclamation threshold and a second memory reclamation threshold, the first memory reclamation threshold is greater than the second memory reclamation threshold, the first memory reclamation threshold is used to indicate a critical value for ending a memory reclamation operation, and the second memory reclamation threshold is used to indicate a critical value for starting a memory reclamation operation;
[0140] Adjustment module for
[0141] The first memory reclamation threshold or the second memory reclamation threshold is adjusted according to a size relationship between the free memory of the first partition and the first memory reclamation threshold or the second memory reclamation threshold.
[0142] Optionally, the adjustment module is used to:
[0143] If it is determined that the number of times the free memory exceeds the first memory reclamation threshold is greater than or equal to a first reference number, the second memory reclamation threshold is increased.
[0144] Optionally, the adjustment module is used to:
[0145] If it is determined that the number of times the free memory is lower than the second memory reclamation threshold is greater than or equal to a second reference number, the first memory reclamation threshold is lowered.
[0146] Optionally, the processor operation parameter includes a memory reclaim operation indication parameter, and the memory reclaim operation indication parameter indicates whether the processor is performing a memory reclaim operation;
[0147] The adjustment module is used to:
[0148] If it is determined that the free memory exceeds the second memory reclamation threshold but is lower than the first memory reclamation threshold, and the memory reclamation operation indication parameter indicates that the processor is performing a memory reclamation operation, the first memory reclamation threshold is lowered.
[0149] Optionally, the operating system is configured with a memory reclamation thread, the processor performs a memory reclamation operation based on the memory reclamation thread, and the memory reclamation operation indication parameter is the processor occupancy of the memory reclamation thread;
[0150] When the processor occupancy rate of the memory reclaim thread is greater than a preset value, it indicates that the processor is performing a memory reclaim operation; when the processor occupancy rate of the memory reclaim thread is equal to the preset value, it indicates that the processor is not performing a memory reclaim operation.
[0151] Optionally, the computer device also includes multiple non-uniform memory access NMUA nodes, the memory of each NUMA node in the multiple NUMA nodes includes a first partition and a second partition, and adjusting the memory recovery threshold refers to adjusting the memory recovery threshold of any NMUA node in the multiple NUMA nodes, and the memory recovery threshold of each NUMA node in the multiple NUMA nodes is independent of each other.
[0152] Optionally, a watermark control file is configured in the computer device, and the watermark control file is used to store parameters indicating a memory recycling threshold;
[0153] The computer equipment also includes:
[0154] The modification module is used to modify the value of the parameter in the waterline control file according to the adjusted memory recovery threshold.
[0155] Optionally, the computer device further includes:
[0156] A display module, used to display a configuration interface, which includes a waterline adjustment control;
[0157] The acquisition module is further configured to: acquire a waterline adjustment rule in response to a selection operation on the waterline adjustment control;
[0158] The watermark adjustment rule includes increasing the memory reclamation threshold, decreasing the memory reclamation threshold, or setting a usage threshold for the second partition.
[0159] In summary, in an embodiment of the present application, the memory reclamation threshold can be adjusted based on memory usage parameters or processor operating parameters in a computer device. It can be seen from this that an embodiment of the present application provides a method for flexibly adjusting the memory reclamation threshold, thereby avoiding the problem that the memory reclamation threshold is usually fixed in memory reclamation mechanisms such as ZRAM technology. In addition, because the memory reclamation threshold can be flexibly adjusted, it can not only avoid the problem that a low memory reclamation threshold does not fully utilize the advantages of memory reclamation technology, but also avoid the problem of low system performance caused by a high memory reclamation threshold.
[0160] It should be noted that the computer device provided in the above embodiment, when adjusting the memory reclamation threshold, only uses the division of the above-mentioned functional modules as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the computer device provided in the above embodiment and the method embodiment for determining the memory reclamation threshold are based on the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.
[0161] In the above embodiments, all or part of the embodiments can be implemented by software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated therein. The available medium may be a magnetic medium (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a digital versatile disc (DVD)), or a semiconductor medium (eg, a solid state disk (SSD)).
[0162] Those skilled in the art will appreciate that all or part of the steps in implementing the above embodiments may be accomplished by hardware, or by a program instructing the relevant hardware to accomplish the steps. The program may be stored in a computer-readable storage medium, which may be a read-only memory, a magnetic disk, or an optical disk. It should be noted that the above description is provided as an embodiment of the present application and is not intended to limit the embodiments of the present application.
Claims
1. A method for determining a memory reclamation threshold, characterized in that: Applied to a computer device, the memory of the computer device includes a first partition and a second partition, the first partition is used to store data read or written by a processor, and the second partition is used to store compressed data migrated from the first partition during a memory reclamation operation; The method comprises: Obtaining a memory usage parameter or a processor operating parameter, wherein the memory usage parameter indicates a current usage of the first partition or the second partition in the memory, and the processor operating parameter indicates the memory reclaiming operation of the processor; The memory reclaiming threshold is adjusted according to the memory usage parameter or the processor operation parameter.
2. The method according to claim 1, wherein The memory usage parameter includes a usage rate of the second partition, and the processor operation parameter includes a memory reclaim operation indication parameter, wherein the memory reclaim operation indication parameter indicates whether the processor is performing a memory reclaim operation; The adjusting the memory reclaim threshold according to the memory usage parameter or the processor operation parameter includes: It is determined that the usage rate of the second partition exceeds a usage rate threshold, and the memory reclamation operation indication parameter indicates that the processor is performing a memory reclamation operation, and then the memory reclamation threshold is lowered.
3. The method according to claim 1, wherein The memory usage parameter includes the free memory of the first partition, the memory reclamation threshold includes a first memory reclamation threshold and a second memory reclamation threshold, the first memory reclamation threshold is greater than the second memory reclamation threshold, the first memory reclamation threshold is used to indicate a critical value for ending a memory reclamation operation, and the second memory reclamation threshold is used to indicate a critical value for starting a memory reclamation operation; The adjusting the memory reclaim threshold according to the memory usage parameter or the processor operation parameter includes: The first memory reclamation threshold or the second memory reclamation threshold is adjusted according to a size relationship between the free memory and the first memory reclamation threshold or the second memory reclamation threshold.
4. The method according to claim 3, wherein The adjusting the first memory reclamation threshold or the second memory reclamation threshold according to a size relationship between the free memory and the first memory reclamation threshold or the second memory reclamation threshold includes: If it is determined that the number of times the free memory exceeds the first memory reclamation threshold is greater than or equal to a first reference number, the second memory reclamation threshold is increased.
5. The method according to claim 3, wherein The adjusting the first memory reclamation threshold or the second memory reclamation threshold according to a size relationship between the free memory and the first memory reclamation threshold or the second memory reclamation threshold includes: If it is determined that the number of times the free memory is lower than the second memory reclamation threshold is greater than or equal to a second reference number, the first memory reclamation threshold is lowered.
6. The method according to claim 3, wherein The processor operation parameter includes a memory reclaim operation indication parameter, and the memory reclaim operation indication parameter indicates whether the processor is performing a memory reclaim operation; The adjusting the first memory reclamation threshold or the second memory reclamation threshold according to a size relationship between the free memory and the first memory reclamation threshold or the second memory reclamation threshold includes: If it is determined that the free memory exceeds the second memory reclamation threshold but is lower than the first memory reclamation threshold, and the memory reclamation operation indication parameter indicates that the processor is performing a memory reclamation operation, the first memory reclamation threshold is lowered.
7. The method according to any one of claims 1 to 6, characterized in that The computer device also includes multiple non-uniform memory access NUMA nodes, the memory of each NUMA node in the multiple NUMA nodes includes the first partition and the second partition, and adjusting the memory reclamation threshold refers to adjusting the memory reclamation threshold of any NUMA node in the multiple NUMA nodes, and the memory reclamation thresholds of each NUMA node in the multiple NUMA nodes are independent of each other.
8. The method according to any one of claims 1 to 7, characterized in that The computer device is configured with a watermark control file, and the watermark control file is used to store parameters indicating the memory reclaim threshold; The method further comprises: According to the adjusted memory reclaim threshold, the value of the parameter stored in the waterline control file is modified.
9. The method according to any one of claims 1 to 8, characterized in that The method further comprises: Display a configuration interface, the configuration interface including a waterline adjustment control; In response to a selection operation on the waterline adjustment control, obtaining a waterline adjustment rule; The waterline adjustment rule includes increasing the magnitude of the memory reclamation threshold, decreasing the magnitude of the memory reclamation threshold, or a usage threshold for the second partition.
10. A computer device, characterized in that: The memory of the computer device includes a first partition and a second partition, the first partition is used to store data read or written by the processor, and the second partition is used to store compressed data migrated from the first partition during a memory reclamation operation; The computer device comprises: an acquisition module, configured to acquire a memory usage parameter or a processor operation parameter, wherein the memory usage parameter indicates a current usage of the first partition or the second partition in the memory, and the processor operation parameter indicates the memory reclaiming operation of the processor; An adjustment module is used to adjust the memory reclaiming threshold according to the memory usage parameter or the processor operation parameter.
11. The computer device according to claim 10, wherein: The memory usage parameter includes a usage rate of the second partition, and the processor operation parameter includes a memory reclaim operation indication parameter, wherein the memory reclaim operation indication parameter indicates whether the processor is performing a memory reclaim operation; The adjustment module is used for: It is determined that the usage rate of the second partition exceeds a usage rate threshold, and the memory reclamation operation indication parameter indicates that the processor is performing a memory reclamation operation, and then the memory reclamation threshold is lowered.
12. The computer device according to claim 10, wherein: The memory usage parameter includes the free memory of the first partition, the memory reclamation threshold includes a first memory reclamation threshold and a second memory reclamation threshold, the first memory reclamation threshold is greater than the second memory reclamation threshold, the first memory reclamation threshold is used to indicate a critical value for ending a memory reclamation operation, and the second memory reclamation threshold is used to indicate a critical value for starting a memory reclamation operation; The adjustment module is used for: The first memory reclamation threshold or the second memory reclamation threshold is adjusted according to a size relationship between the free memory and the first memory reclamation threshold or the second memory reclamation threshold.
13. The computer device of claim 12, wherein: The adjustment module is used for: If it is determined that the number of times the free memory exceeds the first memory reclamation threshold is greater than or equal to a first reference number, the second memory reclamation threshold is increased.
14. The computer device of claim 12, wherein: The adjustment module is used for: If it is determined that the number of times the free memory is lower than the second memory reclamation threshold is greater than or equal to a second reference number, the first memory reclamation threshold is lowered.
15. The computer device of claim 12, wherein: The processor operation parameter includes a memory reclaim operation indication parameter, and the memory reclaim operation indication parameter indicates whether the processor is performing a memory reclaim operation; The adjustment module is used for: If it is determined that the free memory exceeds the second memory reclamation threshold but is lower than the first memory reclamation threshold, and the memory reclamation operation indication parameter indicates that the processor is performing a memory reclamation operation, the first memory reclamation threshold is lowered.
16. The computer device according to any one of claims 10 to 15, wherein: The computer device also includes multiple non-uniform memory access NUMA nodes, the memory of each NUMA node in the multiple NUMA nodes includes the first partition and the second partition, and adjusting the memory reclamation threshold refers to adjusting the memory reclamation threshold of any NMUA node in the multiple NUMA nodes, and the memory reclamation thresholds of each NUMA node in the multiple NUMA nodes are independent of each other.
17. The computer device according to any one of claims 10 to 16, wherein: The computer device is configured with a watermark control file, and the watermark control file is used to store parameters indicating the memory reclaim threshold; The computer device further comprises: The modification module is used to modify the value of the parameter stored in the waterline control file according to the adjusted memory recovery threshold.
18. The computer device according to any one of claims 10 to 17, wherein: The computer device further comprises: A display module, configured to display a configuration interface, wherein the configuration interface includes a waterline adjustment control; The acquisition module is further configured to: acquire a waterline adjustment rule in response to a selection operation on the waterline adjustment control; The waterline adjustment rule includes increasing the magnitude of the memory reclamation threshold, decreasing the magnitude of the memory reclamation threshold, or a usage threshold for the second partition.
19. A computer device, characterized in that: The computer device includes a memory and a processor; The memory is used to store program codes, and the processor is used to execute the program codes to implement the method according to any one of claims 1 to 9.
20. A computer-readable storage medium, wherein instructions are stored in the computer-readable storage medium, and when the computer-readable storage medium is executed, the computer is caused to execute the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
A memory recovery method and device
CN109213539A
Method and system for hybrid garbage collection of multi-tasking systems
US20090276478A1