Memory allocation method and device, electronic equipment and storage medium

Through large-page perception memory allocator and dynamic threshold adjustment, combined with incompletely allocated memory pages, preset memory page collections and cached memory allocation strategies, the problem of inefficiency of traditional memory allocators is solved, and fast response and efficient memory management are achieved.

CN120371724AActive Publication Date: 2025-07-25LANGCHAO ELECTRONIC INFORMATION IND CO LTD

Patent Information

Application Number
CN202510866089.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-26
Publication Date
2025-07-25
Estimated Expiration
2045-06-26

AI Technical Summary

Technical Problem

Traditional user-mode memory allocators are inefficient when handling large-scale memory requests, especially in severe memory fragmentation environments, finding free blocks of appropriate sizes takes a long time, affecting system performance.

Method used

Using a memory allocator based on large page perception, through dynamic threshold adjustment and efficient memory release strategy, combining incompletely allocated memory pages, preset memory page collections, caches and free memory pages of the operating system, flexibly responds to memory applications of different sizes, reduces memory fragmentation and improves memory utilization.

Benefits of technology

Improves the speed and accuracy of memory allocation, reduces the generation of memory fragmentation, improves memory utilization and system performance, especially when facing memory requests of different sizes, can respond quickly.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120371724A_ABST
    Figure CN120371724A_ABST
Patent Text Reader

Abstract

The invention discloses a memory allocation method and device, electronic equipment and a storage medium, and relates to the technical field of computers.The method comprises the steps that when a memory application of a requester is received, the memory size requested by the memory application is determined; if the memory size is smaller than or equal to the first threshold value, responding to the memory application based on the memory page which is not completely allocated; wherein the size of the memory page is larger than or equal to a preset value, and the first threshold value is smaller than the size of the memory page; if the memory size is greater than the first threshold and less than or equal to a second threshold, responding to the memory application based on an idle memory page in a preset memory page set; wherein the second threshold value is larger than the size of the memory page; and if the memory size is greater than the second threshold value, responding to the memory application based on the unreleased idle memory page of the cache and / or the idle memory page in the operating system. The memory allocation efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular, to a memory allocation method, apparatus, electronic device, and storage medium. Background Art

[0002] In the current computer system, memory management is crucial to ensure efficient operation. However, traditional user-mode memory allocators expose significant problems when dealing with large-scale memory requests. Especially during the process of finding a suitable free block to respond to a memory application, these allocators show low efficiency. Due to the adoption of a fixed allocation strategy, they become particularly inflexible when dealing with large memory blocks, especially in an environment with severe memory fragmentation. Sequentially searching for a free block of the appropriate size takes a long time, greatly reducing the efficiency of memory allocation. With the continuous increase in the scale and complexity of application programs, the demand for memory shows an explosive growth, and this inefficient memory allocation method has increasingly become an important factor restricting system performance.

[0003] Therefore, how to improve the efficiency of memory allocation is a technical problem that needs to be solved by those skilled in the art. Summary of the Invention

[0004] The present invention provides a memory allocation method, apparatus, electronic device, and storage medium, which improve the efficiency of memory allocation.

[0005] The present invention provides a memory allocation method, including: when receiving a memory application from a requester, determining the size of the memory requested by the memory application; if the size of the memory is less than or equal to a first threshold, responding to the memory application based on an incompletely allocated memory page; wherein, the size of the memory page is greater than or equal to a preset value, and the first threshold is less than the size of the memory page; if the size of the memory is greater than the first threshold and less than or equal to a second threshold, responding to the memory application based on a free memory page in a preset memory page set; wherein, the second threshold is greater than the size of the memory page; if the size of the memory is greater than the second threshold, responding to the memory application based on a cached unreleased free memory page and / or a free memory page in the operating system.

[0006] The present invention also provides a memory allocation device, including: a determination module, configured to determine the memory size requested by the memory application when receiving a memory application from a requester; a first response module, configured to respond to the memory application based on unallocated memory pages when the memory size is less than or equal to a first threshold; wherein, the size of the memory page is greater than or equal to a preset value, and the first threshold is less than the size of the memory page; a second response module, configured to respond to the memory application based on free memory pages in a preset memory page set when the memory size is greater than the first threshold and less than or equal to a second threshold; wherein, the second threshold is greater than the size of the memory page; a third response module, configured to respond to the memory application based on cached unreleased free memory pages and / or free memory pages in the operating system when the memory size is greater than the second threshold.

[0007] The present invention also provides an electronic device, including: a memory, configured to store a computer program; a processor, configured to implement the steps of any of the above memory allocation methods when executing the computer program.

[0008] The present invention also provides a computer-readable storage medium, in which a computer program is stored, and wherein the computer program implements the steps of any of the above memory allocation methods when executed by a processor.

[0009] The present invention also provides a computer program product, including a computer program, and the computer program implements the steps of any of the above memory allocation methods when executed by a processor.

[0010] The beneficial effects of the present invention are as follows: The memory allocation method provided by the present invention realizes flexible response to different types of memory applications. For smaller memory requests, it responds based on unallocated large-page memories, reducing the generation of memory fragmentation, improving the search efficiency of memory blocks, and increasing the internal utilization rate of memory. For memory requests between the first and second thresholds, the requirements are met by free memory pages in the preset memory page set. This method helps to quickly respond to medium-sized memory requirements while maintaining the stability of the system. When facing large-scale memory requests greater than the second threshold, it relies on cached or free memory pages provided by the operating system to handle them, ensuring that continuous large memory requests can be responded to in a timely manner. In this way, not only does it solve the problem of time-consuming and inefficient search for suitable free blocks in traditional memory allocators, but also significantly improves the speed and accuracy of memory allocation. The present invention also discloses a memory allocation device, an electronic device, a computer-readable storage medium, and a computer program product, which can also achieve the above technical effects.

[0011] It should be understood that the above general description and subsequent detailed description are only exemplary and do not limit the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] To more clearly illustrate the embodiments of the present invention, the following will briefly introduce the drawings required in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0013] Figure 1 It is a flowchart of a memory allocation method shown according to an exemplary embodiment.

[0014] Figure 2 It is a flowchart of a method for adjusting a first threshold shown according to an exemplary embodiment.

[0015] Figure 3 It is a schematic diagram of the memory allocation process in the application embodiment provided by the present invention.

[0016] Figure 4 It is a schematic diagram of the dynamic threshold adjustment process in the application embodiment provided by the present invention.

[0017] Figure 5 It is a schematic diagram of the memory release process in the application embodiment provided by the present invention.

[0018] Figure 6 It is a schematic diagram of the memory return process based on a sliding window in the application embodiment provided by the present invention.

[0019] Figure 7 It is a structural diagram of a memory allocation device shown according to an exemplary embodiment.

[0020] Figure 8 It is a structural diagram of an electronic device shown according to an exemplary embodiment. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0021] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, rather than all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the protection scope of the present invention.

[0022] It should be noted that in the description of the present invention, the terms "comprising", "including" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or elements inherent to such process, method, article or device. The terms "first", "second", etc. in the present invention are used to distinguish similar objects, rather than to describe a specific order or sequence.

[0023] In the related art, there are many drawbacks in memory utilization by memory allocators, and excessive memory fragmentation is a major problem. With the continuous execution of memory allocation and release operations, a large number of small and scattered free memory blocks appear. These fragments cannot be effectively utilized, resulting in wasted memory space and reduced overall memory utilization. At the same time, the memory access latency caused by TLBmiss (Translation Lookaside Buffer Miss) also seriously affects system performance. Due to the large number of page table entries in the traditional memory management mode, TLBmiss frequently occurs during memory access, forcing the processor to spend extra time traversing the page table to obtain the physical address, increasing the memory access latency. Therefore, the present invention constructs a large-page-aware memory allocator, uses large-page memory to allocate space, reduces the generation of memory fragments, and reduces the TLBmiss probability due to the reduction of page table entries in large-page memory, effectively improving the memory utilization efficiency and solving the problems of excessive memory fragments and memory access latency caused by TLBmiss.

