Memory allocation method and device, equipment, readable storage medium and program product

By finding the target memory segment in the memory application request and controlling the allocation of memory resources based on the water level information, the problem of inefficient memory resource flow is solved, and more efficient memory management and resource utilization is achieved.

CN120336017APending Publication Date: 2025-07-18SUGON INFORMATION IND +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510442514.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-09
Publication Date
2025-07-18

AI Technical Summary

Technical Problem

In the prior art, the IO operation efficiency caused by the memory resource flow mechanism is inefficient, and frequent memory application and release require interaction with the memory management module, resulting in waste of resources.

Method used

After receiving the memory application request, find the target memory segment in the free memory segment resource pool that meets the conditions, and allocate memory for the memory application request based on the target memory page. At the same time, determine whether to apply for a new memory segment through the water level information, reduce the interaction with the memory management module, and control the holding of memory resources.

Benefits of technology

It improves the execution efficiency of memory allocation, reduces resource waste, and optimizes the memory resource flow process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120336017A_ABST
    Figure CN120336017A_ABST
Patent Text Reader

Abstract

The invention relates to a memory allocation method and device, equipment, a readable storage medium and a program product. The method comprises the steps that firstly, after a memory application request is received, whether a target memory segment with a currently unused memory page conforming to the memory application request exists in an idle memory segment resource pool or not is judged, and if yes, memory is distributed for the memory application request according to a target memory page in the target memory segment, the target memory page is an unused memory page in the target memory segment, then obtaining water level information, used for representing the number of memory segments in the free memory segment resource pool, of the free memory segment resource pool, and under the condition that the water level information meets a preset condition, applying for a new memory segment and adding the new memory segment to the free memory segment resource pool. By adopting the method, the execution efficiency of the request can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technologies, and in particular, to a memory allocation method, apparatus, device, readable storage medium, and program product. Background Art

[0002] For the key operations of the storage system for data read / write I / O (Input / Output) operations of a device, generally, one I / O operation requires multiple service modules to cooperate to complete, and shared memory resources need to be used for data transfer between different service modules. The memory resources are generally managed by a unified memory management module. Therefore, during the I / O operation, the transfer efficiency of memory resources between each service module and the memory management module is the key factor affecting the I / O operation efficiency.

[0003] Currently, the memory resource transfer mechanism includes applying in real time on demand and releasing in real time after the memory usage is completed. This method will not cause long-term occupation and waste of memory resources. However, each application and release of memory requires interaction with the memory management module, and the execution efficiency of the I / O operation is not high. Summary of the Invention

[0004] Based on this, it is necessary to provide a memory allocation method, apparatus, device, readable storage medium, and program product that can improve the service execution efficiency for the above technical problems.

[0005] In a first aspect, this application provides a memory allocation method, and the method includes:

[0006] After receiving a memory application request, determine whether there is a target memory segment in the free memory segment resource pool, where the target memory segment is a memory segment in which the currently unused memory pages meet the memory application request;

[0007] If there is a target memory segment, allocate memory for the memory application request according to the target memory pages in the target memory segment, where the target memory pages are the unused memory pages in the target memory segment;

[0008] Obtain the water level information of the free memory segment resource pool, where the water level information is used to represent the number of memory segments in the free memory segment resource pool;

[0009] When the water level information meets a preset condition, apply for a new memory segment and add it to the free memory segment resource pool.

[0010] In the above embodiments, first, after receiving a memory application request, it is determined whether there is an unused memory page in the free memory segment resource pool that meets the target memory segment of the memory application request. If there is a target memory segment, memory is allocated for the memory application request according to the target memory page in the target memory segment, where the target memory page is an unused memory page in the target memory segment. Then, the water level information for characterizing the number of memory segments in the free memory segment resource pool is obtained. When the water level information meets a preset condition, a new memory segment is applied for and added to the free memory segment resource pool. In this way, after receiving a memory application request, a target memory segment that meets the conditions in the free memory segment resource pool is searched for, and memory is allocated for the memory application request according to the target memory page in the target memory segment, without the need to interact with the memory management module to re-apply for memory every time, improving the execution efficiency of the request. At the same time, according to the current water level information of the free memory segment resource pool, it is determined whether to apply for a new memory segment, controlling the holding amount of memory resources in the free memory segment resource pool and avoiding resource waste.

[0011] In one of the embodiments, the method further includes:

[0012] If there is no target memory segment, a new memory segment is applied for through a synchronous application method and added to the free memory segment resource pool to make the water level of the free memory segment resource pool reach a preset first water level;

[0013] After the application is successful, the step of determining whether there is a target memory segment in the free memory segment resource pool is continued to be executed.

[0014] In the above embodiments, if there is no target memory segment in the free memory segment resource pool, a new memory segment is applied for through a synchronous application method to meet the memory application request.

[0015] In one of the embodiments, when the water level information meets a preset condition, applying for a new memory segment and adding it to the free memory segment resource pool includes:

[0016] When the water level information is lower than a preset second water level, a new memory segment is applied for through an asynchronous application method and added to the free memory segment resource pool to make the water level of the free memory segment resource pool reach a preset first water level, and the second water level is lower than the first water level.

[0017] In the above embodiments, by judging the water level information of the free memory segment resource pool, it is determined whether to apply for a new memory segment through an asynchronous application method. At the same time, with the asynchronous application method, the current memory application request does not need to wait for the memory segment application task to be executed, and the efficiency is higher.

[0018] In one of the embodiments, the method further includes:

[0019] Determine a first memory segment in the free memory segment resource pool and perform a memory segment return operation on the first memory segment;

[0020] Obtain the current water level information of the free memory segment resource pool;

[0021] If the current water level information is higher than a preset third water level, determine a second memory segment in the free memory segment resource pool and perform a memory segment return operation on the second memory segment, where the third water level is higher than the first water level.

[0022] In the above embodiments, by performing memory segment return operations on the first memory segment and the second memory segment, it is avoided that the service module occupies too much memory, resulting in waste of memory resources, thereby improving the memory turnover efficiency.

[0023] In one of the embodiments, before determining the first memory segment in the free memory segment resource pool and performing a memory segment return operation on the first memory segment, it includes:

[0024] After applying for a new memory segment or after reaching the scheduled time, determine the first memory segment in the free memory segment resource pool and perform a memory segment return operation on the first memory segment.

[0025] In the above embodiments, by returning the first memory segment when the return opportunity is met, the memory utilization rate is improved.

