A memory space management method and device, electronic equipment and storage medium

By using head and tail pointers to mark used space in the memory pool, the problem of discontinuous data storage is solved, thus achieving data storage continuity and improving storage system performance.

CN115168243BActive Publication Date: 2026-01-06SONOSCAPE MEDICAL CORP
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202110356552.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-01
Publication Date
2026-01-06
Estimated Expiration
2041-06-27

AI Technical Summary

Technical Problem

In existing technologies, address discontinuity is prone to occur during data storage, which affects the performance of the storage system.

Method used

The memory pool uses head and tail pointers to mark the space that has been used. By checking whether the free area between the tail pointer and the end address of the memory pool is sufficient to store data, if it is insufficient, the tail pointer is moved to the start address to ensure that the data is stored in the contiguous area between the tail pointer and the head pointer.

Benefits of technology

It ensures the continuity of data storage, improves the performance of the storage system, avoids memory fragmentation, and improves memory utilization efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115168243B_ABST
    Figure CN115168243B_ABST
Patent Text Reader

Abstract

This application discloses a memory space management method, which includes: allocating a memory pool and setting a head pointer and a tail pointer for the memory pool; receiving a data storage task and determining the size of the memory to be allocated corresponding to the data storage task; determining whether the free memory region between the tail pointer and the end address of the memory pool is greater than or equal to the size of the memory to be allocated; if so, storing the new data corresponding to the data storage task in the free memory region between the tail pointer and the end address of the memory pool; if not, updating the address pointed to by the tail pointer to the start address of the memory pool, and storing the new data corresponding to the data storage task in the free memory region between the tail pointer and the head pointer. This application can ensure the continuity of data storage and improve the performance of the storage system. This application also discloses a memory space management device, an electronic device, and a storage medium, which have the above-mentioned beneficial effects.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data storage technology, and in particular to a memory space management method, apparatus, electronic device, and storage medium. Background Technology

[0002] With the development of technologies such as cloud computing, big data, and the Internet of Things, data storage and transmission are receiving increasing attention. During data processing, if input data is received from the previous node, corresponding memory needs to be allocated as an intermediate cache based on the data size. If the data processing stage is complex, multiple memory allocations may be required.

[0003] In related technologies, after receiving a data storage task, the storage is often continued from the location of the previous data storage, which may result in discontinuous data storage addresses and affect the performance of the storage system.

[0004] Therefore, ensuring the continuity of data storage and improving the performance of storage systems are technical problems that need to be solved by those skilled in the art. Summary of the Invention

[0005] The purpose of this application is to provide a memory space management method, apparatus, electronic device, and storage medium that can ensure the continuity of data storage and improve the performance of the storage system.

[0006] To address the aforementioned technical problems, this application provides a memory space management method, which includes:

[0007] Allocate a memory pool and set a head pointer and a tail pointer for the memory pool; wherein the head pointer points to the starting address of the used space in the memory pool, and the tail pointer points to the ending address of the used space in the memory pool;

[0008] Receive data storage task and determine the size of memory to be allocated corresponding to the data storage task;

[0009] Determine whether the free memory region between the tail pointer and the end address of the memory pool is greater than or equal to the size of the memory to be allocated;

[0010] If so, the new data corresponding to the data storage task is stored in the free memory area between the tail pointer and the end address of the memory pool;

[0011] If not, the address pointed to by the tail pointer is updated to the starting address of the memory pool, and the new data corresponding to the data storage task is stored in the free memory area between the tail pointer and the head pointer.

[0012] Optional, also includes:

[0013] Receive a memory reclamation request and determine the memory block to be reclaimed corresponding to the memory reclamation request;

[0014] Determine whether the memory block to be reclaimed is a head memory block or a tail memory block; wherein, the head memory block is a memory block whose starting address is the head pointer, and the tail memory block is a memory block whose ending address is the tail pointer;

[0015] If so, then reclaim the memory block to be reclaimed and the memory block adjacent to the memory block to be reclaimed that is marked as released but not reclaimed;

[0016] If not, then mark the memory block to be reclaimed as the freed memory block.

[0017] Optionally, after updating the address pointed to by the tail pointer to the starting address of the memory pool, the method further includes:

[0018] The free memory region between the tail pointer before the updated address and the end address of the memory pool is marked as the freed memory block.