[0024] In addition, in the related art, most memory allocators adopt a fixed allocation strategy and lack adaptability when facing memory allocation requests of different sizes. They cannot make targeted responses to the memory requirements in different application scenarios. Moreover, many existing memory allocators generally adopt static threshold settings when dealing with large-page memory. Once the threshold for using large-page memory is set, it cannot be flexibly adjusted according to the actual memory usage during system operation. For example, in a scenario where the memory requirement is small at the initial stage of an application program and increases significantly later, the static threshold may cause the large-page memory to be enabled too early or too late, affecting the overall system performance. Therefore, the present invention's efficient memory allocation strategy based on dynamic threshold adjustment can execute different strategies according to allocation requests of different memory sizes, and by dynamically monitoring the memory allocation mode and adjusting the threshold in real time, the system can adaptively select the optimal memory allocation path, effectively solving the problem of the lack of flexibility in memory allocation strategies to meet diverse memory requirements.

[0025] Furthermore, in the related art, the release of large page memory faces a dilemma. Releasing idle large pages prematurely requires re-applying for memory through system calls and triggering page faults when allocating again later, which undoubtedly increases latency and affects the system response speed. Especially for latency-sensitive applications, it may cause a significant drop in their performance. On the other hand, releasing idle large pages too late results in waste of memory resources. In a memory-constrained system, such waste may lead to a sharp decline in system performance. The current memory allocator cannot effectively incorporate the released large page memory back into the allocable resource pool in a timely manner when dealing with large page memory recycling, or does not fully consider the characteristics such as the continuity and locality of large page memory during reallocation, resulting in low utilization of large page memory. Therefore, the present invention proposes an efficient memory release strategy, which effectively solves the problem of unreasonable large page memory release, accurately grasps the timing of large page memory release, avoids both the latency problem caused by premature release and the memory waste caused by late release, and improves the utilization efficiency of large page memory.

[0026] To enable those skilled in the art of this technology to better understand the solution of the present invention, the present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments.

[0027] An embodiment of the present invention provides a memory allocation method. In combination with the execution flow of the memory allocation method, the method will be described in detail. Refer to Figure 1 , a flowchart of a memory allocation method shown according to an exemplary embodiment.

[0028] S101: When receiving a memory application from a requester, determine the size of the memory requested by the memory application.

[0029] Among them, a memory application refers to an operation in which an application requests a memory allocator to allocate a certain size of memory space. The memory size refers to the specific capacity of the requested memory, usually in bytes (Byte).

[0030] In this step, when the memory allocator receives a memory application initiated by a requester (such as an application), it first needs to determine the size of the memory requested by this application. This step is completed by reading the parameters in the memory application. For example, when an application calls a memory allocation function, it will pass in a parameter representing the required memory size, and the memory allocator obtains the requested memory size by parsing this parameter.

[0031] S102: If the memory size is less than or equal to a first threshold, respond to the memory application based on unallocated memory pages; wherein, the size of the memory page is greater than or equal to a preset value, and the first threshold is less than the size of the memory page.

[0032] Among them, the first threshold is a preset memory size threshold used to distinguish small memory requests from larger ones. Unallocated memory pages: refer to memory pages that have been allocated to certain requesters but are not fully occupied. The size of a memory page refers to the basic unit size of memory pages in the system. In this embodiment, the memory pages are large inner pages, that is, the capacity is greater than or equal to a preset value, such as 2MB or 1GB, etc.

[0033] In a specific implementation, if the requested memory size is less than or equal to the first threshold, it indicates a small memory request. At this time, the first memory allocator is used to allocate a memory block for the requester from the memory pages managed by the first memory allocator; among them, the first memory allocator is used to manage unallocated memory pages. Specifically, the first memory allocator is used to record the remaining space of unallocated memory pages and the information of allocated memory blocks. Specifically, the first memory allocator will check if there is enough space in the existing unallocated memory pages to meet this request. If there is, a memory block of the required size is allocated from this memory page; if not, it may be necessary to obtain a new memory page from the cache or the operating system, add it to the unallocated memory pages, and then make the allocation.

[0034] For example, assume the size of a memory page is 2MB and the first threshold is set to 1MB. When a request for a memory size of 512KB is received, the first memory allocator will check the existing unallocated memory pages. If there is an unallocated memory page with 1MB of free space, then 512KB of memory can be allocated from this memory page to meet the request.

[0035] In this way, the existing unallocated memory pages can be fully utilized, reducing the generation of memory fragmentation and improving memory utilization. At the same time, it avoids frequently applying for new memory pages from the operating system, thereby reducing the overhead of system calls and improving the efficiency of memory allocation.

[0036] As a feasible implementation, it further includes: when the memory size is less than or equal to the first threshold and the memory pages managed by the first memory allocator cannot meet the memory request, it is determined whether there are free memory pages in the cache managed by the page manager; if so, a first target memory page is selected from the free memory pages in the cache, a memory block is allocated for the requester in the first target memory page, and the first target memory page is handed over to the first memory allocator for management; if not, a second target memory page is selected from the free memory pages in the operating system, a memory block is allocated for the requester in the second target memory page, and the second target memory page is handed over to the first memory allocator for management.

[0037] In a specific implementation, when the size of the memory application is less than or equal to the first threshold, and there is not enough space in the memory pages managed by the first memory allocator to satisfy the application, the system will further check whether there are free memory pages in the cache managed by the page manager. If there are free memory pages in the cache, the system will select a suitable memory page (referred to as the first target memory page), allocate the required memory block from it to the requester, and hand over this memory page to the first memory allocator for management so that subsequent memory allocation operations can continue to utilize this memory page. If there are no free memory pages in the cache, a new free memory page (referred to as the second target memory page) will be obtained from the operating system, the memory block will be allocated from it to the requester, and this memory page will be handed over to the first memory allocator for management. This strategy reduces frequent requests to the operating system by making full use of the free memory pages in the cache, and at the same time improves the flexibility and efficiency of memory allocation. Especially when dealing with small memory allocation requests, it can effectively reduce memory fragmentation and improve the overall performance of memory management.

[0038] S103: If the memory size is greater than the first threshold and less than or equal to the second threshold, then respond to the memory application based on the free memory pages in the preset memory page set; wherein, the second threshold is greater than the size of the memory page.

[0039] Among them, the second threshold is a preset memory size threshold used to distinguish medium-sized memory applications and large memory applications. The preset memory page set is a pre-allocated memory page set used to respond to medium-sized memory allocation requests.

[0040] In a specific implementation, if the requested memory size is greater than the first threshold and less than or equal to the second threshold, it indicates that this is a medium-sized memory application. At this time, the second memory allocator allocates memory blocks in one or more memory pages managed by the second memory allocator for the requester; wherein, the second memory allocator is used to manage the free memory pages in the preset memory page set. Specifically, the second memory allocator will check whether there are enough free memory pages in the preset memory page set to satisfy this application. If there are, memory blocks of the required size will be allocated from these free memory pages; if not, it may be necessary to obtain new memory pages from the cache or the operating system, add them to the preset memory page set, and then perform the allocation.

[0041] For example, assume that the size of the memory page is 2MB, the first threshold is 1MB, and the second threshold is 16MB. When receiving an application with a requested memory size of 8MB, the memory allocator will check the preset memory page set. If there are enough free memory pages in the set (for example, 4 free memory pages of 2MB), 8MB of memory can be allocated from them to satisfy the application.

