A low-fragmentation memory management method based on multi-size data block management

By adopting multi-size data block management and dynamic adjustment strategies in memory management, the problem of low efficiency of traditional memory management is solved, efficient utilization and adaptability are achieved, memory fragmentation and waste are reduced, and system performance is improved.

CN118409979BActive Publication Date: 2024-10-01WEAPON EQUIP RES INST OF CHINA NAT WEAPON EQUIP GRP
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202410859547.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-28
Publication Date
2024-10-01
Estimated Expiration
2044-06-28

AI Technical Summary

Technical Problem

Traditional memory management strategies cannot effectively adapt to the memory usage patterns of different applications, resulting in inefficient memory utilization and problems of memory fragmentation and waste.

Method used

Adopt a low-fragmentation memory management method based on multi-size data block management, divide the memory space into multiple memory partitions by initializing it, establish a two-way circular linked list, monitor performance indicators and average utilization in real time, dynamically adjust memory allocation and recycling strategies, and optimize memory blocks distribution and recycling.

Benefits of technology

It improves memory utilization, reduces memory fragmentation and waste, improves system performance, and has strong adaptability and simple and efficient algorithms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118409979B_ABST
    Figure CN118409979B_ABST
Patent Text Reader

Abstract

The present invention proposes a low-fragmentation memory management method based on multi-size data block management, which belongs to the field of computer memory management; the method includes: initializing a memory pool, dividing memory areas according to configuration information and establishing a bidirectional circular linked list of memory blocks of different sizes; when allocating memory, allocating free blocks according to the relationship between the size of the application space and the size of the memory block load; when recycling memory, according to the free linked list position recorded by the released memory block, deleting it from the occupied linked list and inserting it into the corresponding free linked list; regularly calculating the performance index and average utilization rate of the system, and dynamically adjusting the memory allocation and recycling strategy according to the changes of the two indicators. The present invention realizes efficient utilization of memory resources, reduces the generation rate of memory fragmentation, improves system performance, and has strong adaptability and practical value by optimizing memory allocation, recycling and dynamic adjustment strategies.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of computer memory management, and in particular relates to a low-fragmentation memory management method based on multi-size data block management. Background Art

[0002] With the continuous development of computer systems, the demand for memory resources by applications is also increasing. Memory management is a very important subsystem in the operating system, responsible for effectively allocating, recycling and managing the system's memory resources. Traditional memory management strategies are usually static and cannot adapt well to the memory usage patterns of different applications, resulting in inefficient memory utilization, memory fragmentation and memory waste.

[0003] In order to improve memory utilization efficiency, researchers have proposed a variety of dynamic memory management strategies, such as best fit, buddy system, etc. These strategies reduce memory fragmentation through algorithm optimization, but there are still some limitations, such as the inability to fully utilize hardware features and the inability to adapt to dynamically changing application scenarios. Summary of the invention

[0004] In view of the shortcomings of the prior art, the present invention proposes a low-fragmentation memory management method based on multi-size data block management. The method comprehensively considers multiple factors such as memory block utilization, access frequency and capacity, and realizes efficient utilization of memory resources through real-time monitoring and dynamic adjustment of memory management strategies.

[0005] The low-fragmentation memory management method based on multi-size data block management comprises the following steps:

[0006] Step 1: Initialize the memory space, divide the memory space into multiple memory partitions according to the configuration information, and establish a bidirectional circular linked list of memory blocks of different sizes in each memory partition;

[0007] Wherein, the bidirectional circular linked list refers to a free linked list and an occupied linked list;

[0008] Step 2: When allocating memory, allocate a free block from the free list of the corresponding memory partition according to the relationship between the application space and the memory block load; insert the free block into the occupied list of the memory space;

[0009] Step 3: When the memory is recycled, the released memory block is deleted from the occupied linked list of the memory space, and inserted into the corresponding free linked list of the memory partition where it is located;

[0010] Step 4: Regularly calculate the system's performance indicators and average utilization, and dynamically adjust the memory allocation and recovery strategy according to changes in the performance indicators and average utilization.

