Memory pool dynamic management method and device, electronic equipment and storage medium
By not allocating memory blocks initially in the memory pool and dynamically allocating and freeing memory blocks according to actual needs, the problem of excessive and waste of memory allocation in memory pool management is solved, and memory usage efficiency and system performance are improved.
Patent Information
- Application Number
- CN202410931873.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-12
- Publication Date
- 2024-11-08
AI Technical Summary
Existing memory pool management strategies in the fields of video decoding and encoding have led to excessive memory allocation and frequent memory application and release operations, which reduces system operation efficiency, and in low-power mobile devices and embedded devices, due to mismatch in memory block sizes. Memory waste and inefficiency.
The memory pool is used that does not contain memory blocks at the beginning, and the memory blocks are dynamically allocated and released according to actual needs. By setting thresholds and monitoring the usage frequency and existence time of memory blocks, the memory pool size is adjusted as needed to ensure the reasonable allocation and release of memory blocks.
It improves memory usage efficiency, reduces memory waste and fragmentation problems, improves system performance and response speed, and adapts to the dynamic changes in the memory requirements of video services.
Smart Images

Figure CN118916154A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of memory management technology, and in particular to a memory pool dynamic management method and device, electronic equipment, and storage medium. Background Art
[0002] In the memory management technology in the field of video decoding and encoding, the maximum allocation mode is traditionally used for core data such as binary compressed code streams, reference frames, and decoded frames. This strategy often leads to excessive memory allocation, which significantly increases memory consumption. In addition, frequent memory application and release operations not only reduce the operating efficiency of the system, but also easily cause memory fragmentation problems, which in turn affects the effective utilization of memory.
[0003] In order to improve memory usage efficiency, the industry currently widely uses memory pool technology to manage memory resources. Taking decoding as an example, before the video service is started, a dedicated memory pool is allocated for the decoder in advance. When a frame of data is processed, the decoder does not immediately release the memory space occupied by the frame, but retains it in the memory pool for subsequent frames to be decoded. This method realizes memory reuse, significantly reduces the frequency of memory recovery and reallocation, and thus improves memory usage efficiency.
[0004] However, existing memory pool management strategies also face challenges. The size of each memory block in the memory pool is usually set based on the maximum requirement of the compressed frame, but in reality not every frame of data will use such a large memory block, which may cause the memory pool to occupy memory space far exceeding the actual business needs, increasing memory costs.
[0005] Especially for low-power mobile devices and embedded devices with camera and display functions, these devices are usually equipped with limited memory capacity due to specific application scenarios and strict cost control requirements. With limited memory resources, in order to meet performance requirements, memory must be managed more finely and efficiently. However, the current memory management strategy still cannot avoid the problem of memory waste in some cases. Therefore, it is necessary to seek an innovative and efficient memory management strategy to further optimize memory usage efficiency. Summary of the invention
[0006] The present invention aims to provide a method and device for dynamic management of a memory pool, an electronic device, and a storage medium. The method creates a memory pool that initially does not contain memory blocks, allocates memory blocks to the memory pool on demand according to the actual needs of memory applications, and when the number of memory blocks reaches a threshold, dynamically replaces the memory blocks in the memory pool according to the usage frequency of the memory blocks and the actual needs. The memory pool management method of on-demand allocation and dynamic adjustment improves the memory usage efficiency.
[0007] To achieve the above object, the present invention proposes the following technical solutions:
[0008] The first aspect of the present application provides a method for dynamic management of a memory pool, comprising creating a memory pool, the memory pool initially not allocating memory blocks, setting a first threshold N, and the number of memory blocks in the memory pool being no greater than N;
[0009] In response to a memory request, determining whether there is an idle memory block in the memory pool that satisfies the memory request;
[0010] If there is no idle memory block in the memory pool that satisfies the memory application, when the number of memory blocks in the memory pool is less than the first threshold value N, the memory block required for the memory application is allocated to the memory pool, and the memory pool provides the newly acquired memory block to the memory application. When the number of memory blocks in the memory pool is equal to the first threshold value N, after the idle memory blocks in the memory pool are released, the memory block required for the memory application is allocated to the memory pool, and the memory pool provides the newly acquired memory block to the memory application.
[0011] If there is an idle memory block in the memory pool that meets the memory request, a memory block is provided for the memory request from the memory pool according to the memory size of the memory block required by the memory request;
[0012] After the memory block is used up, it is returned to the memory pool.
[0013] In some possible implementations, the time t0 when the memory block is allocated to the memory pool, the number of times the memory block is used by the memory application count, the time when the memory application is received is t1, and the usage frequency H of the memory block is defined. When the memory pool needs to release a memory block, the memory block in the memory pool that is idle and has the lowest usage frequency H is released.
[0014] In some possible implementations, the second threshold t is set x , record the existence time t2 of the memory block in the memory pool. When there is no memory block in the memory pool that satisfies the memory request and the number of memory blocks in the memory pool reaches N, release the memory pool when the existence time t2 is greater than the second threshold t x The memory block that is in idle state and has the lowest usage frequency H.
[0015] In some possible implementations, when the memory pool releases a memory block, when there are at least two memory blocks with the smallest usage frequency H, the memory block with the smallest memory capacity is released.
[0016] In some possible implementations, a third threshold T and a fourth threshold n1 are set, and the number of memory blocks in the monitoring memory pool that are in an idle state is m;
[0017] When m>n1 and the duration of this state reaches a third threshold T, the first (m-n1) memory blocks in the memory pool that are in an idle state and whose usage frequencies H are arranged from small to large are released.
[0018] In some possible implementations, a fifth threshold n2 and a sixth threshold n3 are set, wherein n3 is greater than n2, and n2 is greater than n1;
[0019] When n1<m≤n2 and the duration of this state reaches the third threshold T, the first (m-n1) memory blocks in the memory pool that are in an idle state and whose usage frequency H is arranged in ascending order are released;
[0020] When n2<m≤n3 and the duration of this state reaches the third threshold T, the first (m-n2) memory blocks in the memory pool that are in an idle state and whose usage frequency H is arranged in ascending order are released;
[0021] When n3<m≤N and the duration of this state reaches the third threshold T, the first (m-n3) memory blocks in the memory pool that are in an idle state and whose usage frequencies H are arranged from small to large are released.
[0022] In some possible implementations, if there is an idle memory block in the memory pool that meets the memory request, a memory block is provided for the memory request from the memory pool according to the memory size of the memory block required by the memory request, and also includes: selecting a memory block that meets the requirements of the memory request and has the smallest memory capacity from the memory pool, and providing it to the memory request.
[0023] The second aspect of the present application provides a memory pool dynamic management device, comprising:
[0024] The business module is used to issue memory requests and return the used memory blocks after they are used.
[0025] The memory pool management module is used to create a memory pool. The memory pool does not allocate memory blocks initially. The first threshold N is set. The number of memory blocks in the memory pool is not greater than N. The time t0 when each memory block is allocated to the memory pool and the number of times the memory block is used by the memory application count are recorded. The time when the memory application is received is t1. The usage frequency H of the memory block is defined. The second threshold t x , the existence time t2 of the memory block in the memory pool;
[0026] The system memory management module is used to allocate memory blocks to the memory pool management module and receive memory blocks released by the memory pool management module;
[0027] The memory pool management module includes a first judgment submodule, which records the time t0 when each memory block is allocated to the memory pool and the number of times the memory block is used by the memory application count, the time when the memory application is received is t1, the existence time of the memory block in the memory pool is t2, defines the usage frequency H of the memory block, and sets the second threshold t x , used to determine whether there is a memory block in the memory pool that satisfies the memory request when a memory request is received;
[0028] If there is no idle memory block that satisfies the memory application in the memory pool, when the number of memory blocks in the memory pool is less than the first threshold value N, the system management module allocates the memory blocks required for the memory application to the memory pool, and the memory pool management module provides the memory blocks obtained by the memory pool to the business module. When the number of memory blocks in the memory pool is equal to the first threshold value N, the memory blocks in the idle state of the memory pool are selected with the smallest usage frequency H and an existence time t2 greater than the second threshold value t x If there are at least two memory blocks with the smallest usage frequency H, the memory block with the smallest memory capacity is released. After the memory block is released, the system management module allocates the memory block required for the memory application to the memory pool, and the memory pool management module provides the memory block obtained by the memory pool to the business module;
[0029] If there is an idle memory block that meets the memory application in the memory pool, the memory pool management module selects a memory block that meets the memory application requirements and has the smallest memory capacity from the memory pool according to the memory size of the memory block required by the memory application, and provides it to the business module;
[0030] The memory pool management module includes a second judgment submodule, which sets a third threshold T, a fourth threshold n1, a fifth threshold n2 and a sixth threshold n3. The number of memory blocks in the memory pool that are in an idle state is m. When n1<m≤n2 and the duration of the state reaches the third threshold T, the first (m-n1) memory blocks in the memory pool that are in an idle state and whose usage frequency H is arranged from small to large are released to the system memory management module; when n2<m≤n3 and the duration of the state reaches the third threshold T, the first (m-n2) memory blocks in the memory pool that are in an idle state and whose usage frequency H is arranged from small to large are released to the system memory management module; when n3<m≤N and the duration of the state reaches the third threshold T, the first (m-n3) memory blocks in the memory pool that are in an idle state and whose usage frequency H is arranged from small to large are released to the system memory management module.
[0031] In a third aspect, the present application provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus;
[0032] The memory is used to store computer programs;
[0033] The processor is used to implement any method step of the first aspect of the present application when executing the program stored in the memory.
[0034] The fourth aspect of the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, any method step of the first aspect of the present application is implemented.
[0035] Beneficial effects:
[0036] From the above technical solution, we can see that this method builds a memory pool that does not contain any memory blocks in the initial state. According to the memory application requirements in actual applications, the system will dynamically allocate the required memory blocks to the memory pool. When the number of memory blocks in the memory pool reaches the upper limit and the current memory blocks cannot meet the new memory application requirements, the memory blocks with low usage frequency will be released to make room for new memory requirements. This on-demand allocation and flexible adjustment of the memory pool management strategy not only ensures that the memory pool can meet the needs of actual applications, but also significantly reduces the capacity occupancy of the memory pool, thereby significantly improving the efficiency and performance of memory use.
[0037] It should be appreciated that all combinations of the foregoing concepts, as well as additional concepts described in greater detail below, may be considered to be part of the inventive subject matter of the present disclosure, provided such concepts are not mutually inconsistent.
[0038] The foregoing and other aspects, embodiments and features of the present invention can be more fully understood from the following description in conjunction with the accompanying drawings. Other additional aspects of the present invention, such as the features and / or beneficial effects of the exemplary embodiments, will be apparent from the following description or learned from the practice of the specific embodiments according to the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] The drawings are not intended to be drawn to scale. In the drawings, each identical or nearly identical component shown in various figures may be represented by the same reference numeral. For clarity, not every component is labeled in every figure. Embodiments of various aspects of the present invention will now be described by way of example and with reference to the accompanying drawings, in which:
[0040] Figure 1 A flowchart of a memory pool dynamic management method provided by an embodiment of the present invention;
[0041] Figure 2 A flowchart of a memory pool dynamic management method provided by another embodiment of the present invention;
[0042] Figure 3 A flowchart of a memory pool dynamic management method provided by another embodiment of the present invention;
[0043] Figure 4 A flowchart of a memory pool dynamic management method provided by another embodiment of the present invention;
[0044] Figure 5 A flowchart of actively releasing free memory blocks in a hierarchical manner in a memory pool dynamic management method provided by an embodiment of the present invention;
[0045] Figure 6 A schematic diagram of the structure of a memory pool dynamic management device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solution and advantages of the embodiment of the present invention clearer, the technical solution of the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings of the embodiment of the present invention. Obviously, the described embodiment is a part of the embodiment of the present invention, not all of the embodiments. Based on the described embodiment of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. Unless otherwise defined, the technical terms or scientific terms used herein should be the common meanings understood by people with ordinary skills in the field to which the present invention belongs.
[0047] The words "first", "second" and similar words used in the patent application specification and claims of the present invention do not indicate any order, quantity or importance, but are only used to distinguish different components. Similarly, unless the context clearly indicates otherwise, the singular form of "a", "an" or "the" and other similar words do not indicate a quantitative limitation, but indicate the existence of at least one. "Include" or "comprise" and other similar words mean that the elements or objects appearing before "include" or "comprise" include the features, wholes, steps, operations, elements and / or components listed after "include" or "comprise", and do not exclude the existence or addition of one or more other features, wholes, steps, operations, elements, components and / or their collections. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0048] The inventor of the present application has found that when processing a video, both the output of the encoding and the input of the decoding need to frequently apply for memory. Frequent memory application and release operations will cause the system to spend a lot of time on memory management, thereby reducing the execution efficiency of the program. At the same time, a large amount of memory fragmentation will be generated, making it difficult to find a sufficiently large continuous memory block in subsequent memory applications, thereby increasing the risk of memory allocation failure. Therefore, the memory pool technology is currently used to manage the application and release of memory. The memory pool pre-allocates a large memory space and allocates the memory block to the required object during the program running process. When the object no longer needs the memory, it is returned to the memory pool instead of being released directly to the system. This can reduce the number of memory applications and the generation of memory fragments.
[0049] However, the memory pool technology pre-allocates a large memory space. Even if not all memory blocks are used at some point, these unused memory blocks will still be occupied, resulting in a certain degree of memory waste. This waste may be more obvious, especially when the memory pool is not designed properly or the program's memory usage requirements vary greatly. In addition, the memory blocks in the memory pool are usually fixed in size, which means that they may not fully match the memory requirements of all objects. If the memory size required by the object does not match the size of the memory block in the memory pool, it may lead to reduced memory usage efficiency or require additional memory allocation operations. At the same time, it takes a certain amount of time and resources to create and initialize the memory pool at the beginning of the program. If the size of the memory pool is large, this overhead may be more obvious. In addition, if there are many memory blocks in the memory pool that are rarely used during the program's operation after initialization, then this overhead may be unnecessary.
[0050] For low-power mobile devices and embedded devices, these devices are usually equipped with limited memory capacity due to specific application scenarios and strict cost control requirements. If the size of the memory block in the memory pool does not match the needs of the program, it may lead to reduced memory usage efficiency. Wasted memory resources may reduce the ability of embedded devices to run other applications or handle other tasks at the same time, reducing the overall performance of the device. When using the camera recording or video playback function, due to the dynamic change of the video frame size, when a video frame is too large, memory may be frequently requested and released. When the video frame is too small, it will cause memory waste. Therefore, an efficient memory management strategy is needed to further optimize memory usage efficiency.
[0051] In an embodiment of the present invention, a method for dynamic management of a memory pool is provided. Figure 1 As shown, the method includes steps S110 to S170:
[0052] S110: Create a memory pool. Initially, no memory blocks are allocated to the memory pool. The number of memory blocks in the memory pool is set to be no greater than a first threshold N.
[0053] When a program starts, for example, when a video service starts, a memory pool is created, and no memory blocks are allocated in the memory pool. The memory pool can manage subsequently acquired memory blocks in an array or linked list manner, and the maximum number of memory blocks in the memory pool is set to a first threshold value N. Since the memory pool does not contain memory blocks at the beginning, a large amount of memory is not occupied at the beginning of the video service, thereby reducing memory consumption in the initial stage of the service.
[0054] S120: In response to the memory request, determine whether there is an idle memory block in the memory pool that satisfies the memory request.
[0055] The memory blocks in the memory pool that are applied for are marked as busy, and the memory blocks that are not applied for are marked as free. When a memory application is received, it is determined whether there are free memory blocks in the memory pool that meet the memory application. Since the memory pool does not contain memory blocks initially, there are no memory blocks that meet the memory application when the memory application is received for the first time, and step S140 is started to determine whether the number of memory blocks in the memory pool reaches a first threshold value N. Since there are no memory blocks in the memory pool, step S160 is started, and the system allocates memory blocks that meet the memory application requirements to the memory pool. After the memory pool obtains the memory blocks, it provides the memory blocks to the business program that issued the memory application.
[0056] S170: After the memory block is used up, the memory block is returned to the memory pool.
[0057] After the memory pool runs for a period of time, it will contain some memory blocks. When a memory application is received, if there are memory blocks in the memory pool that are in an idle state and meet the memory application, step S130 is started. According to the size of the memory blocks required by the memory application, the memory pool provides memory blocks for the memory application business, so as to complete the reuse of memory blocks and avoid frequent allocation of memory blocks from the system. If there are no memory blocks that meet the requirements in the memory pool, step S140 is started to find that the number of memory blocks reaches the first threshold N at this time, then step S150 is started to release the memory blocks in the memory pool that are in an idle state, and prepare for the dynamic adjustment of the memory blocks in the memory pool. Then step S160 is started, and the system allocates the required memory blocks to the memory pool. After the memory pool obtains the memory blocks, it provides the memory blocks to the business program that issues the memory application. Through the above steps, the passive adjustment of the memory pool is completed, so that the size of the memory pool changes with the business needs, and the memory blocks in the memory pool are allocated on demand, and there will be no waste caused by excessive memory blocks. At the same time, the business program's memory needs are met, so that efficient use of memory is achieved. For video services, the memory requirements for video decoding and encoding are dynamically changing, and this change may be very large. For example, information such as motion, texture, and color in the scene will affect the amount of calculation and memory requirements during decoding and encoding. Complex video content requires more memory to store intermediate results and temporary data. The memory pool management method of this embodiment can improve memory utilization, reduce memory fragmentation, and improve real-time performance.
[0058] It is understandable that the first threshold N can be any positive number according to actual needs, preferably a positive integer. The marking of whether the memory block in the memory pool is busy or idle can be managed by using an array or a linked list, and the present invention does not limit this.
[0059] Figure 2 Another memory pool dynamic management method of this application is shown, such as Figure 2 As shown, steps S210 to S280 are included:
[0060] For step S210, refer to the description of S110 in the above embodiment, which will not be described in detail here.
[0061] S220: In response to the memory request, record the time t1 of the memory request.
[0062] After receiving the memory application, the time t1 at which the memory application is obtained is recorded, and step S230 is started to determine whether there is an idle memory block in the memory pool that satisfies the memory application. When there is no idle memory block in the memory pool that satisfies the memory application, step 250 is started. For step 250, refer to the description of S140 in the above embodiment, and will not be repeated here. When the number of memory blocks does not reach the first threshold N, step 270 is started to allocate the memory blocks required for the memory application to the memory pool, and the memory pool provides the newly obtained memory blocks to the memory applicant, and the allocation time t0 when the memory blocks are allocated to the memory pool is recorded.
[0063] S280: After the memory block is used up, the memory block is returned to the memory pool, and the memory block usage count count is increased by 1.
[0064] like Figure 2 As shown in the figure, when there is no idle memory block in the memory pool that satisfies the memory request and the number of memory blocks reaches the first threshold value N, step S260 is started to calculate the memory pool according to the recorded number of times the memory block is used count and the allocation time t0 of the memory block to the memory pool and the time t1 of this memory request.
[0065] The usage frequency H of each memory block in the idle state is sorted, Release the memory block which is in an idle state and has the lowest usage frequency H. Start step S270, which will not be described in detail here.
[0066] In this embodiment, a refined memory management strategy is adopted. The strategy first records the time t0 when the memory block is allocated to the memory pool, and continuously tracks the number of times each memory block is used count. When the number of memory blocks in the memory pool reaches the preset first threshold N, and the idle memory blocks cannot meet the new memory application requirements, the usage frequency H of each memory block from the last allocation to the current memory application is calculated, so as to accurately identify the memory block with the lowest usage frequency. Subsequently, this memory block with the lowest usage frequency is selected for release to ensure that while releasing the memory, the need to re-apply for memory from the system due to the release of high-frequency memory blocks is minimized.
[0067] Through this precise passive adjustment strategy, this embodiment not only effectively manages memory resources, but also ensures the response speed and performance of the system, which is more in line with actual business needs.
[0068] Figure 3 Another memory pool dynamic management method of this application is shown. Figure 2Compared with the embodiment shown in FIG. 1 , only step S260 is changed. In this embodiment, when there is no idle memory block in the memory pool that satisfies the memory application and the number of memory blocks reaches the first threshold N, t1-t0 obtains the existence time t2 of each idle memory block from the memory pool to the memory application, and sets the second threshold t x , the time t2 in the released memory pool is greater than the second threshold t x A memory block that is in an idle state and has the lowest usage frequency H. In actual program applications, for example in video services, when encountering special situations such as scene changes, the memory demand for video frame processing may increase significantly. If the memory blocks in the memory pool cannot meet this sudden increase in memory demand, the smaller memory blocks are dynamically replaced with memory blocks with larger capacity. However, during this dynamic replacement process, the memory blocks newly allocated to the memory pool may be mistakenly released because of their relatively low usage frequency. In order to avoid this problem of erroneous release due to short existence time, this embodiment limits the existence time of the memory blocks to be released in the memory pool to reach a second threshold value t x This measure improves the accuracy of memory pool management and better adapts to the dynamic changes in memory requirements in actual applications such as video services.
[0069] For the various embodiments provided above, there are also some preferred solutions. When the memory pool responds to a memory request with a memory block, the smallest memory block in the idle state that meets the memory request is selected for use.
[0070] As mentioned above, in various program applications, the demand for memory often changes dynamically. For example, in a video service, the memory blocks required may be relatively large at a certain time, but then the memory capacity requirement may drop to a lower level. In this case, since the number of memory blocks in the memory pool is limited by the first threshold N, there will be a situation where free small memory blocks are released to allocate larger memory blocks, which will cause the memory blocks in the memory pool to gradually increase, causing the total memory usage of the memory pool to gradually increase.
[0071] In order to solve the above problems, Figure 4 Another memory pool dynamic management method of this application is shown in Figure 3 Based on the memory pool dynamic management method, steps S310 and 320 are added.
[0072] S310: Monitor the number m of memory blocks in the memory pool that are in an idle state.
[0073] After the memory pool is created, the number of memory blocks in the memory pool that are in an idle state is continuously monitored, and the fourth threshold n1 and the third threshold T are set.
[0074] S320: When it is monitored that m is greater than the fourth threshold n1 and the duration of this state reaches the third threshold T, the first (m-n1) memory blocks in the memory pool that are in an idle state and whose usage frequencies H are arranged in ascending order are released.
[0075] The number m of memory blocks in the idle state in the memory pool is continuously monitored. When m is greater than the fourth threshold value n1 and the duration reaches the fourth threshold value T, the number of memory blocks in the idle state in the memory pool reflects the demand for memory by the business at that time. If the number of memory blocks in the idle state is always high for a period of time, it means that there are enough memory blocks in the memory pool to meet the requirements of the memory application. At this time, some memory blocks in the idle state are released to achieve the purpose of saving system memory and improve the system memory utilization rate. As mentioned above, the preferred scheme is that when the memory pool responds to the memory application, the smallest memory block in the idle state required to meet the memory application is selected for provision. The method of actively releasing the idle state memory blocks in this embodiment will release some memory blocks with low usage frequency and large capacity, which solves the problem that the memory blocks in the memory pool gradually become larger, making the total memory occupancy of the memory pool gradually increase. By implementing this scheme, we actively release those idle memory blocks with low usage frequency but large capacity. This approach effectively solves the problem that the total memory occupancy continues to grow due to the gradual increase of the memory blocks in the memory pool. Especially in applications such as video services, when memory demand surges during a specific period of time and causes the memory pool to expand, this solution can release large memory blocks that are less frequently used, thereby ensuring that the memory demand for video services drops from the peak. The size of the memory pool can also be dynamically reduced accordingly to achieve efficient use of memory resources.
[0076] The memory requirements of various program services are mostly dynamically changing. Taking the video service as an example, during encoding and decoding, the memory requirements of the video frame will surge and decrease in some time periods, so the size of the memory block in the memory pool and the ratio of busy and idle memory blocks are also dynamically changing. In this embodiment, when the memory requirement increases, due to the limitation of the first threshold N, the idle memory blocks with less frequent use are passively released to obtain the memory blocks that meet the service requirements, so that when the memory requirement is not large, the memory pool size is maintained at a relatively low level, improving the utilization efficiency of the memory, and when the memory requirement increases, the memory requirements of the service are met in time. The frequent allocation and release of memory blocks are effectively avoided, the generation of memory fragments on the system memory is greatly reduced, and the response speed of the video service application for memory is also improved. When the memory demand decreases, the number m of memory blocks in the idle state in the monitoring memory pool is monitored. When m is greater than the set threshold and the time is up to standard, the idle memory blocks in the memory pool are actively released to reduce the capacity of the memory pool. By passively exchanging memory blocks and actively releasing memory blocks, the total memory size occupied by the memory pool is dynamically matched with the business demand for memory, reducing idle memory blocks and wasted memory space.
[0077] like Figure 5 The flowchart of another memory pool dynamic management method of the present application for hierarchical active release of free memory blocks is shown. It can be understood that: Figure 5 This is a preferred solution for step S320.
[0078] Specifically, a fifth threshold n2 and a sixth threshold n3 are set, wherein n3 is greater than n2, and n2 is greater than n1;
[0079] When it is monitored that m is greater than n1, the state change of n1<m≤n2 is monitored. When the duration of this state reaches the third threshold T, the first (m-n1) memory blocks in the memory pool that are in an idle state and whose usage frequency H is arranged in ascending order are released;
[0080] When it is monitored that m is greater than n2, the state change of n2<m≤n3 is monitored. When the duration of this state reaches the third threshold T, the first (m-n2) memory blocks in the memory pool that are in an idle state and whose usage frequency H is arranged in ascending order are released;
[0081] When it is monitored that m is greater than n3, the state change of n3<m≤N is monitored. When the duration of this state reaches the third threshold T, the first (m-n3) memory blocks in the memory pool that are in idle state and whose usage frequency H is arranged from small to large are released.
[0082] When monitoring m, when m drops from one area to another, it is possible to recalculate whether the duration of m in the area reaches the third threshold T, or to accumulate and calculate whether the duration of m greater than the lower limit of the area reaches the third threshold T. This application does not impose any restrictions on this. For example, when m is in the (n2, n3] area, since there are no idle memory blocks in the memory pool that meet the memory application, some idle memory blocks are released. When m is equal to n2, m enters the (n1, n2] area. At this time, it is possible to recalculate whether the duration of m in this area reaches the third threshold T. It is also possible to accumulate the time that m spends in the (n1, n2] and (n2, n3] areas, and then determine whether the accumulated time of m in this area reaches the third threshold T. This application does not impose any restrictions on this.
[0083] On the other hand, embodiments of the present invention provide Figure 6 A memory pool dynamic management device is shown, comprising:
[0084] The business module is used to issue memory requests and return the used memory blocks after they are used.
[0085] The memory pool management module is used to create a memory pool. The memory pool does not allocate memory blocks initially. The first threshold N is set. The number of memory blocks in the memory pool is not greater than N. The time t0 when each memory block is allocated to the memory pool and the number of times the memory block is used by the memory application count are recorded. The time when the memory application is received is t1. The usage frequency H of the memory block is defined. The second threshold t x , the existence time t2 of the memory block in the memory pool;
[0086] The system memory management module manages memory that can be DDR physical memory or virtual memory of the operating system, and is used to allocate memory blocks to the memory pool management module and receive memory blocks released by the memory pool management module;
[0087] The memory pool management module includes a first judgment submodule, which records the time t0 when each memory block is allocated to the memory pool and the number of times the memory block is used by the memory application count, the time when the memory application is received is t1, the existence time of the memory block in the memory pool is t2, defines the usage frequency H of the memory block, and sets the second threshold t x , used to determine whether there is a memory block in the memory pool that satisfies the memory request when a memory request is received;
[0088] If there is no idle memory block that satisfies the memory application in the memory pool, when the number of memory blocks in the memory pool is less than the first threshold value N, the system management module allocates the memory blocks required for the memory application to the memory pool, and the memory pool management module provides the memory blocks obtained by the memory pool to the business module. When the number of memory blocks in the memory pool is equal to the first threshold value N, the memory blocks in the idle state of the memory pool are selected with the smallest usage frequency H and an existence time t2 greater than the second threshold value t x If there are at least two memory blocks with the smallest usage frequency H, the memory block with the smallest memory capacity is released. After the memory block is released, the system management module allocates the memory block required for the memory application to the memory pool, and the memory pool management module provides the memory block obtained by the memory pool to the business module;
[0089] If there is an idle memory block that meets the memory application in the memory pool, the memory pool management module selects a memory block that meets the memory application requirements and has the smallest memory capacity from the memory pool according to the memory size of the memory block required by the memory application, and provides it to the business module;
[0090] The memory pool management module includes a second judgment submodule, which sets a third threshold T, a fourth threshold n1, a fifth threshold n2 and a sixth threshold n3. The number of memory blocks in the memory pool that are in an idle state is m. When n1<m≤n2 and the duration of the state reaches the third threshold T, the first (m-n1) memory blocks in the memory pool that are in an idle state and whose usage frequency H is arranged from small to large are released to the system memory management module; when n2<m≤n3 and the duration of the state reaches the third threshold T, the first (m-n2) memory blocks in the memory pool that are in an idle state and whose usage frequency H is arranged from small to large are released to the system memory management module; when n3<m≤N and the duration of the state reaches the third threshold T, the first (m-n3) memory blocks in the memory pool that are in an idle state and whose usage frequency H is arranged from small to large are released to the system memory management module.
[0091] An electronic device provided in an embodiment of the present application includes: a processor, a communication interface, and a memory, wherein the processor, the communication interface, and the memory are interconnected via a bus, wherein the processor is used to execute instructions stored in the memory. The memory stores program code, and the processor can call the program code stored in the memory to execute all or part of the steps of a memory pool dynamic management method described in any of the above exemplary embodiments.
[0092] In the embodiment of the present application, the processor can have a variety of specific implementation forms, for example, the processor can be any one or more combinations of processors such as CPU, GPU, TPU or NPU, and the processor can also be a single-core processor or a multi-core processor. The processor can be a combination of CPU (GPU, TPU or NPU) and hardware chip. The above-mentioned hardware chip can be an application-specific integrated circuit (ASIC), a programmable logic device (PLD) or a combination thereof. The above-mentioned PLD complex program logic device (CPLD), field programmable gate array (FPGA), general array logic (GAL) or any combination thereof. The processor can also be implemented by a logic device with built-in processing logic alone, such as FPGA or digital signal processor (DSP).
[0093] The communication interface may be a wired interface or a wireless interface for communicating with other modules or devices. The wired interface may be an Ethernet interface, a controller area network (CAN) interface or a local interconnect network (LIN) interface, and the wireless interface may be a cellular network interface or a wireless LAN interface.
[0094] The bus can be divided into address bus, data bus, control bus, etc.
[0095] Optionally, the electronic device may further include an input / output interface, to which an input / output device is connected for receiving input information and outputting operation results.
[0096] In some possible implementations, the electronic device may be the above-mentioned electronic device, or may be a server.
[0097] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. When the computer program runs on a processor, the method steps executed by the electronic device in the above method embodiment can be implemented.
[0098] The embodiment of the present application also provides a computer program product or a computer program, which may include computer instructions, which may be stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor may execute the computer instructions so that the computer device executes the description of the memory pool dynamic management method in the previous embodiment, so it will not be repeated here. In addition, the description of the beneficial effects of using the same method will not be repeated. For technical details not disclosed in the computer program product or computer program embodiment involved in this application, please refer to the description of the method embodiment of this application.
[0099] It should be understood that, although the steps in the flowcharts of the above embodiments are shown in sequence according to the arrows, these steps are not necessarily performed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction for the execution of these steps, and these steps can be performed in other orders.
[0100] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the hardware + program embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0101] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0102] Although this specification provides method operation steps such as embodiments or flow charts, more or fewer operation steps may be included based on conventional or non-creative means. The order of steps listed in the embodiments is only one way of executing the order of many steps and does not represent the only execution order. When the device or terminal product in practice is executed, it can be executed in the order of the method shown in the embodiments or the drawings or in parallel (for example, in a parallel processor or multi-threaded processing environment, or even a distributed data processing environment).
[0103] The terms "comprises", "includes" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, product or apparatus that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, product or apparatus. In the absence of more restrictions, it is not excluded that there are other identical or equivalent elements in the process, method, product or apparatus that includes the elements.
[0104] For the convenience of description, the above devices are described in terms of functions and are divided into various modules. Of course, when implementing the embodiments of this specification, the functions of each module can be implemented in the same or multiple software and / or hardware, or the modules that implement the same function can be implemented by a combination of multiple sub-modules or sub-units. The device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0105] Those skilled in the art also know that, in addition to implementing the controller in a purely computer-readable program code, the controller can be made to implement the same function in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, such a controller can be considered as a hardware component, and the devices for implementing various functions included therein can also be considered as structures within the hardware component. Or even, the devices for implementing various functions can be considered as both software modules for implementing the method and structures within the hardware component.
[0106] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0107] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0108] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0109] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0110] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0111] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include transitory media such as modulated data signals and carrier waves.
[0112] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems or computer program products. Therefore, the embodiments of this specification may take the form of complete hardware embodiments, complete software embodiments or embodiments combining software and hardware. Moreover, the embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0113] The various embodiments in this specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The embodiments of this specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0114] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the embodiments of this specification. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.
[0115] The above are only examples of the embodiments of the present specification and are not intended to limit the embodiments of the present specification. For those skilled in the art, the embodiments of the present specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the embodiments of the present specification shall be included in the scope of the claims of the embodiments of the present specification.
[0116] Although the present invention has been disclosed as above with preferred embodiments, it is not intended to limit the present invention. A person with ordinary knowledge in the technical field to which the present invention belongs may make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, the protection scope of the present invention shall be determined by the definition of the claims.
Claims
1. A memory pool dynamic management method, characterized in that: Creating a memory pool, wherein the memory pool initially does not allocate memory blocks, setting a first threshold N, and the number of memory blocks in the memory pool is not greater than the first threshold N; In response to a memory application, determining whether there is a memory block in the memory pool that satisfies the memory application and is in an idle state; If there is no idle memory block in the memory pool that satisfies the memory application, when the number of memory blocks in the memory pool is less than the first threshold N, the memory block required for the memory application is allocated to the memory pool, and the memory pool provides the newly acquired memory block to the memory application; when the number of memory blocks in the memory pool reaches the first threshold N, after releasing the idle memory blocks in the memory pool, the memory block required for the memory application is allocated to the memory pool, and the memory pool provides the newly acquired memory block to the memory application; If there is an idle memory block in the memory pool that satisfies the memory application, the memory pool provides a memory block for the memory application according to the memory size of the memory block required by the memory application; After the memory block is used up, the memory block is returned to the memory pool.
2. The memory pool dynamic management method according to claim 1, characterized in that When the number of memory blocks in the memory pool reaches a first threshold value N, after releasing the memory blocks in the memory pool that are in an idle state, the method includes: recording the time t0 when the memory block is allocated to the memory pool, the number of times the memory block is used by the memory application count, the time when the memory application is received is t1, defining the usage frequency H of the memory block, When there is no memory block in the memory pool that satisfies the memory application and the number of memory blocks in the memory pool reaches the first threshold N, a memory block in the memory pool that is in an idle state and has the lowest usage frequency H is released.
3. The memory pool dynamic management method according to claim 2, characterized in that: Set the second threshold t x , record the existence time t2 of the memory block in the memory pool; When there is no memory block in the memory pool that satisfies the memory request and the number of memory blocks in the memory pool reaches the first threshold N, the memory blocks in the memory pool whose existence time t2 is greater than the second threshold t x The memory block that is in idle state and has the lowest usage frequency H.
4. The memory pool dynamic management method according to claim 2 or 3, characterized in that: When the memory pool releases a memory block, when there are at least two memory blocks with the smallest usage frequency H, the memory block with the smallest memory capacity is released.
5. The memory pool dynamic management method according to claim 2, characterized in that: Setting a third threshold T and a fourth threshold n1 to monitor the number m of memory blocks in the memory pool that are in an idle state; When m>n1 and the duration of this state reaches the third threshold T, the first (m-n1) memory blocks in the memory pool that are in an idle state and whose usage frequencies H are arranged from small to large are released.
6. The memory pool dynamic management method according to claim 5, characterized in that Also includes: Setting a fifth threshold n2 and a sixth threshold n3, wherein n3>n2>n1; When n1<m≤n2 and the duration of this state reaches the third threshold value T, the first (m-n1) memory blocks in the memory pool that are in an idle state and whose usage frequencies H are arranged in ascending order are released; When n2<m≤n3 and the duration of this state reaches the third threshold T, the first (m-n2) memory blocks in the memory pool that are in an idle state and whose usage frequencies H are arranged in ascending order are released; When n3<m≤N and the duration of this state reaches the third threshold T, the first (m-n3) memory blocks in the memory pool that are in an idle state and whose usage frequencies H are arranged from small to large are released.
7. The memory pool dynamic management method according to claim 1, characterized in that If there is an idle memory block in the memory pool that meets the requirements of the memory application, the memory pool provides memory blocks for the memory application according to the memory size of the memory block required by the memory application, and also includes: the memory pool selects a memory block that meets the requirements of the memory application and has the smallest memory capacity, and provides it to the memory application.
8. A memory pool dynamic management device, characterized in that: include The business module is used to issue memory requests and return the used memory blocks after they are used. A memory pool management module is used to create a memory pool. The memory pool does not allocate memory blocks initially. A first threshold N is set. The number of memory blocks in the memory pool is not greater than N. The time t0 when each memory block is allocated to the memory pool and the number of times count when the memory block is used by the memory application are recorded. The time when the memory application is received is recorded as t1. The usage frequency H of the memory block is defined. Set the second threshold t x , the existence time t2 of the memory block in the memory pool; A system memory management module, used to allocate memory blocks to the memory pool management module and receive memory blocks released by the memory pool management module; The memory pool management module includes a first judgment submodule, which is used to judge whether there is a memory block that meets the memory application in the memory pool when the memory application is received; If there is no idle memory block in the memory pool that satisfies the memory application, when the number of memory blocks in the memory pool is less than the first threshold value N, the system management module allocates the memory blocks required for the memory application to the memory pool, and the memory pool management module provides the newly acquired memory blocks of the memory pool to the business module, and when the number of memory blocks in the memory pool is equal to the first threshold value N, select the memory blocks in the idle state of the memory pool with the smallest usage frequency H and the existence time t2 greater than the second threshold value t x The memory block is released, if there are at least two memory blocks with the smallest usage frequency H, the memory block with the smallest memory capacity is released, after the memory block is released, the system management module allocates the memory block required by the memory application to the memory pool, and the memory pool management module provides the newly acquired memory block of the memory pool to the business module; If there is an idle memory block in the memory pool that meets the memory application, the memory pool management module selects a memory block that meets the requirements of the memory application and has the smallest memory capacity from the memory pool according to the memory size of the memory block required by the memory application, and provides it to the business module; The memory pool management module includes a second judgment submodule, which sets a third threshold T, a fourth threshold n1, a fifth threshold n2 and a sixth threshold n3, monitors the number of memory blocks in the memory pool that are in an idle state as m, and when n1<m≤n2 and the duration of the state reaches the third threshold T, the first (m-n1) memory blocks in the memory pool that are in an idle state and whose usage frequency H is arranged from small to large are released to the system memory management module; when n2<m≤n3 and the duration of the state reaches the third threshold T, the first (m-n2) memory blocks in the memory pool that are in an idle state and whose usage frequency H is arranged from small to large are released to the system memory management module; when n3<m≤N and the duration of the state reaches the third threshold T, the first (m-n3) memory blocks in the memory pool that are in an idle state and whose usage frequency H is arranged from small to large are released to the system memory management module.
9. An electronic device, characterized in that : comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; The memory is used to store computer programs; The processor is used to implement the method steps described in any one of claims 1-7 when executing the program stored in the memory.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps of any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Database memory allocation method, device and equipment
CN119473635A
Memory management method, device and equipment, storage medium and computer program product
CN120407204A
Memory management method, device and equipment, storage medium and computer program product
CN120407204B
Memory management method for dynamic allocation of operating system and storage medium
CN120653439A