[0042] It can be seen that by managing medium-sized memory requests through a dedicated set of pre-allocated memory pages, the efficiency and flexibility of memory allocation can be improved. At the same time, this approach can make better use of the continuity of memory pages, reduce the generation of memory fragmentation, and further improve memory utilization.

[0043] As a feasible implementation, after the second memory allocator allocates memory blocks in one or more memory pages managed by the second memory allocator for the requester, it further includes: if there are unallocated memory blocks in the memory pages allocated to the requester, the memory pages with unallocated memory blocks are handed over to the first memory allocator for management.

[0044] In a specific implementation, after using the second memory allocator (such as a large-granularity allocator) to allocate memory blocks for the requester, if there are still unallocated memory blocks in the memory pages allocated to the requester, then the memory pages with remaining space are handed over to the first memory allocator (such as a small-granularity allocator) for management. This mechanism can make full use of the remaining space of memory pages, avoid memory waste, and enable the small-granularity allocator to better manage these fragmented memory spaces, thereby improving memory utilization and allocation efficiency.

[0045] As a feasible implementation, it further includes: when the memory size is greater than the first threshold and less than or equal to the second threshold, if the memory pages managed by the second memory allocator cannot meet the memory request, it is determined whether there are idle memory pages in the cache managed by the page manager that can meet the memory request; if so, one or more third target memory pages are selected from the idle memory pages in the cache, and memory blocks are allocated for the requester in one or more of the third target memory pages; if not, one or more fourth target memory pages are selected from the idle memory pages in the operating system, and memory blocks are allocated for the requester in one or more of the fourth target memory pages.

[0046] In a specific implementation, when the size of the memory request is greater than the first threshold and less than or equal to the second threshold, if the memory pages managed by the second memory allocator cannot meet the memory request, the system will further check whether there are idle memory pages in the cache managed by the page manager that can meet the request. If there are suitable idle memory pages in the cache, one or more third target memory pages are selected for allocation; if not, one or more fourth target memory pages are selected from the operating system for allocation. This mechanism reduces the frequent calls to the operating system by preferentially using the idle memory pages in the page manager's cache, and at the same time can quickly respond to medium-sized memory requests, improving the efficiency and flexibility of memory allocation.

[0047] As a feasible implementation manner, after allocating memory blocks for the requester in one or more of the third target memory pages, it further includes: if there are unallocated memory blocks in the third target memory pages allocated to the requester, handing over the third target memory pages with unallocated memory blocks to the first memory allocator for management; correspondingly, after allocating memory blocks for the requester in one or more of the fourth target memory pages, it further includes: if there are unallocated memory blocks in the fourth target memory pages allocated to the requester, handing over the fourth target memory pages with unallocated memory blocks to the first memory allocator for management.

[0048] In a specific implementation, after allocating memory blocks in the third target memory page or the fourth target memory page for the requester, if there are still unallocated memory blocks in these target memory pages, then hand over these memory pages with remaining space to the first memory allocator for management. This mechanism ensures that the remaining space of the memory pages can be fully utilized, avoiding the problem of memory fragmentation. By handing over these memory pages to the small-granularity allocator for management, it can better meet subsequent small memory requests, further optimize the collaborative work of the memory allocator, and improve the performance and efficiency of the overall memory management.

[0049] S104: If the memory size is greater than the second threshold, respond to the memory request based on the un-released free memory pages in the cache and / or the free memory pages in the operating system.

[0050] Among them, the un-released free memory pages in the cache refer to the memory pages that were previously allocated and then released, and these memory pages are cached for subsequent reuse. The free memory pages in the operating system refer to the memory pages that the operating system has not currently allocated to any process.

[0051] In a specific implementation, if the requested memory size is greater than the second threshold, it indicates that this is a large memory request. At this time, use the page manager to allocate memory blocks in multiple memory pages for the requester from the un-released free memory pages in the cache, and / or use the resource allocator to allocate memory blocks in multiple memory pages for the requester from the free memory pages in the operating system. Specifically, the page manager will first check whether there are enough free memory pages in the cache to meet this request. If so, directly allocate the required memory pages from the cache; if there are not enough free memory pages, apply for new memory pages from the operating system through the resource allocator, add them to the cache, and then perform the allocation.

[0052] For example, assume that the size of a memory page is 2MB and the second threshold is 16MB. When a request for 32MB of memory is received, the memory allocator checks the cache. If there are 16 free memory pages of 2MB in the cache, these memory pages can be directly allocated from the cache to satisfy the request. If there are only 8 free memory pages of 2MB in the cache, 8 additional memory pages of 2MB need to be requested from the operating system through a system call, and then these memory pages are allocated to the requester.

[0053] In this way, the free memory pages in the cache can be fully utilized, reducing the frequent calls to the operating system, thereby reducing the overhead of system calls. At the same time, for large memory requests, continuous memory pages can be quickly allocated, improving the efficiency and performance of memory allocation.

[0054] As a feasible implementation, using a page manager to allocate memory blocks in multiple memory pages for the requester from the unreleased free memory pages in the cache, and / or using a resource allocator to allocate memory blocks in multiple memory pages for the requester from the free memory pages in the operating system, includes: determining whether the number of free memory pages in the cache managed by the page manager meets the memory request; if so, selecting multiple fifth target memory pages from the free memory pages in the cache and allocating memory blocks for the requester among the multiple fifth target memory pages; if not, selecting multiple sixth target memory pages from the free memory pages in the operating system and allocating memory blocks for the requester among the multiple sixth target memory pages.

[0055] In a specific implementation, when allocating memory blocks in multiple memory pages for the requester, first use the page manager to check whether there are enough free memory pages in the cache it manages to meet the memory request. If the number of free memory pages in the cache is sufficient, select multiple fifth target memory pages from these free memory pages in the cache and allocate the required memory blocks for the requester among these memory pages. If the number of free memory pages in the cache is insufficient, select multiple sixth target memory pages from the operating system through the resource allocator and allocate memory blocks for the requester among these memory pages. This mechanism reduces the frequent calls to the operating system by preferentially using the free memory pages in the page manager cache, and at the same time can quickly respond to large memory requests, improving the efficiency and flexibility of memory allocation.

[0056] As a feasible implementation manner, after allocating memory blocks for the requester in multiple said fifth target memory pages, it further includes: if there are unallocated memory blocks in the fifth target memory pages allocated to the requester, then hand over the fifth target memory pages with unallocated memory blocks to the first memory allocator for management; correspondingly, after allocating memory blocks for the requester in multiple said sixth target memory pages, it further includes: if there are unallocated memory blocks in the sixth target memory pages allocated to the requester, then hand over the sixth target memory pages with unallocated memory blocks to the first memory allocator for management.

[0057] In specific implementation, after allocating memory blocks for the requester in multiple fifth target memory pages or sixth target memory pages, if there are still unallocated memory blocks in these target memory pages, then hand over these memory pages with remaining space to the first memory allocator (such as a small-granularity allocator) for management. This mechanism ensures that the remaining space of the memory pages can be fully utilized, avoiding the problem of memory fragmentation. By handing over these memory pages to the first memory allocator for management, it can better meet subsequent small memory requests, further optimize the collaborative work of the memory allocator, and improve the performance and efficiency of overall memory management.

[0058] The memory allocation method provided by the embodiments of the present invention realizes flexible response to different types of memory requests. For smaller memory requests, it responds based on the large-page memory that is not fully allocated, reducing the generation of memory fragments, improving the search efficiency of memory blocks, and increasing the internal utilization rate of memory. For memory requests between the first and second thresholds, the requirements are met through the free memory pages in the preset memory page set. This method helps to quickly respond to medium-scale memory requirements while maintaining the stability of the system. When facing large-scale memory requests greater than the second threshold, it relies on the free memory pages provided by the cache or the operating system to handle, ensuring that continuous large memory requests can be responded to in a timely manner. In this way, not only the problem of time-consuming and inefficient search for suitable free blocks in traditional memory allocators is solved, but also the speed and accuracy of memory allocation are greatly improved.