[0019] Optionally, the memory block includes a block header and a data area. The block header includes the data length and a release flag, and the data area is used to store the received data.

[0020] Accordingly, marking the memory block to be reclaimed as the freed memory block includes:

[0021] The memory block to be reclaimed is marked as the freed memory block in the block header.

[0022] Optional, also includes:

[0023] After reclaiming a memory block, if the head pointer points to the end address of the memory pool, then the address pointed to by the head pointer is updated to the start address of the memory pool.

[0024] Correspondingly,

[0025] After a memory block is reclaimed, if the tail pointer points to the start address of the memory pool, then the address pointed to by the tail pointer is updated to the end address of the memory pool.

[0026] Optionally, after marking the memory block to be reclaimed as the freed memory block, the method further includes:

[0027] Determine whether the memory block adjacent to the memory block to be reclaimed is marked as the freed memory block;

[0028] If so, then merge adjacent freed memory blocks.

[0029] Optionally, after determining that the free memory region between the tail pointer and the end address of the memory pool is smaller than the size of the memory to be allocated, the method further includes:

[0030] Determine whether the free memory region between the starting address of the memory pool and the head pointer is greater than or equal to the size of the memory to be allocated;

[0031] If so, proceed to the step of updating the address pointed to by the tail pointer to the starting address of the memory pool;

[0032] If not, allocate a new memory pool and store the new data in the new memory pool.

[0033] This application also provides a memory space management device, the device comprising:

[0034] A pointer setting module is used to allocate a memory pool and set a head pointer and a tail pointer for the memory pool; wherein the head pointer points to the starting address of the used space in the memory pool, and the tail pointer points to the ending address of the used space in the memory pool;

[0035] The unallocated memory determination module is used to receive data storage tasks and determine the unallocated memory size corresponding to the data storage tasks;

[0036] The data storage module is used to determine whether the free memory area between the tail pointer and the end address of the memory pool is greater than or equal to the size of the memory to be allocated; if so, the new data corresponding to the data storage task is stored in the free memory area between the tail pointer and the end address of the memory pool; if not, the address pointed to by the tail pointer is updated to the start address of the memory pool, and the new data corresponding to the data storage task is stored in the free memory area between the tail pointer and the head pointer.

[0037] This application also provides a storage medium on which a computer program is stored, wherein the computer program, when executed, implements the steps of the above-described memory space management method.

[0038] This application also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor, when calling the computer program in the memory, implements the steps of the memory space management method described above.

[0039] This application provides a memory space management method, comprising: allocating a memory pool and setting a head pointer and a tail pointer for the memory pool; wherein the head pointer points to the starting address of the used space in the memory pool, and the tail pointer points to the ending address of the used space in the memory pool; receiving a data storage task and determining the size of the memory to be allocated corresponding to the data storage task; determining whether the free memory region between the tail pointer and the ending address of the memory pool is greater than or equal to the size of the memory to be allocated; if yes, storing the new data corresponding to the data storage task in the free memory region between the tail pointer and the ending address of the memory pool; if no, updating the address pointed to by the tail pointer to the starting address of the memory pool, and storing the new data corresponding to the data storage task in the free memory region between the tail pointer and the head pointer.

[0040] This application utilizes head and tail pointers to mark used space in the memory pool. Upon receiving a data storage task, it determines whether the new data to be stored can be stored in the free memory area between the tail pointer and the end address of the memory pool. If the free memory space between the tail pointer and the end address of the memory pool cannot store the new data, the address pointed to by the tail pointer is updated to the start address of the memory pool so that the new data is stored in the free memory area between the tail pointer and the head pointer. This application ensures that the storage address of the new data remains continuous in the memory pool through the above method, thereby ensuring the continuity of data storage and improving the performance of the storage system. This application also provides a memory space management device, an electronic device, and a storage medium, which have the above-mentioned beneficial effects, and will not be elaborated further here. Attached Figure Description

[0041] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0042] Figure 1 A flowchart illustrating a memory space management method provided in an embodiment of this application;

[0043] Figure 2 This is a schematic diagram illustrating the first memory block allocation principle provided in the embodiments of this application;

[0044] Figure 3 This is a schematic diagram illustrating the second type of memory block allocation principle provided in an embodiment of this application;

