Cache management method and device, electronic equipment and storage medium

By using a combined management method of the first memory pool and the second memory pool in cache management, the target memory pool is selected according to the type and occupancy of the previous cache data, and the cache failure problem caused by insufficient memory in the prior art is solved. Improve cache success rate and memory resource utilization efficiency.

CN118963986APending Publication Date: 2024-11-15SHENZHEN INTELLIFUSION TECHNOLOGIES CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410877209.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-01
Publication Date
2024-11-15

AI Technical Summary

Technical Problem

Existing cache management techniques may cause cache failures when receiving data continuously due to insufficient memory, especially when managing multiple types of packets of varying memory sizes.

Method used

Using a combined management method of the first memory pool and the second memory pool, select an appropriate target memory pool for cache by determining the data type and real memory usage of the previous cached data to avoid insufficient memory caused by continuous reception of large data volumes. question.

Benefits of technology

It improves the cache success rate of cached data, avoids cache failure caused by insufficient memory, and optimizes the utilization efficiency of memory resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118963986A_ABST
    Figure CN118963986A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a cache management method, which comprises the following steps of: when current cache data is received, determining a cache pool for storing the previous cache data; if the cache pool storing the previous cache data is the first memory pool, determining that the second memory pool is a target cache pool, and the memory capacity of the first memory pool is the same as that of the second memory pool; and if the cache pool storing the previous cache data is a second memory pool, determining the first memory pool or the second memory pool as a target cache pool according to the data type of the previous cache data and the real memory occupation amount. According to the method and the device, the data type of the previous cache data and the real memory occupancy are used as the prior data of the current cache data, so that a more suitable memory pool can be selected as the target memory pool, and the cache success rate of the cache data is further improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of smart chips, and in particular to a cache management method, device, electronic equipment and storage medium. Background Art

[0002] With the rapid development of multimedia technology and network technology, it is increasingly important to receive data streams reasonably. In the existing cache management technology, data streams are often cached in the form of data packets, and then the cached data packets are parsed by the decoder. Since the memory requirements and data types of different data packets are unknown before they are successfully cached, when the existing memory pool manages data packets of various types and different memory sizes, due to the fixed memory setting of the memory pool, there may be cache failures due to insufficient memory in the case of continuous reception. Summary of the invention

[0003] The embodiment of the present invention provides a cache management method, which aims to solve the problem that the existing cache management technology may fail to cache due to insufficient memory in the case of continuous reception. The cache data is cached and received through the first memory pool and the second memory pool. When the cache pool storing the last cache data is the first memory pool, the second memory pool is directly used as the target memory pool, so that the first memory pool will not cache continuously, thereby avoiding the situation that the cache failure is caused by insufficient capacity of the first memory pool due to the continuous reception of the cache of large amounts of data; when the cache pool storing the last cache data is the second memory pool, the data type and the real memory occupancy of the last cache data are used to select the first memory pool or the second memory pool as the target memory pool of the current cache data, which is equivalent to using the data type and the real memory occupancy of the last cache data as the prior data of the current cache data, and then a more suitable memory pool can be selected as the target memory pool, further improving the cache success rate of the cache data.

[0004] In a first aspect, an embodiment of the present invention provides a cache management method, the method comprising the following steps:

[0005] When receiving the current cache data, determining the cache pool storing the previous cache data;

[0006] If the cache pool storing the last cached data is the first memory pool, determining the second memory pool as the target cache pool, and the memory capacity of the first memory pool and the second memory pool are the same;

[0007] If the cache pool storing the last cache data is the second memory pool, determining the first memory pool or the second memory pool as the target cache pool according to the data type and the actual memory occupancy of the last cache data;

[0008] The current cache data is dynamically cached through the target cache pool.

[0009] Optionally, determining the first memory pool or the second memory pool as the target cache pool according to the data type and the actual memory occupancy of the previous cache data includes:

[0010] If the data type of the previous cache data is a target type, and the actual memory usage of the previous cache data is less than the memory usage threshold, determining that the second memory pool is a target cache pool;

[0011] Otherwise, it is determined that the first memory pool is the target cache pool.

[0012] Optionally, the target cache pool includes at least one unallocated memory node, the memory node has a corresponding memory capacity and a node memory address, and the dynamically caching the current cache data through the target cache pool includes:

[0013] Determine the memory application amount of the current cache data, where the memory application amount is the initial memory capacity of the memory node;

[0014] According to the memory application amount, a target memory node is allocated for the current cache data in the unallocated memory nodes in the order of the node memory addresses, and the memory capacity of the target memory node is greater than or equal to the memory application amount;

[0015] The memory capacity of the target memory node is returned so that the current cached data is cached according to the returned memory capacity.

[0016] Optionally, allocating a target memory node for the current cache data in the unallocated memory nodes in the order of the node memory addresses according to the memory application amount includes:

[0017] In the unallocated memory nodes, determine the current node to be allocated and the memory capacity of the current node to be allocated according to the order of the node memory addresses;