[0059] Based on the above embodiments, as a preferred implementation, it further includes: continuously collecting the memory usage data of the application within a preset time window, including the frequency, size, duration of memory allocation requests, and the pattern of memory release. At the same time, record the memory demand characteristics of the application at different running stages, such as the memory usage in the initialization stage, peak period, and trough period. Based on the collected memory usage data, construct an intelligent prediction model. This model can adopt machine learning algorithms, such as time series analysis, neural network, or other advanced prediction algorithms, to analyze the historical patterns of memory demand and predict the memory demand trend in the future for a period of time. The input of the prediction model includes historical memory allocation and release data, the running state of the application (such as the current running stage), and the system load situation. According to the output of the intelligent prediction model, pre-allocate memory for the application in advance. If the prediction model determines that the application will have a large increase in memory demand in the short term in the future, based on the current memory allocation, apply for additional memory pages from the operating system in advance and add them to the cache of the page manager. The number of pre-allocated memory pages can be dynamically adjusted according to the predicted demand growth rate to ensure that it can meet the needs of the application without over-occupying system resources. After pre-allocating memory, continuously monitor the actual memory usage of the application. If the actual memory demand is lower than the predicted value, release the excess pre-allocated memory pages back to the operating system in a timely manner to avoid resource waste. If the actual demand is higher than the predicted value, continue to apply for more memory pages from the operating system to meet the needs of the application.

[0060] It can be seen that by introducing a dynamic memory pre-allocation mechanism based on intelligent prediction, this embodiment can significantly reduce the allocation delay of the application during the peak period of memory demand. The traditional memory allocation method usually allocates memory when the application requests memory, which may cause delays in high-load situations. However, in this embodiment, by predicting and pre-allocating memory in advance, the application can quickly obtain memory resources when needed, thus improving the system response speed and overall performance. In addition, the mechanism of dynamically adjusting the number of pre-allocated memory can effectively avoid resource waste and ensure the efficient use of system resources. This memory management strategy combining intelligent prediction and dynamic adjustment is particularly suitable for delay-sensitive application scenarios, such as real-time data processing, high-frequency trading systems, and high-performance computing and other fields.

[0061] This embodiment introduces a method for adjusting the first threshold. Specifically, see Figure 2 , Figure 2 which is a flowchart of a method for adjusting the first threshold shown according to an exemplary embodiment.

[0062] S201: Set the first threshold to a preset proportion of the size of the memory page.

[0063] In a specific implementation, during the system initialization or configuration phase, a first threshold is set according to the size of the memory page. The specific method is to multiply the size of the memory page by a preset ratio to obtain the initial value of the first threshold. For example, if the memory page size is 2MB and the preset ratio is 0.5, the initial value of the first threshold is 1MB.

[0064] S202: Statistically analyze the target ratio of the number of memory requests of the directory type to the total number of memory requests within a preset time window; among them, the memory request of the directory type is a memory request whose requested memory size is less than or equal to the first threshold.

[0065] Among them, the preset time window is a fixed time range used to statistically analyze relevant data of memory requests. The memory request of the directory type refers to a memory request whose requested memory size is less than or equal to the first threshold, usually corresponding to a small memory request. The target ratio refers to the ratio of the number of memory requests of the directory type to the total number of all memory requests, and is used to evaluate the frequency of small memory requests.

[0066] In this step, within the preset time window, the system will statistically analyze the total number of all memory requests and the number of memory requests of the directory type (small memory). Then, calculate the ratio of the number of directory type requests to the total number of requests, that is, the target ratio. For example, if within a 10-second time window, the system receives a total of 100 memory requests, and 80 of them are directory type requests (that is, the requested memory size is less than or equal to the first threshold), then the target ratio is 80%.

[0067] By statistically analyzing the target ratio, the system can understand the frequency and proportion of small memory requests in real time. This data provides an important basis for dynamically adjusting the first threshold, enabling the memory allocation strategy to be optimized according to the actual operating conditions, so as to better adapt to different application scenarios and load changes.

[0068] S203: If the target ratio is greater than the first ratio threshold, increase the first threshold; if the target ratio is less than the second ratio threshold, decrease the first threshold; among them, the second ratio threshold is less than the first ratio threshold.

[0069] Among them, the first ratio threshold is a preset upper limit ratio value used to determine whether to increase the first threshold. The second ratio threshold is a preset lower limit ratio value used to determine whether to decrease the first threshold. The second ratio threshold is less than the first ratio threshold, forming a ratio range.

[0070] In a specific implementation, the first threshold is dynamically adjusted by comparing the target ratio with the preset first ratio threshold and second ratio threshold. If the target ratio is greater than the first ratio threshold, it indicates that the ratio of small memory applications is too high. In this case, the first threshold is increased so that more memory applications can be processed according to the small memory allocation strategy, reducing memory fragmentation. If the target ratio is less than the second ratio threshold, it indicates that the ratio of small memory applications is too low. In this case, the first threshold is decreased so that more memory applications can be processed according to the larger memory allocation strategy, improving memory allocation efficiency.

[0071] For example, assume that the first ratio threshold is 80% and the second ratio threshold is 20%. If the target ratio is 85%, which is greater than the first ratio threshold of 80%, the system will increase the first threshold from 1MB to 1.5MB. If the target ratio is 15%, which is less than the second ratio threshold of 20%, the system will decrease the first threshold from 1MB to 0.5MB.

[0072] It can be seen that by dynamically adjusting the first threshold, the system can flexibly optimize the memory allocation strategy according to the actual running situation. When small memory applications are frequent, increasing the first threshold can reduce memory fragmentation and improve memory utilization. When small memory applications are less, decreasing the first threshold can avoid over-packing and improve memory allocation efficiency. This dynamic adjustment mechanism can significantly enhance the flexibility and performance of memory management.

[0073] This embodiment introduces a memory release method.

[0074] S301: When a first memory block less than or equal to the first threshold is released, the first memory page to which the first memory block belongs is handed over to the first memory allocator for management. When the first memory allocator detects that the first memory page is completely idle, the first memory page is handed over to the page manager for management.

[0075] In a specific implementation, when a memory block (the first memory block) is released and its size is less than or equal to the first threshold, the memory page (the first memory page) to which the memory block belongs is handed over to the first memory allocator for management. The first memory allocator will check whether the memory page is completely idle (i.e., all memory blocks in the memory page have been released). If it is completely idle, the memory page is handed over to the page manager for management so that subsequent memory allocations can reuse these idle memory pages.

[0076] For example, assume that the first threshold is 1MB and a memory block with a size of 512KB is released. This memory block belongs to a 2MB memory page. After release, this 2MB memory page is handed over to the first memory allocator for management. If the first memory allocator detects that the other memory blocks in this memory page have also been released, making the entire memory page completely idle, then this memory page will be handed over to the page manager for management.

[0077] By handing over the memory pages to which the small memory blocks belong to the first memory allocator for management, the remaining space of these memory pages can be better utilized, reducing memory fragmentation. At the same time, handing over the completely free memory pages to the page manager for management can improve the reuse efficiency of the memory pages, reduce frequent requests to the operating system, and improve the overall performance of memory management.

[0078] S302: When a second memory block greater than the first threshold and less than or equal to the second threshold is released, hand over the second memory page to which the second memory block belongs to the second memory allocator for management. When the second memory allocator detects that the second memory page is completely free, hand over the second memory page to the page manager for management.

[0079] In a specific implementation, when a memory block (the second memory block) is released and its size is greater than the first threshold and less than or equal to the second threshold, this memory block may span multiple 2MB memory pages. At this time, these memory pages (the second memory pages) are handed over to the second memory allocator for management. The second memory allocator will check whether these memory pages are completely free (that is, all memory blocks in these memory pages have been released). If a certain memory page is completely free, then this memory page is handed over to the page manager for management so that subsequent memory allocations can reuse these free memory pages.