[0026] In one of the embodiments, determining the first memory segment in the free memory segment resource pool includes:

[0027] Determine a first candidate memory segment from the free memory segment resource pool, where the holding time of the first candidate memory segment is greater than a first time threshold;

[0028] Determine a second candidate memory segment from the free memory segment resource pool, where the number of remaining memory pages of the second candidate memory segment is less than a preset number of memory pages and the holding time is greater than a second time threshold;

[0029] Use the first candidate memory segment and the second candidate memory segment as the first memory segment.

[0030] In the above embodiments, use the first candidate memory segment with too long holding time and the second candidate memory segment with fewer remaining memory pages and longer holding time as the first memory segment for return, avoiding occupying memory for a long time to improve the memory turnover efficiency.

[0031] In one of the embodiments, determining the second memory segment in the free memory segment resource pool includes:

[0032] Determine a preset number of memory segments with the longest holding time from the free memory segment resource pool as the second memory segments, where the preset number is determined according to the number of memory segments corresponding to the first water level and the number of memory segments corresponding to the third water level.

[0033] In the above embodiments, the preset number of second memory segments is determined according to the holding time of each memory segment, and the second memory segments are returned, so that the water level of the free memory segment resource pool can be maintained at the first water level.

[0034] In one of the embodiments, the memory segment return operation includes:

[0035] Add the memory segment to be returned to the memory segment resource pool to be returned.

[0036] In the above embodiments, adding the memory segment to be returned to the memory segment resource pool to be returned can be returned uniformly without the need to return individual memory segments, reducing the interaction with the memory management module and improving the efficiency of memory return.

[0037] In one of the embodiments, the method further includes:

[0038] Determine whether there is a memory segment return task currently;

[0039] If there is no memory segment return task currently, perform the memory segment return operation.

[0040] In the above embodiments, determining whether there is a memory segment return task currently and determining whether to perform the memory segment return operation avoid over-consuming task resources through a single task mode.

[0041] In one of the embodiments, applying for a new memory segment and adding it to the free memory segment resource pool includes:

[0042] Determine whether there is a memory segment application task currently;

[0043] If there is no memory segment application task currently, perform the step of applying for a new memory segment and adding it to the free memory segment resource pool.

[0044] In the above embodiments, determining whether there is a memory segment application task currently and determining whether to perform the memory segment application operation avoid over-consuming task resources through a single task mode.

[0045] In a second aspect, the present application further provides a memory allocation device, and the device includes:

[0046] A judgment module, configured to determine whether there is a target memory segment in the free memory segment resource pool after receiving a memory application request, where the target memory segment is a memory segment in which the currently unused memory pages meet the memory application request;

[0047] An allocation module, configured to allocate memory for a memory application request according to a target memory page in a target memory segment if the target memory segment exists, where the target memory page is an unused memory page in the target memory segment;

[0048] An acquisition module, configured to acquire water level information of a free memory segment resource pool, where the water level information is used to represent the number of memory segments in the free memory segment resource pool;

[0049] An application module, configured to apply for a new memory segment and add it to the free memory segment resource pool when the water level information meets a preset condition.

[0050] In a third aspect, the present application further provides a computer device, including a memory and a processor, where the memory stores a computer program, and when the processor executes the computer program, it implements the memory allocation method according to any one of the above first aspects.

[0051] In a fourth aspect, the present application further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the memory allocation method according to any one of the above first aspects.

[0052] In a fifth aspect, the present application further provides a computer program product, including a computer program, and when the computer program is executed by a processor, it implements the memory allocation method according to any one of the above first aspects.

[0053] For the above memory allocation method, device, device, readable storage medium and program product, first, after receiving a memory application request, it is determined whether there is an unused memory page in the free memory segment resource pool that meets the target memory segment of the memory application request. If the target memory segment exists, memory is allocated for the memory application request according to the target memory page in the target memory segment, where the target memory page is an unused memory page in the target memory segment. Then, the water level information used to represent the number of memory segments in the free memory segment resource pool of the free memory segment resource pool is acquired, and when the water level information meets a preset condition, a new memory segment is applied for and added to the free memory segment resource pool. In this way, after receiving a memory application request, a target memory segment that meets the conditions in the free memory segment resource pool is searched for, and memory is allocated for the memory application request according to the target memory page in the target memory segment, without the need to interact with the memory management module to reapply for memory each time, improving the execution efficiency of the request. At the same time, according to the current water level information of the free memory segment resource pool, it is determined whether to apply for a new memory segment, and the holding amount of memory resources in the free memory segment resource pool is controlled to avoid resource waste. Description of the Drawings

[0054] To more clearly illustrate the technical solutions in the embodiments of the present application or the related art, the following will briefly introduce the drawings required for the description of the embodiments of the present application or the related art. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other related drawings can also be obtained based on these drawings.

[0055] Figure 1 It is a schematic flowchart of the memory allocation method in an embodiment;

[0056] Figure 2 It is a schematic structural diagram of a memory segment in an embodiment;

[0057] Figure 3 It is a schematic structural diagram of the free memory segment resource pool in an embodiment;

[0058] Figure 4 It is a schematic flowchart of the memory allocation method in another embodiment;

[0059] Figure 5 It is a schematic flowchart of the memory allocation method in another embodiment;

[0060] Figure 6 It is a schematic structural diagram of the memory segment resource pool to be returned in an embodiment;

[0061] Figure 7 It is a schematic flowchart of the memory allocation method in another embodiment;

[0062] Figure 8 It is a schematic flowchart of the memory allocation method in another embodiment;

[0063] Figure 9 It is a flowchart of the memory segment return task in another embodiment;

[0064] Figure 10 It is a schematic flowchart of the memory allocation method in another embodiment;

[0065] Figure 11 It is a flowchart of the memory segment application task in another embodiment;

[0066] Figure 12 It is a schematic flowchart of the memory allocation method in another embodiment;

[0067] Figure 13 It is a module interaction diagram of the memory allocation method in an embodiment;

[0068] Figure 14 It is a schematic diagram of the life cycle of the memory segment return in an embodiment;

[0069] Figure 15 It is a flowchart of an IO task in an embodiment;

[0070] Figure 16 It is a structural block diagram of a memory allocation device in an embodiment;

[0071] Figure 17 It is an internal structure diagram of a computer device in an embodiment. Detailed implementation manners