[0011] In particular, in step 1: according to the configuration information, the available continuous memory space is divided into multiple memory partitions, each of the memory partitions includes a manager space and multiple different memory blocks; the manager space stores statistical and configuration information; for each of the memory partitions, a bidirectional circular free list and an occupied list are created, the free list is used to manage all unallocated memory blocks in the memory partition, and the occupied list is used to manage all allocated memory blocks in the memory partition.

[0012] In particular, in step 2, allocating free blocks from the free linked list of the corresponding memory partition according to the relationship between the application space and the memory block load specifically includes:

[0013] When the requested space is greater than or equal to the maximum memory block load, the largest free block is allocated first. If the largest free block is smaller than the requested space, the manager's free block area is traversed to find the free list of the memory partition where the first free block that meets the conditions is located for allocation;

[0014] When the requested space is less than or equal to the minimum memory block load, reversely traverse the manager's free block area, find the free list of the memory partition where the first free block that meets the conditions is located, and allocate it. At this time, the minimum free memory block is allocated;

[0015] When the requested space falls between different memory block loads, first search for a free block in the memory partition where the memory block with the smallest load is located. If no free block is found, search in reverse until a free block that meets the conditions is found for allocation.

[0016] In particular, in step 3, when allocating memory, the allocated memory block is inserted into the header of the occupied linked list, or inserted into the subchain of a node in the occupied linked list; wherein:

[0017] When the allocated memory block is the first memory block allocated in the current memory block allocation process, insert it into the header of the occupied linked list; otherwise, insert it into the tail of the subchain of the node corresponding to the first memory block allocated in the current memory block allocation process in the occupied linked list;

[0018] When memory is recycled, the released memory block is directly inserted into the end of the corresponding free list.

[0019] In particular, in step 4, the performance index is calculated as follows:

[0020]

[0021] in, represents the performance index within the time period T, M represents the total memory capacity, represents the utilization rate of the i-th memory block in the time period T; Indicates the capacity of the i-th memory block; Indicates the access frequency of the i-th memory block; represents the remaining space of the i-th memory block in the time period T, and N represents the total number of memory blocks.

[0022] In particular, in step 4, the average utilization rate is calculated as follows:

[0023] in, represents the average memory utilization within the time period T, N represents the total number of memory blocks, It represents the actual usage of the i-th memory block in the time period T, and M represents the total memory capacity.

[0024] In particular, in step 4, dynamically adjusting the memory allocation and recovery strategy according to the changes in the performance index and the average utilization rate specifically includes:

[0025] When allocating memory, give priority to performance indicators by setting the upper and lower limits of the performance indicator judgment threshold. The memory partitions whose values ​​are greater than the upper limit of the performance indicator judgment threshold are allocated to improve the overall memory utilization efficiency; at the same time, a memory partition size configuration list is recommended according to the upper limit of the performance indicator judgment threshold;

[0026] When reclaiming memory, the average utilization rate is prioritized by setting the upper and lower limits of the average utilization rate judgment threshold. The memory blocks in the memory partition whose value is lower than the lower limit of the average utilization judgment threshold are used to release more available memory space.

[0027] In particular, in the method: when the average utilization When the average utilization rate drops to the lower limit of the average utilization rate judgment threshold, memory merging and recycling operations are triggered;

[0028] When the performance index When the performance indicator drops to the lower limit of the judgment threshold, the memory allocation strategy is adjusted.

[0029] In particular, the triggering of memory consolidation and recycling operations specifically includes: when the average utilization When it drops to the lower limit of the average utilization judgment threshold, all free lists are traversed to find adjacent free memory blocks, and the adjacent free blocks are merged into a new free block; the merged free block is updated, adjusted to the corresponding memory partition according to its load size, and inserted into the corresponding position in the free list of the memory partition, finally realizing the merging and recycling of memory.