[0080] For example, assume that the first threshold is 1MB and the second threshold is 16MB, and a memory block of size 8MB is released. Since the size of the memory page is fixed at 2MB, this 8MB memory block may span 4 2MB memory pages. After release, these 4 memory pages are handed over to the second memory allocator for management. If the second memory allocator detects that other memory blocks in a certain memory page have also been released, making the entire memory page completely free, then this memory page will be handed over to the page manager for management.

[0081] By handing over multiple memory pages to which the medium-sized memory blocks belong to the second memory allocator for management, the remaining space of these memory pages can be better utilized, reducing memory fragmentation. At the same time, handing over the completely free memory pages to the page manager for management can improve the reuse efficiency of the memory pages, reduce frequent requests to the operating system, and improve the overall performance of memory management.

[0082] S303: When a third memory block greater than the second threshold is released, hand over the third memory page to which the third memory block belongs to the page manager for management.

[0083] In a specific implementation, when a memory block (the third memory block) is released and its size is greater than the second threshold, the memory block may span multiple 2MB memory pages. At this time, these memory pages (the third memory pages) are directly handed over to the page manager for management. The page manager will check whether these memory pages are completely free (that is, all memory blocks in these memory pages have been released). If a certain memory page is completely free, it will be included in the cache of the page manager so that subsequent memory allocations can reuse these free memory pages.

[0084] For example, assume that the second threshold is 16MB and a 32MB memory block is released. Since the size of the memory page is fixed at 2MB, this 32MB memory block may span 16 2MB memory pages. After release, these 16 memory pages are directly handed over to the page manager for management. The page manager will check whether these memory pages are completely free. If a certain memory page is completely free, it will be included in the cache so that subsequent memory allocations can reuse these free memory pages.

[0085] By directly handing over multiple memory pages belonging to a large memory block to the page manager for management, these memory pages can be quickly released, improving the reuse efficiency of memory pages. This method can reduce frequent requests to the operating system and improve the overall performance of memory management. Especially when dealing with large memory applications, it can significantly improve the system's response speed. At the same time, the page manager can better manage these free memory pages to ensure the efficiency of subsequent memory allocations.

[0086] Based on the above embodiments, as a preferred implementation, it further includes: counting the minimum required number of memory pages and the maximum required number of memory pages for memory applications within a preset time window, and calculating the difference in the number of memory pages between the maximum required number of memory pages and the minimum required number of memory pages; when the number of free memory pages managed by the page manager is greater than the difference in the number of memory pages, the free memory pages in the cache managed by the page manager are released to the operating system.

[0087] In a specific implementation, by counting the minimum required memory page count and the maximum required memory page count for memory applications within a preset time window and calculating the difference between the two, the number of free memory pages managed by the page manager is dynamically adjusted. Specifically, the system determines the rationality of the free memory pages in the page manager based on the fluctuation range of memory requirements (i.e., the difference between the maximum and minimum requirements). If the number of free memory pages managed by the page manager exceeds this difference, it indicates that there are too many free memory pages in the current cache that are idle and not fully utilized. At this time, the system releases the excess free memory pages to the operating system so that this part of the memory resources can be reallocated to other processes or applications in need, thereby improving the overall memory utilization rate of the system. This method can effectively avoid waste of memory resources, reduce memory occupation problems caused by excessive free memory pages, and further optimize the efficiency and performance of memory management.

[0088] The following introduces an application embodiment provided by the present invention. The large-page-aware memory allocator in this embodiment includes a small-granularity allocator, a large-granularity allocator, a page manager, and a resource allocator. These components work together to achieve efficient large-page memory management.

[0089] The small-granularity allocator component is used to manage partially used large pages (i.e., large pages that are not fully allocated); the large-granularity allocator component is used to manage allocations across multiple large pages; the main function of the page manager component is to cache unused large pages to reduce system calls; the resource allocator component directly interacts with the operating system and is responsible for allocating and releasing large pages from the operating system. The size of the large page adopted by the system is 2MB, and the allocator is managed at a 4KB granularity. When a memory allocation request is received, a suitable allocation path is selected according to the threshold (0 - 2MB) of the allocation request. The specific allocation process is as Figure 3 shown.

[0090] When there is a memory application, first, the size of the requested memory is counted, and subsequently, the threshold is dynamically adjusted according to the size of the requested memory. Secondly, in the allocation process, the size of the memory request is compared with the threshold size to select a suitable allocation path.

[0091] When the size of the requested allocated memory is less than this threshold, it indicates that the size of the requested allocated memory is smaller than a large page. The small-granularity allocator packs these requests into the same large page as much as possible to improve memory utilization. The small-granularity allocator internally maintains a data structure that records the remaining space of each incompletely allocated large page and the information of the allocated memory blocks, such as the starting address, size, etc., to facilitate quickly finding a suitable large page for allocation. When there is no suitable memory for allocation in the small-granularity allocator linked list, it will traverse the page manager to check if there are any free large pages. If there are, it will allocate one of them, and the remaining memory of the large page will be managed by the linked list of the small-granularity allocator; if there are no free large pages in the page manager, it will obtain a large page from the system in the form of mmap (Memory Map) through the resource allocator, and similarly, the remaining part will be managed by the linked list of the small-granularity allocator.

[0092] When the size of the requested allocated memory is greater than this threshold and less than 1G, memory allocation will be performed through the large-granularity allocator. Internally, it manages the large page set and the allocated area information through a data structure such as a tree structure to support fast search and allocation. When there is an allocation request within the management scope of this component, the large-granularity allocator will search for a suitable large page or combination of large pages from the large page set it manages for allocation. If the large-granularity allocator cannot meet the demand, it will first query the page manager. If there is one in the cache, it will be allocated; otherwise, it will obtain a large page from the operating system in the form of mmap through the resource allocator.

[0093] When the size of the requested allocated memory is greater than 1G, multiple consecutive large pages will be obtained from the page manager or the resource allocator. If there are enough consecutive large pages in the page manager (which manages the large page cache), they will be allocated from the cache; if not, the resource allocator will obtain consecutive large pages from the operating system for allocation. If the size of the requested memory is exactly an integer multiple of the large page, multiple large pages will be directly obtained from the page manager or the resource allocator for allocation. Otherwise, large pages will be allocated according to the size of the allocation request, and the remaining part will be donated to the small-granularity allocator component for management. For example, if a request is made to allocate 1.1G (1126.4MB) of memory, then 1128MB (564 large pages) will be obtained from the system through the page manager or the resource allocator, and the remaining 1.6MB of memory will be handed over to the small-granularity allocator for management to supply memory requests smaller than the threshold.

[0094] It should be noted that the threshold parameter in the above allocation process is not fixed, but is optimized in real time through a dynamic threshold adjustment mechanism. The flowchart of the dynamic threshold adjustment is as Figure 4 shown, and the specific implementation is as follows: First, a dedicated counter is set in the memory allocation module. Whenever the system receives an allocation request, it determines whether the allocation method of the request is through the small-granularity allocator, large-granularity allocator, or resource allocator. If it is the small-granularity allocator, the small memory allocation request count is incremented by 1; at the same time, a total request counter is set, which is incremented by 1 for each received request (regardless of size). Secondly, a time window is defined, within which the proportions of small memory allocation requests, medium memory allocation requests, and large memory allocation requests are respectively counted. When the proportion of small memory allocation requests exceeds 80%, the small memory allocation threshold is adjusted from 1 / 2 of the large page size to 3 / 4 of the large page size, enabling more small requests to be packaged and allocated through the small-granularity allocator, thereby reducing the memory fragmentation pressure; when the proportion of small memory allocation requests is below 20%, the small memory allocation threshold is adjusted to 1 / 4 of the large page size. This dynamic threshold adjustment can effectively improve the memory allocation efficiency and reduce the memory fragmentation rate.