[0018] If the memory capacity of the current node to be allocated is equal to the memory application amount, the current node to be allocated is determined as the target memory node of the current cache data;

[0019] If the memory capacity of the current node to be allocated is greater than the memory application amount, split the current node to be allocated into a first subnode and a second subnode according to the memory capacity, and the memory capacity of the first subnode is equal to the memory application amount;

[0020] The first child node is determined as the target memory node of the current cached data, and the memory capacity of the current node to be allocated is updated to the memory capacity of the second child node.

[0021] Optionally, after returning the memory capacity of the target memory node so that the current cache data is cached according to the returned memory capacity, the method further includes:

[0022] When the current cache data is completely cached in the target memory node, determining the actual memory usage of the current cache data;

[0023] If the actual memory usage of the current cached data is less than the memory capacity of the target memory node, then calculating the remaining memory capacity of the target memory node;

[0024] The remaining memory capacity is returned to the target cache pool.

[0025] Optionally, returning the remaining memory capacity to the target cache pool includes:

[0026] In the unallocated memory nodes, a first adjacent node adjacent to the target memory node is determined according to the node memory address;

[0027] The remaining memory capacity is merged into the first adjacent node to obtain a new unallocated node.

[0028] Optionally, after returning the memory capacity of the target memory node so that the current cache data is cached according to the returned memory capacity, the method further includes:

[0029] After the current cache data is consumed, in the unallocated memory node, a second adjacent node adjacent to the target memory node is determined according to the node memory address;

[0030] Determine whether the node memory address of the target memory node is continuous with the node memory address of the second adjacent node;

[0031] If they are continuous, the target memory node and the second adjacent node are merged to obtain a new unallocated node.

[0032] In a second aspect, an embodiment of the present invention further provides a cache management device, the cache management device comprising:

[0033] A receiving module, configured to determine a cache pool storing previous cache data upon receiving current cache data;

[0034] A first processing module, configured to determine that a second memory pool is a target cache pool if the cache pool storing the last cached data is a first memory pool, and the first memory pool and the second memory pool have the same memory capacity;

[0035] A second processing module, configured to determine, if the cache pool storing the last cache data is the second memory pool, whether the first memory pool or the second memory pool is a target cache pool according to the data type and actual memory usage of the last cache data;

[0036] The cache module is used to dynamically cache the current cache data through the target cache pool.

[0037] In a third aspect, an embodiment of the present invention provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the cache management method provided in the embodiment of the present invention when executing the computer program.

[0038] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the cache management method provided in the embodiment of the invention are implemented.

[0039] In the embodiment of the present invention, when the current cache data is received, the cache pool storing the last cache data is determined; if the cache pool storing the last cache data is the first memory pool, the second memory pool is determined as the target cache pool, and the memory capacity of the first memory pool and the second memory pool is the same; if the cache pool storing the last cache data is the second memory pool, the first memory pool or the second memory pool is determined as the target cache pool according to the data type and the real memory occupancy of the last cache data. The cache data is cached and received through the first memory pool and the second memory pool. When the cache pool storing the last cache data is the first memory pool, the second memory pool is directly used as the target memory pool, so that the first memory pool will not be cached continuously, thereby avoiding the situation that the first memory pool capacity is insufficient due to the continuous reception of the cache of large amounts of data; when the cache pool storing the last cache data is the second memory pool, the data type and the real memory occupancy of the last cache data are used to select the first memory pool or the second memory pool as the target memory pool of the current cache data, which is equivalent to using the data type and the real memory occupancy of the last cache data as the prior data of the current cache data, thereby selecting a more suitable memory pool as the target memory pool, further improving the cache success rate of the cache data. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0041] Figure 1 is a flow chart of a cache management method provided by an embodiment of the present invention;

[0042] Figure 2 is a management flow chart of another cache management method provided by an embodiment of the present invention;

[0043] Figure 3 This is a memory application flow chart provided by an embodiment of the present invention;

[0044] Figure 4 This is a schematic diagram of returning excess memory provided by an embodiment of the present invention;

[0045] Figure 5 is a schematic structural diagram of a cache management device provided in an embodiment of the present invention;

[0046] Figure 6 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0047] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0048] like Figure 1 As shown, Figure 1 : is a flow chart of a cache management method provided by an embodiment of the present invention, the cache management method comprising the steps of:

[0049] 101. When current cache data is received, determine a cache pool storing previous cache data.

[0050] In an embodiment of the present invention, the above-mentioned cache management method can be applied to a video cache platform, which has functions such as current cache data parsing, current cache data caching, and current cache data release, and can be constructed based on an electronic device with video stream data cache management capabilities.

[0051] The above-mentioned current cache data can be understood as the video stream data that currently needs to be cached, wherein the cache pool used to store the cache data may include a first memory pool and a second memory pool, and the memory capacity of the first memory pool and the second memory pool is the same. Therefore, when the current cache data is received, it is determined that the cache pool storing the previous cache data is the first memory pool or the second memory pool.