[0030] In particular, in the method, when the performance indicator When the performance index decreases, adjust the memory allocation strategy, including: When the performance indicator falls below the lower limit of the performance indicator judgment threshold, the performance indicator is determined Reason for decline: If the performance index is affected by the decrease in memory block utilization If it decreases, the utilization of the i-th memory block will be increased. weight in the allocation strategy;

[0031] If the performance index is affected by the decrease in the access frequency of the memory block decreases, the access frequency of the i-th memory block increases. The weight in the allocation strategy.

[0032] The beneficial effects brought by the method proposed by the present invention include:

[0033] 1. Improve memory utilization. The present invention reduces the generation of memory fragments and improves the utilization of available memory space by optimizing memory allocation and recycling strategies. At the same time, dynamically adjusting the memory management strategy can respond to changes in system status in a timely manner and further optimize memory utilization efficiency.

[0034] 2. Reduce memory waste. The present invention takes into account factors such as the access frequency and capacity of memory blocks, and preferentially allocates and recycles memory blocks with larger capacity and lower utilization, thereby effectively reducing the waste of memory space.

[0035] 3. Improve system performance. The present invention introduces the concept of performance index, comprehensively considers multiple factors such as the capacity, utilization and access frequency of memory blocks, and gives priority to allocating memory blocks that have a greater impact on system performance, thereby improving the operating efficiency of the overall system.

[0036] 4. Strong adaptability. The present invention adopts a mechanism for dynamically adjusting the memory management strategy, which can automatically adjust the memory allocation and recovery strategy according to the real-time monitored system status. It has strong adaptability and is suitable for different application scenarios.

[0037] 5. The algorithm is simple and efficient. The dynamic adaptive memory management algorithm proposed in the present invention is reasonably designed, relatively simple to implement, and has low computational overhead. It can run efficiently on various hardware platforms and provide stable and efficient memory support for upper-level applications.

[0038] In summary, the low-fragmentation memory management method based on multi-size data block management proposed in the present invention achieves efficient utilization of memory resources, reduces memory fragmentation and waste, improves system performance, and has strong adaptability and practical value by optimizing memory allocation, recovery and dynamic adjustment strategies. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 A schematic flow chart of the low-fragmentation memory management method based on multi-size data block management proposed by the present invention. DETAILED DESCRIPTION

[0040] The present invention is described in detail below with reference to the accompanying drawings and embodiments.

[0041] The present invention provides a low-fragmentation memory management method based on multi-size data block management, such as Figure 1 As shown, the following steps are included:

[0042] Step 1, initialize the memory space, divide the memory space into multiple memory partitions according to the configuration information, and establish a bidirectional circular linked list of memory blocks of different sizes in each of the memory partitions; wherein the bidirectional circular linked list refers to a free linked list and an occupied linked list.

[0043] In this embodiment, the memory is divided into three levels: memory space, memory partition and memory block; each memory partition of the second level has a manager, and each second-level manager maintains a bidirectional linked list for managing each memory block in the memory partition. During the initialization phase, each memory block is in an idle state.

[0044] For each of the memory partitions, a bidirectional circular linked list is created. The so-called bidirectional linked list means that each node contains two pointer fields in addition to the data field, one pointing to the direct successor node and the other pointing to the direct predecessor node. Through these two pointers, the linked list can be traversed in any direction.

[0045] Specifically: through the two successor pointers, a traversal path in the next direction can be formed. That is, starting from the current node, the next node can be found through the successor pointer. Through the two predecessor pointers, a traversal path in the previous direction can be formed. That is, starting from the current node, the previous node can be found through the predecessor pointer. Such a bidirectional linked list structure allows the memory blocks in the memory partition to be flexibly added and deleted, improving the efficiency of memory management.