[0045] Figure 4 A flowchart illustrating a memory space management method provided in an embodiment of this application;

[0046] Figure 5 This is a schematic diagram of the structure of a memory block provided in an embodiment of this application;

[0047] Figure 6 A schematic diagram illustrating the principle of a header memory block reclamation method provided in an embodiment of this application;

[0048] Figure 7 A schematic diagram illustrating the principle of a tail memory block reclamation method provided in an embodiment of this application;

[0049] Figure 8 A schematic diagram illustrating the principle of the first method for reclaiming a middle memory block provided in this application embodiment;

[0050] Figure 9 A schematic diagram illustrating the principle of the second method for reclaiming a middle memory block provided in this application embodiment;

[0051] Figure 10 This is a schematic diagram of a head pointer position setting method provided in an embodiment of this application;

[0052] Figure 11 This is a schematic diagram of a tail pointer position setting method provided in an embodiment of this application. Detailed Implementation

[0053] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0054] Please see below. Figure 1 , Figure 1 This is a flowchart illustrating a memory space management method provided in an embodiment of this application.

[0055] Specific steps may include:

[0056] S101: Allocate a memory pool and set the head and tail pointers for the memory pool.

[0057] This embodiment can be applied to electronic devices with data storage capabilities, such as storage servers and image processing devices. Before this step, this embodiment can request the operating system to allocate a contiguous block of memory as a circular memory pool, where the start and end addresses of the circular memory pool are adjacent. This embodiment provides an interface for users to allocate a small block of memory (i.e., a memory block) of the desired size from the memory pool as needed. The memory pool includes used space and free memory space, with a head pointer pointing to the start address of the used space in the memory pool and a tail pointer pointing to the end address of the used space in the memory pool.

[0058] It is understandable that this embodiment allocates memory blocks by adjusting the position of the tail pointer. During the memory block allocation process, except for the tail pointer jumping to the start address of the memory pool, the tail pointer always moves towards the end address of the memory pool. If the memory pool is represented by a ring diagram, during the memory block allocation process, the position of the head pointer remains unchanged, while the position of the tail pointer always moves in a clockwise or counterclockwise direction. During the memory block reclamation process, the addresses of both the head pointer and the tail pointer can move as the memory block is reclaimed.

[0059] S102: Receive the data storage task and determine the size of the memory to be allocated corresponding to the data storage task.

[0060] Upon receiving a data storage task, the task can be parsed to determine the size of the memory to be allocated. The size of the memory to be allocated may differ for each data storage task. In this embodiment, a memory block of the corresponding size can be dynamically allocated from the memory pool based on the allocation requirements for each task, so that the new data corresponding to the data storage task can be stored in the memory block.

[0061] S103: Determine whether the free memory region between the tail pointer and the end address of the memory pool is greater than or equal to the size of the memory to be allocated; if yes, proceed to S104; if no, proceed to S105.

[0062] Since the allocated memory blocks need to remain contiguous in the memory pool, it is necessary to determine whether the free memory region between the tail pointer and the end address of the memory pool is greater than or equal to the size of the memory to be allocated before allocating the memory block. If so, the tail pointer can be adjusted directly to allocate the memory block. Otherwise, the tail pointer is updated to the start address of the memory pool before the tail pointer is adjusted to allocate the memory block.

[0063] S104: Store the new data corresponding to the data storage task in the free memory area between the tail pointer and the end address of the memory pool.

[0064] S105: Update the address pointed to by the tail pointer to the starting address of the memory pool, and store the new data corresponding to the data storage task in the free memory area between the tail pointer and the head pointer.

[0065] This embodiment uses head and tail pointers to identify the used space in the memory pool, reducing the overall memory consumption of the system while ensuring the temporary memory needs of image processing. Specifically, the head pointer points to the start address of the used space, and the tail pointer points to the end address of the used space. The used space is the space in the memory pool where data has been stored or where data can no longer be stored contiguously; all allocated memory blocks in the memory pool are within the used space. The space in the memory pool other than the used space is the free memory region. In this embodiment, the position of the tail pointer can be moved towards the nearest free memory region to allocate new memory blocks in the memory pool.

