Memory allocation method, device, electronic device and readable storage medium
By directly identifying and ending the target process to release memory when memory is insufficient, the system lag caused by memory recycling and swapping is solved, and the memory allocation efficiency and process operation stability are improved.
Patent Information
- Application Number
- CN202510437187.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-09
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2045-04-09
AI Technical Summary
When the memory capacity is insufficient, the existing technology frequently recycles and swaps memory, causing the system to freeze, occupying a large amount of CPU resources and affecting the normal operation of other processes.
By responding to the memory allocation request of the current process, the system's available memory capacity is obtained. If it is less than or equal to the preset threshold, the target process is determined from the current process and other processes, and the target process is terminated to release memory and directly allocated to the current process, avoiding real-time detection and frequent memory recycling and swapping.
This avoids the extra overhead of real-time memory change detection, reduces system stalls, improves memory allocation efficiency, and ensures the normal operation of other processes.
Smart Images

Figure CN119961005B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a memory allocation method, device, electronic device, and readable storage medium. Background Art
[0002] Memory is a computer's storage component, temporarily storing programs and data currently being run by the central processing unit (CPU). The CPU can quickly read and write data from memory, ensuring efficient program execution. Proper memory management and effective utilization of limited memory space are essential for proper program execution.
[0003] In the related art, when the memory capacity becomes very low, a specific process is called to continuously recycle and swap memory, thereby increasing the available memory capacity so that the program can run normally.
[0004] However, related technologies require real-time memory detection and continuous memory recycling and swapping, which takes up a lot of computing resources, generates additional overhead, affects the normal operation of other processes, and causes system freezes. Summary of the Invention
[0005] The embodiments of the present application provide a memory allocation method, device, electronic device, and readable storage medium to solve problems in the prior art.
[0006] In a first aspect, an embodiment of the present application discloses a memory allocation method, comprising:
[0007] In response to a memory allocation request sent by the current process, obtain the available memory capacity of the system;
[0008] If the available memory capacity is less than or equal to a preset memory capacity threshold, determining a target process from the current process and other processes running in the system;
[0009] If the target process belongs to the other process, the target process is terminated and the memory occupied by the target process is released, and the released memory is allocated to the current process.
[0010] In a second aspect, an embodiment of the present application discloses a memory allocation device, comprising:
[0011] A trigger module, configured to obtain the available memory capacity of the system in response to a memory allocation request sent by the current process;
[0012] a process determination module, configured to determine a target process from the current process and other processes running in the system if the available memory capacity is less than or equal to a preset memory capacity threshold;
[0013] The first memory allocation module is configured to terminate the target process and release the memory occupied by the target process if the target process belongs to the other process, and allocate the released memory to the current process.
[0014] In a third aspect, an embodiment of the present application further provides an electronic device, including a processor;
[0015] a memory for storing instructions executable by the processor;
[0016] The processor is configured to execute the instructions to implement the method of the first aspect.
[0017] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, which, when instructions in the computer-readable storage medium are executed by a processor of an electronic device, enables the electronic device to execute the method of the first aspect.
[0018] In this embodiment, in response to a memory allocation request sent by the current process, the available memory capacity of the system is obtained; if the available memory capacity is less than or equal to a preset memory capacity threshold, a target process is determined from the current process and other processes running in the system; if the target process belongs to other processes, the target process is terminated and the memory occupied by the target process is released, and the released memory is allocated to the current process. Memory detection is triggered by the memory allocation request sent by the current process, thereby avoiding the additional overhead of real-time detection of system memory. When it is detected that the available memory capacity is less than or equal to the preset memory capacity threshold, memory recovery and swapping are not performed. Instead, the target process is directly selected and terminated, and the memory of the target process is released and allocated to the current process requesting memory allocation. This can avoid system lag caused by frequent memory recovery and swapping.
[0019] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 This is a step diagram of a memory allocation method provided in an embodiment of the present application;
[0021] Figure 2 This is a step diagram of another memory allocation method provided in an embodiment of the present application;
[0022] Figure 3 This is a flowchart of a method for determining a target process based on a memory overflow score provided in an embodiment of the present application;
[0023] Figure 4 This is a step diagram of another memory allocation method provided in an embodiment of the present application;
[0024] Figure 5 is a block diagram of a memory allocation device provided in an embodiment of the present application;
[0025] Figure 6 is a block diagram of an electronic device of the present application;
[0026] Figure 7 It is a schematic diagram of the structure of the server in some embodiments of the present application. DETAILED DESCRIPTION
[0027] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0028] The terms "first", "second", etc. in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, the term "and / or" in the specification and claims is used to describe the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. In the embodiments of this application, the term "multiple" refers to two or more, and other quantifiers are similar.
[0029] When a process requests memory from the operating system kernel, the kernel allocates free memory to the process to meet its memory needs. In related technologies, when memory capacity is low and an application is actively requesting memory, resulting in high memory pressure, the kernel will call on a specific process to frequently reclaim and swap memory, thereby increasing available memory capacity and allocating memory to the application to meet its needs, ensuring normal operation.
[0030] However, when performing memory reclaim operations and reclaiming memory cache pages, if a process is accessing these pages, the process's data hit rate will decrease, forcing the process to frequently access the disk. However, the slow disk I / O speed may cause blocking. When performing memory swap operations, memory data needs to be stored in other storage devices (for example, the disk's swap partition). The disk's read and write speed is much slower than that of memory. When a large amount of memory data needs to be swapped, a large number of disk I / O requests will be generated, occupying a large amount of system resources, causing the system to be unable to respond to other tasks in a timely manner, resulting in lag. In other words, the memory allocation method of the related art will occupy a large amount of CPU resources and cause the process to lock, causing serious lag in the entire system. In addition, the memory allocation method of the related art requires real-time monitoring of memory changes at the application layer and maintaining the status of process memory usage. Because the service that monitors memory changes in real time needs to build a process list and periodically occupy CPU resources, this method incurs additional overhead.
[0031] In order to solve the above-mentioned problems of the related art, the present application provides a memory allocation method, an electronic device and a readable storage medium, which responds to a memory allocation request sent by the current process to obtain the available memory capacity of the system; if the available memory capacity is less than or equal to a preset memory capacity threshold, the target process is determined from the current process and other processes running in the system; if the target process belongs to other processes, the target process is terminated and the memory occupied by the target process is released, and the released memory is allocated to the current process. In the embodiment of the present application, memory detection is triggered by a memory allocation request sent by the current process, which avoids the extra overhead caused by real-time detection of system memory. When it is detected that the available memory capacity is less than or equal to the preset memory capacity threshold, memory recovery and exchange are not performed, but the target process is directly selected and terminated, and the memory of the target process is released and allocated to the current process requesting memory allocation, thereby avoiding the system jamming problem caused by frequent memory recovery and exchange.
[0032] The memory allocation method of the present application is further exemplified below with reference to the accompanying drawings and specific embodiments.
[0033] Figure 1 A step diagram of a memory allocation method provided in an embodiment of the present application is shown, referring to Figure 1 , the method may include the following steps:
[0034] Step 101: In response to a memory allocation request sent by a current process, obtain the available memory capacity of the system.
[0035] In an embodiment of the present application, the steps of the memory allocation method may be executed by a computer device, wherein the computer device runs an operating system and has a memory for storing data.
[0036] Specifically, the current process in this step is the process that sends a memory allocation request to the operating system kernel. The available memory capacity is the size of the free memory that is not occupied by other processes and can be allocated by the operating system kernel.
[0037] For example, the operating system kernel manages the allocation and release of physical memory. The kernel's process management module maintains a free list that records memory information. The free list records which memory blocks are free and which memory blocks have been allocated for use. The operating system kernel can obtain the available memory capacity based on the free list.
[0038] Furthermore, the memory allocation request is used to request the operating system kernel to allocate a new memory page for the current process. In response to the received memory allocation request, the operating system kernel starts to detect the available memory capacity of the system.
[0039] Step 102: If the available memory capacity is less than or equal to the preset memory capacity threshold, a target process is determined from the current process and other processes running in the system.
[0040] The preset memory capacity threshold may be determined based on user needs. For example, the preset memory capacity threshold may be set to 64 megabytes (MB), or other numbers of bytes, which are not limited here.
[0041] If the available memory capacity is less than or equal to the preset memory capacity threshold, it indicates that the available memory capacity is insufficient and the memory pressure is too high. Therefore, more memory needs to be released to reduce memory pressure and avoid system lag. There are many reasons for insufficient available memory capacity. For example, it may be that multiple applications are currently open and occupy a large amount of memory, resulting in insufficient available memory capacity. It may also be that there are many offline services currently, which occupy a large amount of memory and have not been released, resulting in insufficient available memory capacity.
[0042] Step 103: If the target process belongs to another process, the target process is terminated and the memory occupied by the target process is released, and the released memory is allocated to the current process.
[0043] Furthermore, if the target process is the current process requesting memory allocation, the current process requesting memory allocation is directly terminated. If the current process requesting memory allocation is determined to be the target process, the entire memory allocation process ends.
[0044] Specifically, after the target process ends, the memory page corresponding to the target process is recycled to release the memory occupied by the target process. After the memory occupied by the target process is released, this part of the memory becomes part of the available memory and can be allocated to the current process that requests memory allocation.
[0045] In related art, when a process requests memory allocation and the current available memory capacity is relatively low, memory reclamation and swapping mechanisms are first used to increase available memory capacity. After these mechanisms are used to process memory, if the available memory capacity still does not meet the memory capacity requested by the application process, an Out of Memory Kill (OOM) mechanism is then used to select a process from the system, terminate the selected process, and release the memory occupied by the process, which is then allocated to the application process requesting memory allocation. In other words, the related art method requires real-time monitoring of memory conditions. When available memory capacity is low, free pages are first obtained through memory reclamation and swapping, and the reclaimed memory is allocated to the process requesting memory allocation until there is no more free memory. Then, an OOM kill mechanism is used to select a process and terminate it, freeing its corresponding memory to obtain more free memory. When processing based on the OOM kill mechanism, the process management module of the operating system kernel (for example, the Linux operating system) already maintains a process list that records each process's memory overflow score. However, the operating system kernel's service for real-time memory change detection requires building a new process list and periodically using the CPU to monitor system status, which incurs additional overhead.
[0046] The principle behind related technical methods is to avoid terminating processes as much as possible. Therefore, when available memory capacity is insufficient, memory is reclaimed and swapped as much as possible. If available memory capacity is still insufficient after reclaiming and swapping, the OOMkill mechanism is used. However, reclaiming memory can block the current process and some system services. Under high memory pressure, the probability of memory reclaim failure is high, and swapping memory has slow read and write speeds, all of which can cause system lag. Specifically, under high memory pressure, reclaiming and swapping memory typically takes a long time, which can cause prolonged system lag.
[0047] In this embodiment, in response to a memory allocation request sent by the current process, the available memory capacity of the system is obtained; if the available memory capacity is less than or equal to a preset memory capacity threshold, a target process is determined from the current process and other processes running in the system; if the target process belongs to a process other than the current process, the target process is terminated and the memory occupied by the target process is released, and the released memory is allocated to the current process. Memory detection is triggered by the memory allocation request sent by the current process, and there is no need to detect memory changes in real time. Therefore, there is no need to construct an additional process list, nor is there any need to periodically occupy the CPU to monitor the system status, thus avoiding the additional overhead caused by real-time detection of system memory. When it is detected that the available memory capacity is less than or equal to the preset memory capacity threshold, memory recovery and swapping are not performed. Instead, the target process is directly selected and terminated, and the memory of the target process is released and allocated to the current process requesting memory allocation. This can avoid system freezes caused by frequent memory recovery and swapping.
[0048] Figure 2 This is another embodiment of the memory allocation method provided by this application, refer to Figure 2 The method of this embodiment may include the following steps:
[0049] Step 201: In response to a memory allocation request sent by a current process, obtain the available memory capacity of the system.
[0050] The method of this step has been described in the aforementioned step 101 and will not be repeated here.
[0051] Step 202: If the available memory capacity is less than or equal to the preset memory capacity threshold, the memory overflow scores of the current process and other processes are obtained respectively.
[0052] The memory overflow score is used to reflect the probability that the process corresponding to the memory overflow score is determined as the target process.
[0053] For example, the memory overflow score is positively correlated with the probability of the corresponding process being determined as the target process. Therefore, the higher the memory overflow score, the easier it is for the corresponding process to be determined as the target process.
[0054] For another example, the memory overflow score is negatively correlated with the probability of the corresponding process being determined as the target process. Therefore, the lower the memory overflow score, the more likely the corresponding process is to be determined as the target process.
[0055] Optionally, step 202 may include sub-steps 2021-2022:
[0056] Sub-step 2021, obtaining characteristic information of the current process and other processes respectively.
[0057] The feature information is used to reflect the importance and memory usage of the process corresponding to the feature information. For example, the feature information of a process may include the amount of physical memory required by the process and a preset score used to represent its survivability priority.
[0058] The preset score representing the survivability priority can be determined based on user needs and the importance of the process. For example, the preset score and the memory overflow score can be positively correlated, and the memory overflow score and the probability of the corresponding process being determined as a target process are positively correlated. Thus, the higher the preset score, the higher the memory overflow score calculated based on the preset score, and the higher the probability that the corresponding process will be determined as a target process to be terminated.
[0059] Sub-step 2022: obtaining a memory overflow score of the current process based on the characteristic information of the current process, and obtaining memory overflow scores of other processes based on the characteristic information of other processes.
[0060] Each process has a corresponding memory overflow score. For example, the memory overflow score can be dynamically calculated by the operating system kernel based on the running status of the process or other processes. For example, the memory overflow score oom_score can be obtained according to the following formula (1):
[0061] oom_score=[(task_rss+task_swap)×1000 / total_memory]+oom_adj formula (1)
[0062] Among them, task_rss indicates the size of physical memory used by the process; task_swap indicates the size of the swap partition used by the process; total_memory indicates the size of the system memory.
[0063] oom_adj is a priority adjustment parameter, representing a user-adjustable preset score. Specifically, by adjusting the preset score, oom_adj, you can prevent high-importance processes from being terminated, or prioritize the termination of low-importance processes. For example, if a process is considered important and would affect the normal operation of the operating system, its preset score, oom_adj, can be set to a lower value. Alternatively, if an offline task is considered unimportant, its preset score, oom_adj, can be set to a higher value.
[0064] Furthermore, according to the above formula for obtaining the memory overflow score, oom_adj is positively correlated with the memory overflow score oom_score, and the memory overflow score is positively correlated with the probability that the process is determined to be a target process that needs to be terminated.
[0065] Therefore, if the importance of a process is high, oom_adj is set to be smaller. As a result, the memory overflow score oom_score of the process obtained based on oom_adj is also relatively small, and the probability of the process being determined as a target process that needs to be terminated is relatively low.
[0066] If the importance of the process is low, oom_adj is set to a larger value. As a result, the memory overflow score oom_score of the process obtained based on oom_adj is also relatively large, and the probability that the process is easily determined to be a target process that needs to be terminated is relatively high.
[0067] Furthermore, the preset score oom_adj has a preset range and a default value. For example, the default value may be 0, and the preset range may be [-1000, 1000]. The user can then adjust the value based on the default value to obtain a preset score oom_adj within the preset range. For example, the preset range may be [-17, 50], [-17, 15], or any other set range. The preset ranges of the preset scores oom_adj for different operating system kernel versions may be different. The preset range corresponding to the current operating system kernel version may be obtained, and then the preset score oom_adj used to calculate the memory overflow score may be adjusted within the preset range.
[0068] For example, a memory optimization process (such as the kswapd process) can monitor memory pressure. When the memory pressure exceeds the threshold, it indicates that available memory is low. In this case, the memory overflow scores of the current process and other processes are obtained. A preset mechanism (such as the OOM kill mechanism) is used to identify the target process and reclaim its memory. The reclaimed memory is then allocated to the current process that requested memory allocation. It should be noted that the OOM kill mechanism's handling strategy is to select the process with the highest memory overflow score and terminate it.
[0069] Step 203 : determining a target process from the current process and other processes running in the system according to the memory overflow scores of the current process and other processes.
[0070] For example, if the memory overflow score is positively correlated with the probability of the corresponding process being identified as the target process, the process with the highest memory overflow score is selected from the current process and other processes running on the system and is determined as the target process. For another example, if the memory overflow score is negatively correlated with the probability of the corresponding process being identified as the target process, the process with the lowest memory overflow score is selected from the current process and other processes running on the system and is determined as the target process.
[0071] Optionally, set the memory overflow score and the probability of the process corresponding to the memory overflow score being determined as the target process to be positively correlated, refer to Figure 3 , step 203 may include sub-steps 2031-2033:
[0072] Sub-step 2031 : If the memory overflow score of the current process is higher than the memory overflow scores of all other processes, the current process is determined to be the target process.
[0073] Furthermore, after determining that the current process is the target process, the method further includes: terminating the current process. That is, if it is determined that the current process requesting memory allocation is the target process, the current process is directly terminated without continuing the subsequent memory allocation process, and the entire memory allocation process ends.
[0074] The memory overflow score is positively correlated with the probability of a process being identified as a target process. If the current process's memory overflow score is higher than the memory overflow scores of all other processes, it indicates that the current process has the highest memory overflow score among all processes in the system. The memory overflow score is positively correlated with the probability of a process being identified as a target process. Therefore, if the current process's memory overflow score is higher than the memory overflow scores of all other processes, the current process is identified as a target process.
[0075] Sub-step 2032: If the memory overflow score of the current process is lower than the memory overflow score of any other process, the memory overflow score of the current process is increased to obtain an updated memory overflow score of the current process.
[0076] The memory overflow score is positively correlated with the probability of the corresponding process being identified as the target process. Therefore, the higher the memory overflow score, the more likely the corresponding process is to be identified as the target process. Therefore, if the memory overflow score of the current process is lower than the memory overflow score of any other process, this indicates that the memory overflow score of the current process requesting memory allocation is not the highest. In this case, the memory overflow score of the current process is increased to obtain an updated memory overflow score for the current process, thereby increasing the probability of the current process being terminated first and reducing the probability of terminating other running processes, thereby minimizing the impact on other processes.
[0077] For example, modifying the memory overflow score of the process in sub-step 2032 may include: performing a sum operation on the memory overflow score of the current process and a preset memory overflow score to obtain an updated memory overflow score of the current process.
[0078] For example, according to the above formula (1), the memory overflow score oom_score of each process is calculated:
[0079] oom_score=[(task_rss+task_swap)×1000 / total_memory]+oom_adj formula (1)
[0080] If the current process's memory overflow score (oom_score) is lower than the memory overflow score of any other process, the current process's memory overflow score (oom_score) is summed with the preset memory overflow score (oom_score_1) to obtain the updated memory overflow score: oom_score + oom_score_1. This is used as the updated memory overflow score for the current process. Based on the updated memory overflow score (oom_score + oom_score_1) of the current process and the memory overflow scores of other processes, the target process is determined from the current process and other processes running in the system.
[0081] The preset memory overflow score can be set according to user needs and the importance of the current process that applies for memory allocation. For example, if the importance of the current process that applies for memory allocation is relatively low, and it is necessary to give priority to ensuring the normal operation of other processes, the preset memory overflow score can be set higher. Based on this, after summing the memory overflow score of the current process and the preset memory overflow score, the updated memory overflow score of the current process is relatively high. When the target process to be terminated is subsequently determined based on the updated memory overflow score of the current process, the probability of the current process that applies for memory allocation being determined as the target process is relatively high, while the probability of other processes being determined as target processes is relatively low. In this way, it is possible to ensure that other processes are not terminated as much as possible and ensure the normal operation of other processes.
[0082] For another example, if the current process applying for memory allocation is of high importance, it is necessary to prioritize ensuring that the process applying for memory allocation can successfully apply for memory and ensure the normal operation of the process applying for memory allocation. In this case, the preset memory overflow score can be set lower. Based on this, after summing the memory overflow score of the current process and the preset memory overflow score, the updated memory overflow score of the current process is relatively low. When the target process to be terminated is subsequently determined based on the updated memory overflow score of the current process, the probability that the current process applying for memory allocation is determined as the target process is relatively low. In this way, it is possible to ensure that the current process applying for memory allocation is not terminated as much as possible, and ensure the normal operation of the current process applying for memory allocation.
[0083] For example, the preset memory overflow score can be set to 1 point, 5 points, or other scores, which are determined according to user needs and the importance of the current process requesting memory allocation, and are not limited here.
[0084] Sub-step 2033 , determining a target process from the current process and other processes running in the system according to the updated memory overflow score of the current process and the memory overflow scores of other processes.
[0085] Specifically, the updated memory overflow score of the current process is compared with the memory overflow scores of other processes, and according to the comparison result, a target process is determined from the current process and other processes running in the system.
[0086] Furthermore, if the updated memory overflow score of the current process is the highest, the current process applying for memory allocation is determined as the target process; if the memory overflow score of another process is the highest, the other process corresponding to the highest memory overflow score is determined as the target process.
[0087] Step 204: If the target process belongs to another process, the target process is terminated and the memory occupied by the target process is released, and the released memory is allocated to the current process.
[0088] If the target process belongs to another process, you can use the OOM kill mechanism of the operating system kernel to end the target process.
[0089] After the target process ends, the operating system kernel reclaims the target process's memory pages, freeing up the memory occupied by the target process. After freeing up the memory, the operating system kernel allocates it as free memory to the current process that requested the memory.
[0090] Step 205: If the target process is the current process, end the current process.
[0091] For example, if the target process is the current process that sent the memory allocation request, the current process can be terminated using the OOM kill mechanism of the operating system kernel. Furthermore, if the target process is the current process that sent the memory allocation request, the current process is terminated. After the current process is terminated, no more memory is allocated to it, and the entire memory allocation process ends.
[0092] According to the aforementioned steps, if the current process's memory overflow score is not the highest among all processes, its memory overflow score is increased to obtain an updated memory overflow score for the current process, and then the target process is determined based on the updated memory overflow score of the current process. If, after modifying its memory overflow score, the memory overflow score of the current process requesting memory allocation is the highest among all processes running on the system, in this case, it is determined as the target process and terminated to prevent the current process requesting memory allocation from repeatedly requesting memory allocation, occupying excessive CPU resources, and causing system lag.
[0093] Step 206: If the available memory capacity is greater than the preset memory capacity threshold, directly allocate memory to the current process.
[0094] If the memory capacity is greater than the preset memory capacity threshold, it indicates that there is sufficient available memory. In this case, there is no need to obtain the memory overflow scores of the current process and other processes, nor is there any need to determine and terminate the target process based on the memory overflow scores. In this case, memory is immediately allocated to the current process requesting memory allocation. This avoids selecting and terminating the target process from among the current process requesting memory allocation and other processes, thus avoiding the termination of running processes and ensuring the normal operation of processes as much as possible.
[0095] Among them, the preset memory capacity threshold is set according to user needs and has nothing to do with the memory allocation needs of the current process that applies for memory allocation. Furthermore, if the memory allocated to the current process does not meet its memory needs when directly allocating memory to the current process, it is necessary to enter the step of obtaining the system's available memory capacity in response to the memory allocation request sent by the current process to perform the memory allocation operation again. Because this memory allocation operation has allocated at least part of the free memory to the current process that applied for memory allocation, the available memory capacity representing the size of the spatial memory will be reduced in the next memory allocation operation, and whether the reduced available memory capacity is greater than the preset memory capacity threshold needs to be re-judged during the next memory allocation operation.
[0096] Step 207: If the memory allocated to the current process does not meet the memory requirements of the current process, re-enter the step of responding to the memory allocation request sent by the current process and obtaining the available memory capacity of the system until the memory allocated to the current process meets the memory requirements of the process, or the current process is determined to be the target process.
[0097] Furthermore, if the memory allocated to the current process meets the memory requirement of the current process, the memory allocation operation for the process requesting memory allocation is terminated, and the entire memory allocation process ends.
[0098] For example, if the memory capacity allocated to the process requesting memory allocation is less than the memory capacity required by the current process, it is determined that the memory allocated to the current process does not meet the memory requirements of the process, and it is necessary to re-enter the step of responding to the memory allocation request sent by the current process and obtaining the available memory capacity of the system to perform the above steps again, and then repeat the memory allocation process for the current process requesting memory allocation until the memory allocated to the current process meets the memory requirements of the current process, or the current process is determined to be the target process. Furthermore, in the case where the current process is determined to be the target process, the current process is terminated and there is no need to continue the memory allocation process.
[0099] Specifically, if the memory allocated to the current process does not meet the memory requirements of the current process, the current process will again send a memory allocation request to the operating system kernel. The operating system kernel enters step 201 to respond to the memory allocation request sent by the current process and obtain the system's available memory capacity, and performs memory allocation processing according to the methods of steps 202 to 207. This loop operation is performed until the memory allocated to the current process meets the memory requirements of the current process, or the current process is determined as a target process and terminated. That is, during the loop operation, if any of the following conditions is met, the memory allocation processing flow is terminated: the memory allocated to the current process requesting memory allocation meets its memory requirements, and the current process requesting memory allocation is determined as a target process.
[0100] For example, if the memory allocated to the current process does not meet the memory requirements of the current process, the preset score oom_adj used to calculate the memory overflow score is increased to obtain an updated preset score oom_adj; wherein the preset score oom_adj is positively correlated with the memory overflow score. Based on this, when re-entering the step of obtaining the system's available memory capacity in response to the memory allocation request sent by the current process to once again perform memory allocation processing on the current process, the memory overflow score calculated using the updated preset score oom_adj will be higher than the memory overflow score calculated last time. As the number of loops increases, the memory overflow score of the current process will become higher and higher. If the current process continuously requests memory allocation, the probability of the current process being identified as the target process and terminated will also increase. This can avoid the current process from repeatedly requesting memory allocation, because each time a memory allocation request is made, other processes may be identified as target processes and terminated. Therefore, based on this method, it is possible to avoid too many other processes being terminated, reducing the impact on other processes.
[0101] In related technologies, it is necessary to monitor the memory situation in real time. When the memory is insufficient, the memory is first recycled and exchanged. If the available memory still does not meet the memory demand after recycling and exchanging the memory, the OOM kill mechanism is used to select the process and terminate the process. The memory occupied by the process is then released and allocated to the process that requested memory allocation. In the case of insufficient memory, after recycling and exchanging the memory, the memory is likely to still not meet the demand, and the OOM kill operation needs to be continued to select the running process and terminate it to release the memory space it occupies. In addition, in the case of insufficient memory, if the current process requires memory allocation, a large number of other processes may be terminated to meet the memory allocation needs of the current process.
[0102] In this embodiment, the detection of available memory capacity is triggered by a memory allocation request sent by the current process, eliminating the need for real-time memory monitoring and reducing the overhead incurred by real-time memory monitoring services. If the available memory capacity exceeds a preset memory capacity threshold, memory is directly allocated to the current process, improving memory allocation efficiency and avoiding system lags. It also minimizes the need to terminate the current process or other processes while meeting the current process's memory allocation requirements.
[0103] In this embodiment, when the available memory capacity is less than or equal to the preset memory capacity threshold, it is determined whether the memory overflow score of the current process applying for memory allocation is the highest. If it is, it is directly determined as the target process and terminated, thereby avoiding terminating other processes with low memory overflow scores and ensuring the normal operation of other processes. If the memory overflow score of the current process applying for memory allocation is not the highest, its memory overflow score is increased, and the target process is determined based on the updated memory overflow score of the current process. If the target process is the process applying for memory allocation, the current process is terminated. If the target process is another process, the target process is terminated and the memory occupied by it is released, and the released memory is allocated to the current process applying for memory allocation. The memory overflow score is positively correlated with the probability of the process corresponding to the memory overflow score being determined as the target process. By increasing the memory overflow score of the current process, the probability of the current process applying for memory allocation being determined as the target process can be increased, and the probability of terminating other processes can be reduced, so that other processes can run as normally as possible.
[0104] In some operating systems, memory overflow handling mechanisms directly select and terminate processes from the current process and other processes based on a dynamically calculated memory overflow score to maximize the satisfaction of the current process's memory allocation request. However, this approach can affect other running processes. In memory overflow mechanisms, upon detecting an operating system memory overflow, the current process requesting memory allocation can be directly terminated. This causes the operating system to be less proactive in reclaiming memory, significantly reducing the probability of satisfying the current process's memory allocation request. These mechanisms fail to balance the memory allocation needs of the current process requesting memory allocation with the normal operation requirements of other already running processes.
[0105] Based on this embodiment, after ending the target process, releasing the memory occupied by the target process, and allocating the released memory to the memory requested for memory allocation, it is determined whether the memory allocated to the current process meets the memory requirements of the current process. If not, the next memory allocation process is performed in a loop until the allocated memory meets the memory requirements of the current process, or the current process is determined to be a target process and terminated. During the loop, if the memory overflow score of the current process requesting memory allocation is not the highest, its memory overflow score is increased. Thus, as the number of loops increases, the memory overflow score of the current process will become higher and higher. If the current process continuously requests memory allocation, multiple loops will be performed to execute the method of this embodiment multiple times, and its memory overflow score will also become higher and higher, and the probability of being determined as a target process and being terminated will also become higher and higher. Based on the loop processing, until the current process becomes the target process with the highest memory overflow score and is terminated, or the memory allocated to the current process meets its memory allocation requirements. In this way, it is possible to avoid directly terminating the current process requesting memory allocation when the available memory is insufficient, and it is also possible to avoid the current process requesting memory allocation continuously and repeatedly applying for memory allocation, resulting in other processes being terminated during each memory allocation cycle. Based on this embodiment, it is possible to reasonably balance the memory allocation needs of the current process requesting memory allocation and the normal operation needs of other already running processes.
[0106] Figure 4 The flowchart of another memory allocation method provided by the embodiment of the present application is shown. Figure 4 , the method may include the following steps:
[0107] Step 301: Obtain available memory capacity in response to a memory allocation request sent by a current process.
[0108] The method of this step has been described in the aforementioned step 201 and will not be repeated here.
[0109] Step 302 , determining whether the available memory capacity is less than a preset memory capacity threshold, if so, proceeding to step 304 , otherwise proceeding to step 303 .
[0110] Specifically, the available memory capacity is compared with a preset memory capacity threshold to determine whether the memory capacity is less than the preset memory capacity threshold.
[0111] Step 303: immediately allocate memory for the current process, and then proceed to step 311.
[0112] If the available memory capacity is less than or equal to the preset memory capacity threshold, it indicates that there is insufficient free memory and it cannot be allocated immediately. Therefore, it is necessary to proceed to step 304 to determine the target process, reclaim its corresponding memory, and then allocate it. If the available memory capacity is greater than the preset memory capacity threshold, it indicates that there is sufficient free memory, and the memory can be allocated immediately without determining and terminating the target process, releasing its occupied memory, and allocating it to the current process requesting the memory allocation.
[0113] Step 304: Obtain the memory overflow scores of all processes running in the system.
[0114] Among them, all processes include the current process that applies for memory allocation and other processes.
[0115] The memory overflow score in this step may be a memory overflow score defined based on the OOM kill mechanism. The method for obtaining the memory overflow score may refer to the description in sub-step 2032 and will not be repeated here.
[0116] Step 305 , determining whether the memory overflow score of the current process requesting memory allocation is the highest, if yes, proceed to step 306 , otherwise proceed to step 307 .
[0117] Among them, the memory overflow score is positively correlated with the probability that the corresponding process is identified as the target process.
[0118] The memory overflow score of the current process making the memory allocation request is compared with the memory overflow scores of all other processes. If the memory overflow score of the current process is higher than the memory overflow scores of all other processes, it is determined that its memory overflow score is the highest; if the memory overflow score of the current process is lower than the memory overflow score of any other process, it is determined that its memory overflow score is not the highest.
[0119] Step 306: End the current process requesting memory allocation.
[0120] After the current process requesting memory allocation is terminated, no subsequent memory allocation processing is required.
[0121] Step 307: Increase the memory overflow score of the current process requesting memory allocation to obtain an updated memory overflow score of the current process.
[0122] For example, the memory overflow score of a process can be obtained based on the OOM kill mechanism. During each loop, if the current process's memory overflow score is not the highest among all processes, its memory overflow score is increased to obtain an updated memory overflow score for the current process. For example, during the first loop, the memory overflow score of the current process obtained based on the OOM kill mechanism is A. If the memory overflow score A is lower than the memory overflow score of any other process, the memory overflow score A and the preset memory overflow score B (for example, 1) are summed to obtain an updated memory overflow score A+B for the current process. Furthermore, during this loop, the memory overflow score A+B is compared with the memory overflow scores of other processes to determine whether the memory overflow score A+B is the highest memory overflow score. If so, the current process is determined to be the target process; otherwise, the other process with the highest memory overflow score is determined to be the target process.
[0123] Among them, in this step, when increasing the memory overflow score of the current process, there is no need to use an additional scoring system for management. The memory overflow score dynamically calculated by the OOM kill mechanism can be directly obtained, and the memory overflow score obtained by the OOM kill mechanism can be added to obtain an updated memory overflow score corresponding to the current process.
[0124] Step 308: Determine the target process with the highest memory overflow score based on the updated memory overflow score of the current process and the memory overflow scores of other processes.
[0125] The updated memory overflow score of the current process is compared with the memory overflow scores of other processes, and the process with the highest memory overflow score is determined as the target process.
[0126] Step 309 , determining whether the target process is the current process requesting memory allocation, if so, proceeding to step 306 , otherwise proceeding to step 310 .
[0127] Step 310: reclaim the memory page corresponding to the target process, and allocate the memory corresponding to the target process to the current process that requests memory allocation.
[0128] Furthermore, the target process can be terminated through the OOM kill mechanism, and the memory pages corresponding to the target process can be reclaimed to release the memory occupied by it, and the reclaimed memory pages can be allocated to the current process that requests memory allocation.
[0129] Step 310 , determining whether the memory allocated to the current process meets the memory allocation requirement, if yes, then the process ends, otherwise, returns to step 301 .
[0130] In the related art, memory changes can be monitored in real time, and a process list can be maintained. When memory is insufficient, memory is first recovered and swapped. If the available memory is still less than the threshold value after the memory is recovered and swapped, the low-priority process is actively terminated and its memory is reclaimed. The embodiment of the present application does not perform memory recovery and swapping. Instead, when the available memory capacity is less than or equal to the preset memory capacity threshold, it directly intervenes in the mechanism for determining and terminating the target process (for example, the OOM kill mechanism), releases the memory occupied by the target process, and allocates it to the current process that makes the memory allocation request. In addition, in this embodiment, memory is allocated to the process that requests memory allocation through a cyclic memory allocation process, and in each cyclic processing process, it is determined whether the memory overflow score of the current process is the highest. If not, its memory overflow score is increased to increase the probability that the current process that requests memory allocation is determined as the target process and terminated, thereby reducing the impact on other processes. Based on the mechanism of increasing the process memory overflow score, as the number of cycles increases, the memory overflow score of the current process will become higher and higher, and the probability of it being identified as the target process and terminated will also become higher and higher. This can avoid system lag problems caused by the process repeatedly applying for memory.
[0131] Figure 5 4 is a block diagram of a memory allocation device provided in an embodiment of the present application, wherein the device 40 includes:
[0132] The trigger module 401 is used to obtain the available memory capacity of the system in response to the memory allocation request sent by the current process;
[0133] The process determination module 402 is configured to determine a target process from the current process and other processes running in the system if the available memory capacity is less than or equal to a preset memory capacity threshold;
[0134] The first memory allocation module 403 is configured to terminate the target process and release the memory occupied by the target process if the target process belongs to another process, and allocate the released memory to the current process.
[0135] Optionally, the process determination module 402 includes:
[0136] The score acquisition submodule is used to obtain the memory overflow scores of the current process and other processes respectively; the memory overflow score is positively correlated with the probability that the process corresponding to the memory overflow score is determined as the target process;
[0137] The process determination submodule is used to determine the target process from the current process and other processes running in the system according to the memory overflow scores of the current process and other processes.
[0138] Optionally, the memory overflow score is positively correlated with the probability that the process corresponding to the memory overflow score is determined as the target process; the process determination submodule may include:
[0139] a score modifying unit, configured to modify the memory overflow score of the current process if the memory overflow score of the current process is lower than the memory overflow score of any other process, to obtain an updated memory overflow score of the current process;
[0140] The first process determining unit is configured to determine a target process from the current process and other processes running in the system according to the updated memory overflow score of the current process and the memory overflow scores of other processes.
[0141] Optional score acquisition submodule, including:
[0142] A feature information acquisition unit, used to respectively acquire feature information of the current process and other processes;
[0143] The memory overflow score acquisition unit is used to acquire the memory overflow score of the current process based on the feature information of the current process, and acquire the memory overflow scores of other processes based on the feature information of other processes.
[0144] Optionally, the memory overflow score is positively correlated with the probability that the process corresponding to the memory overflow score is determined as the target process; the process determination submodule may include:
[0145] The second process determination unit is configured to determine the current process as a target process if the memory overflow score of the process is higher than the memory overflow scores of all other processes.
[0146] Optionally, the device 40 also includes: a second memory allocation module, which is used to obtain the available memory capacity of the system in response to the memory allocation request sent by the current process, and directly allocate memory to the current process if the available memory capacity is greater than a preset memory capacity threshold.
[0147] Optionally, the device 40 further includes:
[0148] a loop processing module, configured to, after allocating the released memory to the current process, if the memory allocated to the current process does not meet the memory requirement of the current process, re-enter the step of responding to the memory allocation request sent by the current process and obtaining the available memory capacity of the system until the memory allocated to the current process meets the memory requirement of the process, or the current process is determined to be the target process;
[0149] The device 40 further comprises:
[0150] The end processing module is used to end the current process if the target process is the current process that sends the memory allocation request.
[0151] In this embodiment, in response to a memory allocation request sent by the current process, the available memory capacity of the system is obtained; if the available memory capacity is less than or equal to a preset memory capacity threshold, a target process is determined from the current process and other processes running in the system; if the target process belongs to other processes, the target process is terminated and the memory occupied by the target process is released, and the released memory is allocated to the current process. Memory detection is triggered by the memory allocation request sent by the current process, thereby avoiding the additional overhead of real-time detection of system memory. When it is detected that the available memory capacity is less than or equal to the preset memory capacity threshold, memory recovery and swapping are not performed. Instead, the target process is directly selected and terminated, and the memory of the target process is released and allocated to the current process requesting memory allocation. This can avoid system lag caused by frequent memory recovery and swapping.
[0152] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0153] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0154] Regarding the apparatus in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0155] An embodiment of the present application provides a memory allocation device, comprising a memory and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by one or more processors to include methods for performing one or more of the above embodiments.
[0156] Figure 6 FIG2 is a block diagram of a memory allocation apparatus 500 according to an exemplary embodiment. For example, the apparatus 500 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0157] Reference Figure 6 , apparatus 500 may include one or more of the following components: a processing component 502 , a memory 504 , a power component 506 , a multimedia component 508 , an audio component 510 , an input / output (I / O) interface 512 , a sensor component 514 , and a communication component 516 .
[0158] The processing component 502 generally controls the overall operation of the device 500, such as operations associated with display, phone calls, data communications, camera operation, and recording operations. The processing component 502 may include one or more processors 520 to execute instructions to perform all or part of the steps of the above-described method. In addition, the processing component 502 may include one or more modules to facilitate interaction between the processing component 502 and other components. For example, the processing component 502 may include a multimedia module to facilitate interaction between the multimedia component 508 and the processing component 502.
[0159] The memory 504 is configured to store various types of data to support operations on the device 500. Examples of such data include instructions for any application or method operating on the device 500, contact data, phone book data, messages, pictures, videos, etc. The memory 504 can be implemented by any type of volatile or non-volatile storage device, or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk, or optical disk.
[0160] The power supply component 506 provides power to the various components of the device 500. The power supply component 506 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device 500.
[0161] The multimedia component 508 includes a screen that provides an output interface between the device 500 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, it may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, slides, and gestures on the touch panel. The touch sensors can detect not only the boundaries of a touch or slide action, but also the duration and pressure associated with the touch or slide action. In some embodiments, the multimedia component 508 includes a front-facing camera and / or a rear-facing camera. When the device 500 is in an operating mode, such as a capture mode or a video mode, the front-facing camera and / or the rear-facing camera can receive external multimedia data. Each front-facing camera and the rear-facing camera can have a fixed optical lens system or have a variable focal length and optical zoom capability.
[0162] The audio component 510 is configured to output and / or input audio signals. For example, the audio component 510 includes a microphone (MIC) that is configured to receive external audio signals when the device 500 is in an operating mode, such as a call mode, a recording mode, or a voice information processing mode. The received audio signals may be further stored in the memory 504 or transmitted via the communication component 516. In some embodiments, the audio component 510 also includes a speaker for outputting audio signals.
[0163] I / O interface 512 provides an interface between processing component 502 and peripheral interface modules, such as a keyboard, click wheel, buttons, etc. These buttons may include but are not limited to: a home button, volume buttons, a start button, and a lock button.
[0164] The sensor assembly 514 includes one or more sensors for providing various aspects of the status assessment of the device 500. For example, the sensor assembly 514 can detect the open / closed state of the device 500, the relative positioning of components, such as the display and keypad of the device 500. The sensor assembly 514 can also search for changes in the position of the device 500 or a component of the device 500, the presence or absence of user contact with the device 500, the orientation or acceleration / deceleration of the device 500, and the temperature change of the device 500. The sensor assembly 514 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 514 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 514 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0165] The communication component 516 is configured to facilitate wired or wireless communication between the apparatus 500 and other devices. The apparatus 500 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 516 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 516 also includes a near-field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency information processing (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0166] In an exemplary embodiment, the apparatus 500 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above methods.
[0167] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 504 including instructions. The instructions can be executed by the processor 520 of the apparatus 500 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0168] Figure 7 6 is a schematic diagram of the server structure in some embodiments of the present application. The server 600 may vary significantly depending on configuration or performance, and may include one or more central processing units (CPUs) 622 (e.g., one or more processors), memory 632, and one or more storage media 630 (e.g., one or more mass storage devices) storing application programs 642 or data 644. The memory 632 and storage media 630 may be either transient or persistent storage. The program stored in the storage medium 630 may include one or more modules (not shown), each of which may include a series of instruction operations on the server. Furthermore, the CPU 622 may be configured to communicate with the storage medium 630 to execute the series of instruction operations in the storage medium 630 on the server 600.
[0169] The server 600 may also include one or more power supplies 626, one or more wired or wireless network interfaces 650, one or more input and output interfaces 658, one or more keyboards 656, and / or one or more operating systems 641, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0170] A non-transitory computer-readable storage medium, when the instructions in the storage medium are executed by the processor of a device (server or terminal), enables the device to perform the method of the above embodiment. Therefore, it will not be described in detail here. In addition, the description of the beneficial effects of using the same method will not be repeated. For technical details not disclosed in the computer program product or computer program embodiments involved in this application, please refer to the description of the method embodiments of this application.
[0171] In addition, it should be noted that the embodiments of the present application also provide a computer program product or computer program, which may include computer instructions, which may be stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor may execute the computer instructions, so that the computer device performs the description of the method of the above embodiment, and therefore, it will not be repeated here. In addition, the description of the beneficial effects of adopting the same method will not be repeated. For technical details not disclosed in the computer program product or computer program embodiment involved in this application, please refer to the description of the method embodiment of this application.
[0172] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the application disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered as exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0173] It should be understood that the present application is not limited to the exact structures described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
[0174] The above are only preferred embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application.
[0175] The above is a detailed introduction to a memory allocation method, device, electronic device and computer-readable storage medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A memory allocation method, characterized in that: The method comprises: In response to a memory allocation request sent by the current process, obtain the available memory capacity of the system; If the available memory capacity is less than or equal to a preset memory capacity threshold, then respectively obtaining memory overflow scores of the current process and other processes running in the system; the memory overflow scores are used to reflect the probability that the process corresponding to the memory overflow score is determined as the target process; Determining a target process from the current process and other processes running in the system according to the memory overflow scores of the current process and the other processes; If the target process belongs to the other process, then the target process is terminated and the memory occupied by the target process is released, and the released memory is allocated to the current process; if the target process is the current process, then the current process is terminated; The step of determining a target process from the current process and other processes running in the system according to the memory overflow scores of the current process and the other processes includes: When the memory overflow score is positively correlated with the probability that the process corresponding to the memory overflow score is determined to be the target process, if the memory overflow score of the current process is lower than the memory overflow score of any of the other processes, increasing the memory overflow score of the current process to obtain an updated memory overflow score of the current process; When the memory overflow score is negatively correlated with the probability that the process corresponding to the memory overflow score is determined to be the target process, if the memory overflow score of the current process is higher than the memory overflow score of any of the other processes, reducing the memory overflow score of the current process to obtain an updated memory overflow score of the current process; According to the updated memory overflow score of the current process and the memory overflow scores of the other processes, a target process is determined from the current process and other processes running in the system to increase the probability of the current process being terminated first and reduce the impact on other processes.
2. The method according to claim 1, characterized in that The obtaining of the memory overflow scores of the current process and the other processes respectively includes: respectively obtaining characteristic information of the current process and the other processes; Based on the characteristic information of the current process, a memory overflow score of the current process is obtained, and based on the characteristic information of the other processes, the memory overflow scores of the other processes are obtained.
3. The method according to claim 1, characterized in that The memory overflow score is positively correlated with the probability that the process corresponding to the memory overflow score is determined to be the target process; The determining of a target process from the current process and other processes running in the system according to the memory overflow scores of the current process and the other processes includes: If the memory overflow score of the current process is higher than the memory overflow scores of all other processes, the current process is determined to be the target process.
4. The method according to claim 1, wherein After obtaining the available memory capacity of the system in response to the memory allocation request sent by the current process, the method further includes: If the available memory capacity is greater than the preset memory capacity threshold, memory is directly allocated to the current process.
5. The method according to any one of claims 1 to 4, characterized in that After allocating the released memory to the current process, the method further includes: If the memory allocated to the current process does not meet the memory requirements of the current process, re-enter the step of obtaining the system's available memory capacity in response to the memory allocation request sent by the current process until the memory allocated to the current process meets the memory requirements of the current process, or the current process is determined to be the target process.
6. A memory allocation device, characterized in that: The device comprises: A trigger module, configured to obtain the available memory capacity of the system in response to a memory allocation request sent by the current process; a process determination module configured to, if the available memory capacity is less than or equal to a preset memory capacity threshold, obtain memory overflow scores for the current process and other processes running in the system, respectively; the memory overflow scores are used to reflect the probability that the process corresponding to the memory overflow scores is determined as the target process; and determine the target process from the current process and other processes running in the system based on the memory overflow scores of the current process and the other processes; A first memory allocation module is configured to terminate the target process and release the memory occupied by the target process if the target process belongs to the other process, and allocate the released memory to the current process; and terminate the current process if the target process is the current process; The process determination module is further configured to: when the memory overflow score is positively correlated with the probability that the process corresponding to the memory overflow score is determined as the target process, if the memory overflow score of the current process is lower than the memory overflow score of any of the other processes, increase the memory overflow score of the current process to obtain an updated memory overflow score of the current process; When the memory overflow score is negatively correlated with the probability that the process corresponding to the memory overflow score is determined to be the target process, if the memory overflow score of the current process is higher than the memory overflow score of any of the other processes, reducing the memory overflow score of the current process to obtain an updated memory overflow score of the current process; According to the updated memory overflow score of the current process and the memory overflow scores of the other processes, a target process is determined from the current process and other processes running in the system to increase the probability of the current process being terminated first and reduce the impact on other processes.
7. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Memory overflow OOM processing method, electronic equipment and computer storage medium
CN109582442A
Memory optimization method and device, and computer storage medium
CN113722080A
Core dump method and device based on embedded equipment and computer equipment
CN118519783A