[0072] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0073] The data read / write IO operations of the device need to be completed through the cooperation of multiple service modules. Shared memory resources are required for data transfer between different service modules, and the memory resources are generally managed by a unified memory management module. Therefore, during the IO operation process, the transfer efficiency of the memory resources between each service module and the memory management module is the key factor affecting the IO operation efficiency.

[0074] Currently, the memory resource transfer mechanism includes applying in real time on demand and releasing in real time after the memory usage is completed. This method will not cause long-term occupation and waste of memory resources. However, each application and release of memory requires interaction with the memory management module, and the execution efficiency of the IO operation is not high.

[0075] In view of this, the present application proposes a memory allocation method. After receiving a memory application request, it searches for a target memory segment that meets the conditions in the free memory segment resource pool, and allocates memory for the memory application request according to the target memory page in the target memory segment, without the need to interact with the memory management module to reapply for memory every time, improving the execution efficiency of the request. At the same time, according to the water level information of the current free memory segment resource pool, it determines whether to apply for a new memory segment to control the holding amount of memory resources in the free memory segment resource pool and avoid resource waste.

[0076] In an exemplary embodiment, as Figure 1 shown, a memory allocation method is provided. Taking the application of this method to a server as an example for illustration, the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. It can be understood that this method can also be applied to a terminal, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server, including the following steps:

[0077] Step 101: After receiving a memory application request, determine whether there is a target memory segment in the free memory segment resource pool.

[0078] Among them, the target memory segment is a memory segment whose currently unused memory pages meet the memory application request. The memory application request can be a request initiated by a service module when it needs to use memory resources for data read / write IO operations. The free memory segment resource pool includes at least one memory segment pre-allocated for the service module, and different service modules correspond to different free memory segment resource pools. The structure of the memory segment is as Figure 2 shown. The size of the memory segment can be SEG_SZ bytes, which can be equally divided into n memory pages, including the allocated and used memory pages and the currently unused free memory pages. The size of each memory page can be PAGE_SZ.

[0079] After receiving the memory application request, traverse all the memory segments in the free memory segment resource pool to find whether there is a memory segment whose number of currently unused memory pages meets the number of memory pages required by the memory application request. If so, this memory segment can meet the requirements of the memory application request and is the target memory segment. Optionally, the free memory segment resource pool is in a linked list structure, as Figure 3 shown. freeHead is the head of the linked list, which includes a total of m memory segments, and some memory pages in some memory segments have been allocated and used.

[0080] Step 102: If there is a target memory segment, allocate memory for the memory application request according to the target memory pages in the target memory segment.

[0081] Among them, the target memory pages are the unused memory pages in the target memory segment. The memory segments in the free memory segment resource pool are managed internally by the service module, and the memory pages of the memory segments in the free memory segment resource pool can be directly allocated for use by the memory application request without further interaction with the memory management module. Therefore, after determining the target memory pages that meet the memory application request, allocate the target memory pages for the memory application request to use.

[0082] Step 103: Obtain the water level information of the free memory segment resource pool.

[0083] Among them, the water level information is used to represent the number of memory segments in the free memory segment resource pool. If there are few memory segments in the free memory segment resource pool, it may not be able to meet the memory application requests of business modules in a timely manner. If there are many memory segments in the free memory segment resource pool, that is, the business modules may occupy too much memory resources, which may affect the overall utilization rate of memory resources. Therefore, after allocating memory for a memory application request, obtain the number of memory segments held in the free memory segment resource pool, that is, the water level information. Through the water level information, it can be determined whether the number of memory segments in the free memory segment resource pool is small, medium, or large, so as to adjust the total amount of memory resources in the free memory segment resource pool.

[0084] Step 104, when the water level information meets a preset condition, apply for a new memory segment and add it to the free memory segment resource pool.

[0085] Among them, the preset condition may be that the number of memory segments in the free memory segment resource pool represented by the water level information is small. When the water level information meets the preset condition, that is, although the current memory application request has been allocated memory, due to the small number of memory segments, it may not be able to meet the next memory application request. Therefore, interact with the memory management module to apply for a new memory segment and add it to the free memory segment resource pool, so that the memory segments in the free memory segment resource pool can meet the other memory application requests of the business modules.

[0086] In the above embodiment, first, after receiving a memory application request, determine whether there is a currently unused memory page in the free memory segment resource pool that meets the target memory segment of the memory application request. If there is a target memory segment, allocate memory for the memory application request according to the target memory page in the target memory segment, where the target memory page is the unused memory page in the target memory segment. Then, obtain the water level information of the free memory segment resource pool used to represent the number of memory segments in the free memory segment resource pool. When the water level information meets the preset condition, apply for a new memory segment and add it to the free memory segment resource pool. In this way, after receiving a memory application request, find the target memory segment that meets the conditions in the free memory segment resource pool, and allocate memory for the memory application request according to the target memory page in the target memory segment, without the need to interact with the memory management module to reapply for memory every time, improving the execution efficiency of the request. At the same time, according to the current water level information of the free memory segment resource pool, determine whether to apply for a new memory segment, and control the amount of memory resources held in the free memory segment resource pool to avoid resource waste.

[0087] In the embodiment of the present application, if there is no target memory segment after traversing the free memory segment resource pool, as Figure 4 shown, the method further includes:

[0088] Step 401: If there is no target memory segment, apply for a new memory segment through synchronous application and add it to the free memory segment resource pool to make the water level of the free memory segment resource pool reach a preset first water level.

[0089] Among them, the preset first water level can be a medium water level, that is, the number of memory segments in the free memory segment resource pool is medium. Specifically, the memory segment quantity value corresponding to the first water level can be set according to the total memory resource and the demand ratio of each service module, and the embodiments of the present application do not limit this. If there is no target memory segment, that is, none of the memory segments in the current free memory segment resource pool can meet the memory application request. Therefore, a memory segment application task is triggered through synchronous application to apply for a new memory segment for the service module and add it to the free memory segment resource pool to make the water level of the free memory segment resource pool reach the preset first water level.

[0090] The synchronous application method means that the current memory application request needs to wait for the completion of the memory segment application task, and then allocate memory for the memory application request according to the application result.

[0091] Step 402: After the application is successful, continue to execute the step of determining whether there is a target memory segment in the free memory segment resource pool.

[0092] After the memory segment application is successful, re-traverse and check whether there is a target memory segment in the free memory segment resource pool. If the memory segment application fails, return that the memory application request fails and exit the process.

[0093] In the above embodiments, if there is no target memory segment in the free memory segment resource pool, a new memory segment is applied for through synchronous application to meet the memory application request.