[0052] Specifically, a management linked list may be stored in the video cache platform, and the management linked list may include a management linked list of memory nodes to be allocated and a management linked list of allocated memory nodes. When the current cache data is received, the cache pool storing the previous cache data may be queried in the management linked list of allocated memory nodes.

[0053] The above-mentioned cache data can be a network abstraction layer unit (NALU), that is, the output data of the video encoder and the input data of the video decoder. It can not only be used to specify the format of the video data, which mainly provides header information, that is, used to identify various transmission and storage formats suitable for the media, but also can be used to transmit the data unit after video encoding in the network. Generally speaking, when the above-mentioned video cache platform caches and receives the above-mentioned cache data, the cache data needs to occupy a certain amount of memory.

[0054] The types of cached data may include but are not limited to I-frame packets (key frame type NALU packets), P-frame packets (predictive coding image NALU packets) and B-frame packets (bidirectional predictive coding image frame NALU packets). Among them, I-frame packets can be used as reference frames for P-frame packets and B-frame packets in video encoding, that is, I-frame packets can affect the quality of P-frame packets and B-frame packets in video parsing.

[0055] The above-mentioned cache pool may refer to a memory block used to cache and receive the above-mentioned cache data. There are two cache pools, including a first cache pool and a second cache pool, and the memory capacity of the first cache pool and the second cache pool is the same. Initialization begins by applying for two memories of the same size for the first cache pool and the second cache pool, receiving the above-mentioned cache data through the first cache pool and the second cache pool, and after calculating the actual amount of memory used after receiving, the remaining amount of memory can be returned to the current memory pool. Generally speaking, the memory capacity of the above-mentioned cache pool can be obtained according to the following formula:

[0056] PoolSize = W × H × 1.5

[0057] Among them, the above PoolSize is the memory capacity of the above cache pool. Generally speaking, the memory capacity is sufficient for caching and receiving one frame of cache data of any type and size. W is the video width and H is the video height. Generally speaking, the above W and H can be obtained through the network connection management protocol. From the above formula, a memory block that can completely receive one frame of cache data of any type and size can be obtained, and the coefficient 1.5 in the above formula can be confirmed according to the specific implementation plan.

[0058] The cache receiving may refer to a process of parsing the frame image in the cache data and saving it locally through the cache pool, and returning the unoccupied memory capacity to the memory pool.

[0059] In a possible embodiment, after receiving the current cache data, the video cache platform may query a cache pool storing previous cache data.

[0060] 102. If the cache pool storing the previous cache data is the first memory pool, determine the second memory pool as the target cache pool.

[0061] In an embodiment of the present invention, the second memory pool and the first memory pool may be memory blocks with the same memory size, that is, the first memory pool and the second memory pool have the same memory capacity. The difference between the first memory pool and the second memory pool is that they receive cache data of different types or sizes. Generally speaking, in this embodiment, the first memory pool is mainly used to receive cache data of I frame type or cache data requiring a large amount of memory, and the second memory pool is mainly used to receive cache data of P frame type or B frame type.

[0062] Among them, after the first memory pool caches and receives the previous cache data, the second memory pool will receive the current cache data, that is, after the previous cache data is received by the first memory pool, the second memory pool will not use the size and type of the cache data as judgment conditions. Therefore, if the cache pool storing the previous cache data is the first memory pool, the second memory pool is determined as the target cache pool for caching the current cache data.

[0063] In a possible embodiment, after the video cache platform performs cache management on the previous cache data through the first memory pool, it automatically receives the current cache data through the second memory pool.

[0064] In another possible embodiment, the video cache platform performs cache management on the second cache data according to the second memory pool, and returns unused memory to the second memory pool.

[0065] 103. If the cache pool storing the previous cache data is the second memory pool, determine the first memory pool or the second memory pool as the target cache pool according to the data type of the previous cache data and the actual memory usage.

[0066] In the embodiment of the present invention, the data types of the cached data include the I frame packet type, the P frame packet type and the B frame packet type. The real memory occupancy can be understood as the memory capacity actually required to cache the current cached data.

[0067] Specifically, the actual memory occupancy of the previous cached data can be compared with a preset memory occupancy threshold. When the actual memory occupancy of the previous cached data is less than the above-mentioned memory occupancy threshold, and the above-mentioned data type of the previous cached data is an I frame packet type, the above-mentioned first memory pool will be used as the above-mentioned target cache pool; otherwise, the above-mentioned first memory pool will be used as the above-mentioned target cache pool.

[0068] 104. Dynamically cache the current cache data through the target cache pool.

[0069] In the embodiment of the present invention, after the target buffer pool is determined, the current buffer data may be buffered in the target buffer pool, and the current buffer data may be parsed in the target buffer pool to obtain image frames or image sequences corresponding to the current buffer data.