[0066] Please see Figure 2 , Figure 2 This is a schematic diagram of the first memory block allocation principle provided in the embodiments of this application, as shown below. Figure 2 As shown, this embodiment uses a head pointer and a tail pointer to mark the start and end addresses of the used space, with the remaining space being unused free memory. When allocating memory, both the head and tail pointers point to the head of the memory pool. Each time memory is requested, this embodiment can allocate memory by moving backward from the position pointed to by the tail pointer, as shown... Figure 2 As shown, memory block 1 is allocated first, then memory block 2, and then memory block 3.

[0067] This embodiment uses head and tail pointers to mark the used space in the memory pool. When a data storage task is received, it determines whether the new data to be stored can be stored in the free memory area between the tail pointer and the end address of the memory pool. If the free memory space between the tail pointer and the end address of the memory pool cannot store the new data, the address pointed to by the tail pointer is updated to the start address of the memory pool so that the new data is stored in the free memory area between the tail pointer and the head pointer. This embodiment ensures that the storage address of the new data remains continuous in the memory pool, thereby ensuring the continuity of data storage and improving the performance of the storage system.

[0068] As for Figure 1 In a further description of the corresponding embodiment, after updating the address pointed to by the tail pointer to the start address of the memory pool, the free memory region between the tail pointer before the updated address and the end address of the memory pool can also be marked as the released memory block. Please refer to [link to relevant documentation]. Figure 3 , Figure 3 This is a schematic diagram illustrating the second type of memory block allocation principle provided in the embodiments of this application, as shown below. Figure 3As shown, when memory blocks 4 to 6 have been allocated in the memory pool, if the free memory area at the tail of the memory pool cannot accommodate the upcoming allocation of memory block 7, it will attempt to return to the head of the memory pool for allocation. At this time, the tail pointer will return to the head area of ​​the memory pool, and the remaining area at the tail of the memory pool will be marked as a released memory block. Figure 3 In the scheme shown, the freed memory block generated by updating the tail pointer position is a memory block between the head pointer and the tail pointer that cannot store new data, that is, it belongs to the used area in the memory pool.

[0069] In related technologies, memory is often released immediately after data stored in memory is transferred to the next node. However, the above memory management methods are prone to memory fragmentation. When there is a large amount of memory fragmentation in the system, it may lead to the inability to allocate memory as needed, ultimately causing storage system abnormalities.

[0070] Please see below. Figure 4 , Figure 4 This is a flowchart illustrating a memory space management method provided in an embodiment of this application. This embodiment can ensure the continuity of allocated memory blocks in the memory pool, avoid memory fragmentation, and improve storage system performance. This embodiment may include the following steps:

[0071] S401: Receive a memory reclamation request and determine the memory block to be reclaimed corresponding to the memory reclamation request.

[0072] In this embodiment, after receiving a memory reclamation request, the memory reclamation request can be parsed to obtain the identifier of the memory to be reclaimed, and then the corresponding memory block to be reclaimed can be determined.

[0073] S402: Determine whether the memory block to be reclaimed is a head memory block or a tail memory block; if yes, proceed to S403; if no, proceed to S404.

[0074] In this embodiment, allocated memory blocks are divided into three categories based on their location in the used space: head memory blocks, middle memory blocks, and tail memory blocks. Specifically, the head memory block is the memory block whose starting address is the head pointer, the tail memory block is the memory block whose ending address is the tail pointer, and the other allocated memory blocks in the used space besides the head and tail memory blocks are the middle memory blocks.

[0075] S403: Reclaim memory blocks to be reclaimed and memory blocks adjacent to the memory blocks to be reclaimed that are marked as freed but not reclaimed.

[0076] The aforementioned reclaimed memory blocks include memory blocks to be reclaimed, as well as freed memory blocks that are adjacent to the memory blocks to be reclaimed and have not been reclaimed.

[0077] S404: Mark the memory block to be reclaimed as a freed memory block.

[0078] It is understandable that directly deleting a middle memory block will lead to discontinuity in the used space of the memory pool. When frequently allocating and reclaiming memory blocks, memory fragmentation is highly likely to occur in the memory pool. This embodiment provides a scheme for reclaiming memory blocks based on their type: when a memory block to be reclaimed is determined to be a head or tail memory block, it can be reclaimed; when a memory block to be reclaimed is determined to be a middle memory block, it is only marked, and no actual memory reclamation operation is performed. Furthermore, when determining whether a memory block to be reclaimed is a head or tail memory block, this embodiment also checks whether there is an adjacent memory block marked as released. If so, both the memory block to be reclaimed and the marked released memory block are reclaimed together. This scheme avoids memory fragmentation caused by reclaiming middle memory blocks, ensuring the continuity of the used area in the memory pool. This embodiment can be applied to scenarios with frequent allocation and release of temporary memory, improving memory allocation efficiency and memory reuse.