[0094] In one embodiment, after allocating memory for the memory application request, in order to control the holding amount of memory segments in the free memory segment resource pool, the above step 104 may include:

[0095] In the case where the water level information is lower than a preset second water level, apply for a new memory segment through asynchronous application and add it to the free memory segment resource pool to make the water level of the free memory segment resource pool reach the preset first water level, where the second water level is lower than the first water level.

[0096] Among them, the second water level is lower than the first water level, that is, the number of memory segments corresponding to the second water level is less than the number of memory segments corresponding to the first water level. The second water level can be a low water level, that is, the number of memory segments in the free memory segment resource pool is a relatively small number. Specifically, the value of the number of memory segments corresponding to the second water level can be set according to the total amount of memory resources and the demand ratio of each service module, and the embodiments of the present application do not limit this. When the water level information is lower than the second water level, a memory segment application task is triggered through an asynchronous application method to apply for new memory segments for the service module and add them to the free memory segment resource pool, so that the number of memory segments in the free memory segment resource pool reaches the number of memory segments corresponding to the first water level, that is, the medium water level. The asynchronous application method does not need to wait for the completion of the memory segment application task when allocating memory for the current memory application request.

[0097] In the above embodiment, by judging the water level information of the free memory segment resource pool, it is determined whether to apply for new memory segments through the asynchronous application method. At the same time, with the asynchronous application method, the current memory application request does not need to wait for the execution of the memory segment application task, and the efficiency is higher.

[0098] In one embodiment, the above method establishes a memory segment shared resource pool for each service module during the initialization of each service module and applies for memory segments to be added to the memory segment shared resource pool. However, if a service module occupies a large amount of memory for a long time, it is not conducive to the recycling and redistribution of memory resources and is likely to cause waste of memory resources. Therefore, in order to improve the turnover efficiency of memory segments, as Figure 5 shown, the method further includes:

[0099] Step 501, determine the first memory segment in the free memory segment resource pool and perform a memory segment return operation on the first memory segment.

[0100] Among them, the first memory segment is a memory segment that meets the return conditions and needs to be forcibly returned. The return conditions can be a long holding time or a memory page usage rate exceeding a preset threshold. The first memory segment is screened out in the free memory segment resource pool, and a memory segment return operation is performed on the first memory segment, that is, an interaction is carried out with the memory management module to release the first memory segment and return it to the total memory. Optionally, the memory segment return operation triggers a memory segment return task, which can directly return the first memory segment to the memory. The memory segment return is an asynchronous return mode, that is, it is asynchronous with the current memory application request.

[0101] Optionally, the first memory segment can be returned when the return timing is met. For example, after applying for a new memory segment or after reaching a scheduled time, the first memory segment is determined in the free memory segment resource pool and a memory segment return operation is performed on the first memory segment.

[0102] After applying for a new memory segment, the number of memory segments in the free memory segment resource pool increases at this time. Therefore, the first memory segment is triggered to perform a memory segment return operation. Alternatively, through timed triggering, a timing time is set, and when the timing time arrives, the first memory segment is triggered to perform a memory segment return operation, so as to avoid the situation where a business module has no memory application request for a long time, no memory segment application task is triggered, but still holds a relatively large number of memory segments. By returning the first memory segment when the return timing is met, the utilization rate of memory is improved.

[0103] Optionally, the memory segment return operation further includes: adding the memory segment to be returned to the memory segment resource pool to be returned.

[0104] As Figure 6 shown, the memory segment resource pool to be returned is a linked list structure, returnHead is the head of the linked list, and a total of n memory segments are included. The first memory segment is added to the memory segment resource pool to be returned and waits to be returned.

[0105] In the above embodiment, adding the memory segment to be returned to the memory segment resource pool to be returned can be returned uniformly, without the need to return individual memory segments, reducing the interaction with the memory management module and improving the efficiency of memory return.

[0106] Step 502, obtain the current water level information of the free memory segment resource pool.

[0107] Wherein, the current water level information is the water level information after the first memory segment in the free memory segment resource pool is returned.

[0108] Step 503, if the current water level information is higher than a preset third water level, determine a second memory segment in the free memory segment resource pool and perform a memory segment return operation on the second memory segment.

[0109] Wherein, the third water level is higher than the first water level, that is, the number of memory segments corresponding to the third water level is greater than the number of memory segments corresponding to the first water level. The third water level can be a high water level, that is, corresponding to a relatively large number of memory segments in the free memory segment resource pool. Specifically, the value of the number of memory segments corresponding to the third water level can be set according to the total amount of memory resources and the demand ratio of each business module, and the embodiments of the present application do not limit this. According to the number of memory segments in the current free memory segment resource pool, it is detected whether the water level information is higher than the third water level. If the number of memory segments in the current free memory segment resource pool is greater than the number of memory segments corresponding to the third water level, it is determined that the water level information is higher than the third water level. If the number of memory segments in the current free memory segment resource pool is not greater than the number of memory segments corresponding to the third water level, it is determined that the water level information is lower than the third water level.

[0110] If the current water level information is higher than the third water level, that is, the current number of memory segments is still relatively large, continue to determine the second memory segment in the free memory segment resource pool. Among them, the second memory segment can be the memory segment with a relatively long holding time in the free memory segment resource pool. Then, perform a memory segment return operation on the second memory segment, such as adding the second memory segment to the memory segments to be returned resource pool.

[0111] In the above embodiments, by performing a memory segment return operation on the first memory segment and the second memory segment, it is avoided that the service module occupies too much memory, resulting in waste of memory resources, thereby improving the turnover efficiency of memory.

[0112] In the embodiments of the present application, the first memory segment is determined in the free memory segment resource pool according to the return condition, such as Figure 7 shown, including:

[0113] Step 701, determine the first candidate memory segment from the free memory segment resource pool.

[0114] Obtain the holding time of each memory segment in the free memory segment resource pool. Among them, the holding time of the first candidate memory segment is greater than the first time threshold, and the first time threshold can be set according to the requirements of each service module.

[0115] Step 702, determine the second candidate memory segment from the free memory segment resource pool.

[0116] Among them, the number of remaining memory pages of the second candidate memory segment is less than the preset number of memory pages, and the holding time is greater than the second time threshold. Both the second time threshold and the preset number of memory pages can be set according to the requirements of each service module, and the second time threshold is less than the first time threshold. The number of remaining memory pages is less than the preset number of memory pages, that is, the remaining memory pages of the memory segment are relatively few, which may not meet the requirements of the memory application request. Therefore, it can be returned.