[0046] In step 1: according to the configuration information, the available continuous memory space is divided into multiple memory partitions, each of which includes a manager space and multiple different memory blocks; the manager space stores statistics and configuration information; for each of the memory partitions, a free list and an occupied list are created, the free list is used to manage all unallocated memory blocks in the memory partition, and the occupied list is used to manage all allocated memory blocks in the memory partition. Specifically, the configuration information is read and stored. By reading the custom data block partition configuration, a data block size list is obtained. For example, the configured size list is {{512, 2}, {256, 4}, {128, 4}, {64, 8}, {32, 16}}. Among them, {512, 2} means that the maximum memory block load space is 512 bytes, and the maximum memory block area occupies 2M space; {32, 16} means that the minimum memory block load space is 32 bytes, and the minimum memory block area occupies 16M space; the memory block load refers to the space in the memory block that can be effectively stored except for the management information.

[0047] The load of adjacent data blocks in the configuration list is 2 times, and the data block load space is an integer power of 2. The above example list is expected to divide the memory block into 5 partitions, each partition manages a memory block of one size.

[0048] The number of partitions and the division information of each partition are recorded in the global manager MemAreaManager_t structure. NR is used in the following text to represent the number of valid partitions.

[0049] When dividing the memory area, first apply for a piece of memory space, and store the global manager MemAreaManager_t structure at the beginning of this space. The global structure stores information such as the memory starting address, size number, free partition / linked list manager array MemBlockManager_t[N], index to the occupied linked list, total occupied space, total number of records, total number of occupied blocks, total size of fragmented space, etc. The space of the entire memory area except the manager structure is divided into MemAreaManager.blockTypesCnt partitions according to the configuration items. The space size of each partition is freeMgr[i].memAreaSize. Each partition space is further divided into several memory blocks of sizeof(MemNodeA_t) or sizeof(MemNodeB_t) or sizeof(MemNodeC_t) bytes according to the configuration. The memory block structure of different areas is different. The value[SIZE_N] array in the memory block is the load space, and the memory block load of different areas is different. After the memory area is divided, the entire memory space structure is manager-memory area-memory block. The relevant fields include:

[0050]

[0051] int blockTypesCnt; the number of memory areas divided (equal to the number of memory block load sizes)

[0052] MemBlockManager_t freeMgr[N]; memory pool secondary manager, responsible for managing a certain memory partition

[0053] int indexOfAreaBusy; the partition index of the first node of the occupied linked list

[0054] int indexOfBlocksBusy; the block index where the first node of the occupied linked list is located

[0055] int items; total number of data entries

[0056] int totalSize; the total size of the stored data

[0057] int totalBlocks; the total number of blocks occupied by the linked list

[0058] int memFragmentSize; total size of memory pool fragments

[0059] When constructing a linked list structure, in order to facilitate free memory management, a bidirectional circular linked list needs to be established in each memory partition. In the secondary manager MemBlockManager_t, there are two successor node indexes pointing to the first node of the linked list in this area, and two predecessor nodes pointing to the tail node of the linked list in this area. When the linked list is empty, the index value is -1. Each data block points to the next block through two successor indexes, namely the partition index nextIndexOfArea of ​​the next block and the block index nextIndexOfBlocks of the next block, and points to the predecessor block through the predecessor block partition index preIndexOfArea and the predecessor block index preIndexOfBlocks. The free blocks in each memory partition form a bidirectional circular linked list structure, which is managed by their respective MemBlockManager structures. Each MemBlockManager structure forms an array and exists in the manager structure.

[0060] The global manager MemAreaManager_t structure manages the occupied linked list and fragment count. Two indexes are used to point to the first node of the occupied linked list: indexOfAreaBusy; records the memory area where the first node of the occupied linked list is located, and indexOfBlocksBusy records the block index of the first node of the occupied linked list.

[0061] At initialization, since all memory blocks are free.

[0062] Step 2, when allocating memory, according to the size relationship between the application space size and the memory block load, allocate a free block from the free linked list of the corresponding memory partition; insert the free block into the occupied linked list of the memory space; in step 2, allocating the free block from the free linked list of the corresponding memory partition according to the size relationship between the application space size and the memory block load specifically includes:

[0063] When the requested space is greater than or equal to the maximum memory block load, the largest free block is allocated first. If the largest free block is smaller than the requested space, the manager's MemBlockManager_t array is traversed to find the area with free blocks. The smaller the array subscript, the larger the memory block corresponding to the linked list in this area. The free linked list of the memory partition where the first free block that meets the conditions is located is found and allocated.