[0095] For memory release, similar to memory allocation, different memory sizes have different release strategies. The flow diagram of memory release is as Figure 5 shown, and the process is as follows: First, when releasing memory smaller than the threshold, it is first returned to the small-granularity allocator. The small-granularity allocator checks whether the large page is completely free. If it is completely free, it attempts to release it to the page custodian. When returning medium-allocated memory, it is returned to the large-granularity allocator. The large-granularity allocator checks whether the relevant large page is completely free. If it is free, it is returned to the large page cache area. When releasing large-allocated memory, it is directly released to the page custodian. After the free large page is returned to the page custodian, the number of large pages required by the current system and the number of large pages owned by the page custodian are counted, and the excess free large pages are released to the operating system according to the system requirements.

[0096] Furthermore, through the following mechanism for returning free large pages to the operating system, a balance is found between reducing memory occupancy and reducing system call overhead, predicting future demands through short-term historical demands, and avoiding the limitations of static policies. The flow chart is as Figure 6 shown, and the process is as follows: First, a statistical mechanism with a sliding window is adopted, fixing the time window. Within this time window, the system continuously records the relevant data of memory requirements. Specifically, a dedicated monitoring module is used to monitor the memory usage in real time and accurately record each memory allocation and release operation. Then, based on these recorded data, the maximum value (max) and minimum value (min) of the memory requirements for memory applications within these 2 seconds are calculated. This statistical method can quickly reflect the short-term fluctuations in memory requirements and provide a reliable basis for subsequent memory release decisions.

[0097] When the number of free large pages in the page host exceeds max - min, the system returns the excess large pages to the Operating System (OS). If the number of free large pages in the page host exceeds this fluctuation range, it indicates that there are too many large pages idle in the current cache and not being fully utilized. The resource processor unmaps these large pages and returns the excess large pages to the OS, enabling this part of the memory resources to return to the system for use by other processes or applications, thereby improving the overall memory utilization rate of the system.

[0098] It can be seen that through the collaborative work of different components in this embodiment, the system can intelligently select the optimal allocation path according to memory requests of different sizes. The small - granularity allocator packs and manages small memory requests to improve the internal utilization rate of large pages; the large - granularity allocator optimizes the allocation efficiency of medium - sized memory; while the page host and the resource allocator ensure the rapid allocation of large contiguous memory, thus overall improving the memory management efficiency. In addition, in this embodiment, by statistically analyzing the memory request distribution in real - time and dynamically adjusting the small - memory allocation threshold, the system reduces fragmentation during high - frequency small requests and avoids over - packing when there are more large requests, thus flexibly adapting to the requirements of different application scenarios. Further, this embodiment adopts a demand prediction strategy based on a sliding window, enabling the system to dynamically adjust the release timing of free large pages, achieving a balance between reducing memory occupancy and reducing system call overhead. Compared with the fixed - rate release strategy, this mechanism can more accurately predict future memory requirements and avoid the overhead or waste caused by premature or late release.

[0099] Next, a memory allocation device provided by an embodiment of the present invention will be introduced. The memory allocation device described below can be referred to in mutual reference with the memory allocation method described above. Refer to Figure 7 , a structural diagram of a memory allocation device shown according to an exemplary embodiment.

[0100] A determination module 100, configured to determine the size of the memory requested by the memory application when receiving a memory application from a requester.

[0101] A first response module 200, configured to respond to the memory application based on un - fully allocated memory pages when the memory size is less than or equal to a first threshold; wherein, the size of the memory page is greater than or equal to a preset value, and the first threshold is less than the size of the memory page.

[0102] A second response module 300, configured to respond to the memory application based on free memory pages in a preset memory page set when the memory size is greater than the first threshold and less than or equal to a second threshold; wherein, the second threshold is greater than the size of the memory page.

[0103] The third response module 400 is configured to, when the memory size is greater than the second threshold, respond to the memory application based on the unreleased free memory pages in the cache and / or the free memory pages in the operating system.

[0104] The memory allocation device provided by the embodiments of the present invention realizes flexible response to different types of memory applications. For relatively small memory requests, it responds based on the large pages of memory that have not been fully allocated, reducing the generation of memory fragmentation, improving the search efficiency of memory blocks, and increasing the internal utilization rate of memory. For memory requests between the first and second thresholds, the free memory pages in the preset memory page set are used to meet the requirements. This method helps to quickly respond to medium-sized memory requirements while maintaining the stability of the system. When facing large-scale memory requests greater than the second threshold, it relies on the free memory pages provided by the cache or the operating system to handle them, ensuring that continuous large memory requests can be responded to in a timely manner. In this way, not only is the problem of time-consuming and inefficient search for suitable free blocks in traditional memory allocators solved, but also the speed and accuracy of memory allocation are greatly improved.

[0105] Based on the above embodiments, as a preferred implementation manner, the first response module 200 is specifically configured to: allocate a memory block for the requester in the memory pages managed by the first memory allocator by using the first memory allocator; wherein, the first memory allocator is used to manage the memory pages that have not been fully allocated; correspondingly, the second response module 300 is specifically configured to: allocate a memory block in one or more memory pages for the requester in the memory pages managed by the second memory allocator by using the second memory allocator; wherein, the second memory allocator is used to manage the free memory pages in the preset memory page set; correspondingly, the third response module 400 is specifically configured to: allocate a memory block in multiple memory pages for the requester from the unreleased free memory pages in the cache by using the page host, and / or allocate a memory block in multiple memory pages for the requester from the free memory pages in the operating system by using the resource allocator.

[0106] Based on the above embodiments, as a preferred implementation manner, the first memory allocator is used to record the remaining space of the memory pages that have not been fully allocated and the information of the allocated memory blocks.

[0107] Based on the above embodiments, as a preferred implementation manner, it further includes: a first allocation module, configured to, when the memory size is less than or equal to a first threshold and the memory pages managed by the first memory allocator cannot satisfy the memory application, determine whether there are free memory pages in the cache managed by the page manager; if so, select a first target memory page from the free memory pages in the cache, allocate a memory block for the requester in the first target memory page, and hand over the first target memory page to the first memory allocator for management; if not, select a second target memory page from the free memory pages in the operating system, allocate a memory block for the requester in the second target memory page, and hand over the second target memory page to the first memory allocator for management.

[0108] Based on the above embodiments, as a preferred implementation manner, it further includes: a first management module, configured to, after allocating a memory block in one or more memory pages managed by the second memory allocator for the requester by using the second memory allocator, if there are unallocated memory blocks in the memory pages allocated to the requester, hand over the memory pages with unallocated memory blocks to the first memory allocator for management.

[0109] Based on the above embodiments, as a preferred implementation manner, it further includes: a second allocation module, configured to, when the memory size is greater than the first threshold and less than or equal to a second threshold, if the memory pages managed by the second memory allocator cannot satisfy the memory application, determine whether there are free memory pages in the cache managed by the page manager that can satisfy the memory application; if so, select one or more third target memory pages from the free memory pages in the cache, and allocate a memory block for the requester in one or more of the third target memory pages; if not, select one or more fourth target memory pages from the free memory pages in the operating system, and allocate a memory block for the requester in one or more of the fourth target memory pages.

[0110] Based on the above embodiments, as a preferred implementation manner, it further includes: a second management module, configured to, after allocating a memory block for the requester in one or more of the third target memory pages, if there are unallocated memory blocks in the third target memory pages allocated to the requester, hand over the third target memory pages with unallocated memory blocks to the first memory allocator for management; a third management module, configured to, after allocating a memory block for the requester in one or more of the fourth target memory pages, if there are unallocated memory blocks in the fourth target memory pages allocated to the requester, hand over the fourth target memory pages with unallocated memory blocks to the first memory allocator for management.