[0079] Furthermore, after marking the memory block to be reclaimed as a freed memory block, it can be determined whether the memory blocks adjacent to the memory block to be reclaimed are also marked as freed memory blocks; if so, the memory blocks corresponding to the adjacent freed memory blocks are merged. This embodiment does not limit the number of freed memory blocks; in this embodiment, the memory block to be reclaimed can be merged with one or more adjacent memory blocks marked as freed memory blocks.

[0080] The above embodiments can be applied to ultrasound image processing algorithms. When processing images, due to the large size of the image data and frequent processing, a large amount of memory needs to be allocated for storing image data input, output, and intermediate buffers. To obtain ultrasound image data from the operating system driver, a block of memory needs to be allocated according to the data size, the data copied from the driver, and then this memory is passed to downstream processing stages. After receiving input data from upstream, the data processing stage (e.g., image enhancement algorithm) needs to allocate corresponding intermediate buffers according to the data size, process the data, and then copy the processing results to the output buffer. The above embodiments, by sharing a single memory block, avoid each algorithm's processing stage allocating its own memory, reducing memory usage and improving memory efficiency. This embodiment differs from general memory pool solutions; it does not require complex management structures to maintain memory, but only uses head and tail pointers to identify the available effective memory area, improving memory allocation efficiency. This embodiment is suitable for scenarios requiring frequent allocation and release of temporary memory, thus eliminating the problem of memory fragmentation.

[0081] This embodiment uses head and tail pointers to mark allocated memory blocks in the memory pool. When reclaiming memory blocks, it first determines whether the memory block to be reclaimed is a head or tail block. If the memory block to be reclaimed is neither a head nor a tail block, it is simply marked as a released memory block and not reclaimed. If the memory block to be reclaimed is a head or tail block, then the memory block to be reclaimed, along with any adjacent but not yet reclaimed released memory blocks, are reclaimed together. This method ensures the continuity of allocated memory blocks in the memory pool, avoids memory fragmentation, and improves storage system performance.

[0082] Please see Figure 5 , Figure 5 This is a schematic diagram of the structure of a memory block provided in an embodiment of this application, as shown below. Figure 5 Each memory block shown includes a block header and a data area. The block header records information such as the length of the data area and the block status (whether it is marked as free). The data area is used to return the memory actually used by the applicant. The block status is either marked as free or not marked as free. Accordingly, the above embodiment can mark the memory block to be reclaimed as a free memory block in the following way: mark the memory block to be reclaimed as a free memory block in the block header.

[0083] Please see Figure 6 , Figure 6 This is a schematic diagram illustrating the principle of a header memory block reclamation method provided in an embodiment of this application. Header memory block reclamation refers to reclamating the memory block to be reclaimed, which is the memory block pointed to by the header pointer. At this time, the header pointer can be moved backward (towards the end address of the memory pool). Figure 6 As shown, the head pointer moves backward to reclaim memory block 1 and memory block 2 in sequence.

[0084] Please see Figure 7 , Figure 7 This is a schematic diagram illustrating the principle of a tail memory block reclamation method provided in an embodiment of this application. Tail memory block reclamation refers to reclamating the memory block pointed to by the tail pointer, at which point the tail pointer can be moved forward (towards the starting address of the memory pool). Figure 7 As shown, the head pointer moves backward to reclaim memory block 3 and memory block 2 in sequence.

[0085] Please see Figure 8 , Figure 8This is a schematic diagram illustrating the principle of the first method for reclaiming a middle memory block provided in this application. When the memory block to be reclaimed is a middle memory block, it can be marked as a released memory block. When the adjacent head or tail memory blocks are about to be reclaimed, they are reclaimed together. Therefore, if the memory block to be reclaimed is the head memory block, the position of the head pointer can be adjusted to reclaim both the memory block to be reclaimed and the adjacent memory blocks marked as released. Figure 8 As shown, if the memory block to be reclaimed is memory block 2, memory block 2 can be marked as a freed memory block. If memory block 1 is to be reclaimed, both memory block 1 and memory block 2 (i.e., memory block 2) can be marked as freed memory blocks. Figure 8 The freed memory blocks in the memory are reclaimed together.