[0064] When the requested space is less than or equal to the minimum memory block load, reversely traverse the manager's MemBlockManager_t array to find the area with free blocks, find the free list of the memory partition where the first free block that meets the conditions is located, and allocate it. At this time, the minimum free memory block is allocated;

[0065] When the requested space falls between different memory block loads, first search for a free block in the memory partition where the memory block with the smallest load is located. If no free block is found, search in reverse until a free block that meets the conditions is found for allocation.

[0066] Specifically, memory application adopts a combination of recursion and "right neighbor block selection" method. "Right neighbor block selection" means to try to decompose the size of the application space into the sum of the load size and the remaining number of the block on the right side of the list interval. For example, the load size list interval in the example of this article is {512, 256, 128, 64, 32}. If 612 bytes are applied for, it is decomposed into 512+100 bytes. If 70 bytes are applied for, it is decomposed into 64+6 bytes. Each recursion obtains a free block in the linked list of the calculated target interval, and the remaining unallocated space enters the next recursion. The basic principle is:

[0067] Since the load of different memory blocks decreases from left to right, the corresponding manager array indexes range from 0 to NR-1. Therefore, space application is divided into three cases:

[0068] (1) When the application space is greater than or equal to the leftmost load, the application falls on the left boundary;

[0069] (2) When the application space is less than or equal to the rightmost load, the application falls on the right boundary;

[0070] (3) When the requested space falls between different inner block loads, the request falls in the load list;

[0071] Case (1) is the scenario of handling the left boundary. In this case, the ideal block is to allocate a maximum block each time until the remaining unused space size falls into the load list, and then decompose it according to the right neighbor rule. However, in reality, there is a situation where the leftmost memory block in the list is not free (when freeMgr[0].freeNum is 0). Therefore, the general approach for case (1) is to first compare whether the total free list space is greater than the number of applications. If the free space is insufficient, an error is directly returned. If the total free space is greater than the number of applications, the MemBlockManager_t array is traversed from 0 to NR-1. The first array element with freeMgr[i].freeNum greater than 0 is the manager of the maximum free block list. The manager holds the head node index of the free list. Delete this maximum free block from the free list and insert it to the head position of the occupied list maintained by the global manager (in the case of allocating a leader block) or append it to the end of a sublist of the occupied list.

[0072] Explanation for inserting into the head of the occupied list and appending to the tail of the sub-list: Since the recursive function recur_find(size, level) passes in the recursive depth level, when level is 0, it means the first recursion. When the depth level is 0, the free block obtained is the leader block of this application, and the block obtained in the subsequent recursive process is the leader's sub-block. The leader block constitutes the main node of the occupied list. The non-leader blocks obtained during the recursion are attached to the leader block to form a sub-list, which is managed by the leader node. The nextIndexOfArea and nextIndexOfBlocks of the leader structure point to its sub-chain, and the nextIndexOfArea and nextIndexOfBlocks values ​​of the tail sub-block are -1.

[0073] The main process of the linked list operation implemented by the above process is: searching the target free linked list, taking free blocks, assigning values, inserting into the occupied linked list or appending to the leader sub-linked list. During the linked list operation, the freeNum count of the corresponding management array, the first index and the tail index of the free linked list pointed to by the array should be updated synchronously; the items, totalSize, and totalBlocks counts of the global manager, the first node index of the occupied block, and the fragment space size of the global manager should be modified; the predecessor / successor node index of the MemNode_t structure of the memory block before and after the deletion point and the insertion point and the sub-chain maintenance record should be modified. The key points of the linked list operation are the same in the three cases.

[0074] Case (2) is the scenario of processing the right boundary. When the requested block is smaller than the minimum load memory block, we want to find a minimum free block. We traverse the MemBlockManager_t array from NR-1 to 0 in reverse order, find the linked list with the first free block (the linked list corresponding to the array element freeMgr->freeNum>0), take its head node as the current minimum free block, and insert this memory block into the occupied linked list head node position. The process is the same as the linked list operation above. If there is no free block in each array after the traversal, it means that there is insufficient space.

