Memory management method and device, electronic equipment and storage medium
By using table jump data structures to manage memory blocks in embedded IoT operating systems, the problem of inefficient memory management is solved and more efficient memory allocation and query is achieved.
Patent Information
- Application Number
- CN202310958029.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-01
- Publication Date
- 2025-02-14
AI Technical Summary
The memory management efficiency of embedded IoT operating systems is low. The existing algorithms have long and uncertain allocation time when memory fragments are large, and the Slab algorithm is prone to internal fragmentation.
The table jump data structure is used to manage memory blocks, and the threshold node and target memory block are obtained to determine their insertion position. Larger memory blocks are inserted into the lowest-level linked list, while smaller memory blocks are inserted into the index layer linked list randomly.
It improves the efficiency of memory management, reduces the time complexity of memory allocation and query, and reduces the generation of memory fragmentation.
Smart Images

Figure CN119440787A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a memory management method, device, electronic device and storage medium. Background Art
[0002] IoT OS (Operating System for Internet of Things) refers to a software platform based on an operating system kernel, such as a real-time operating system (RTOS) or Linux, which includes relatively complete middleware components such as a file system and a graphics library, and has low power consumption, security, communication protocol support, and cloud connection capabilities. This type of operating system has a simple structure, complete functions, and strong real-time performance. It is mainly aimed at lightweight embedded systems such as the Internet of Things, requires very little kernel code space and data storage space (KB level), and has good real-time and scalability. It is very suitable for lightweight embedded products such as smart power strips, smart speakers, watches, Bluetooth headsets, and remote controls.
[0003] In view of the characteristics of small memory resources and low CPU frequency of IoT devices, the selection of memory management strategy for IoT operating system is particularly important. At present, the common memory management strategies of IoT operating system are: sequential search algorithm and scalable allocator algorithm (Slab algorithm).
[0004] The sequential search algorithm takes a long and uncertain time to allocate when the memory fragmentation is large. The Slab algorithm memory management algorithm makes good use of the idea of memory pool to solve the problem of external fragmentation, but because the allocated memory size is fixed, it is easy to cause large internal fragmentation.
[0005] Based on this, the current memory management efficiency of embedded IoT operating systems is low. Summary of the invention
[0006] The embodiments of the present application provide a memory management method, device, electronic device and storage medium to solve the technical problem of low memory management efficiency of an embedded Internet of Things operating system.
[0007] In a first aspect, an embodiment of the present application provides a memory management method, including:
[0008] Obtaining a threshold node of the jump table, wherein the threshold node is a memory unit whose memory is greater than a set value;
[0009] Obtain a target memory block to be inserted into the jump table;
[0010] If the target memory block is greater than or equal to the memory of the threshold node, inserting the target memory block into the bottom-level linked list of the skip list;
[0011] If the target memory block is smaller than the memory of the threshold node, the target memory block is randomly inserted into the index layer linked list of the skip list.
[0012] In one embodiment, after obtaining the threshold node of the jump table, the method further includes:
[0013] Get the memory to be queried;
[0014] If the memory to be queried is greater than or equal to the memory of the threshold node, traverse the memory cells of the jump table starting from the target index node corresponding to the threshold node until a memory cell matching the memory to be queried is found;
[0015] If the memory to be queried is smaller than the memory of the threshold node, the memory units are traversed starting from the head index node of the highest level linked list of the skip list until a memory unit matching the memory to be queried is found.
[0016] In one embodiment, after obtaining the threshold node of the jump table, the method further includes:
[0017] A target index node is determined, and a pointer of the target index node is pointed to the threshold node.
[0018] In one embodiment, after obtaining the threshold node of the jump table, the method further includes:
[0019] Get the memory to be deleted;
[0020] If the memory to be deleted is greater than or equal to the memory of the threshold node, traverse the memory cells of the jump table starting from the target index node corresponding to the threshold node until a memory cell matching the memory to be deleted is found, and delete the memory cell matching the memory to be deleted;
[0021] If the memory to be deleted is smaller than the memory of the threshold node, the memory unit is traversed starting from the header index node of the highest level linked list of the jump list until a memory unit matching the memory to be deleted is found, and the memory unit matching the memory to be deleted is deleted.
[0022] In one embodiment, inserting the target memory block into the bottom-level linked list of the jump list includes:
[0023] Obtain the first insertion position of the target memory block in the bottom-level linked list of the jump list;
[0024] Creating a new node at the first insertion position, and determining a memory value of the new node based on the size of the target memory block;
[0025] The previous node and the next node of the new node are obtained, a pointer of the previous node is pointed to the new node, and a pointer of the new node is pointed to the next node.
[0026] In one embodiment, randomly inserting the target memory block into the index level linked list of the jump list includes:
[0027] Based on a random function, obtaining a target index layer to which the target memory block is to be inserted;
[0028] A second insertion position of the target memory block in the target index layer is obtained, and the target memory block is inserted into the second insertion position.
[0029] In one embodiment, a skip list data structure is used to store memory blocks, wherein the skip list data structure includes the bottom-level linked list, the index-level linked list, and the threshold node, and the memory block is a free memory block.
[0030] In a second aspect, an embodiment of the present application provides a memory management device, including:
[0031] A first acquisition module is used to acquire a threshold node of a jump table, where the threshold node is a memory unit whose memory is greater than a set value;
[0032] A second acquisition module, used for acquiring a target memory block to be inserted into the jump table;
[0033] A first insertion module, configured to insert the target memory block into the bottom-level linked list of the jump list if the target memory block is greater than or equal to the memory of the threshold node;
[0034] The second insertion module is used to randomly insert the target memory block into the index layer linked list of the jump list if the target memory block is smaller than the memory of the threshold node.
[0035] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor and a memory storing a computer program, wherein the processor implements the steps of the memory management method described in the first aspect when executing the program.
[0036] In a fourth aspect, an embodiment of the present application provides a non-transitory computer-readable storage medium having a computer program stored thereon, which implements the memory management method of the first aspect when executed by a processor.
[0037] The memory management method, device, electronic device and storage medium provided in the embodiments of the present application are implemented by obtaining a threshold node of a skip list, wherein the threshold node is a memory unit whose memory is greater than a set value; obtaining a target memory block to be inserted into the skip list; if the target memory block is greater than or equal to the memory of the threshold node, inserting the target memory block into the bottom-level linked list of the skip list; if the target memory block is less than the memory of the threshold node, randomly inserting the target memory block into the index-level linked list of the skip list. The embodiments of the present application improve the efficiency of memory management by setting a threshold node in a skip list and directly inserting a larger target memory block into the bottom-level linked list based on the threshold node. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions in the present application or the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0039] Figure 1 It is a flowchart of the memory management method provided in the embodiment of the present application;
[0040] Figure 2 It is a schematic diagram of the structure of the jump table and its index linked table provided in the embodiment of the present application;
[0041] Figure 3 It is a schematic diagram of the structure of a jump table with a threshold node provided in an embodiment of the present application;
[0042] Figure 4 is a schematic diagram of the structure of a memory management device provided in an embodiment of the present application;
[0043] Figure 5 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions in this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0045] Figure 1 A flowchart of a memory management method provided in an embodiment of the present application. Figure 1 , an embodiment of the present application provides a memory management method, including:
[0046] S100, obtaining a threshold node of a jump table, where the threshold node is a memory unit whose memory is greater than a set value;
[0047] The embodiment of the present application is to perform memory management for an embedded IoT operating system. An embedded IoT operating system is an operating system designed specifically for embedded devices and IoT applications. It runs on resource-constrained embedded devices and provides functions to support IoT communications and application development.
[0048] like Figure 2 As shown in the figure, a skip list is a data structure based on a linked list, which is used for fast search, insertion and deletion of elements. It introduces multi-layer indexes on the basis of an ordered linked list, and improves search efficiency by accessing nodes in a jumping manner. The core idea of a skip list is to speed up search operations by establishing multi-layer indexes. At the bottom layer, the skip list is an ordinary ordered linked list; and at each layer above, some nodes are selected as index nodes with a certain probability, pointing to the nodes at the same position in the next layer. In this way, the time complexity of the search can be reduced by skipping some nodes during the search. The skip list has the characteristics of fast search, dynamicity, and relative simplicity. However, the space complexity of the skip list is higher than that of an ordinary linked list structure because additional storage of index nodes is required. At the same time, the design of the skip list requires a reasonable setting of the number of index layers and the probability of node distribution to balance search efficiency and space overhead. The memory unit is a node in the skip list. For embedded devices whose random access memory (RAM) size is generally at the KB level, a skip list with too high a level will occupy more memory. In order to save memory space, the index level of the node should be as small as possible on the basis of ensuring efficient traversal of the linked list.
[0049] According to the usage of memory units or the memory distribution of memory units, the memory of the threshold node is determined, and the memory of the threshold node is greater than the set value. For example, the distribution of memory units is 5, 5, 5, 10, 10, 10, 20, 20, ···1k, 2k, indicating that there are more small memory units and fewer large memory units in the distribution of memory units, so the large memory unit 1k is set as the memory of the threshold node. For example, the distribution of memory units is 5, 10, 15, 20, 25, 30···100, among which the memory unit with a memory of 30 is used most frequently, and other memory units are rarely used, so 30 is set as the memory of the threshold node. Set the threshold node in the bottom-level linked list of the skip list, and the threshold node is the 0-level node of the skip list.
[0050] S200, obtaining a target memory block to be inserted into a jump table;
[0051] The target memory block is a free memory block in the operating system that needs to be allocated to a process or application. In the operating system, the memory is divided into different areas, including allocated memory blocks and free memory blocks. The free memory block is a memory area in the computer system that has not been allocated to any process or application.
[0052] Obtain a target memory block to be inserted into the jump list, including obtaining a memory value of the target memory block.
[0053] S300, if the target memory block is greater than or equal to the memory of the threshold node, insert the target memory block into the bottom-level linked list of the skip list;
[0054] Compare the memory value of the target memory block with the memory of the threshold node. When the memory value of the target memory block is greater than or equal to the memory of the threshold node, it means that the target memory block is a memory block with a larger memory. Start traversing the memory units from the threshold node until the first insertion position is found. Insert the target memory block into the bottom-level linked list at the first insertion position.
[0055] S400: If the target memory block is smaller than the memory of the threshold node, the target memory block is randomly inserted into the index layer linked list of the skip list.
[0056] Compare the memory value of the target memory block with the memory of the threshold node. When the memory value of the target memory block is smaller than the memory of the threshold node, it means that the target memory block is a memory block with smaller memory. Traverse the memory units in the index layer linked list until the second insertion position is found. Insert the target memory block into the index layer linked list at the second insertion position.
[0057] The memory management method provided by the embodiment of the present application obtains the threshold node of the skip list, where the threshold node is a memory unit whose memory is greater than a set value; obtains the target memory block to be inserted into the skip list; if the target memory block is greater than or equal to the memory of the threshold node, the target memory block is inserted into the bottom-level linked list of the skip list; if the target memory block is less than the memory of the threshold node, the target memory block is randomly inserted into the index-level linked list of the skip list. The embodiment of the present application improves the efficiency of memory management by setting a threshold node in the skip list and directly inserting a larger target memory block into the bottom-level linked list based on the threshold node.
[0058] Based on the above embodiment, after obtaining the threshold node of the jump list, the memory management method further includes:
[0059] S110, obtaining the memory to be queried;
[0060] S120, if the memory to be queried is greater than or equal to the memory of the threshold node, traverse the memory cells of the jump table starting from the target index node corresponding to the threshold node until a memory cell matching the memory to be queried is found;
[0061] S130, if the memory to be queried is smaller than the memory of the threshold node, traverse the memory units starting from the head index node of the highest level linked list of the skip list until a memory unit matching the memory to be queried is found.
[0062] The header index node is the top-level node and the starting node of the entire skip list. The header index node has no actual value, it only contains a pointer to the next level of linked list nodes.
[0063] When you need to query a memory cell with a fixed memory value in the skip list, get the memory value of the memory to be queried. Compare the memory value of the memory to be queried with the memory of the threshold node. When the memory value of the memory to be queried is greater than or equal to the memory of the threshold node, traverse the memory cells of the skip list directly from the threshold node through the target index node until a memory cell matching the memory to be queried is found. For example, Figure 3 As shown, the memory of the threshold node is 4k, and the memory value of the memory to be queried is 8k. By comparison, it can be seen that the memory value of the memory to be queried is greater than the memory of the threshold node. Through the target index node, the memory cells of the jump table are traversed directly from the threshold node. When the memory cell of 8k is traversed, the query ends.
[0064] When the memory value of the memory to be queried is less than the memory of the threshold node, the memory cells are traversed level by level starting from the head index node of the highest level linked list of the skip list until a memory cell matching the memory to be queried is found. Figure 3 As shown, the index layer linked list of the embodiment of the present application has a total of 4 layers, which are the fourth-level index layer, the third-level index layer, the second-level index layer, and the first-level index layer from top to bottom. The memory of the threshold node is 4k, and the memory value of the memory to be queried is 100; by comparison, it can be known that the memory value of the memory to be queried is less than the memory of the threshold node. Starting from the header index node of the highest-level linked list (i.e., the fourth-level index layer), the memory unit traversal is 0, 40, 1k, and the memory to be queried is not found. Then, the traversal starts from the memory unit 40 of the third-level index layer, and the traversed memory units are 40 and 300; continue to traverse from the memory unit 40 of the second-level index layer, and the traversed units are 40, 60, and 300; continue to traverse from the memory unit 60 of the first-level index layer, and the traversed units are 60 and 200; finally, traverse from the memory unit 60 of the original linked list, and the traversed units are 60 and 100, and the traversal ends.
[0065] In an embodiment of the present application, when the memory to be queried is larger than the memory of the threshold node, traversal is started directly from the threshold node, which reduces the traversal time and improves the efficiency of querying the memory unit.
[0066] Based on the above embodiment, after obtaining the threshold node of the jump table, the method further includes:
[0067] S140, determining a target index node, and pointing the pointer of the target index node to the threshold node.
[0068] The target index node is a newly set index node, and the target index node points to the threshold node from the adjacent previous memory unit of the threshold node.
[0069] The embodiment of the present application sets a target index node, which is beneficial for traversing the memory units of the jump table directly from the threshold node corresponding to the target index node, thereby improving the efficiency of memory management.
[0070] Based on the above embodiment, after obtaining the threshold node of the jump list, the memory management method further includes:
[0071] S150, obtaining the memory to be deleted;
[0072] S160, if the memory to be deleted is greater than or equal to the memory of the threshold node, traverse the memory cells of the jump table starting from the target index node corresponding to the threshold node until a memory cell matching the memory to be deleted is found, and delete the memory cell matching the memory to be deleted;
[0073] S170, if the memory to be deleted is less than the memory of the threshold node, traverse the memory units starting from the header index node of the highest level linked list of the jump list until a memory unit matching the memory to be deleted is found, and delete the memory unit matching the memory to be deleted.
[0074] When a memory cell with a fixed memory value in the jump table needs to be deleted, the memory value of the memory to be deleted is obtained. The memory value of the memory to be deleted is compared with the memory of the threshold node. When the memory value of the memory to be deleted is greater than or equal to the memory of the threshold node, the memory cells of the jump table are traversed directly from the threshold node through the target index node until a memory cell matching the memory to be deleted is found. For example, Figure 3 As shown, the memory of the threshold node is 4k, and the memory value of the memory to be deleted is 8k. By comparison, it can be seen that the memory value of the memory to be deleted is greater than the memory of the threshold node. Through the target index node, the memory cells of the jump table are traversed directly from the threshold node. When the memory cell of 8k is traversed, the memory cell of 8k is deleted.
[0075] When the memory value of the memory to be deleted is less than the memory of the threshold node, the memory cells are traversed level by level starting from the head index node of the highest level linked list of the jump list until a memory cell matching the memory to be deleted is found. Figure 3As shown, the memory of the threshold node is 4k, and the memory value of the memory to be deleted is 100; by comparison, it can be seen that the memory value of the memory to be deleted is less than the memory of the threshold node. Starting from the header index node of the highest level linked list (i.e., the fourth-level index layer), the memory units are 0, 40, and 1k. No memory to be deleted is found, and then the traversal starts from the memory unit 40 of the third-level index layer, and the traversed memory units are 40 and 300; continue to traverse from the memory unit 40 of the second-level index layer, and the traversed units are 40, 60, and 300; continue to traverse from the memory unit 60 of the first-level index layer, and the traversed units are 60 and 200; finally, start traversing from the memory unit 60 of the original linked list, and the traversed units are 60 and 100, and end the traversal. Delete the memory unit with a memory value of 100.
[0076] In an embodiment of the present application, when the memory to be deleted is greater than the memory of a threshold node, traversal is started directly from the threshold node, which reduces the traversal time and improves the efficiency of deleting memory units.
[0077] Based on the above embodiment, inserting the target memory block into the bottom-level linked list of the jump list includes:
[0078] S310, obtaining the first insertion position of the target memory block in the bottom-level linked list of the skip list;
[0079] S320, creating a new node at the first insertion position, and determining a memory value of the new node based on the size of the target memory block;
[0080] S330, obtaining the previous node and the next node of the new node, pointing the pointer of the previous node to the new node, and pointing the pointer of the new node to the next node.
[0081] Through the target index node, traverse from the threshold node until a memory cell whose memory is greater than or equal to the memory value of the target memory block is found, and the memory cell is set as the pre-insertion memory cell; for example, the memory value of the target memory block is 8k, and traversal starts from the threshold node and ends when traversal reaches memory cell 8k, then 8k is the pre-insertion memory cell, and the position immediately before or after the pre-insertion memory cell 8k is the first insertion position.
[0082] Create a new node at the first insertion position and set the memory value of the target memory block to the memory value of the new node.
[0083] The pre-inserted memory unit is used as the next node of the new node, and the previous node of the pre-inserted memory unit is used as the previous node of the new node. The pointer of the previous node points to the new node, and the pointer of the new node points to the next node. Optionally, the pre-inserted memory unit is used as the previous node of the new node, and the next node of the pre-inserted memory unit is used as the next node of the new node.
[0084] The embodiment of the present application obtains the first insertion position of the target memory block and inserts the target memory block from the first insertion position, which is conducive to quickly and accurately inserting the target memory block and improves the efficiency of memory management.
[0085] Based on the above embodiment, randomly inserting the target memory block into the index layer linked list of the jump list includes:
[0086] S410, based on a random function, obtaining a target index layer to which a target memory block is to be inserted;
[0087] S420, obtaining a second insertion position of the target memory block in the target index layer, and inserting the target memory block at the second insertion position.
[0088] The index layer linked list includes at least one level of index layer. The index layer linked list of the embodiment of the present application includes multiple levels of index layers. Figure 2 As shown, the memory units with memory values of 0, 4, and 15 are the first-level index layer, and the memory units with memory values of 0 and 15 are the second-level index layer.
[0089] When the target memory block needs to be inserted, a random function is used to determine whether to insert the target memory block into the index of the current level, which can improve the efficiency of the insertion operation. The specific steps are as follows:
[0090] (1) Randomly determine the highest level at which the target memory block is inserted: insert the target memory block into the bottom-level linked list of the skip list, and record the current level as level 0.
[0091] (2) Starting from layer 0, traverse each layer upward in turn.
[0092] (3) For each level, a random function is used to determine whether to connect the target memory block to the index of the current level. If the random function returns an "insert" result, the index level of the current level is the target index level.
[0093] (4) If the random function returns the result of "not inserted", stop traversing upward and the insertion process ends.
[0094] Compare the memory value of the target memory block with the memory size of the memory unit in the target index layer, and determine two adjacent memory units, one of which has a memory value greater than the memory value of the target memory, and is adjacent memory unit A; the other adjacent memory unit has a memory value less than the memory value of the target memory, and is adjacent memory unit B. The next node position of memory unit B is the second insertion position, and the target memory is inserted at the second insertion position.
[0095] The embodiment of the present application determines the target index layer of the target memory block through a random function, and can skip some nodes when inserting the target memory block, thereby improving the efficiency of inserting the memory block; it is beneficial to improve the efficiency of memory management.
[0096] Based on the above embodiment, a skip list data structure is used to store memory blocks, wherein the skip list data structure includes a bottom-level linked list, an index-level linked list, and a threshold node, and the memory blocks are free memory blocks.
[0097] Determine the memory value of the free memory block. A free memory block corresponds to a memory unit in the jump table. The memory value of the free memory block is the memory value of the memory unit. According to the size of the memory value, the memory units are arranged in order, for example, from small to large, to form the bottom-level linked list. Determine the index number corresponding to the memory unit, where the function for determining the index number is:
[0098] Level=random(0,MAX_LEVEL);
[0099] Among them, Level is the number of levels of the index layer linked list, and MAX_LEVEL is the highest level of the index layer linked list.
[0100] The index layer linked list of the jump list is determined according to the index number of the internal memory unit. The threshold node is determined according to the usage of the free memory or the distribution of the memory, and a new target index node is created, and the target index node points to the threshold node from the head of the index layer linked list.
[0101] The embodiment of the present application manages free memory units through a jump table structure containing threshold nodes, thereby improving the management efficiency of the memory units.
[0102] The memory management device provided in the embodiment of the present application is described below. The memory management device described below and the memory management method described above can be referred to in correspondence with each other. Figure 4 , Figure 4 Schematic diagram of the structure of a memory management device provided in an embodiment of the present application. A memory identification device includes:
[0103] A first acquisition module 401 is used to acquire a threshold node of a jump table, where the threshold node is a memory unit whose memory is greater than a set value;
[0104] A second acquisition module 402 is used to acquire a target memory block to be inserted into the jump table;
[0105] A first insertion module 403, configured to insert the target memory block into the bottom linked list of the skip list if the target memory block is greater than or equal to the memory of the threshold node;
[0106] The second inserting module 404 is configured to randomly insert the target memory block into the index level linked list of the skip list if the target memory block is smaller than the memory of the threshold node.
[0107] The memory management device provided by the embodiment of the present application obtains the threshold node of the skip list, where the threshold node is a memory unit whose memory is greater than a set value; obtains the target memory block to be inserted into the skip list; if the target memory block is greater than or equal to the memory of the threshold node, the target memory block is inserted into the bottom-level linked list of the skip list; if the target memory block is less than the memory of the threshold node, the target memory block is randomly inserted into the index layer linked list of the skip list. The embodiment of the present application improves the efficiency of memory management by setting a threshold node in the skip list and directly inserting a larger target memory block into the bottom-level linked list based on the threshold node.
[0108] In one embodiment, the first acquisition module 401 is also used to: acquire the memory to be queried; if the memory to be queried is greater than or equal to the memory of the threshold node, traverse the memory cells of the jump list starting from the target index node corresponding to the threshold node until a memory cell matching the memory to be queried is found; if the memory to be queried is less than the memory of the threshold node, traverse the memory cells starting from the header index node of the highest level linked list of the jump list until a memory cell matching the memory to be queried is found.
[0109] In one embodiment, the first acquisition module 401 is further used to: determine a target index node, and point the pointer of the target index node to the threshold node.
[0110] In one embodiment, the first acquisition module 401 is also used to: acquire the memory to be deleted; if the memory to be deleted is greater than or equal to the memory of the threshold node, traverse the memory cells of the jump list starting from the target index node corresponding to the threshold node until a memory cell matching the memory to be deleted is found, and delete the memory cell matching the memory to be deleted; if the memory to be deleted is less than the memory of the threshold node, traverse the memory cells starting from the header index node of the highest level linked list of the jump list until a memory cell matching the memory to be deleted is found, and delete the memory cell matching the memory to be deleted.
[0111] In one embodiment, the first insertion module 403 is used to: obtain the first insertion position of the target memory block in the bottom-level linked list of the jump list; create a new node at the first insertion position, and determine the memory value of the new node based on the size of the target memory block; obtain the previous node and the next node of the new node, point the pointer of the previous node to the new node, and point the pointer of the new node to the next node.
[0112] In one embodiment, the second insertion module 404 is used to: obtain the target index layer where the target memory block is to be inserted based on a random function; obtain the second insertion position of the target memory block in the target index layer, and insert the target memory block at the second insertion position.
[0113] In one embodiment, a skip list data structure is used to store memory blocks, wherein the skip list data structure includes a bottom-level linked list, an index-level linked list, and a threshold node, and the memory blocks are free memory blocks.
[0114] Figure 5 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 5 As shown, the electronic device may include: a processor 510, a communication interface 520, a memory 530 and a communication bus 540, wherein the processor 510, the communication interface 520 and the memory 530 communicate with each other via the communication bus 540. The processor 510 may call a computer program in the memory 530 to execute the steps of the memory management method, for example including:
[0115] Get the threshold node of the skip list, which is a memory unit whose memory is greater than the set value; get the target memory block to be inserted into the skip list; if the target memory block is greater than or equal to the memory of the threshold node, insert the target memory block into the bottom-level linked list of the skip list; if the target memory block is less than the memory of the threshold node, randomly insert the target memory block into the index-level linked list of the skip list.
[0116] In addition, the logic instructions in the above-mentioned memory 530 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art, and the computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0117] On the other hand, an embodiment of the present application further provides a computer program product, the computer program product including a computer program, the computer program can be stored on a non-transitory computer-readable storage medium, and when the computer program is executed by a processor, the computer can perform the steps of the memory management method provided in the above embodiments, for example, including:
[0118] Get the threshold node of the skip list, which is a memory unit whose memory is greater than the set value; get the target memory block to be inserted into the skip list; if the target memory block is greater than or equal to the memory of the threshold node, insert the target memory block into the bottom-level linked list of the skip list; if the target memory block is less than the memory of the threshold node, randomly insert the target memory block into the index-level linked list of the skip list.
[0119] On the other hand, an embodiment of the present application further provides a processor-readable storage medium, wherein the processor-readable storage medium stores a computer program, wherein the computer program is used to enable the processor to execute the steps of the memory management method provided in the above embodiments, for example, including:
[0120] Get the threshold node of the skip list, which is a memory unit whose memory is greater than the set value; get the target memory block to be inserted into the skip list; if the target memory block is greater than or equal to the memory of the threshold node, insert the target memory block into the bottom-level linked list of the skip list; if the target memory block is less than the memory of the threshold node, randomly insert the target memory block into the index-level linked list of the skip list.
[0121] The processor-readable storage medium can be any available medium or data storage device that can be accessed by the processor, including but not limited to magnetic storage (such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc.), optical storage (such as CD, DVD, BD, HVD, etc.), and semiconductor storage (such as ROM, EPROM, EEPROM, non-volatile memory (NANDFLASH), solid-state drive (SSD)), etc.
[0122] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0123] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0124] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A memory management method, characterized in that: include: Obtaining a threshold node of the jump table, wherein the threshold node is a memory unit whose memory is greater than a set value; Obtain a target memory block to be inserted into the jump table; If the target memory block is greater than or equal to the memory of the threshold node, inserting the target memory block into the bottom-level linked list of the skip list; If the target memory block is smaller than the memory of the threshold node, the target memory block is randomly inserted into the index layer linked list of the skip list.
2. The memory management method according to claim 1, characterized in that: After obtaining the threshold node of the jump table, the method further includes: Get the memory to be queried; If the memory to be queried is greater than or equal to the memory of the threshold node, traverse the memory cells of the jump table starting from the target index node corresponding to the threshold node until a memory cell matching the memory to be queried is found; If the memory to be queried is smaller than the memory of the threshold node, the memory units are traversed starting from the head index node of the highest level linked list of the skip list until a memory unit matching the memory to be queried is found.
3. The memory management method according to claim 2, characterized in that: After obtaining the threshold node of the jump table, the method further includes: A target index node is determined, and a pointer of the target index node is pointed to the threshold node.
4. The memory management method according to claim 1, characterized in that: After obtaining the threshold node of the jump table, the method further includes: Get the memory to be deleted; If the memory to be deleted is greater than or equal to the memory of the threshold node, traverse the memory cells of the jump table starting from the target index node corresponding to the threshold node until a memory cell matching the memory to be deleted is found, and delete the memory cell matching the memory to be deleted; If the memory to be deleted is smaller than the memory of the threshold node, the memory unit is traversed starting from the header index node of the highest level linked list of the jump list until a memory unit matching the memory to be deleted is found, and the memory unit matching the memory to be deleted is deleted.
5. The memory management method according to claim 1, characterized in that: Inserting the target memory block into the bottom-level linked list of the jump list comprises: Obtain the first insertion position of the target memory block in the bottom-level linked list of the jump list; Creating a new node at the first insertion position, and determining a memory value of the new node based on the size of the target memory block; The previous node and the next node of the new node are obtained, a pointer of the previous node is pointed to the new node, and a pointer of the new node is pointed to the next node.
6. The memory management method according to claim 1, characterized in that: The step of randomly inserting the target memory block into the index layer linked list of the jump table comprises: Based on a random function, obtaining a target index layer to which the target memory block is to be inserted; A second insertion position of the target memory block in the target index layer is obtained, and the target memory block is inserted into the second insertion position.
7. The memory management method according to claim 1, characterized in that: A skip list data structure is used to store memory blocks, wherein the skip list data structure includes the bottom layer linked list, the index layer linked list and the threshold node, and the memory block is a free memory block.
8. A memory management device, characterized in that: include: A first acquisition module is used to acquire a threshold node of a jump table, where the threshold node is a memory unit whose memory is greater than a set value; A second acquisition module, used for acquiring a target memory block to be inserted into the jump table; A first insertion module, configured to insert the target memory block into the bottom-level linked list of the jump list if the target memory block is greater than or equal to the memory of the threshold node; The second insertion module is used to randomly insert the target memory block into the index layer linked list of the jump list if the target memory block is smaller than the memory of the threshold node.
9. An electronic device comprising a processor and a memory storing a computer program, characterized in that: When the processor executes the computer program, the steps of the memory management method according to any one of claims 1 to 7 are implemented.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the memory management method according to any one of claims 1 to 7 is implemented.