[0117] Step 703, use the first candidate memory segment and the second candidate memory segment as the first memory segment.

[0118] In the above embodiments, the first candidate memory segment with too long holding time and the second candidate memory segment with relatively few remaining memory pages and relatively long holding time are used as the first memory segment for return, avoiding occupying memory for a long time to improve the turnover efficiency of memory.

[0119] Optionally, determining the second memory segment in the free memory segment resource pool includes: determining a preset number of memory segments with the longest holding time in the free memory segment resource pool as the second memory segment, and the preset number is determined according to the number of memory segments corresponding to the first water level and the number of memory segments corresponding to the third water level.

[0120] Among them, if the water level information after the first memory segment is returned is still higher than the first water level, the second memory segment is determined. The memory segments in the free memory segment resource pool are sorted in descending order according to the holding time, and the preset number of memory segments with the highest ranking, that is, the preset number of memory segments with the longest holding time, are used as the second memory segments. In order to maintain the water level information at the first water level, the preset number is the difference between the number of memory segments corresponding to the third water level and the number of memory segments corresponding to the first water level.

[0121] In the above embodiment, the preset number of second memory segments are determined according to the holding time of each memory segment, and the second memory segments are returned, so that the water level of the free memory segment resource pool can be maintained at the first water level.

[0122] In one embodiment, in order to reduce the waste of task resources, such as Figure 8 shown, the method further includes:

[0123] Step 801, determine whether there is currently a memory segment return task.

[0124] Step 802, if there is currently no memory segment return task, perform the memory segment return operation.

[0125] If there is currently no memory segment return task, trigger the memory segment return task and perform the memory segment return operation to avoid duplicate delivery of tasks and waste of task resources. If there is currently a memory segment return task, wait for the current memory segment return task to end. Optionally, the process of the above memory segment return task can be as Figure 9 shown. Determine whether the memory segment return task is idle. If it is idle, it means that there is currently no memory segment return task; otherwise, the current memory segment return task is in progress, and wait for the existing memory segment return task to end. Then, determine whether the return condition is met. The memory segments that meet the return condition are determined as the first memory segments and added to the memory segment resource pool to be returned. Then, determine whether the water level information of the free memory segment resource pool is higher than the third water level. If so, determine the second memory segments and add them to the memory segment resource pool to be returned, and perform the return of the memory segments. If there are no memory segments that meet the return condition, that is, there are no first memory segments, then determine whether the water level information of the free memory segment resource pool is higher than the third water level. If the water level information of the free memory segment resource pool is not higher than the third water level, loop to determine whether there are currently memory segments that meet the return condition.

[0126] In the above embodiment, by determining whether there is currently a memory segment return task and determining whether to perform the memory segment return operation, through a single task mode, excessive consumption of task resources is avoided.

[0127] In one embodiment, before applying for a new memory segment and adding it to the free memory segment resource pool, as Figure 10 shown, it includes:

[0128] Step 1001: Determine whether there is a memory segment application task currently.

[0129] Step 1002: If there is no memory segment application task currently, then execute the step of applying for a new memory segment and adding it to the free memory segment resource pool.

[0130] If there is no memory segment application task currently, then trigger a memory segment application task and execute the operation of applying for a new memory segment. Each time a memory segment is applied for, it can be used for the memory application requests of multiple IO operations. When multiple IO operations simultaneously detect a shortage of memory segments, only one of the IO operations needs to initiate a memory application task once, and the other IO operations can join the waiting queue. If there is a memory segment application task currently, then wait for the current memory application task to end to avoid waste of task resources caused by repeated submission of tasks. If all IO operations initiate memory segment application tasks, it will also lead to a decrease in the performance of IO operations.

[0131] Optionally, the process of the above memory segment application task can be as Figure 11 shown. Among them, the waiting queue is the queue of IO tasks. When an IO operation needs to apply for memory, it initiates a memory application request, determines whether the memory segment application task is idle. If it is, then determines whether the water level information is lower than the second water level. If so, applies for a memory segment to join the free memory segment resource pool and wakes up all IOs in the waiting queue. If the memory segment application task is not idle, then waits for the task to end. If the water level information is not lower than the second water level, then determines whether there is a memory application request waiting. If so, that is, some memory application requests do not have a qualified target memory segment, then applies for a memory segment to join the free memory segment resource pool, otherwise ends.

[0132] In the above embodiment, by determining whether there is a memory segment application task currently to determine whether to execute the memory segment application operation, the single-task mode is adopted to avoid excessive consumption of task resources.

[0133] In the embodiment of the present application, as Figure 12 shown, a memory allocation method is provided, including:

[0134] Step 1201: After receiving a memory application request, determine whether there is a target memory segment in the free memory segment resource pool.

[0135] Step 1202: If there is a target memory segment, then allocate memory for the memory application request according to the target memory page in the target memory segment.

[0136] Step 1203: Obtain the water level information of the free memory segment resource pool.

[0137] Step 1204, when the water level information is lower than the preset second water level, apply for a new memory segment through an asynchronous application method and add it to the free memory segment resource pool, so that the water level of the free memory segment resource pool reaches the preset first water level.

[0138] Step 1205, if there is no target memory segment, apply for a new memory segment through a synchronous application method and add it to the free memory segment resource pool, so that the water level of the free memory segment resource pool reaches the preset first water level.

[0139] Step 1206, after applying for a new memory segment or after reaching the scheduled time, determine the first memory segment in the free memory segment resource pool and perform a memory segment return operation on the first memory segment.

[0140] Step 1207, obtain the current water level information of the free memory segment resource pool.

[0141] Step 1208, if the current water level information is higher than the preset third water level, determine the second memory segment in the free memory segment resource pool and perform a memory segment return operation on the second memory segment.

[0142] In the embodiments of the present application, the above memory allocation method may include an IO task module, a memory segment application task module, a memory segment return task module, a free memory segment management linked list, and a to-be-returned memory segment management linked list. The interaction between each module and linked list is as Figure 13 shown. Each service module applies for and returns memory to the memory management module in terms of memory segments, and uses the memory application requests for IO operations allocated to the service module in terms of memory pages.