[0070] In the embodiment of the present invention, when the current cache data is received, the cache pool storing the last cache data is determined; if the cache pool storing the last cache data is the first memory pool, the second memory pool is determined as the target cache pool, and the memory capacity of the first memory pool and the second memory pool is the same; if the cache pool storing the last cache data is the second memory pool, the first memory pool or the second memory pool is determined as the target cache pool according to the data type and the real memory occupancy of the last cache data. The cache data is cached and received through the first memory pool and the second memory pool. When the cache pool storing the last cache data is the first memory pool, the second memory pool is directly used as the target memory pool, so that the first memory pool will not be cached continuously, thereby avoiding the situation that the first memory pool capacity is insufficient due to the continuous reception of the cache of large amounts of data; when the cache pool storing the last cache data is the second memory pool, the data type and the real memory occupancy of the last cache data are used to select the first memory pool or the second memory pool as the target memory pool of the current cache data, which is equivalent to using the data type and the real memory occupancy of the last cache data as the prior data of the current cache data, thereby selecting a more suitable memory pool as the target memory pool, further improving the cache success rate of the cache data.

[0071] Optionally, in the step of determining the first memory pool or the second memory pool as the target cache pool based on the data type and actual memory occupancy of the previous cached data, if the data type of the previous cached data is the target type and the actual memory occupancy of the previous cached data is less than the memory occupancy threshold, the second memory pool is determined to be the target cache pool; otherwise, the first memory pool is determined to be the target cache pool.

[0072] In the embodiment of the present invention, after the last cached data is dynamically cached, the actual memory occupancy of the last cached data and the data type of the last cached data can be determined in the cache pool storing the last cached data.

[0073] Specifically, the actual memory occupancy of the previous cached data can be compared with a preset memory occupancy threshold. When the actual memory occupancy of the previous cached data is less than the above-mentioned memory occupancy threshold, and the above-mentioned data type of the previous cached data is an I frame packet type, the above-mentioned first memory pool will be used as the above-mentioned target cache pool; otherwise, the above-mentioned first memory pool will be used as the above-mentioned target cache pool.

[0074] At the beginning, the video cache platform obtains a memory segment in the first memory pool (ie, pool0), and the size of the memory segment is SI, which is used to receive the first current cache data, wherein the SI can be obtained by the following formula:

[0075] SI=W×H×0.9

[0076] From the above formula, it can be obtained that the memory size of SI, and the coefficient of 0.9 in the formula can be adjusted according to the actual implementation plan. After obtaining the actual size S of the above-mentioned previous cache data, the unused memory (i.e., SI-S) is returned to the current memory pool pool0, and then a section of memory is obtained in the second memory pool (i.e., pool1), and the size of the memory is also SI, which is used to receive the above-mentioned current cache data. After obtaining the actual size S of the above-mentioned current cache data, the unused memory (i.e., SI-S) is returned to the current memory pool pool1, and then the cache pool of the next cache data to be received is judged, and the cache pool for receiving the next cache data is judged according to the actual memory size and type of the current cache data. If the current cache data satisfies the required memory size less than 0.5×PoolSize and the type of the current cache data is non-I frame type, the current cache data is received by the second memory pool. If it does not meet the above-mentioned required memory size less than 0.5×PoolSize and the type of the current cache data is non-I frame type, it is received by the first memory pool.

[0077] Optionally, the target cache pool includes at least one unallocated memory node, and the memory node has a corresponding memory capacity and a node memory address. In the step of dynamically caching the current cache data through the target cache pool, the memory request amount of the current cache data can also be determined, and the memory request amount is the initial memory capacity of the memory node; according to the memory request amount, a target memory node is allocated for the current cache data in the unallocated memory nodes in the order of the node memory addresses, and the memory capacity of the target memory node is greater than or equal to the memory request amount; the memory capacity of the target memory node is returned so that the current cache data is cached according to the returned memory capacity.

[0078] In an embodiment of the present invention, the above-mentioned memory application amount is fixed, and each time a memory application is made to the target cache pool with a fixed memory application amount. The above-mentioned target cache pool initially has at least one unallocated memory node, and the initial memory capacity of each memory node is the same. Multiple memory nodes are arranged according to memory addresses, and the above-mentioned memory application amount is the initial memory capacity of the memory node.

[0079] Specifically, during the cache receiving process, memory nodes greater than or equal to the memory application amount are searched in turn in the unallocated memory nodes of the target cache pool, and the memory nodes are applied for. Memory nodes less than the memory application amount are skipped.

[0080] The above preset memory application rules can be used as follows Figure 3 The memory application flow chart shown in the figure is used to illustrate. First, the memory of the pre-applied PoolSize size is taken as the management object. Each segment of allocated or unallocated memory is represented by a node (memory node). free_list is a bidirectional circular linked list used to manage unallocated memory. used_list is a bidirectional circular linked list used to manage allocated memory nodes. Initially, free_list has only one memory, that is, the pre-applied PoolSize size memory, and free_list is empty initially. start_node represents the starting address of the memory amount, cur_node is the current node to be allocated, and start_node and cur_node are the same initially. Instructions can be issued to the bidirectional circular linked list to change the address of the current search memory amount, so as to achieve the purpose of changing the application memory amount of the current memory pool.

[0081] After the target memory node is determined, the memory is returned according to the address of the target memory node, and the current cache data is cached through the returned memory.