[0086] Please see Figure 9 , Figure 9 This is a schematic diagram illustrating the principle of the second method for reclaiming middle memory blocks provided in this application. When the memory block to be reclaimed is a middle memory block, it can be marked as a released memory block. When the head or tail memory block adjacent to the released memory block is about to be reclaimed, it will be reclaimed together. Therefore, if the memory block to be reclaimed is the tail memory block, the position of the tail pointer is adjusted to reclaim the memory block to be reclaimed, as well as the adjacent memory blocks marked as released but not reclaimed. Figure 9 As shown, if the memory block to be reclaimed is memory block 2, memory block 2 can be marked as a freed memory block. If memory block 3 is to be reclaimed, memory block 2 (i.e., memory block 3) can be marked as a freed memory block. Figure 9 The freed memory block in the memory block and memory block 3 were reclaimed together.

[0087] Furthermore, during the memory block reclamation process, if the head pointer points to the end address of the memory pool, the address pointed to by the head pointer is updated to the start address of the memory pool. If the tail pointer points to the start address of the memory pool, the address pointed to by the tail pointer is updated to the end address of the memory pool.

[0088] according to Figure 8 and Figure 9 According to the corresponding implementation, if the memory block to be reclaimed is neither the head memory block pointed to by the head pointer nor the tail memory block pointed to by the tail pointer, it means that the memory block to be reclaimed is the middle memory block. In this case, only the modules marked as released in the middle memory block will be reclaimed together with the head memory block or the tail memory block.

[0089] Please see Figure 10 , Figure 10This is a schematic diagram illustrating a head pointer position setting method provided in an embodiment of this application. As shown in the figure, if the head pointer points to the end address of the memory pool, then the head pointer is updated to the start address of the memory pool. Please refer to [link to relevant documentation]. Figure 11 , Figure 11 This is a schematic diagram illustrating a tail pointer position setting method provided in an embodiment of this application. When the memory block to be reclaimed is located at the head or tail of the memory pool, the head pointer or tail pointer will cross the tail of the memory pool. Furthermore, if the tail pointer points to the start address of the memory pool, the head pointer is updated to the end address of the memory pool.

[0090] Furthermore, when the free memory area in the memory pool cannot meet the new allocation needs, an allocation failure message can be returned, or a new memory pool can be initialized to meet subsequent allocation needs. Specifically, after determining that the free memory area between the tail pointer and the end address of the memory pool is smaller than the size of the memory to be allocated, if the free memory area between the start address and the head pointer of the memory pool cannot store new data, it indicates that the remaining space of the memory pool is insufficient. At this time, a new memory pool can be reallocated, and the new data is stored in the free memory area between the head and tail pointers of the new memory pool and the end address of the new memory pool. At this time, both the head and tail pointers point to the start address. It can be understood that the new memory pool has its own head and tail pointers. After the new memory pool is allocated, both the head and tail pointers of the new memory pool point to the start address of the new memory pool. During the data storage process, the new data can be stored in the free memory space of the new memory pool according to the address of the tail pointer.

[0091] Of course, if the free memory area between the original memory pool's starting address and the head pointer can store new data, the address pointed to by the tail pointer can be updated to the original memory pool's starting address, and the new data corresponding to the data storage task can be stored in the free memory area between the original memory pool's tail pointer and the head pointer.

[0092] This application embodiment also provides a memory space management device, which may include:

[0093] A pointer setting module is used to allocate a memory pool and set a head pointer and a tail pointer for the memory pool; wherein the head pointer points to the starting address of the used space in the memory pool, and the tail pointer points to the ending address of the used space in the memory pool;

[0094] The unallocated memory determination module is used to receive data storage tasks and determine the unallocated memory size corresponding to the data storage tasks;

[0095] The data storage module is used to determine whether the free memory area between the tail pointer and the end address of the memory pool is greater than or equal to the size of the memory to be allocated; if so, the new data corresponding to the data storage task is stored in the free memory area between the tail pointer and the end address of the memory pool; if not, the address pointed to by the tail pointer is updated to the start address of the memory pool, and the new data corresponding to the data storage task is stored in the free memory area between the tail pointer and the head pointer.

