Memory allocation method and device, electronic equipment and readable storage medium
By triggering memory detection during memory allocation requests and directly ending the target process when memory is insufficient to free up memory, the system lag caused by memory recycling and exchange in the prior art is solved, and more efficient memory allocation is achieved.
Patent Information
- Application Number
- CN202510437187.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-09
- Publication Date
- 2025-05-09
- Estimated Expiration
- 2045-04-09
AI Technical Summary
When the memory capacity is insufficient, the existing technology requires real-time detection and frequent memory recycling and exchange, which causes the system to occupy a large amount of computing resources, generate additional overhead, affecting the normal operation of other processes, and causing system lag.
Memory detection is triggered through the memory allocation request sent by the current process. If the available memory capacity is less than or equal to the preset threshold, no memory recovery and exchange are performed, but the target process is directly selected and ended, free its memory and allocated to the requesting process.
It avoids the additional overhead of real-time detection of system memory, reduces system lag problems caused by memory recycling and exchange, and improves memory allocation efficiency.
Smart Images

Figure CN119961005A_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 the storage component of a computer, used to temporarily store programs and data being run by the central processing unit (CPU). The CPU can quickly read and write data from memory to ensure efficient execution of programs. It is necessary to manage memory reasonably and effectively utilize limited memory space so that programs can run normally.
[0003] In the related art, when the memory capacity becomes very small, a specific process is called to continuously recycle and exchange memory, thereby increasing the available memory capacity so that the program can run normally.
[0004] However, in related technologies, it is necessary to detect memory in real time and continuously recycle and exchange memory, which will take up a lot of computing resources, generate additional overhead, affect the normal operation of other processes, and cause 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 the problems in the prior art.
[0006] In a first aspect, an embodiment of the present application discloses a memory allocation method, comprising: 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, determining a target process from the current process and other processes running in the system; 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.
[0007] In a second aspect, an embodiment of the present application discloses a memory allocation device, including: A trigger module, used 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 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; The first memory allocation module is used 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.
[0008] In a third aspect, an embodiment of the present application further provides an electronic device, including a processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the method of the first aspect.
[0009] 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.
[0010] 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, 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. The memory detection is triggered by the 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 system freezes caused by frequent memory recovery and exchange.
[0011] 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
[0012] Figure 1 It is a step diagram of a memory allocation method provided in an embodiment of the present application; Figure 2 is a step diagram of another memory allocation method provided in an embodiment of the present application; Figure 3 is a flowchart of a method for determining a target process according to a memory overflow score provided in an embodiment of the present application; Figure 4 It is a step diagram of another memory allocation method provided in an embodiment of the present application; Figure 5 is a block diagram of a memory allocation device provided in an embodiment of the present application; Figure 6 is a block diagram of an electronic device of the present application; Figure 7It is a schematic diagram of the structure of the server in some embodiments of the present application. DETAILED DESCRIPTION
[0013] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0014] The terms "first", "second", etc. in the specification and claims of the present 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 a class, 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 kinds of relationships can exist, for example, A and / or B can be represented: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the front and back associated objects are a kind of "or" relationship. In the embodiment of the present application, the term "multiple" refers to two or more, and other quantifiers are similar.
[0015] When a process requests memory allocation from the operating system kernel, the operating system kernel will allocate free memory to the process to meet the memory needs of the process. In related technologies, when the memory capacity is relatively small and an application is actively requesting memory, resulting in high memory pressure, the operating system kernel will call a specific process to frequently recycle and swap memory, thereby increasing the available memory capacity and allocating memory that meets the application's needs to enable the application to run normally.
[0016] However, when performing memory recycling operations and recycling memory cache pages, if a process happens to be accessing these pages, the hit rate of the process accessing data will decrease, causing the process to frequently access the disk, and the slow disk I / O speed may cause blocking. When performing memory swap operations, the memory data needs to be stored in other storage devices (for example, the swap partition of the disk), and the read and write speed of the disk is much slower than the 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 jams. 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 jams in the entire system. In addition, the memory allocation method of the related art needs to monitor memory changes in real time at the application layer and maintain the state of the process occupying memory, because the service that monitors memory changes in real time needs to build a process list and periodically occupy CPU resources. This method will generate additional overhead.
[0017] 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 respond 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 the 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, the memory detection is triggered by the 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.
[0018] The memory allocation method of the present application is further exemplified below in conjunction with the accompanying drawings and specific embodiments.
[0019] 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: Step 101, in response to a memory allocation request sent by the current process, obtain the available memory capacity of the system.
[0020] 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.
[0021] 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.
[0022] 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.
[0023] 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.
[0024] 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.
[0025] The preset memory capacity threshold may be based on user requirements. For example, the preset memory capacity threshold may be set to 64 megabytes (MB) or other numbers of bytes, which are not limited here.
[0026] When 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, so more memory needs to be released to reduce the memory pressure and avoid system freezes. There are many reasons for the insufficient available memory capacity. For example, it may be that multiple applications are currently open and the applications occupy a lot of memory, resulting in insufficient available memory capacity. It may also be that there are many offline businesses currently, and these offline businesses occupy a lot of memory and have not been released, resulting in insufficient available memory capacity.
[0027] 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.
[0028] 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 processing flow ends.
[0029] Specifically, after the target process ends, the memory page corresponding to the target process is recovered to release the memory occupied by the target process. After the memory occupied by the target process is released, the memory becomes part of the available memory and can be allocated to the current process requesting memory allocation.
[0030] In the related art, when a process requests memory allocation and the current available memory capacity is relatively small, the available memory capacity is first increased through memory recycling and exchange mechanisms. After memory processing through these mechanisms, when the available memory capacity still does not meet the memory capacity requested by the application process, the process is selected from the system through the Out Of Memory Kill (OOM kill) mechanism, the selected process is terminated, and the memory occupied by the process is released and allocated to the application process that requested memory allocation. In other words, the method of the related art needs to detect the memory situation in real time. When the available memory capacity is relatively small, free pages are first obtained through memory recycling and exchange, and the recycled memory is allocated to the process requesting memory allocation until there is no available memory, and then a process is selected through the OOM kill mechanism to end it and release its corresponding memory to obtain more free memory. When processing based on the OOM kill mechanism, the process management module of the kernel of the operating system (for example, the Linux operating system) has maintained a process list, and the process list records the memory overflow score of each process. The service of the operating system kernel to detect memory changes in real time needs to build a new process list and needs to periodically occupy the CPU to monitor the system status, which will generate additional overhead.
[0031] The processing principle of the relevant technical method is to try not to end the running of the process. Therefore, when the available memory capacity is insufficient, the memory is recycled and exchanged as much as possible. When the available memory capacity is still insufficient after recycling and exchanging the memory, the OOMkill mechanism is intervened. However, recycling memory will block the current process and some system services, and when the memory pressure is high, the probability of memory recycling failure is high, and the exchange memory has the problem of slow reading and writing speed, all of which will cause the system to freeze. That is, when the memory pressure is high, it usually takes a long time to recycle and exchange memory, which will cause the system to freeze for a long time.
[0032] 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, the target process is determined from the current process and other processes running in the system; if the target process belongs to other processes 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. The 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, and there is no need to periodically occupy the CPU to monitor the system status, which avoids the real-time detection of system memory and generates additional overhead. 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, which can avoid system freezes caused by frequent memory recovery and exchange.
[0033] Figure 2 This is another embodiment of the memory allocation method provided by the present application, referring to Figure 2 The method of this embodiment may include the following steps: Step 201, in response to a memory allocation request sent by the current process, obtain the available memory capacity of the system.
[0034] The method of this step has been described in the aforementioned step 101 and will not be repeated here.
[0035] 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.
[0036] 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.
[0037] 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.
[0038] For another example, the memory overflow score is negatively correlated with the probability of the corresponding process being determined as the target process. The lower the memory overflow score, the easier it is for the corresponding process to be determined as the target process.
[0039] Optionally, step 202 may include sub-steps 2021-2022: Sub-step 2021, obtaining characteristic information of the current process and other processes respectively.
[0040] The characteristic information is used to reflect the importance and memory usage of the process corresponding to the characteristic information. For example, the characteristic information of a process may include the size of physical memory that the process needs to occupy and a preset score used to characterize its survivability priority.
[0041] The preset score representing the priority of survivability can be determined according to 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 the target process are positively correlated. 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 is determined as the target process that needs to be terminated.
[0042] Sub-step 2022, based on the characteristic information of the current process, obtain the memory overflow score of the current process, and based on the characteristic information of other processes, obtain the memory overflow scores of other processes.
[0043] Each process has a corresponding memory overflow score. For example, the memory overflow score can be dynamically calculated by the operating system kernel according to 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): oom_score=[(task_rss+task_swap)×1000 / total_memory]+oom_adj formula (1) 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; and total_memory indicates the size of the system memory.
[0044] Among them, oom_adj is a priority adjustment parameter, which is a preset score that can be adjusted by the user. Specifically, the user can adjust the preset score oom_adj to control the high-importance processes in the system not to be terminated first, or to control the low-importance processes in the system to be terminated first. For example, the importance of the process that will affect the normal operation of the operating system after termination is high, and for such a process, its preset score oom_adj can be set smaller; for another example, the importance of the offline task process is low, and for such a process, its preset score oom_adj can be set larger.
[0045] 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 as a target process that needs to be terminated.
[0046] Therefore, if the importance of the process is high, oom_adj is set to be smaller. Therefore, the memory overflow score oom_score of the process obtained based on oom_adj is also relatively small, and the probability that the process is determined as a target process that needs to be terminated is relatively low.
[0047] If the importance of the process is low, oom_adj is set larger. Therefore, 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 as a target process that needs to be terminated is relatively high.
[0048] 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]. Then the user may adjust the preset score oom_adj 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 range of the preset score 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 within the preset range, the preset score oom_adj used to calculate the memory overflow score may be adjusted.
[0049] For example, the memory pressure value can be detected by the memory optimization process (for example, the kswapd process). When the memory pressure value exceeds the memory pressure value threshold, it means that there is little available memory. In this case, the memory overflow scores of the current process and other processes are obtained respectively, and the target process is determined through a preset mechanism (for example, the OOM kill mechanism) and memory is reclaimed for it, and the reclaimed memory is allocated to the current process that applies for memory allocation. It should be noted that the processing strategy of the OOM kill mechanism is: select the process with the highest memory overflow score from the process and terminate the process.
[0050] Step 203: According to the memory overflow scores of the current process and other processes, a target process is determined from the current process and other processes running in the system.
[0051] For example, the memory overflow score is positively correlated with the probability that the corresponding process is determined as the target process. The one with the highest memory overflow score is determined from the current process and other processes running in the system and is determined as the target process. For another example, the memory overflow score is negatively correlated with the probability that the corresponding process is determined as the target process. The one with the lowest memory overflow score is determined from the current process and other processes running in the system and is determined as the target process.
[0052] Optionally, set the memory overflow score and the probability that the process corresponding to the memory overflow score is determined as the target process to be positively correlated, refer to Figure 3 , step 203 may include sub-steps 2031-2033: Sub-step 2031 , if the memory overflow score of the current process is higher than the memory overflow scores of all other processes, then the current process is determined to be the target process.
[0053] Furthermore, after determining that the current process is the target process, the method further includes: terminating the current process. That is, if the current process applying for memory allocation is determined to be the target process, the current process is directly terminated without continuing the subsequent memory allocation process, and the entire memory allocation process ends.
[0054] Among them, the memory overflow score is positively correlated with the probability of the corresponding process being determined as the target process. If the memory overflow score of the current process is higher than the memory overflow scores of all other processes, it means that the memory overflow score of the current process is the highest among all processes in the system, and the memory overflow score is positively correlated with the probability of the process being determined as the target process. Therefore, when 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.
[0055] 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.
[0056] Among them, the memory overflow score is positively correlated with the probability of the corresponding process being determined as the target process. The higher the memory overflow score, the easier it is for the corresponding process to be determined 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, it 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 of the current process, so as to increase the probability of the current process being terminated first and reduce the probability of terminating other running processes, thereby reducing the impact on other processes.
[0057] By way of 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.
[0058] For example, according to the above formula (1), the memory overflow score oom_score of each process is calculated: oom_score=[(task_rss+task_swap)×1000 / total_memory]+oom_adj formula (1) If the memory overflow score oom_score of the current process is lower than the memory overflow score of any other process, the memory overflow score oom_score of the current process and the preset memory overflow score oom_score_1 are summed to obtain an updated memory overflow score: oom_score+oom_score_1 as the updated memory overflow score of the current process. Then, according to the updated memory overflow score of the current process (oom_score+oom_score_1) and the memory overflow scores of other processes, the target process is determined from the current process and other processes running in the system.
[0059] 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 that the current process that applies for memory allocation is determined as the target process is relatively high, while the probability that other processes are 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.
[0060] For another example, if the current process that applies for memory allocation is of high importance, it is necessary to give priority to ensuring that the process that applies for memory allocation can successfully apply for memory and ensure the normal operation of the process that applies for memory allocation, then the preset memory overflow score can be set lower. Based on this, after the memory overflow score of the current process and the preset memory overflow score are summed, 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 that applies for memory allocation is determined as the target process is relatively low. In this way, it is possible to ensure that the current process that applies for memory allocation is not terminated as much as possible, and ensure the normal operation of the current process that applies for memory allocation.
[0061] 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 applying for memory allocation, and are not limited here.
[0062] 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.
[0063] 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.
[0064] 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 other processes is the highest, the other processes corresponding to the highest memory overflow score are determined as the target process.
[0065] 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.
[0066] 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.
[0067] After the target process ends, the operating system kernel reclaims the target process's memory pages to release the memory occupied by the target process. After releasing the memory, the operating system kernel allocates it as free memory to the current process that requested the memory.
[0068] Step 205: If the target process is the current process, end the current process.
[0069] For example, if the target process is the current process that sends the memory allocation request, the current process can be terminated through the OOM kill mechanism of the operating system kernel. Further, if the target process is the current process that sends the memory allocation request, the current process is terminated. After the current process is terminated, no memory needs to be allocated to it, and the entire memory allocation process ends.
[0070] According to the above steps, if the memory overflow score of the current process is not the highest score among all processes, its memory overflow score is increased to obtain an updated memory overflow score of the current process, and then the target process is determined based on the updated memory overflow score of the current process. If the memory overflow score of the current process applying for memory allocation is the highest among all processes running in the system after modifying its memory overflow score, in this case, it is determined as the target process and terminated to prevent the current process applying for memory allocation from continuously and repeatedly applying for memory allocation, occupying too much CPU resources, and causing system lag.
[0071] Step 206: If the available memory capacity is greater than the preset memory capacity threshold, memory is directly allocated to the current process.
[0072] If the memory capacity is greater than the preset memory capacity threshold, it indicates that the current available memory is sufficient. In this case, there is no need to obtain the memory overflow scores of the current process and other processes, nor is there a 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 that requests memory allocation. In this way, it is possible to avoid selecting a target process from the current process and other processes that apply for memory allocation and performing process termination processing on them, and it is possible to avoid terminating the running process, thereby achieving the purpose of ensuring the normal operation of the process as much as possible.
[0073] Among them, the preset memory capacity threshold is set according to user needs and has nothing to do with the memory allocation requirements of the current process that applies for memory allocation. Furthermore, if the memory allocated to the process does not meet its memory requirements when directly allocating memory to the current process, it is necessary to enter the step of responding to the memory allocation request sent by the current process and obtaining the system's available memory capacity 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 during a new memory allocation operation, and whether the reduced available memory capacity is greater than the preset memory capacity threshold needs to be re-judged during a new memory allocation operation.
[0074] 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 as the target process.
[0075] 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 is terminated.
[0076] 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, so as 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 as the target process. Furthermore, in the case where the current process is determined as the target process, the current process is terminated without continuing to perform memory allocation processing on it.
[0077] Specifically, when the memory allocated to the current process does not meet the memory requirements of the current process, the current process will send a memory allocation request to the operating system kernel again. 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. The loop operation is performed in this way 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.
[0078] 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 available memory capacity of the system in response to the memory allocation request sent by the current process to perform memory allocation processing on the current process again, the memory overflow score calculated by the updated preset score oom_adj will be higher than the memory overflow score calculated last time. As the number of cycles increases, the memory overflow score of the current process will become higher and higher. If the current process continuously requests memory allocation, the probability that the current process is determined as the target process and is terminated is also higher and higher, which can avoid the situation where the current process continuously and repeatedly applies for memory allocation, because each time an application is made for memory allocation, other processes may be determined 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.
[0079] In the related technology, it is necessary to monitor the memory situation in real time. When the memory is insufficient, the memory is first recovered and exchanged. If the available memory still does not meet the memory demand after the memory is recovered and exchanged, the process is selected and terminated through the OOM kill mechanism, and then the memory occupied by it is released and allocated to the process that applied for memory allocation. In the case of insufficient memory, after the memory is recovered and exchanged, 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 end 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.
[0080] In this embodiment, the detection of available memory capacity is triggered by the memory allocation request sent by the current process, and the memory does not need to be monitored in real time, thus saving the extra overhead generated by the service of real-time monitoring of memory. When the available memory capacity is greater than the preset memory capacity threshold, memory is directly allocated to the current process, which improves the memory allocation efficiency, avoids system freezes, and can also avoid ending the current process or other processes as much as possible while meeting the memory allocation requirements of the current process.
[0081] 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 according to the updated memory overflow score of the current process, and the current process is terminated if the target process is the one applying for memory allocation, and 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.
[0082] In the memory overflow processing mechanism of some operating systems, the system directly selects and terminates processes from the current process and other processes based on the memory overflow score dynamically calculated by the system, so as to satisfy the memory allocation request of the current process as much as possible. However, this method will affect other running processes. In the memory overflow mechanism, when the memory overflow phenomenon of the operating system is detected, the current process requesting memory allocation can be directly terminated, which will cause the operating system to not actively reclaim memory and greatly reduce the probability of the memory allocation request of the current process being satisfied. These mechanisms cannot balance the memory allocation requirements of the current process requesting memory allocation and the normal operation requirements of other running processes.
[0083] Based on this embodiment, after terminating 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 as 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, and 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 requirements of the current process requesting memory allocation and the normal operation requirements of other processes that are already running.
[0084] 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: Step 301, in response to a memory allocation request sent by the current process, obtain available memory capacity.
[0085] The method of this step has been described in the aforementioned step 201 and will not be repeated here.
[0086] Step 302, determine whether the available memory capacity is less than a preset memory capacity threshold, if so, proceed to step 304, otherwise proceed to step 303.
[0087] 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.
[0088] Step 303, immediately allocate memory for the current process, and then enter step 311.
[0089] If the available memory capacity is less than or equal to the preset memory capacity threshold, it means that the free memory is insufficient and cannot be allocated immediately, so 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 means that the free memory is sufficient, and the memory can be allocated immediately without determining and ending the target process, releasing the memory occupied by it and allocating it to the current process of the memory allocation request.
[0090] Step 304, respectively obtain the memory overflow scores of all processes running in the system.
[0091] Among them, all processes include the current process that applies for memory allocation and other processes.
[0092] 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.
[0093] 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 .
[0094] Among them, the memory overflow score is positively correlated with the probability that the corresponding process is determined as the target process.
[0095] 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.
[0096] Step 306, ending the current process requesting memory allocation.
[0097] After the current process requesting memory allocation is terminated, no subsequent memory allocation processing is required.
[0098] 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.
[0099] For example, the memory overflow score of the process can be obtained according to the OOM kill mechanism, and in each loop, if the memory overflow score of the current process is not the highest among all processes, its memory overflow score is increased to obtain an updated memory overflow score of the current process. For example, in the first loop, the memory overflow score of the current process obtained according to 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 point) are summed to obtain an updated memory overflow score A+B of the current process. In addition, during the processing of 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.
[0100] 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.
[0101] Step 308: Determine the target process with the highest memory overflow score according to the updated memory overflow score of the current process and the memory overflow scores of other processes.
[0102] 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.
[0103] Step 309, determine whether the target process is the current process requesting memory allocation, if yes, proceed to step 306, otherwise proceed to step 310.
[0104] 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 the memory allocation.
[0105] Furthermore, the target process can be terminated through the OOM kill mechanism, and the memory page corresponding to the target process can be reclaimed to release the memory occupied by it, and the reclaimed memory page can be allocated to the current process requesting memory allocation.
[0106] Step 310, determine whether the memory allocated to the current process meets the memory allocation requirement, if yes, then end, otherwise return to step 301.
[0107] In the related art, memory changes can be monitored in real time, and a process list can be maintained. When the memory is insufficient, the memory is first recovered and exchanged. If the available memory is still less than the threshold value after the memory is recovered and exchanged, the low-priority process is actively terminated to recycle its memory. The embodiment of the present application does not perform memory recovery and exchange, but directly intervenes in the mechanism for determining and terminating the target process (for example, OOM kill mechanism) when the available memory capacity is less than or equal to the preset memory capacity threshold, releases the memory occupied by the target process, and allocates it to the current process that makes a memory allocation request. In addition, in the present embodiment, memory is allocated to the process that applies for 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 applies for 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 loops increases, the memory overflow score of the current process will become higher and higher, and the probability of it being identified as a target process and terminated will also become higher and higher. This can avoid system freezes caused by repeated memory requests by the process.
[0108] 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: 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; The process determination module 402 is used to determine the target process from the current process and other processes running in the system if the available memory capacity is less than or equal to the preset memory capacity threshold; The first memory allocation module 403 is used to terminate the target process and release the memory occupied by the target process if the target process belongs to other processes, and allocate the released memory to the current process.
[0109] Optionally, the process determination module 402 includes: 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; 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.
[0110] 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: A score modification unit, used for modifying 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; The first process determination unit is used 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.
[0111] Optional, score acquisition submodule, including: A characteristic information acquisition unit, used to respectively acquire characteristic information of the current process and other processes; 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.
[0112] 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: The second process determination unit is used to determine the current process as the target process if the memory overflow score of the process is higher than the memory overflow scores of all other processes.
[0113] Optionally, the device 40 also includes: a second memory allocation module, which is used to directly allocate memory to the current process after obtaining the available memory capacity of the system in response to a memory allocation request sent by the current process, if the available memory capacity is greater than a preset memory capacity threshold.
[0114] Optionally, the device 40 further includes: 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 as the target process; The device 40 further comprises: 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.
[0115] 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, 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. The memory detection is triggered by the 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 system freezes caused by frequent memory recovery and exchange.
[0116] 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.
[0117] 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.
[0118] Regarding the device 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.
[0119] An embodiment of the present application provides a memory allocation device, including a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors to include methods for performing one or more of the above embodiments.
[0120] Figure 6 is a block diagram of a memory allocation device 500 according to an exemplary embodiment. For example, the device 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.
[0121] Reference Figure 6 , the device 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 .
[0122] The processing component 502 generally controls the overall operation of the device 500, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 502 may include one or more processors 520 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 502 may include one or more modules to facilitate the interaction between the processing component 502 and other components. For example, the processing component 502 may include a multimedia module to facilitate the interaction between the multimedia component 508 and the processing component 502.
[0123] 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.
[0124] 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 for the device 500.
[0125] 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, the screen 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 touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 508 includes a front camera and / or a rear camera. When the device 500 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0126] The audio component 510 is configured to output and / or input audio signals. For example, the audio component 510 includes a microphone (MIC), and when the device 500 is in an operating mode, such as a call mode, a recording mode, and a voice information processing mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 504 or sent via the communication component 516. In some embodiments, the audio component 510 also includes a speaker for outputting audio signals.
[0127] I / O interface 512 provides an interface between processing component 502 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0128] The sensor assembly 514 includes one or more sensors for providing various aspects of status assessment for 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, and 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 acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0129] The communication component 516 is configured to facilitate wired or wireless communication between the device 500 and other devices. The device 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 a broadcast signal 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.
[0130] 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.
[0131] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 504 including instructions, and the instructions can be executed by the processor 520 of the device 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.
[0132] Figure 7 6 is a schematic diagram of the structure of the server in some embodiments of the present application. The server 600 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 622 (for example, one or more processors) and memory 632, and one or more storage media 630 (for example, one or more mass storage devices) storing application programs 642 or data 644. Among them, the memory 632 and the storage medium 630 can be short-term storage or permanent storage. The program stored in the storage medium 630 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Furthermore, the central processing unit 622 can be configured to communicate with the storage medium 630 to execute a series of instruction operations in the storage medium 630 on the server 600.
[0133] 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.
[0134] A non-temporary computer-readable storage medium, when the instructions in the storage medium are executed by the processor of the device (server or terminal), enables the device to perform the above-mentioned embodiment method, so it will not be repeated 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 embodiment involved in this application, please refer to the description of the method embodiment of this application.
[0135] In addition, it should be noted that: the embodiment of the present application also provides a computer program product or a 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, so it will not be repeated here. In addition, the description of the beneficial effects of 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.
[0136] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the application disclosed herein. The present application is intended to cover any variations, uses or adaptations of the present application, which follow the general principles of the present application and include common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0137] It should be understood that the present application is not limited to the precise structures that have been 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.
[0138] The above are only preferred embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.
[0139] 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 in this article 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 general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method 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, determining a target process from the current process and other processes running in the system; 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.
2. The method according to claim 1, characterized in that Determining a target process from the current process and other processes running in the system includes: Obtaining memory overflow scores of the current process and the other processes respectively; 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; According to the memory overflow scores of the current process and the other processes, a target process is determined from the current process and other processes running in the system.
3. The method according to claim 2, characterized in that 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; and determining 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 the other processes, comprises: If the memory overflow score of the current process is lower than the memory overflow score of any of the other processes, the memory overflow score of the current process is increased 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.
4. The method according to claim 2, characterized in that: The obtaining 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.
5. The method according to claim 2, characterized in that: 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 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: 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.
6. The method according to claim 1, characterized in that 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.
7. The method according to any one of claims 1 to 6, 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 requirement of the current process, re-entering the step of obtaining the available memory capacity of the system in response to the memory allocation request sent by the current process, until the memory allocated to the current process meets the memory requirement of the current process, or the current process is determined as the target process; The method further includes: if the target process is the current process, ending the current process.
8. A memory allocation device, characterized in that: The device comprises: A trigger module, used 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 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; The first memory allocation module is used 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.
9. 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 7.
10. 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 as claimed in any one of claims 1 to 7.
Citation Information
Patent Citations
Memory overflow OOM processing method, electronic equipment and computer storage medium
CN109582442A
Memory management method and device, vehicle-mounted system and vehicle
CN112463358A
Memory optimization method and device, and computer storage medium
CN113722080A
Process control method and device, electronic equipment and storage medium
CN118484274A
Core dump method and device based on embedded equipment and computer equipment
CN118519783A