[0082] Optionally, in the step of allocating a target memory node for the current cached data in the unallocated memory nodes according to the memory application amount and in the order of the node memory addresses, the current node to be allocated and the memory capacity of the current node to be allocated can also be determined in the unallocated memory nodes in the order of the node memory addresses; if the memory capacity of the current node to be allocated is equal to the memory application amount, the current node to be allocated is determined as the target memory node for the current cached data; if the memory capacity of the current node to be allocated is greater than the memory application amount, the current node to be allocated is split into a first child node and a second child node according to the memory capacity, and the memory capacity of the first child node is equal to the memory application amount; the first child node is determined as the target memory node for the current cached data, and the memory capacity of the current node to be allocated is updated with the memory capacity of the second child node.

[0083] In an embodiment of the present invention, the above-mentioned preset memory circular linked list can be the above-mentioned bidirectional circular linked list for managing unallocated memory nodes, or it can be the above-mentioned bidirectional circular linked list for managing allocated memory nodes. The preset memory circular linked list contains the starting address of the memory node and the address of the current node to be allocated. Generally speaking, in the circular linked list, the above-mentioned address can be identified by a pointer, and the memory capacity of each unallocated node can be determined by the above-mentioned actual address and the address indicated by the pointer.

[0084] When applying for memory in the first memory pool and the second memory pool, the memory application can be performed by searching for memory nodes in sequence through a bidirectional circular linked list. When the current node to be allocated is found, the memory capacity of the current node to be allocated can be determined. When the memory capacity of the current node to be allocated is greater than or equal to the memory application amount, it means that the current node to be allocated can be used to receive the current cached data. At this time, the current node to be allocated can be determined as the target memory node of the current cached data.

[0085] The memory capacity of the current node to be allocated is determined by reading the address pointer of the current node to be allocated and the starting address, and the memory capacity of the current node to be allocated is compared with the above memory application amount to determine whether the current node to be allocated is the target memory node or whether the target memory node can be split according to the comparison result.

[0086] Specifically, due to the existence of a memory return mechanism, after a memory application is made, the amount of memory of the unallocated memory nodes in the cache pool will change due to splitting or merging. Therefore, when making a memory application, you may encounter memory nodes whose memory capacity is less than or greater than the memory application amount. Memory nodes whose memory capacity is less than the memory application amount will be skipped, and can be skipped specifically through a bidirectional circular linked list. For memory nodes whose memory capacity is greater than the memory application amount, the memory node will be split into a first child node and a second child node. The memory capacity of the first child node is the same as the memory application amount, and the memory capacity of the second child node is the original memory capacity minus the memory application amount. At the same time, the first child node is determined as the target memory node, and the second child node is the unallocated node. For memory nodes whose memory capacity is equal to the memory application amount, they can be directly determined as target memory nodes.

[0087] Specifically, at the beginning, in the above-mentioned preset memory circular linked list, the memory capacity size of the current node to be allocated is obtained, and compared with the above-mentioned memory application amount. When the memory capacity size of the above-mentioned current node to be allocated is consistent with the above-mentioned memory application amount, the current node to be allocated is removed from the above-mentioned circular double linked list for managing unallocated memory nodes, and at the same time, the starting address of the current node to be allocated is updated to the next unallocated memory node, and the above-mentioned memory application amount is returned as the application memory of the target cache node.

[0088] When the above-mentioned memory application amount is less than the memory capacity of the current node to be allocated, a new memory node is generated, and the memory size of the new memory node is consistent with the above-mentioned memory application amount. The new memory node is inserted into the above-mentioned circular double linked list for managing the allocated memory nodes, and is returned as the memory application amount of the target cache pool. The memory capacity of the current node to be allocated is updated to the memory capacity of the current node to be allocated minus the maximum and minimum value of the above-mentioned memory application.

[0089] When the preset requested memory amount is greater than the memory capacity of the current node to be allocated, the current node to be allocated is updated to the next adjacent memory node, and the above-mentioned steps of determining that the memory capacity of the current node to be allocated is greater than the memory request amount and the memory capacity of the current node to be allocated is equal to the memory request amount are repeated. It should be noted that if there is still no suitable memory amount after searching the preset memory circular linked list once, a prompt indicating that the memory request failed is returned.

[0090] Optionally, after returning the memory capacity of the target memory node so that the current cached data is cached according to the returned memory capacity, the actual memory usage of the current cached data can be determined after the current cached data is cached in the target memory node; if the actual memory usage of the current cached data is less than the memory capacity of the target memory node, the remaining memory capacity of the target memory node is calculated; and the remaining memory capacity is returned to the target cache pool.

[0091] In an embodiment of the present invention, after the current cached data is cached in the target memory node, the actual memory occupancy of the current cached data can be calculated. When the actual memory occupancy of the current cached data is less than the memory capacity of the target memory node, the unoccupied memory capacity will be returned to the target cache pool.

[0092] Optionally, in the step of returning the remaining memory capacity to the target cache pool, the first adjacent node adjacent to the target memory node can be determined in the unallocated memory nodes according to the node memory address; the remaining memory capacity can be merged into the first adjacent node to obtain a new unallocated node.