[0075] Case (3) is when the requested size falls within the load range. The recursive right-neighbor block selection method is used to allocate free blocks. The linked list manager array freeMgr is traversed from 0 to NR-1 according to the array index. When the requested space falls between the freeMgr[i] and freeMgr[i+1] linked list loads, the inner loop traverses the arrays from freeMgr[i+1] to freeMgr[NR]. When the first array item with freeMgr->freeNum greater than 0 is found, the double loop ends. At this time, the free block index of the matched array points to the first node of the linked list selected by the adjacent block selection method. According to the linked list operation in the above text and update the manager and block node data, the recur_find(size, level) input parameter is modified to enter the next recursion. If no array item with freeMgr->freeNum greater than 0 is found in the above inner loop, it means that the linked lists managing smaller blocks are not free and there are no available right-neighbor blocks. At this point, the array from freeMgr[i] to freeMgr[0] is traversed in reverse order to search for linked lists of larger blocks. The double loop ends when the first array with freeMgr->freeNum greater than 0 is found. At this point, the smallest data block that can accommodate the request has been found, and the entire recursion ends. If no linked list with free blocks is found when traversing the array in reverse order, it means that there is insufficient space.

[0076] Step 3, when memory is recycled, the released memory block is deleted from the occupied linked list of the memory space, and inserted into the corresponding free linked list of the memory partition where it is located; In step 3:

[0077] When allocating memory, the allocated memory block is inserted into the header of the occupied linked list, or into the subchain of a node in the occupied linked list; wherein:

[0078] When the allocated memory block is the first memory block allocated in the current memory block allocation process, insert it into the header of the occupied linked list; otherwise, insert it into the tail of the subchain of the node corresponding to the first memory block allocated in the current memory block allocation process in the occupied linked list;

[0079] When memory is recycled, the released memory block is directly inserted into the end of the corresponding free list.

[0080] So that subsequent memory allocation can find suitable free blocks as soon as possible. Releasing space is the reverse operation of applying for memory. Unlike the application process, there is only one occupied linked list and it is managed by the global manager MemAreaManager. Therefore, there is no matching occupied linked list process. The linked list node deletion / insertion operation is similar to the application. Release process: find the leader node to be released in the occupied linked list according to the release conditions, traverse and delete each node of the sub-chain according to the childNextIndexOfArea and childNextIndexOfBlock information recorded by the leader node, add the deleted block to the end of the corresponding free linked list according to the indexOfArea information of the deleted node, restore the key and value of the deleted block to null values, modify the predecessor and successor indexes of the memory blocks before and after the deletion point and the insertion point, and modify the statistical records of the linked list manager and the global manager.

[0081] Step 4: regularly calculate the system's performance indicators and average utilization, and dynamically adjust the memory allocation and recovery strategy according to the changes in the performance indicators and average utilization. In step 4, the performance indicators are calculated as follows:

[0082]

[0083] in, represents the performance index within the time period T, M represents the total memory capacity, represents the utilization rate of the i-th memory block, that is, the usage of the i-th memory block in the time period T; Indicates the capacity of the i-th memory block; Indicates the access frequency of the i-th memory block; represents the remaining space of the i-th memory block in the time period T, and N represents the total number of memory blocks.

[0084] In step 4, the average utilization rate is calculated as follows:

[0085] represents the average memory utilization within the time period T, N represents the total number of memory blocks, It represents the actual usage of the i-th memory block in the time period T, and M represents the total memory capacity.

[0086] In step 4, dynamically adjusting the memory allocation and recovery strategy according to the changes in the performance index and the average utilization rate specifically includes:

[0087] When allocating memory, give priority to performance indicators by setting the upper and lower limits of the performance indicator judgment threshold. The memory partitions whose values ​​are greater than the upper limit of the performance indicator judgment threshold are allocated to improve the overall memory utilization efficiency; at the same time, a memory partition size configuration list is recommended according to the upper limit of the performance indicator judgment threshold;