[0111] Based on the above embodiments, as a preferred implementation, the third response module 400 is specifically configured to: determine whether the number of free memory pages in the cache managed by the page host meets the memory application; if so, select multiple fifth target memory pages from the free memory pages in the cache, and allocate memory blocks to the requester among the multiple fifth target memory pages; if not, select multiple sixth target memory pages from the free memory pages in the operating system, and allocate memory blocks to the requester among the multiple sixth target memory pages.

[0112] Based on the above embodiments, as a preferred implementation, it further includes: a fourth management module, configured to, after allocating memory blocks to the requester among the multiple fifth target memory pages, if there are unallocated memory blocks in the fifth target memory pages allocated to the requester, hand over the fifth target memory pages with unallocated memory blocks to the first memory allocator for management; a fifth management module, configured to, after allocating memory blocks to the requester among the multiple sixth target memory pages, if there are unallocated memory blocks in the sixth target memory pages allocated to the requester, hand over the sixth target memory pages with unallocated memory blocks to the first memory allocator for management.

[0113] Based on the above embodiments, as a preferred implementation, it further includes: an adjustment module, configured to set the first threshold to a preset ratio of the size of the memory page; count the target ratio of the number of memory applications of the directory type to the total number of memory applications within a preset time window; wherein, the memory application of the directory type is a memory application whose requested memory size is less than or equal to the first threshold; if the target ratio is greater than the first ratio threshold, increase the first threshold; if the target ratio is less than the second ratio threshold, decrease the first threshold; wherein, the second ratio threshold is less than the first ratio threshold.

[0114] Based on the above embodiments, as a preferred implementation, it further includes: a first memory release module, configured to, when a first memory block whose size is less than or equal to the first threshold is released, hand over the first memory page to which the first memory block belongs to the first memory allocator for management, and when the first memory allocator detects that the first memory page is completely free, hand over the first memory page to the page host for management; a second memory release module, configured to, when a second memory block whose size is greater than the first threshold and less than or equal to the second threshold is released, hand over the second memory page to which the second memory block belongs to the second memory allocator for management, and when the second memory allocator detects that the second memory page is completely free, hand over the second memory page to the page host for management; a third memory release module, configured to, when a third memory block whose size is greater than the second threshold is released, hand over the third memory page to which the third memory block belongs to the page host for management.

[0115] Based on the above embodiments, as a preferred implementation manner, it further includes: a fourth memory release module, configured to count the minimum required memory page quantity and the maximum required memory page quantity of memory applications within a preset time window, and calculate the memory page quantity difference between the maximum required memory page quantity and the minimum required memory page quantity; when the quantity of free memory pages managed by the page manager is greater than the memory page quantity difference, release the free memory pages in the cache managed by the page manager to the operating system.

[0116] Regarding the device in the above embodiments, the specific manners in which each module performs operations have been described in detail in the embodiments related to the method, and will not be elaborated herein.

[0117] An embodiment of the present invention further provides an electronic device, Figure 8 which is a structural diagram of an electronic device shown according to an exemplary embodiment, as Figure 8 shown, the electronic device includes: a communication interface 1, capable of interacting with other devices such as network devices; a processor 2, connected to the communication interface 1 to achieve information interaction with other devices, and configured to execute the memory allocation method provided by the above one or more technical solutions when running a computer program. And the computer program is stored on a memory 3.

[0118] Of course, in actual application, each component in the electronic device is coupled together through a bus system 4. It can be understood that the bus system 4 is used to realize the connection and communication between these components. The bus system 4 includes, in addition to a data bus, a power bus, a control bus, and a status signal bus. However, for the sake of clear illustration, in Figure 8 all kinds of buses are labeled as the bus system 4.

[0119] The memory 3 in the embodiment of the present invention is used to store various types of data to support the operation of the electronic device. Examples of these data include: any computer program for operating on the electronic device.

[0120] It can be understood that the memory 3 can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM, Read Only Memory), a programmable read-only memory (PROM, Programmable Read-Only Memory), an erasable programmable read-only memory (EPROM, Erasable Programmable Read-Only Memory), an electrically erasable programmable read-only memory (EEPROM, Electrically Erasable Programmable Read-Only Memory), a ferromagnetic random access memory (FRAM, ferromagnetic random access memory), a flash memory (Flash Memory), a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM, Compact Disc Read-Only Memory); the magnetic surface memory can be a disk memory or a tape memory. The volatile memory can be a random access memory (RAM, Random Access Memory), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as a static random access memory (SRAM, Static Random Access Memory), a synchronous static random access memory (SSRAM, Synchronous Static Random Access Memory), a dynamic random access memory (DRAM, Dynamic Random Access Memory), a synchronous dynamic random access memory (SDRAM, Synchronous Dynamic Random Access Memory), a double data rate synchronous dynamic random access memory (DDR SDRAM, Double Data Rate Synchronous Dynamic Random Access Memory), an enhanced synchronous dynamic random access memory (ESDRAM, Enhanced Synchronous Dynamic Random Access Memory), a sync link dynamic random access memory (SLDRAM, SyncLink Dynamic Random Access Memory), a direct rambus random access memory (DRRAM, Direct Rambus Random Access Memory).The memory 3 described in the embodiments of the present invention is intended to include, but is not limited to, these and any other suitable types of memories.

[0121] The method disclosed in the above embodiments of the present invention can be applied to the processor 2 or implemented by the processor 2. The processor 2 may be an integrated circuit chip with the ability to process signals. In the implementation process, the steps of the above method can be completed by the integrated logic circuit in the hardware of the processor 2 or by instructions in the form of software. The above-mentioned processor 2 may be a general-purpose processor, a DSP, or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor 2 can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present invention. The general-purpose processor may be a microprocessor or any conventional processor, etc. Combining the steps of the method disclosed in the embodiments of the present invention can be directly embodied as being executed and completed by the hardware decoding processor, or by a combination of the hardware and software modules in the decoding processor. The software module may be located in the storage medium, which is located in the memory 3. The processor 2 reads the program in the memory 3 and combines its hardware to complete the steps of the foregoing method.

[0122] When the processor 2 executes the program, it implements the corresponding processes in the various methods of the embodiments of the present invention. For the sake of brevity, it will not be described in detail here.

[0123] The embodiments of the present invention also provide a computer-readable storage medium, in which a computer program is stored. Among them, the computer program is set to execute the steps in any of the above embodiments of the memory allocation method when running.

[0124] In an exemplary embodiment, the above computer-readable storage medium may include, but is not limited to: USB flash drives, read-only memories (ROM for short), random access memories (RAM for short), mobile hard disks, magnetic disks, or optical disks, etc., all kinds of media that can store computer programs.

[0125] The embodiments of the present invention also provide a computer program product. The above computer program product includes a computer program, and when the computer program is executed by the processor 2, it implements the steps in any of the above embodiments of the memory allocation method.

[0126] The embodiments of the present invention also provide another computer program product, including a non-volatile computer-readable storage medium. The non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by the processor 2, it implements the steps in any of the above embodiments of the memory allocation method.

[0127] Those skilled in the art may further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.

[0128] The above has introduced in detail a memory allocation system, method, device, equipment, medium, and product provided by the present invention. Specific examples have been used herein to illustrate the principle and implementation manner of the present invention. The description of the above embodiments is only used to help understand the method and its core idea of the present invention. It should be noted that for those of ordinary skill in the art in the technical field, without departing from the principle of the present invention, several improvements and modifications can still be made to the present invention, and these improvements and modifications also fall within the protection scope of the present invention.

Claims