[0093] In an embodiment of the present invention, the returned memory amount may be the remaining memory amount after the memory pool is used to cache the currently cached data, that is, the memory not used in the actual receiving process. Generally speaking, it can be calculated based on the applied memory and the memory amount required for the currently cached data.

[0094] The starting address of the returned memory amount can be determined according to the pointer in the preset memory circular linked list, and the starting address of the returned memory amount is determined by the identification address of the pointer in the preset memory circular linked list of the cache receiving platform.

[0095] The memory address adjacent to the returned memory amount may have an adjacent relationship with the tail address of the returned memory amount, that is, the tail address of the remaining memory capacity has an adjacent relationship with the first address of the first adjacent node, and the first adjacent node is the subsequent memory node of the target memory node.

[0096] Specifically, we can use Figure 4 The schematic diagram of excess memory return is illustrated. As shown in the figure, when node1 is used as the memory requester, the actually used memory amount in the node1 memory block is obtained, and the starting address of the actually used memory amount is determined through the pointer, and the starting address of the actually unused memory amount is obtained by calculating the applied memory and the memory amount required for the above-mentioned current cached data. Finally, according to the address adjacency relationship, the above-mentioned actually unused memory amount is merged with node 2 with an address adjacency relationship to obtain a new node2 memory block, thereby completing the process of returning memory.

[0097] Optionally, after returning the memory capacity of the target memory node so that the current cached data is cached according to the returned memory capacity, after the current cached data is consumed, in the unallocated memory nodes, a second adjacent node adjacent to the target memory node can be determined according to the node memory address; and a determination can be made as to whether the node memory address of the target memory node and the node memory address of the second adjacent node are continuous; if they are continuous, the target memory node and the second adjacent node are merged to obtain a new unallocated node.

[0098] In an embodiment of the present invention, after the current cached data is consumed, the target memory node corresponding to the current cached data becomes vacant, and the memory capacity of the target memory node needs to be released to receive subsequent cached data. The above-mentioned second adjacent node can be the previous node or the next node of the target memory node. When the target memory node and the second adjacent node are continuous in memory address, it means that the target memory node and the second adjacent node can be merged to obtain a larger unallocated memory node. When the target memory node and the second adjacent node are not continuous in memory address, it means that the target memory node is isolated, and the target memory node can be directly used as a new unallocated memory node.

[0099] Specifically, the size and address of the memory to be released can be found in the circular linked list for managing the allocated memory according to the pointer in the preset memory circular linked list.

[0100] The above release process may refer to a process of removing the allocated target memory node from the circular linked list of allocated memory and adding it to the circular linked list of unallocated memory nodes, that is, converting the target memory node from an allocated state to an unallocated state.

[0101] In a possible embodiment, by matching the address and size of the memory amount that meets the release condition in the circular linked list of allocated memory, the matched memory amount is removed from the circular linked list of allocated memory and added to the circular linked list of unallocated memory, and then the memory amount at the adjacent address of the memory amount is confirmed through a pointer, and the memory amount is merged with the memory amount at the adjacent address to obtain a new memory amount.

[0102] like Figure 5 As shown, an embodiment of the present invention provides a cache management device, the cache management device comprising:

[0103] The receiving module 501 is used to determine the cache pool storing the previous cache data when receiving the current cache data;

[0104] A first processing module 502 is configured to determine that a second memory pool is a target cache pool if the cache pool storing the last cached data is a first memory pool, and the first memory pool and the second memory pool have the same memory capacity;

[0105] A second processing module 503 is configured to determine, if the cache pool storing the last cache data is the second memory pool, whether the first memory pool or the second memory pool is a target cache pool according to the data type and actual memory usage of the last cache data;

[0106] The cache module 504 is used to dynamically cache the current cache data through the target cache pool.

[0107] Optionally, the second processing module 503 includes:

[0108] a first determination submodule, configured to determine that the second memory pool is a target cache pool if the data type of the previous cache data is a target type and the actual memory usage of the previous cache data is less than a memory usage threshold;

[0109] The second determining submodule is used to determine that the first memory pool is a target cache pool otherwise.

[0110] Optionally, the target cache pool includes at least one unallocated memory node, the memory node has a corresponding memory capacity and a node memory address, and the cache module 504 includes:

[0111] A third determination submodule is used to determine the memory application amount of the current cache data, where the memory application amount is the initial memory capacity of the memory node;

[0112] A first allocation submodule, configured to allocate a target memory node for the current cache data in the unallocated memory nodes according to the memory application amount and in the order of the node memory addresses, wherein the memory capacity of the target memory node is greater than or equal to the memory application amount;

[0113] The first cache submodule is used to return the memory capacity of the target memory node so that the current cache data is cached according to the returned memory capacity.

[0114] Optionally, the first allocation submodule includes:

[0115] A first determining unit is used to determine, in the unallocated memory nodes, a current node to be allocated and a memory capacity of the current node to be allocated according to the order of the node memory addresses;