[0088] When reclaiming memory, the average utilization rate is prioritized by setting the upper and lower limits of the average utilization rate judgment threshold. The memory blocks in the memory partition whose value is lower than the lower limit of the average utilization judgment threshold are used to release more available memory space.

[0089] In the method: when the average utilization When the average utilization rate drops to the lower limit of the average utilization rate judgment threshold, memory merging and recycling operations are triggered;

[0090] When the performance index When the performance indicator drops to the lower limit of the judgment threshold, the memory allocation strategy is adjusted.

[0091] The triggering of memory consolidation and recycling operations specifically includes: When it drops to the lower limit of the average utilization judgment threshold, all free lists are traversed to find adjacent free memory blocks, and the adjacent free blocks are merged into a new free block; the merged free block is updated, adjusted to the corresponding memory partition according to its load size, and inserted into the corresponding position in the free list of the memory partition, finally realizing the merging and recycling of memory.

[0092] In the method, when the performance indicator When the resource usage decreases, adjust the memory allocation strategy, including:

[0093] When the performance index When the performance indicator falls below the lower limit of the performance indicator judgment threshold, the performance indicator is determined Reasons for the decline:

[0094] If the performance indicator is caused by the decrease in memory block utilization If it decreases, the utilization of the i-th memory block will be increased. weight in the allocation strategy;

[0095] If the performance index is affected by the decrease in the access frequency of the memory block decreases, the access frequency of the i-th memory block increases. The weight in the allocation strategy.

[0096] In summary, the above are only preferred embodiments of the present invention and are not intended to limit the protection scope of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

[0097] It is obvious to those skilled in the art that the embodiments of the present invention are not limited to the details of the above exemplary embodiments, and that the embodiments of the present invention can be implemented in other specific forms without departing from the spirit or basic features of the embodiments of the present invention. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-restrictive, and the scope of the embodiments of the present invention is limited by the attached claims rather than the above description, so it is intended to include all changes that fall within the meaning and scope of the equivalent elements of the claims in the embodiments of the present invention. Any figure mark in the claims should not be regarded as limiting the claims involved. In addition, it is obvious that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units, modules or devices stated in the system, device or terminal claims can also be implemented by the same unit, module or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.

[0098] Finally, it should be noted that the above implementation modes are only used to illustrate the technical solutions of the embodiments of the present invention and are not intended to limit them. Although the embodiments of the present invention have been described in detail with reference to the above preferred implementation modes, those skilled in the art should understand that the technical solutions of the embodiments of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A low-fragmentation memory management method based on multi-size data block management, characterized in that: The method comprises the following steps: Step 1: Initialize the memory space, divide the memory space into multiple memory partitions according to the configuration information, and establish a bidirectional circular linked list of memory blocks of different sizes in each memory partition; Wherein, the bidirectional circular linked list refers to a free linked list and an occupied linked list; Step 2: When allocating memory, allocate a free block from the free list of the corresponding memory partition according to the relationship between the application space and the memory block load; insert the free block into the occupied list of the memory space; Step 3: When the memory is recycled, the released memory block is deleted from the occupied linked list of the memory space, and inserted into the corresponding free linked list of the memory partition where it is located; Step 4: Regularly calculate the system's performance indicators and average utilization, and dynamically adjust the memory allocation and recovery strategy according to changes in the performance indicators and average utilization; In step 4, the performance index is calculated as follows: , in, represents the performance index within the time period T, M represents the total memory capacity, represents the utilization rate of the i-th memory block in the time period T, Indicates the capacity of the i-th memory block; represents the access frequency of the i-th memory block, represents the remaining space of the i-th memory block in the time period T, and N represents the total number of memory blocks; In step 4, the average utilization rate is calculated as follows: , in, represents the average memory utilization within the time period T, N represents the total number of memory blocks, represents the actual usage of the i-th memory block in the time period T, and M represents the total memory capacity; In step 4, dynamically adjusting the memory allocation and recovery strategy according to the changes in the performance index and the average utilization rate specifically includes: When allocating memory, give priority to performance indicators by setting the upper and lower limits of the performance indicator judgment threshold. The memory partitions whose values ​​are greater than the upper limit of the performance indicator judgment threshold are allocated to improve the overall memory utilization efficiency; at the same time, a memory partition size configuration list is recommended according to the upper limit of the performance indicator judgment threshold; When reclaiming memory, the average utilization rate is prioritized by setting the upper and lower limits of the average utilization rate judgment threshold. The memory blocks in the memory partition whose value is lower than the lower limit of the average utilization judgment threshold are released to release more available memory space; In the method: when the average utilization When the average utilization rate drops to the lower limit of the threshold, the memory merging and recycling operation is triggered; when the performance index When the performance indicator drops to the lower limit of the judgment threshold, the memory allocation strategy is adjusted.