[0143] Among them, the life cycle of the memory segment can be as Figure 14 shown. The applied memory segment is added to the free memory segment resource pool, allocated for use by the memory application request. After applying for a new memory segment or after reaching the scheduled time, the memory segment to be returned is added to the to-be-returned memory segment resource pool for memory segment return. The process of the memory application request for the IO task is as Figure 15 shown. Upon receiving the memory application request for IO, traverse the free memory segment resource pool to find the target memory segment. If the target memory segment is found, allocate the target memory page to the memory application request, and trigger the memory segment asynchronous application task when the current water level information is lower than the low water level. If there is no available target memory segment, trigger the memory segment synchronous application task. After the memory segment application task is successfully applied, trigger the memory segment return task.

[0144] It should be understood that although the steps in the flowcharts involved in the above-described embodiments are shown in sequence according to the indications of the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise clearly stated in this article, the execution of these steps has no strict order limit, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-described embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be executed alternately or in turn with at least a part of other steps or steps or stages in other steps.

[0145] Based on the same inventive concept, an embodiment of the present application further provides a memory allocation device for implementing the above-mentioned memory allocation method. The solution provided by this device to solve the problem is similar to the solution described in the above method. Therefore, the specific limitations in one or more embodiments of the memory allocation device provided below can refer to the limitations on the memory allocation method in the above text, and will not be repeated here.

[0146] In an exemplary embodiment, as Figure 16 shown, a memory allocation device 1600 is provided, including: a judgment module 1601, an allocation module 1602, an acquisition module 1603, and an application module 1604, where:

[0147] The judgment module 1601 is configured to judge whether there is a target memory segment in the free memory segment resource pool after receiving a memory application request, and the target memory segment is a memory segment in which the currently unused memory pages meet the memory application request;

[0148] The allocation module 1602 is configured to, if there is a target memory segment, allocate memory for the memory application request according to the target memory pages in the target memory segment, where the target memory pages are the unused memory pages in the target memory segment;

[0149] The acquisition module 1603 is configured to acquire the water level information of the free memory segment resource pool, and the water level information is used to characterize the number of memory segments in the free memory segment resource pool;

[0150] The application module 1604 is configured to apply for a new memory segment and add it to the free memory segment resource pool when the water level information meets a preset condition.

[0151] In one embodiment, the device further includes a synchronization application module 1604, configured to, if there is no target memory segment, apply for a new memory segment through a synchronization application method and add it to the free memory segment resource pool, so that the water level of the free memory segment resource pool reaches a preset first water level; after the application is successful, continue to execute the step of determining whether there is a target memory segment in the free memory segment resource pool.

[0152] In one embodiment, the application module 1604 is specifically configured to, when the water level information is lower than a preset second water level, apply for a new memory segment through an asynchronous application method and add it to the free memory segment resource pool, so that the water level of the free memory segment resource pool reaches a preset first water level, and the second water level is lower than the first water level.

[0153] In one embodiment, the device further includes a return module, configured to determine a first memory segment in the free memory segment resource pool and perform a memory segment return operation on the first memory segment; obtain the current water level information of the free memory segment resource pool; if the current water level information is higher than a preset third water level, determine a second memory segment in the free memory segment resource pool and perform a memory segment return operation on the second memory segment, and the third water level is higher than the first water level.

[0154] In one embodiment, the return module is specifically configured to, after applying for a new memory segment or after reaching a timing time, determine a first memory segment in the free memory segment resource pool and perform a memory segment return operation on the first memory segment.

[0155] In one embodiment, the return module is specifically configured to determine a first candidate memory segment from the free memory segment resource pool, where the holding time of the first candidate memory segment is greater than a first time threshold; determine a second candidate memory segment from the free memory segment resource pool, where the number of remaining memory pages of the second candidate memory segment is less than a preset number of memory pages and the holding time is greater than a second time threshold; use the first candidate memory segment and the second candidate memory segment as the first memory segment.

[0156] In one embodiment, the return module is specifically configured to determine a preset number of memory segments with the longest holding time from the free memory segment resource pool as the second memory segment, and the preset number is determined according to the number of memory segments corresponding to the first water level and the number of memory segments corresponding to the third water level.

[0157] In one embodiment, the return module is specifically configured to add the memory segment to be returned to the memory segment resource pool to be returned.

[0158] In one embodiment, the device further includes a task judgment module 1601, configured to judge whether there is a memory segment return task currently; if there is no memory segment return task currently, perform a memory segment return operation.

[0159] In one embodiment, the application module 1604 is specifically configured to determine whether there is a memory segment application task currently; if there is no memory segment application task currently, then perform the steps of applying for a new memory segment and adding it to the free memory segment resource pool.

[0160] Each module in the above memory allocation device can be implemented in whole or in part by software, hardware, and their combination. The above modules can be embedded in the processor in the computer device in hardware form or independent of the processor, or stored in the memory in the computer device in software form, so that the processor can call and execute the operations corresponding to the above modules.

[0161] In an exemplary embodiment, a computer device is provided. The computer device can be a server, and its internal structure diagram can be as Figure 17 shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, abbreviated as I / O), and a communication interface. Among them, the processor, the memory, and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store memory data. The input / output interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with external terminals through a network connection. When the computer program is executed by the processor, it implements a memory allocation method.

[0162] Those skilled in the art can understand that Figure 17 the structure shown in

[0163] In an exemplary embodiment, a computer device is provided, including a memory and a processor. A computer program is stored in the memory. When the processor executes the computer program, the following steps are implemented: after receiving a memory application request, determine whether there is a target memory segment in the free memory segment resource pool, where the target memory segment is a memory segment in which the currently unused memory pages meet the memory application request; if there is a target memory segment, allocate memory for the memory application request according to the target memory pages in the target memory segment, where the target memory pages are the unused memory pages in the target memory segment; obtain the water level information of the free memory segment resource pool, and the water level information is used to characterize the number of memory segments in the free memory segment resource pool; when the water level information meets a preset condition, apply for a new memory segment and add it to the free memory segment resource pool.

[0164] In an embodiment, when the processor executes the computer program, the following steps are further implemented: if there is no target memory segment, apply for a new memory segment through a synchronous application method and add it to the free memory segment resource pool to make the water level of the free memory segment resource pool reach a preset first water level; after the application is successful, continue to execute the step of determining whether there is a target memory segment in the free memory segment resource pool.

[0165] In an embodiment, when the processor executes the computer program, the following steps are further implemented: when the water level information is lower than a preset second water level, apply for a new memory segment through an asynchronous application method and add it to the free memory segment resource pool to make the water level of the free memory segment resource pool reach a preset first water level, and the second water level is lower than the first water level.