[0096] This embodiment uses head and tail pointers to mark the used space in the memory pool. When a data storage task is received, it determines whether the new data to be stored can be stored in the free memory area between the tail pointer and the end address of the memory pool. If the free memory space between the tail pointer and the end address of the memory pool cannot store the new data, the address pointed to by the tail pointer is updated to the start address of the memory pool so that the new data is stored in the free memory area between the tail pointer and the head pointer. This embodiment ensures that the storage address of the new data remains continuous in the memory pool, thereby ensuring the continuity of data storage and improving the performance of the storage system.

[0097] Furthermore, it also includes:

[0098] The module for determining memory blocks to be reclaimed is used to receive memory reclamation requests and determine the memory blocks to be reclaimed corresponding to the memory reclamation requests.

[0099] The determination module is used to determine whether the memory block to be reclaimed is a head memory block or a tail memory block; wherein, the head memory block is a memory block whose starting address is the head pointer, and the tail memory block is a memory block whose ending address is the tail pointer;

[0100] The recycling module is used to recycle the memory block to be recycled and the memory blocks adjacent to the memory block to be recycled that are marked as released but not recycled, if the memory block to be recycled is a head memory block or a tail memory block.

[0101] The marking module is used to mark the memory block to be reclaimed as the released memory block if the memory block to be reclaimed is not a head memory block or a tail memory block.

[0102] Furthermore, it also includes:

[0103] The freed memory block setting module is used to mark the freed memory region between the tail pointer before the updated address and the end address of the memory pool as the freed memory block after updating the address pointed to by the tail pointer to the start address of the memory pool.

[0104] Furthermore, the memory block includes a block header and a data area. The block header includes the data length and a release flag, and the data area is used to store the received data.

[0105] Accordingly, the marking module is used to mark the memory block to be reclaimed as the freed memory block in the block header of the memory block to be reclaimed.

[0106] Furthermore, it also includes:

[0107] The head pointer adjustment module is used to update the address pointed to by the head pointer to the start address of the memory pool if the head pointer points to the end address of the memory pool after the memory block is reclaimed.

[0108] The tail pointer adjustment module is used to update the address pointed to by the tail pointer to the end address of the memory pool if the tail pointer points to the start address of the memory pool after a memory block is reclaimed.

[0109] Furthermore, it also includes:

[0110] The merging module is used to determine whether the memory blocks adjacent to the memory block to be reclaimed are marked as the freed memory blocks after the memory block to be reclaimed is marked as the freed memory blocks; if so, the adjacent freed memory blocks are merged.

[0111] Furthermore, it also includes:

[0112] The memory pool creation module is used to determine whether the free memory region between the tail pointer and the end address of the memory pool is greater than or equal to the size of the memory to be allocated after determining that the free memory region between the start address of the memory pool and the head pointer is less than the size of the memory to be allocated; if yes, then proceed to the step of updating the address pointed to by the tail pointer to the start address of the memory pool; if no, then allocate a new memory pool and store the new data in the free memory region between the tail pointer and the end address of the new memory pool.

[0113] Since the embodiments of the apparatus and the embodiments of the method correspond to each other, please refer to the description of the embodiments of the method for the embodiments of the apparatus, which will not be repeated here.

[0114] This application also provides a storage medium on which a computer program is stored, which, when executed, can perform the steps provided in the above embodiments. The storage medium may include various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0115] This application also provides an electronic device that may include a memory and a processor. The memory stores a computer program, and when the processor calls the computer program in the memory, it can implement the steps provided in the above embodiments. Of course, the electronic device may also include various network interfaces, power supplies, and other components.

[0116] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section. It should be noted that those skilled in the art can make various improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of the claims of this application.

[0117] It should also be noted that, in this specification, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

Claims