2. The memory management method according to claim 1, characterized in that: In the step 1: according to the configuration information, the available continuous memory space is divided into a plurality of memory partitions, each of the memory partitions includes a manager space and a plurality of different memory blocks; The manager space stores statistics and configuration information; for each of the memory partitions, a bidirectional circular free list and an occupied list are created, the free list is used to manage all unallocated memory blocks in the memory partition, and the occupied list is used to manage all allocated memory blocks in the memory partition.

3. The memory management method according to claim 2, characterized in that: In step 2, allocating free blocks from the free linked list of the corresponding memory partition according to the relationship between the application space and the memory block load specifically includes: When the requested space is greater than or equal to the maximum memory block load, the largest free block is allocated first. If the largest free block is smaller than the requested space, the manager's free block area is traversed to find the free list of the memory partition where the first free block that meets the conditions is located for allocation; When the requested space is less than or equal to the minimum memory block load, reversely traverse the manager's free block area, find the free list of the memory partition where the first free block that meets the conditions is located, and allocate it. At this time, the minimum free memory block is allocated; When the requested space falls between different memory block loads, first search for a free block in the memory partition where the memory block with the smallest load is located. If no free block is found, search in reverse until a free block that meets the conditions is found for allocation.

4. The memory management method according to claim 3, characterized in that: In step 3: When allocating memory, the allocated memory block is inserted into the header of the occupied linked list, or into the subchain of a node in the occupied linked list; wherein: When the allocated memory block is the first memory block allocated in the current memory block allocation process, insert it into the header of the occupied linked list; otherwise, insert it into the tail of the subchain of the node corresponding to the first memory block allocated in the current memory block allocation process in the occupied linked list; When memory is recycled, the released memory block is directly inserted into the end of the corresponding free list.

5. The memory management method according to claim 4, characterized in that: The triggering of memory consolidation and recycling operations specifically includes: When it drops to the lower limit of the average utilization judgment threshold, all free lists are traversed to find adjacent free memory blocks, and the adjacent free blocks are merged into a new free block; the merged free block is updated, adjusted to the corresponding memory partition according to its load size, and inserted into the corresponding position in the free list of the memory partition, finally realizing the merging and recycling of memory.

6. The memory management method according to claim 5, characterized in that: In the method, when the performance indicator When the resource usage decreases, adjust the memory allocation strategy, including: When the performance index When the performance indicator falls below the lower limit of the performance indicator judgment threshold, the performance indicator is determined Reasons for the decline: If the performance indicator is caused by the decrease in memory block utilization If it decreases, the utilization of the i-th memory block will be increased. weight in the allocation strategy; If the performance index is affected by the decrease in the access frequency of the memory block decreases, the access frequency of the i-th memory block increases. The weight in the allocation strategy.

Citation Information

Patent Citations

  • Cache method for file system with changeable data block length

    CN101968795A

  • Embedded software memory management method

    CN108038002A

  • Dynamic memory area of embedded equipment without memory management unit and management method

    CN112395087A

  • Memory management method and apparatus, computer device, and storage medium

    WO2024078429A1