[0166] In an embodiment, when the processor executes the computer program, the following steps are further implemented: determine a first memory segment in the free memory segment resource pool and perform a memory segment return operation on the first memory segment; obtain the current water level information of the free memory segment resource pool; if the current water level information is higher than a preset third water level, determine a second memory segment in the free memory segment resource pool and perform a memory segment return operation on the second memory segment, and the third water level is higher than the first water level.

[0167] In an embodiment, when the processor executes the computer program, the following steps are further implemented: after applying for a new memory segment or after reaching the timing time, determine a first memory segment in the free memory segment resource pool and perform a memory segment return operation on the first memory segment.

[0168] In one embodiment, when the processor executes a computer program, the following steps are further implemented: determining a first candidate memory segment from the free memory segment resource pool, where the holding time of the first candidate memory segment is greater than a first time threshold; determining a second candidate memory segment from the free memory segment resource pool, where the number of remaining memory pages of the second candidate memory segment is less than a preset number of memory pages and the holding time is greater than a second time threshold; and using the first candidate memory segment and the second candidate memory segment as the first memory segment.

[0169] In one embodiment, when the processor executes a computer program, the following steps are further implemented: determining a preset number of memory segments with the longest holding times from the free memory segment resource pool as the second memory segment, where the preset number is determined according to the number of memory segments corresponding to a first water level and the number of memory segments corresponding to a third water level.

[0170] In one embodiment, when the processor executes a computer program, the following steps are further implemented: adding the memory segment to be returned to the memory segment resource pool to be returned.

[0171] In one embodiment, when the processor executes a computer program, the following steps are further implemented: determining whether there is a memory segment return task currently; if there is no memory segment return task currently, then performing a memory segment return operation.

[0172] In one embodiment, when the processor executes a computer program, the following steps are further implemented: determining whether there is a memory segment application task currently; if there is no memory segment application task currently, then performing the steps of applying for a new memory segment and adding it to the free memory segment resource pool.

[0173] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented: after receiving a memory application request, determining whether there is a target memory segment in the free memory segment resource pool, where the target memory segment is a memory segment whose currently unused memory pages meet the memory application request; if there is a target memory segment, then allocating memory for the memory application request according to the target memory pages in the target memory segment, where the target memory pages are the unused memory pages in the target memory segment; obtaining the water level information of the free memory segment resource pool, where the water level information is used to characterize the number of memory segments in the free memory segment resource pool; and applying for a new memory segment and adding it to the free memory segment resource pool when the water level information meets a preset condition.

[0174] In one embodiment, when the computer program is executed by the processor, the following steps are further implemented: if there is no target memory segment, then applying for a new memory segment by a synchronous application method and adding it to the free memory segment resource pool to make the water level of the free memory segment resource pool reach a preset first water level; and after the application is successful, continuing to execute the step of determining whether there is a target memory segment in the free memory segment resource pool.

[0175] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented: when the water level information is lower than a preset second water level, apply for a new memory segment through an asynchronous application method and add it to the free memory segment resource pool, so that the water level of the free memory segment resource pool reaches a preset first water level, and the second water level is lower than the first water level.

[0176] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented: determine a first memory segment in the free memory segment resource pool, and perform a memory segment return operation on the first memory segment; obtain the current water level information of the free memory segment resource pool; if the current water level information is higher than a preset third water level, determine a second memory segment in the free memory segment resource pool, and perform a memory segment return operation on the second memory segment, and the third water level is higher than the first water level.

[0177] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented: after applying for a new memory segment or after reaching a timing time, determine a first memory segment in the free memory segment resource pool, and perform a memory segment return operation on the first memory segment.

[0178] In one embodiment, when the processor executes the computer program, the following steps are further implemented: determine a first candidate memory segment from the free memory segment resource pool, and the holding time of the first candidate memory segment is greater than a first time threshold; determine a second candidate memory segment from the free memory segment resource pool, and the number of remaining memory pages of the second candidate memory segment is less than a preset number of memory pages, and the holding time is greater than a second time threshold; use the first candidate memory segment and the second candidate memory segment as the first memory segment.

[0179] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented: determine a preset number of memory segments with the longest holding time from the free memory segment resource pool as the second memory segment, and the preset number is determined according to the number of memory segments corresponding to the first water level and the number of memory segments corresponding to the third water level.

[0180] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented: add the memory segment to be returned to the memory segment resource pool to be returned.

[0181] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented: determine whether there is a memory segment return task currently; if there is no memory segment return task currently, perform a memory segment return operation.

[0182] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented: determine whether there is a memory segment application task currently; if there is no memory segment application task currently, perform the steps of applying for a new memory segment and adding it to the free memory segment resource pool.

[0183] In one embodiment, a computer program product is provided, including a computer program which, when executed by a processor, implements the following steps: after receiving a memory application request, determine whether there is a target memory segment in the free memory segment resource pool, where the target memory segment is a memory segment in which the currently unused memory pages meet the memory application request; if there is a target memory segment, allocate memory for the memory application request according to the target memory pages in the target memory segment, where the target memory pages are the unused memory pages in the target memory segment; obtain the water level information of the free memory segment resource pool, where the water level information is used to represent the number of memory segments in the free memory segment resource pool; and when the water level information meets a preset condition, apply for a new memory segment and add it to the free memory segment resource pool.

[0184] In one embodiment, when the computer program is executed by the processor, it further implements the following steps: if there is no target memory segment, apply for a new memory segment by means of synchronous application and add it to the free memory segment resource pool to make the water level of the free memory segment resource pool reach a preset first water level; after the application is successful, continue to execute the step of determining whether there is a target memory segment in the free memory segment resource pool.

[0185] In one embodiment, when the computer program is executed by the processor, it further implements the following steps: when the water level information is lower than a preset second water level, apply for a new memory segment by means of asynchronous application and add it to the free memory segment resource pool to make the water level of the free memory segment resource pool reach the preset first water level, where the second water level is lower than the first water level.

[0186] In one embodiment, when the computer program is executed by the processor, it further implements the following steps: determine a first memory segment in the free memory segment resource pool and perform a memory segment return operation on the first memory segment; obtain the current water level information of the free memory segment resource pool; if the current water level information is higher than a preset third water level, determine a second memory segment in the free memory segment resource pool and perform a memory segment return operation on the second memory segment, where the third water level is higher than the first water level.

[0187] In one embodiment, when the computer program is executed by the processor, it further implements the following steps: after applying for a new memory segment or after reaching a timing time, determine a first memory segment in the free memory segment resource pool and perform a memory segment return operation on the first memory segment.