1. A memory allocation method, characterized in that, Including: When receiving a memory application from a requester, determining the memory size requested by the memory application; If the memory size is less than or equal to a first threshold, responding to the memory application based on unallocated memory pages; wherein, the size of the memory pages is greater than or equal to a preset value, and the first threshold is less than the size of the memory pages; If the memory size is greater than the first threshold and less than or equal to a second threshold, responding to the memory application based on free memory pages in a preset memory page set; wherein, the second threshold is greater than the size of the memory pages; If the memory size is greater than the second threshold, responding to the memory application based on cached unreleased free memory pages and / or free memory pages in the operating system.

2. The memory allocation method according to claim 1, wherein Responding to the memory application based on unallocated memory pages includes: Using a first memory allocator to allocate a memory block for the requester in the memory pages managed by the first memory allocator; wherein, the first memory allocator is used to manage unallocated memory pages; Correspondingly, responding to the memory application based on free memory pages in a preset memory page set includes: Using a second memory allocator to allocate a memory block in one or more memory pages for the requester in the memory pages managed by the second memory allocator; wherein, the second memory allocator is used to manage free memory pages in a preset memory page set; Correspondingly, responding to the memory application based on cached unreleased free memory pages and / or free memory pages in the operating system includes: Using a page manager to allocate a memory block in multiple memory pages for the requester from cached unreleased free memory pages, and / or, using a resource allocator to allocate a memory block in multiple memory pages for the requester from free memory pages in the operating system.

3. The memory allocation method according to claim 2, wherein The first memory allocator is used to record the remaining space of unallocated memory pages and the information of allocated memory blocks.

4. The memory allocation method according to claim 2, wherein It also includes: When the memory size is less than or equal to the first threshold and the memory pages managed by the first memory allocator cannot satisfy the memory application, determining whether there are free memory pages in the cache managed by the page manager; If so, selecting a first target memory page from the free memory pages in the cache, allocating a memory block for the requester in the first target memory page, and handing over the first target memory page to the first memory allocator for management; If not, selecting a second target memory page from the free memory pages in the operating system, allocating a memory block for the requester in the second target memory page, and handing over the second target memory page to the first memory allocator for management.

5. The memory allocation method according to claim 2, wherein After using the second memory allocator to allocate a memory block in one or more memory pages for the requester in the memory pages managed by the second memory allocator, it further includes: If there are unallocated memory blocks in the memory pages allocated to the requester, handing over the memory pages with unallocated memory blocks to the first memory allocator for management.

6. The memory allocation method according to claim 2, wherein It also includes: When the memory size is greater than the first threshold and less than or equal to the second threshold, if the memory pages managed by the second memory allocator cannot satisfy the memory application, it is determined whether there are free memory pages in the cache managed by the page manager that can satisfy the memory application; If so, one or more third target memory pages are selected from the free memory pages in the cache, and memory blocks are allocated to the requester in one or more of the third target memory pages; If not, one or more fourth target memory pages are selected from the free memory pages in the operating system, and memory blocks are allocated to the requester in one or more of the fourth target memory pages.

7. The memory allocation method according to claim 6, wherein After allocating memory blocks to the requester in one or more of the third target memory pages, it further includes: If there are unallocated memory blocks in the third target memory pages allocated to the requester, the third target memory pages with unallocated memory blocks are handed over to the first memory allocator for management; Correspondingly, after allocating memory blocks to the requester in one or more of the fourth target memory pages, it further includes: If there are unallocated memory blocks in the fourth target memory pages allocated to the requester, the fourth target memory pages with unallocated memory blocks are handed over to the first memory allocator for management.

8. The memory allocation method according to claim 2, wherein Allocating memory blocks in multiple memory pages for the requester by using the page manager from the unreleased free memory pages in the cache, and / or allocating memory blocks in multiple memory pages for the requester by using the resource allocator from the free memory pages in the operating system, includes: Determining whether the number of free memory pages in the cache managed by the page manager meets the memory application; If so, multiple fifth target memory pages are selected from the free memory pages in the cache, and memory blocks are allocated to the requester in multiple of the fifth target memory pages; If not, multiple sixth target memory pages are selected from the free memory pages in the operating system, and memory blocks are allocated to the requester in multiple of the sixth target memory pages.

9. The memory allocation method according to claim 8, wherein After allocating memory blocks to the requester in multiple of the fifth target memory pages, it further includes: If there are unallocated memory blocks in the fifth target memory pages allocated to the requester, the fifth target memory pages with unallocated memory blocks are handed over to the first memory allocator for management; Correspondingly, after allocating memory blocks to the requester in multiple of the sixth target memory pages, it further includes: If there are unallocated memory blocks in the sixth target memory pages allocated to the requester, the sixth target memory pages with unallocated memory blocks are handed over to the first memory allocator for management.

10. The memory allocation method according to claim 1, wherein It further includes: Setting the first threshold to a preset ratio of the size of the memory page; Counting the target ratio of the number of memory applications of the directory type to the total number of memory applications within a preset time window; wherein, the memory application of the directory type is a memory application whose requested memory size is less than or equal to the first threshold; If the target ratio is greater than the first ratio threshold, the first threshold is increased; If the target ratio is less than the second ratio threshold, the first threshold is decreased; wherein, the second ratio threshold is less than the first ratio threshold.

11. The memory allocation method according to claim 2, wherein It further includes: When a first memory block less than or equal to the first threshold is released, the first memory page to which the first memory block belongs is handed over to the first memory allocator for management. When the first memory allocator detects that the first memory page is completely idle, the first memory page is handed over to the page manager for management; When a second memory block greater than the first threshold and less than or equal to the second threshold is released, the second memory page to which the second memory block belongs is handed over to the second memory allocator for management. When the second memory allocator detects that the second memory page is completely idle, the second memory page is handed over to the page manager for management; When a third memory block greater than the second threshold is released, the third memory page to which the third memory block belongs is handed over to the page manager for management.

12. The memory allocation method according to claim 2, wherein Further included are: Counting the number of memory pages with the lowest memory requirements and the number of memory pages with the highest memory requirements for memory applications within a preset time window, and calculating the difference in the number of memory pages between the highest memory requirement memory page number and the lowest memory requirement memory page number; When the number of free memory pages managed by the page manager is greater than the difference in the number of memory pages, the free memory pages in the cache managed by the page manager are released to the operating system.

13. A memory allocation device, characterized in that, Included are: A determination module for determining the memory size requested by the memory application when a memory application from a requester is received; A first response module for, when the memory size is less than or equal to the first threshold, responding to the memory application based on the memory pages that are not fully allocated; wherein, the size of the memory page is greater than or equal to a preset value, and the first threshold is less than the size of the memory page; A second response module for, when the memory size is greater than the first threshold and less than or equal to the second threshold, responding to the memory application based on the free memory pages in a preset memory page set; wherein, the second threshold is greater than the size of the memory page; A third response module for, when the memory size is greater than the second threshold, responding to the memory application based on the cached free memory pages that have not been released and / or the free memory pages in the operating system.

14. An electronic device, characterized in that, Included are: A memory for storing a computer program; A processor for implementing the steps performed by the memory allocation method according to any one of claims 1 to 12 when executing the computer program.

15. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, and when the computer program is executed, the steps performed by the memory allocation method according to any one of claims 1 to 12 are implemented.

Citation Information

Patent Citations

  • Internal memory management method and system

    CN101414281A

  • Memory management system and method

    CN105302734A

  • Memory allocation processing method and device

    CN107153618A

  • Memory management method and device, storage medium and electronic device

    CN110888746A

  • Memory anti-fragmentation method and system and storage medium

    CN111338981A

Cited By

  • User mode memory management method, product, electronic equipment and storage medium

    CN120849136A

  • A user-mode memory management method, product, electronic device and storage medium

    CN120849136B

  • Method and system for adapting credential host to deep learning framework based on edge calculation

    CN121031726A