[0116] A second determining unit is used to determine the current node to be allocated as the target memory node of the current cache data if the memory capacity of the current node to be allocated is equal to the memory application amount;

[0117] A first splitting unit is used for splitting the current node to be allocated into a first sub-node and a second sub-node according to the memory capacity if the memory capacity of the current node to be allocated is greater than the memory application amount, and the memory capacity of the first sub-node is equal to the memory application amount;

[0118] The first updating unit is used to determine the first child node as the target memory node of the current cached data, and to update the memory capacity of the second child node with the memory capacity of the current node to be allocated.

[0119] Optionally, the cache management device further includes:

[0120] A fourth determination submodule, configured to determine the actual memory usage of the current cached data after the current cached data is cached in the target memory node;

[0121] A first calculation submodule, configured to calculate the remaining memory capacity of the target memory node if the actual memory occupancy of the current cached data is less than the memory capacity of the target memory node;

[0122] The first returning submodule is used to return the remaining memory capacity to the target cache pool.

[0123] Optionally, the first return submodule includes:

[0124] A third determining unit is used to determine, in the unallocated memory nodes, a first adjacent node adjacent to the target memory node according to the node memory address;

[0125] The first merging unit is used to merge the remaining memory capacity into the first adjacent node to obtain a new unallocated node.

[0126] Optionally, the cache management device further includes:

[0127] a fifth determination submodule, configured to determine, in the unallocated memory node, a second adjacent node adjacent to the target memory node according to the node memory address after the current cache data is consumed;

[0128] A first judgment submodule is used to judge whether the node memory address of the target memory node is continuous with the node memory address of the second adjacent node;

[0129] The first merging submodule is used to merge the target memory node with the second adjacent node if they are continuous, to obtain a new unallocated node.

[0130] like Figure 6 As shown, an embodiment of the present invention further provides an electronic device, including a processor, and the processor can execute any one of the above cache management methods.

[0131] Specifically, it includes a processor 601, a memory 602, and a computer program for executing the cache management method which is stored in the memory 602 and can be run on the processor 601, wherein:

[0132] The processor 601 runs the computer program of the cache management method stored in the memory 602 to perform the following steps:

[0133] When receiving the current cache data, determining the cache pool storing the previous cache data;

[0134] If the cache pool storing the last cached data is the first memory pool, determining the second memory pool as the target cache pool, and the memory capacity of the first memory pool and the second memory pool are the same;

[0135] If the cache pool storing the last cache data is the second memory pool, determining the first memory pool or the second memory pool as the target cache pool according to the data type and the actual memory occupancy of the last cache data;

[0136] The current cache data is dynamically cached through the target cache pool.

[0137] Optionally, the determining, by the processor 601, according to the data type and the actual memory occupancy of the previous cache data, that the first memory pool or the second memory pool is a target cache pool includes:

[0138] If the data type of the previous cache data is a target type, and the actual memory usage of the previous cache data is less than the memory usage threshold, determining that the second memory pool is a target cache pool;

[0139] Otherwise, it is determined that the first memory pool is the target cache pool.

[0140] Optionally, the target cache pool includes at least one unallocated memory node, the memory node has a corresponding memory capacity and a node memory address, and the processor 601 executes the dynamic caching of the current cache data through the target cache pool, including:

[0141] Determine the memory application amount of the current cache data, where the memory application amount is the initial memory capacity of the memory node;

[0142] According to the memory application amount, a target memory node is allocated for the current cache data in the unallocated memory nodes in the order of the node memory addresses, and the memory capacity of the target memory node is greater than or equal to the memory application amount;

[0143] The memory capacity of the target memory node is returned so that the current cached data is cached according to the returned memory capacity.

[0144] Optionally, the processor 601 allocates a target memory node for the current cache data in the unallocated memory nodes according to the memory application amount and in the order of the node memory addresses, including:

[0145] In the unallocated memory nodes, determine the current node to be allocated and the memory capacity of the current node to be allocated according to the order of the node memory addresses;

[0146] If the memory capacity of the current node to be allocated is equal to the memory application amount, the current node to be allocated is determined as the target memory node of the current cache data;

[0147] If the memory capacity of the current node to be allocated is greater than the memory application amount, split the current node to be allocated into a first subnode and a second subnode according to the memory capacity, and the memory capacity of the first subnode is equal to the memory application amount;

[0148] The first child node is determined as the target memory node of the current cached data, and the memory capacity of the current node to be allocated is updated to the memory capacity of the second child node.

[0149] Optionally, after returning the memory capacity of the target memory node so that the current cache data is cached according to the returned memory capacity, the method executed by the processor 601 further includes:

[0150] When the current cache data is completely cached in the target memory node, determining the actual memory usage of the current cache data;

[0151] If the actual memory usage of the current cached data is less than the memory capacity of the target memory node, then calculating the remaining memory capacity of the target memory node;

[0152] The remaining memory capacity is returned to the target cache pool.

[0153] Optionally, the returning the remaining memory capacity to the target cache pool performed by the processor 601 includes:

[0154] In the unallocated memory nodes, a first adjacent node adjacent to the target memory node is determined according to the node memory address;

[0155] The remaining memory capacity is merged into the first adjacent node to obtain a new unallocated node.

[0156] Optionally, after returning the memory capacity of the target memory node so that the current cache data is cached according to the returned memory capacity, the method executed by the processor 601 further includes:

[0157] After the current cache data is consumed, in the unallocated memory node, a second adjacent node adjacent to the target memory node is determined according to the node memory address;

[0158] Determine whether the node memory address of the target memory node is continuous with the node memory address of the second adjacent node;

[0159] If they are continuous, the target memory node and the second adjacent node are merged to obtain a new unallocated node.

[0160] An embodiment of the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the various processes of the cache management method or the application-side cache management method provided in the embodiment of the present invention are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0161] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.

[0162] The above disclosure is only the preferred embodiment of the present invention, which certainly cannot be used to limit the scope of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope of the present invention.

Claims

1. A cache management method, characterized in that: The method comprises the following steps: When receiving the current cache data, determining the cache pool storing the previous cache data; If the cache pool storing the last cached data is the first memory pool, determining the second memory pool as the target cache pool, the first memory pool and the second memory pool have the same memory capacity; If the cache pool storing the last cache data is the second memory pool, determining the first memory pool or the second memory pool as the target cache pool according to the data type and the actual memory occupancy of the last cache data; The current cache data is dynamically cached through the target cache pool.

2. The cache management method according to claim 1, characterized in that: The determining, according to the data type and the actual memory occupancy of the previous cache data, that the first memory pool or the second memory pool is a target cache pool includes: If the data type of the previous cache data is a target type, and the actual memory usage of the previous cache data is less than the memory usage threshold, determining that the second memory pool is a target cache pool; Otherwise, it is determined that the first memory pool is the target cache pool.

3. The cache management method according to claim 1, characterized in that: The target cache pool includes at least one unallocated memory node, the memory node has a corresponding memory capacity and a node memory address, and the current cache data is dynamically cached through the target cache pool, including: Determine the memory application amount of the current cache data, where the memory application amount is the initial memory capacity of the memory node; According to the memory application amount, a target memory node is allocated for the current cache data in the unallocated memory nodes in the order of the node memory addresses, and the memory capacity of the target memory node is greater than or equal to the memory application amount; The memory capacity of the target memory node is returned so that the current cached data is cached according to the returned memory capacity.

4. The cache management method according to claim 3, characterized in that: According to the memory application amount, a target memory node is allocated for the current cache data in the unallocated memory nodes in the order of the node memory addresses, including: In the unallocated memory nodes, determine the current node to be allocated and the memory capacity of the current node to be allocated according to the order of the node memory addresses; If the memory capacity of the current node to be allocated is equal to the memory application amount, the current node to be allocated is determined as the target memory node of the current cache data; If the memory capacity of the current node to be allocated is greater than the memory application amount, split the current node to be allocated into a first subnode and a second subnode according to the memory capacity, and the memory capacity of the first subnode is equal to the memory application amount; The first child node is determined as the target memory node of the current cached data, and the memory capacity of the current node to be allocated is updated to the memory capacity of the second child node.

5. The cache management method according to claim 3 or 4, after returning the memory capacity of the target memory node so that the current cache data is cached according to the returned memory capacity, the method further comprises: When the current cache data is completely cached in the target memory node, determining the actual memory usage of the current cache data; If the actual memory usage of the current cached data is less than the memory capacity of the target memory node, then calculating the remaining memory capacity of the target memory node; The remaining memory capacity is returned to the target cache pool.

6. The cache management method according to claim 5, characterized in that: The returning the remaining memory capacity to the target cache pool includes: In the unallocated memory nodes, a first adjacent node adjacent to the target memory node is determined according to the node memory address; The remaining memory capacity is merged into the first adjacent node to obtain a new unallocated node.

7. The cache management method according to any one of claims 3 to 6, characterized in that: After returning the memory capacity of the target memory node so that the current cache data is cached according to the returned memory capacity, the method further includes: After the current cache data is consumed, in the unallocated memory node, a second adjacent node adjacent to the target memory node is determined according to the node memory address; Determine whether the node memory address of the target memory node is continuous with the node memory address of the second adjacent node; If they are continuous, the target memory node and the second adjacent node are merged to obtain a new unallocated node.

8. A cache management device, characterized in that: The cache management device comprises: A receiving module, configured to determine a cache pool storing previous cache data upon receiving current cache data; A first processing module, configured to determine that a second memory pool is a target cache pool if the cache pool storing the last cached data is a first memory pool, and the first memory pool and the second memory pool have the same memory capacity; A second processing module, configured to determine, if the cache pool storing the last cache data is the second memory pool, whether the first memory pool or the second memory pool is a target cache pool according to the data type and actual memory usage of the last cache data; The cache module is used to dynamically cache the current cache data through the target cache pool.

9. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the cache management method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the cache management method according to any one of claims 1 to 7 are implemented.