[0188] In one embodiment, when the processor executes the computer program, the following steps are further implemented: determining a first candidate memory segment from the free memory segment resource pool, where the holding time of the first candidate memory segment is greater than a first time threshold; determining a second candidate memory segment from the free memory segment resource pool, where the number of remaining memory pages of the second candidate memory segment is less than a preset number of memory pages, and the holding time is greater than a second time threshold; using the first candidate memory segment and the second candidate memory segment as a first memory segment.

[0189] In one embodiment, when the computer program is executed by the processor, the following steps are further implemented: determining a preset number of memory segments with the longest holding time from the free memory segment resource pool as a second memory segment, where the preset number is determined according to the number of memory segments corresponding to a first water level and the number of memory segments corresponding to a third water level.

[0190] In one embodiment, when the computer program is executed by the processor, the following steps are further implemented: adding the memory segment to be returned to the memory segment resource pool to be returned.

[0191] In one embodiment, when the computer program is executed by the processor, the following steps are further implemented: determining whether there is a memory segment return task currently; if there is no memory segment return task currently, then performing a memory segment return operation.

[0192] In one embodiment, when the computer program is executed by the processor, the following steps are further implemented: determining whether there is a memory segment application task currently; if there is no memory segment application task currently, then performing the steps of applying for a new memory segment and adding it to the free memory segment resource pool.

[0193] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use, and processing of relevant data need to comply with relevant regulations.

[0194] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, database, or other medium used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The databases involved in the embodiments provided in this application can include at least one of relational databases and non-relational databases. Non-relational databases can include distributed databases based on blockchain, etc., and are not limited thereto. The processors involved in the embodiments provided in this application can be general-purpose processors, central processors, graphics processors, digital signal processors, programmable logic devices, data processing logics based on quantum computing, artificial intelligence (AI) processors, etc., and are not limited thereto.

[0195] The technical features of the above embodiments can be combined arbitrarily. For the sake of concise description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as within the scope recorded in this application.

[0196] The above-described embodiments merely represent several implementation manners of the present application. The description thereof is relatively specific and detailed, but it should not be construed as a limitation on the patent scope of the present application. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all fall within the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the appended claims.

Claims

1. A memory allocation method, characterized in that, The method includes: After receiving a memory application request, determining whether there is a target memory segment in the free memory segment resource pool, where the target memory segment is a memory segment in which the currently unused memory pages meet the memory application request; If there is the target memory segment, allocating memory for the memory application request according to the target memory pages in the target memory segment, where the target memory pages are the unused memory pages in the target memory segment; Obtaining the water level information of the free memory segment resource pool, where the water level information is used to characterize the number of memory segments in the free memory segment resource pool; When the water level information meets a preset condition, applying for a new memory segment and adding it to the free memory segment resource pool.

2. The method according to claim 1, wherein The method further includes: If there is no such target memory segment, applying for a new memory segment by means of synchronous application and adding it to the free memory segment resource pool to make the water level of the free memory segment resource pool reach a preset first water level; After the application is successful, continue to execute the step of determining whether there is the target memory segment in the free memory segment resource pool.

3. The method according to claim 1, wherein The step of, when the water level information meets a preset condition, applying for a new memory segment and adding it to the free memory segment resource pool includes: When the water level information is lower than a preset second water level, applying for a new memory segment by means of asynchronous application and adding it to the free memory segment resource pool to make the water level of the free memory segment resource pool reach a preset first water level, where the second water level is lower than the first water level.

4. The method according to claim 2 or 3, characterized in that, The method further includes: Determining a first memory segment in the free memory segment resource pool and performing a memory segment return operation on the first memory segment; Obtaining the current water level information of the free memory segment resource pool; If the current water level information is higher than a preset third water level, determining a second memory segment in the free memory segment resource pool and performing a memory segment return operation on the second memory segment, where the third water level is higher than the first water level.

5. The method according to claim 4, wherein Before determining the first memory segment in the free memory segment resource pool and performing the memory segment return operation on the first memory segment, it includes: After applying for a new memory segment or after reaching a timing time, determining a first memory segment in the free memory segment resource pool and performing a memory segment return operation on the first memory segment.

6. The method according to claim 4, wherein The step of determining the first memory segment in the free memory segment resource pool includes: Determining a first candidate memory segment from the free memory segment resource pool, where the holding time of the first candidate memory segment is greater than a first time threshold; Determining a second candidate memory segment from the free memory segment resource pool, where the number of remaining memory pages of the second candidate memory segment is less than a preset number of memory pages and the holding time is greater than a second time threshold; Taking the first candidate memory segment and the second candidate memory segment as the first memory segment.

7. The method according to claim 4, wherein The step of determining the second memory segment in the free memory segment resource pool includes: Determine a preset number of memory segments with the longest holding time from the free memory segment resource pool as the second memory segments, where the preset number is determined according to the number of memory segments corresponding to the first water level and the number of memory segments corresponding to the third water level.

8. The method according to claim 4, wherein The memory segment return operation includes: Adding the memory segment to be returned to the memory segment resource pool to be returned.

9. The method according to claim 4, characterized in that The method further includes: Judging whether there is a memory segment return task currently; If there is no memory segment return task currently, then execute the memory segment return operation.

10. The method according to claim 1, characterized in that, The applying for a new memory segment and adding it to the free memory segment resource pool includes: Judging whether there is a memory segment application task currently; If there is no memory segment application task currently, then execute the step of applying for a new memory segment and adding it to the free memory segment resource pool.

11. A memory allocation device, characterized in that, The device includes: A judging module, configured to judge whether there is a target memory segment in the free memory segment resource pool after receiving a memory application request, where the target memory segment is a memory segment whose currently unused memory pages meet the memory application request; An allocation module, configured to, if there is the target memory segment, allocate memory for the memory application request according to the target memory pages in the target memory segment, where the target memory pages are the unused memory pages in the target memory segment; An obtaining module, configured to obtain the water level information of the free memory segment resource pool, where the water level information is used to characterize the number of memory segments in the free memory segment resource pool; An application module, configured to, when the water level information meets a preset condition, apply for a new memory segment and add it to the free memory segment resource pool.

12. A computer device, comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, the steps of the method according to any one of claims 1 to 10 are implemented.

13. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, the steps of the method according to any one of claims 1 to 10 are implemented.

14. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, the steps of the method according to any one of claims 1 to 10 are implemented.