1. A memory space management method characterized by comprising: The method comprises the following steps: allocating a memory pool and setting a head pointer and a tail pointer for the memory pool; wherein the head pointer points to the start address of the used space in the memory pool, and the tail pointer points to the end address of the used space in the memory pool; receiving a data storage task and determining the size of the memory to be allocated corresponding to the data storage task; determining whether the idle memory region between the tail pointer and the end address of the memory pool is greater than or equal to the size of the memory to be allocated; if yes, storing new data corresponding to the data storage task in the idle memory region between the tail pointer and the end address of the memory pool; if no, updating the address pointed to by the tail pointer to the start address of the memory pool, and storing new data corresponding to the data storage task in the idle memory region between the tail pointer and the head pointer; wherein the memory space management method further comprises: receiving a memory recovery request and determining the memory block to be recovered corresponding to the memory recovery request; determining whether the memory block to be recovered is a head memory block or a tail memory block; wherein the head memory block is a memory block whose start address is the head pointer, and the tail memory block is a memory block whose end address is the tail pointer; if yes, recovering the memory block to be recovered and the memory block adjacent to the memory block to be recovered and marked as released but not recovered; if no, marking the memory block to be recovered as a released memory block.

2. The memory space management method of claim 1, wherein, After updating the address pointed to by the tail pointer to the start address of the memory pool, further comprising: marking the idle memory region between the tail pointer before the updated address and the end address of the memory pool as the released memory block.

3. The memory space management method of claim 1, wherein, The memory block comprises a block header and a data area, the block header comprises a data length and a release flag, and the data area is used for storing received data; Correspondingly, marking the memory block to be recovered as the released memory block comprises: marking the memory block to be recovered as the released memory block in the block header of the memory block to be recovered.

4. The memory space management method of claim 1, wherein, Further comprising: after recovering the memory block, if the head pointer points to the end address of the memory pool, updating the address pointed to by the head pointer to the start address of the memory pool; Correspondingly, after recovering the memory block, if the tail pointer points to the start address of the memory pool, updating the address pointed to by the tail pointer to the end address of the memory pool.

5. The memory space management method of claim 1, wherein, After marking the memory block to be recovered as the released memory block, further comprising: determining whether the memory block adjacent to the memory block to be recovered is marked as the released memory block; if yes, merging the adjacent released memory blocks.

6. The memory space management method according to any one of claims 1 to 5, wherein, After determining that the idle memory region between the tail pointer and the end address of the memory pool is less than the size of the memory to be allocated, further comprising: determining whether the idle memory region between the start address of the memory pool and the head pointer is greater than or equal to the size of the memory to be allocated; if yes, entering the step of updating the address pointed to by the tail pointer to the start address of the memory pool; if no, allocating a new memory pool and storing the new data in the new memory pool.

7. A memory space management apparatus characterized by comprising: The method comprises the following steps: The pointer setting module is configured to allocate a memory pool and set a head pointer and a tail pointer for the memory pool; the head pointer points to a start address of a used space in the memory pool, and the tail pointer points to an end address of the used space in the memory pool; The to-be-allocated memory determining module is configured to receive a data storage task and determine a size of to-be-allocated memory corresponding to the data storage task; The data storage module is configured to judge whether a free memory region between the tail pointer and an end address of the memory pool is greater than or equal to the size of to-be-allocated memory; if yes, store new data corresponding to the data storage task in the free memory region between the tail pointer and the end address of the memory pool; if no, update an address pointed to by the tail pointer to a start address of the memory pool, and store the new data corresponding to the data storage task in a free memory region between the tail pointer and the head pointer; The to-be-recycled memory block determining module is configured to receive a memory recycling request and determine a to-be-recycled memory block corresponding to the memory recycling request; The judging module is configured to judge whether the to-be-recycled memory block is a head memory block or a tail memory block; the head memory block is a memory block whose start address is the head pointer, and the tail memory block is a memory block whose end address is the tail pointer; The recycling module is configured to recycle the to-be-recycled memory block and a memory block adjacent to the to-be-recycled memory block and marked as released but not recycled, if the to-be-recycled memory block is the head memory block or the tail memory block. The marking module is configured to mark the to-be-recycled memory block as a released memory block, if the to-be-recycled memory block is not the head memory block or the tail memory block.

8. An electronic device, comprising: The memory and the processor are included, the computer program is stored in the memory, and the processor calls the computer program in the memory to realize the steps of the memory space management method in any one of claims 1 to 6.

9. A storage medium, characterized by The computer executable instructions are stored in the storage medium, and the computer executable instructions are loaded and executed by the processor to realize the steps of the memory space management method in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Variable-length data storing method and device

    CN103605485A