A memory allocation method, device, equipment and computer-readable storage medium

By allocating storage pools to threads and adjusting their positions as needed, the problem of memory allocation pressure on the storage system is solved and the performance and utilization of the storage system are improved.

CN114564307BActive Publication Date: 2024-10-15INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210188859.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-28
Publication Date
2024-10-15
Estimated Expiration
2042-02-28

AI Technical Summary

Technical Problem

In the storage system, frequent use of system functions to apply for memory will lead to a decrease in storage IO throughput and increase system pressure. It is necessary to reduce the memory allocation pressure of the storage system.

Method used

Allocate a storage pool for threads, allocate memory space for operation instructions according to the available space in the storage pool, adjust the start and end positions of the storage pool, reduce the occupation of operating system memory, and improve the utilization of the storage pool by recycling the service chain list.

Benefits of technology

It effectively reduces the memory allocation pressure of the storage system, improves the read and write performance of the storage system, and improves the utilization of the storage pool.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114564307B_ABST
    Figure CN114564307B_ABST
Patent Text Reader

Abstract

The embodiment of the present application discloses a memory allocation method, device, equipment and computer-readable storage medium, which allocates a corresponding storage pool to a thread; when the thread receives an operation instruction, the available space of the storage pool is determined according to the starting position and the ending position of the storage pool; when the available space meets the space required by the operation instruction, the corresponding memory space is allocated to the operation instruction, and the ending position of the storage pool is adjusted according to the memory space; after completing the operation corresponding to the operation instruction, the starting position of the storage pool is adjusted. By allocating a storage pool to a thread, there is no need to call a system function to apply for memory when the thread receives an instruction, which reduces the pressure of the storage system to allocate memory and effectively improves the read and write performance of the storage system. And based on the execution of the instruction, the starting position and the ending position of the storage pool are dynamically adjusted, which improves the utilization rate of the storage pool while ensuring the normal execution of the instruction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of storage services, and in particular to a memory allocation method, apparatus, device and computer-readable storage medium. Background Art

[0002] SCSI (Small Computer System Interface) is a processor-independent standard for system-level interfaces between computers and intelligent devices. iSCSI (Internet Small Computer System Interface) is a standard for block data transmission over TCP (Transmission Control Protocol) / IP.

[0003] The target implemented in user mode, such as TGT service, is a commonly used iSCSI service. Currently, all iSCSI and SCSI commands received by TGT service use system functions (malloc) to apply for memory. When the storage pressure is high, frequent use of system functions to apply for memory will affect the storage IO (input / output) throughput, causing high pressure on the storage system.

[0004] It can be seen that how to reduce the pressure of memory allocation of the storage system is a problem that needs to be solved by those skilled in the art. Summary of the invention

[0005] The purpose of the embodiments of the present application is to provide a memory allocation method, apparatus, device and computer-readable storage medium, which can reduce the pressure of memory allocation on the storage system.

[0006] In order to solve the above technical problems, an embodiment of the present application provides a memory allocation method, including:

[0007] Allocate the corresponding storage pool for the thread;

[0008] When the thread receives an operation instruction, determining the available space of the storage pool according to the start position and the end position of the storage pool;

[0009] In the case where the available space satisfies the space required by the operation instruction, a corresponding memory space is allocated to the operation instruction, and an end position of the storage pool is adjusted according to the memory space;

[0010] After completing the operation corresponding to the operation instruction, the starting position of the storage pool is adjusted.

[0011] Optionally, allocating a corresponding storage pool to the thread includes:

[0012] Determine whether there is an available storage pool in the recycling service linked list;

[0013] If there is an available storage pool in the recycling service linked list, an available storage pool is used as the storage pool corresponding to the thread;

[0014] If there is no available storage pool in the recycling service linked list, a memory block matching the storage requirement of the thread is obtained from the operating system, and the memory block is used as the storage pool corresponding to the thread.

[0015] Optionally, when the available space satisfies the space required by the operation instruction, allocating corresponding memory space to the operation instruction includes:

[0016] In a case where the available space is greater than or equal to the space required by the operation instruction, and the available space belongs to the storage space opened from the end position of the storage pool, allocating the corresponding memory space for the operation instruction starting from the end position of the storage pool;

[0017] When the available space is greater than or equal to the space required for the operation instruction, and the available space belongs to the storage space opened from the head position of the storage pool, the end position is jumped to the head position of the storage pool, and the corresponding memory space is allocated to the operation instruction starting from the end position after the jump.

[0018] Optionally, when the available space is greater than or equal to the space required by the operation instruction, and the available space belongs to the storage space opened from the end position of the storage pool, allocating the corresponding memory space for the operation instruction starting from the end position of the storage pool includes:

[0019] When the value of the end position of the storage pool is smaller than the value of the start position, and the available space from the end position to the start position is greater than or equal to the space required by the operation instruction, a corresponding memory space is allocated for the operation instruction starting from the end position of the storage pool;

[0020] In a case where the value of the end position of the storage pool is greater than or equal to the value of the start position, determining whether the available space from the end position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction;

[0021] If the available space from the end position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction, the corresponding memory space is allocated to the operation instruction starting from the end position of the storage pool.

[0022] Optionally, when the available space is greater than or equal to the space required by the operation instruction, and the available space belongs to the storage space opened from the head position of the storage pool, jumping the end position to the head position of the storage pool, and allocating corresponding memory space for the operation instruction starting from the end position after the jump includes:

[0023] If the available space from the end position of the storage pool to the end position of the storage pool is less than the space required by the operation instruction, determining whether the available space from the head position of the storage pool to the start position of the storage pool is greater than or equal to the space required by the operation instruction;

[0024] If the available space from the head position of the storage pool to the start position of the storage pool is greater than or equal to the space required by the operation instruction, the end position is jumped to the head position of the storage pool, and the corresponding memory space is allocated to the operation instruction starting from the end position after the jump.

[0025] Optionally, adjusting the starting position of the storage pool includes:

[0026] In a case where the value of the end position of the storage pool is greater than the value of the start position, moving the start position of the storage pool according to the memory space corresponding to the operation instruction;

[0027] In a case where the value of the end position of the storage pool is less than or equal to the value of the start position, determining whether the space from the start position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction;

[0028] If the space from the start position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction, then moving the start position of the storage pool according to the memory space corresponding to the operation instruction;

[0029] If the space from the start position of the storage pool to the end position of the storage pool is smaller than the space required by the operation instruction, the start position is jumped to the head position of the storage pool, and the jumped start position is moved according to the memory space corresponding to the operation instruction.

[0030] Optionally, after determining the available space of the storage pool according to the start position and the end position of the storage pool, the method further includes:

[0031] When the available space does not satisfy the space required by the operation instruction, a memory block matching the storage requirement of the thread is obtained from the operating system, and the memory block is used as a new storage pool of the thread;

[0032] Putting the storage pool whose available space does not meet the space required by the operation instruction into a recycling service linked list;

[0033] Setting a recycling cycle for the storage pool put into the recycling service linked list;

[0034] When the storage pool reaches a recycling period and no thread is reallocated, the storage pool is released.

[0035] The embodiment of the present application also provides a memory allocation device, including a first allocation unit, a determination unit, a second allocation unit, a first adjustment unit, and a second adjustment unit;

[0036] The first allocation unit is used to allocate a corresponding storage pool to the thread;

[0037] The determining unit is configured to determine the available space of the storage pool according to the start position and the end position of the storage pool when the thread receives the operation instruction;

[0038] The second allocation unit is used to allocate corresponding memory space to the operation instruction when the available space meets the space required by the operation instruction;

[0039] The first adjustment unit is used to adjust the end position of the storage pool according to the memory space;

[0040] The second adjustment unit is used to adjust the starting position of the storage pool after completing the operation corresponding to the operation instruction.

[0041] Optionally, the first allocating unit includes a determining subunit, an acting subunit and an acquiring subunit;

[0042] The determination subunit is used to determine whether there is an available storage pool in the recycling service linked list;

[0043] The subunit is used to use an available storage pool as the storage pool corresponding to the thread if there is an available storage pool in the recycling service linked list;

[0044] The acquisition subunit is used to acquire a memory block matching the storage requirement of the thread from the operating system if there is no available storage pool in the recycling service linked list, and use the memory block as the storage pool corresponding to the thread.

[0045] Optionally, the second allocation unit includes a sequential allocation subunit and a jump subunit;

[0046] The sequential allocation subunit is configured to allocate the corresponding memory space for the operation instruction starting from the end position of the storage pool when the available space is greater than or equal to the space required by the operation instruction and the available space belongs to the storage space opened from the end position of the storage pool;

[0047] The jump subunit is used to jump the end position to the head position of the storage pool when the available space is greater than or equal to the space required by the operation instruction and the available space belongs to the storage space opened from the head position of the storage pool, and allocate corresponding memory space for the operation instruction starting from the end position after the jump.

[0048] Optionally, the sequential allocation subunit is used to allocate corresponding memory space for the operation instruction starting from the end position of the storage pool when the value of the end position of the storage pool is smaller than the value of the start position and the available space from the end position to the start position is greater than or equal to the space required by the operation instruction;

[0049] In a case where the value of the end position of the storage pool is greater than or equal to the value of the start position, determining whether the available space from the end position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction;

[0050] If the available space from the end position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction, the corresponding memory space is allocated to the operation instruction starting from the end position of the storage pool.

[0051] Optionally, the jump subunit is used to determine whether the available space from the head position of the storage pool to the start position of the storage pool is greater than or equal to the space required by the operation instruction if the available space from the end position of the storage pool to the end position of the storage pool is less than the space required by the operation instruction;

[0052] If the available space from the head position of the storage pool to the start position of the storage pool is greater than or equal to the space required by the operation instruction, the end position is jumped to the head position of the storage pool, and the corresponding memory space is allocated to the operation instruction starting from the end position after the jump.

[0053] Optionally, the second adjustment unit is used to move the starting position of the storage pool according to the memory space corresponding to the operation instruction when the value of the ending position of the storage pool is greater than the value of the starting position;

[0054] In a case where the value of the end position of the storage pool is less than or equal to the value of the start position, determining whether the space from the start position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction;

[0055] If the space from the start position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction, then moving the start position of the storage pool according to the memory space corresponding to the operation instruction;

[0056] If the space from the start position of the storage pool to the end position of the storage pool is smaller than the space required by the operation instruction, the start position is jumped to the head position of the storage pool, and the jumped start position is moved according to the memory space corresponding to the operation instruction.

[0057] Optionally, it also includes a taking unit, a putting unit, a setting unit and a releasing unit;

[0058] The serving unit is used for obtaining a memory block matching the storage requirement of the thread from the operating system when the available space does not meet the space required by the operation instruction, and using the memory block as a new storage pool for the thread;

[0059] The placing unit is used to place the storage pool whose available space does not meet the space required by the operation instruction into a recycling service linked list;

[0060] The setting unit is used to set a recycling cycle for the storage pool put into the recycling service linked list;

[0061] The release unit is used to release the storage pool when the storage pool reaches a recycling period and no thread is reallocated.

[0062] The present application also provides an electronic device, including:

[0063] Memory for storing computer programs;

[0064] A processor is used to execute the computer program to implement the steps of the above-mentioned memory allocation method.

[0065] An embodiment of the present application further 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 above-mentioned memory allocation method are implemented.

[0066] It can be seen from the above technical solution that a corresponding storage pool is allocated to the thread; when the thread receives an operation instruction, the available space of the storage pool is determined based on the starting position and the ending position of the storage pool; when the available space meets the space required by the operation instruction, the corresponding memory space is allocated to the operation instruction, and the ending position of the storage pool is adjusted based on the memory space; after the operation corresponding to the operation instruction is completed, the starting position of the storage pool is adjusted. In this technical solution, by allocating a storage pool to a thread, when the thread receives an instruction, there is no need to call a system function to apply for memory, but to directly allocate memory space for the operation instruction from the storage pool, which reduces the pressure of the storage system to allocate memory and effectively improves the read and write performance of the storage system. And based on the execution of the instruction, the starting position and the ending position of the storage pool are dynamically adjusted, which improves the utilization rate of the storage pool while ensuring the normal execution of the instruction. BRIEF DESCRIPTION OF THE DRAWINGS

[0067] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only 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.

[0068] Figure 1 A flowchart of a memory allocation method provided in an embodiment of the present application;

[0069] Figure 2 A flowchart of a method for allocating corresponding memory space to an operation instruction provided in an embodiment of the present application;

[0070] Figure 3 A schematic diagram of the structure of a memory allocation device provided in an embodiment of the present application;

[0071] Figure 4 A structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

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

[0073] The terms "including" and "having" and any variations thereof in the specification and claims of this application and the above drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but may include steps or units that are not listed.

[0074] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0075] Next, a memory allocation method provided by an embodiment of the present application is described in detail. Figure 1 A flowchart of a memory allocation method provided in an embodiment of the present application, the method comprising:

[0076] S101: Allocate a corresponding storage pool for the thread.

[0077] In an embodiment of the present application, in order to reduce the calls to system functions when applying for memory for instructions, a storage pool can be established for threads.

[0078] The TGT service contains multiple epoll threads, and a corresponding storage pool can be allocated for each epoll thread. In order to improve memory usage and avoid frequently applying for new memory blocks from the operating system as storage pools, a recycling mechanism can be set for the storage pool. When the storage pool is full of instructions, a new storage pool can be allocated to the thread, so that the storage pool filled with instructions is put into the recycling service list.

[0079] Therefore, in practical applications, when allocating a corresponding storage pool for a thread, it is possible to first determine whether there is an available storage pool in the recycling service linked list.

[0080] If there is an available storage pool in the recycling service linked list, an available storage pool is used as the storage pool corresponding to the thread. If there is no available storage pool in the recycling service linked list, a memory block matching the storage requirement of the thread can be obtained from the operating system and the memory block is used as the storage pool corresponding to the thread.

[0081] By setting up a recycling service linked list, the storage pool can be recycled and reused. When a storage pool needs to be allocated for a thread, there is no need to obtain a memory block from the operating system each time. When there is an available storage pool in the recycling service linked list, the available storage pool in the recycling service linked list can be directly called, which improves the utilization rate of the storage pool and reduces the large amount of operating system memory occupied by the thread.

[0082] S102: When the thread receives the operation instruction, the available space of the storage pool is determined according to the start position and the end position of the storage pool.

[0083] In practical applications, memory space needs to be allocated for operation instructions to ensure smooth execution of the operation instructions. Each thread has its corresponding storage pool, and each thread processes the operation instructions in a similar manner. In the embodiments of this application, one thread is used as an example for introduction.

[0084] When a thread receives an operation instruction, it needs to allocate a piece of memory space for the operation instruction from the storage pool.

[0085] Considering that the corresponding memory space can be released after the operation instruction is executed, and the storage pool can provide memory space for multiple operation instructions, in order to ensure the orderly allocation of the storage pool, the storage pool can be set with a start position and an end position.

[0086] The start position indicates the starting end of the memory space occupied by the currently valid operation instructions in the storage pool, and the end position indicates the end of the memory space occupied by the currently valid operation instructions in the storage pool.

[0087] The size of the storage pool is a known quantity. Based on the start and end positions of the storage pool, the available space of the storage pool can be determined. Available space refers to the unused continuous memory space in the storage pool.

[0088] S103: When the available space satisfies the space required by the operation instruction, a corresponding memory space is allocated to the operation instruction, and an end position of the storage pool is adjusted according to the memory space.

[0089] In order to allocate the corresponding memory space for the operation instructions, it is necessary to ensure that the available space in the storage pool is greater than or equal to the space required by the operation instructions.

[0090] When the available space of the storage pool is less than the space required by the operation instruction, it means that the available space does not meet the space required by the operation instruction. At this time, a new storage pool can be reallocated to the thread.

[0091] In the initial state, the start position and end position of the storage pool are the same. As the number of operation instructions received by the thread accumulates, the end position of the storage pool will change. As each operation instruction is completed, the start position of the storage pool will also change. Therefore, there may be a situation where the value of the start position of the storage pool is less than the value of the end position, and there may also be a situation where the value of the start position of the storage pool is greater than or equal to the value of the end position.

[0092] In the case where the available space is greater than or equal to the space required by the operation instruction, if the available space belongs to the storage space opened from the end position of the storage pool, the corresponding memory space can be allocated to the operation instruction starting from the end position of the storage pool. If the available space belongs to the storage space opened from the head position of the storage pool, the end position can be jumped to the head position of the storage pool, and the corresponding memory space can be allocated to the operation instruction starting from the end position after the jump.

[0093] After the corresponding memory space is allocated to the operation instruction, the end position of the storage pool needs to be adjusted according to the memory space occupied by the operation instruction.

[0094] S104: After completing the operation corresponding to the operation instruction, adjust the start position of the storage pool.

[0095] After the operation corresponding to the operation instruction is completed, the memory space occupied by the operation instruction needs to be released. In the embodiment of the present application, the purpose of releasing the memory space can be achieved by moving the starting position of the storage pool.

[0096] Based on the above description, the value of the start position of the storage pool may be greater than or equal to the value of the end position, or the value of the start position of the storage pool may be less than the value of the end position. For these two cases, the operation process of moving the start position of the storage pool will be different.

[0097] In a specific implementation, when the value of the end position of the storage pool is greater than the value of the start position, the start position of the storage pool may be directly moved according to the memory space corresponding to the operation instruction.

[0098] The size of the memory space corresponding to the operation instruction can be determined by moving the starting position of the storage pool to the same size of memory space.

[0099] When the value of the end position of the storage pool is less than or equal to the value of the start position, it is necessary to further determine whether the space from the start position to the end position of the storage pool is greater than or equal to the space required by the operation instruction.

[0100] The storage pool has a fixed size. In the embodiments of the present application, for ease of description, the head of the storage pool may be referred to as the head position, and the tail of the storage pool may be referred to as the tail position. The head position and the tail position of the storage pool are fixed. In order to achieve multiple uses of the storage pool, the start position and the end position of the storage pool may be dynamically adjusted based on the memory usage of the storage pool. The movement of the start position and the end position of the storage pool is in the direction from the head position to the tail position of the storage pool.

[0101] If the space from the start position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction, it means that the start position of the storage pool can be moved toward the end position of the storage pool. At this time, the start position of the storage pool can be moved according to the memory space corresponding to the operation instruction.

[0102] If the space from the start position of the storage pool to the end position of the storage pool is less than the space required by the operation instruction, the start position is jumped to the head position of the storage pool, and the jumped start position is moved according to the memory space corresponding to the operation instruction.

[0103] The size of the memory space corresponding to the operation instruction can be determined by moving the starting position of the storage pool to the same size of memory space.

[0104] It can be seen from the above technical solution that a corresponding storage pool is allocated to the thread; when the thread receives an operation instruction, the available space of the storage pool is determined based on the starting position and the ending position of the storage pool; when the available space meets the space required by the operation instruction, the corresponding memory space is allocated to the operation instruction, and the ending position of the storage pool is adjusted based on the memory space; after the operation corresponding to the operation instruction is completed, the starting position of the storage pool is adjusted. In this technical solution, by allocating a storage pool to a thread, when the thread receives an instruction, there is no need to call a system function to apply for memory, but to directly allocate memory space for the operation instruction from the storage pool, which reduces the pressure of the storage system to allocate memory and effectively improves the read and write performance of the storage system. And based on the execution of the instruction, the starting position and the ending position of the storage pool are dynamically adjusted, which improves the utilization rate of the storage pool while ensuring the normal execution of the instruction.

[0105] When allocating memory space for operation instructions from the storage pool, it depends on the start position and end position of the storage pool. Combined with the above introduction, it can be seen that the size relationship between the start position and the end position of the storage pool is different, and the way of allocating memory space for operation instructions will be different.

[0106] Figure 2 A flowchart of a method for allocating corresponding memory space to an operation instruction provided in an embodiment of the present application, the method comprising:

[0107] S201: Determine whether the value of the end position of the storage pool is smaller than the value of the start position.

[0108] When the value of the end position of the storage pool is less than the value of the start position, it means that the storage space between the end position and the start position of the storage pool is not occupied. In order to allocate available space to the operation instruction, it is necessary to check whether there is available space from the end position to the start position. At this time, S202 can be executed.

[0109] When the value of the end position of the storage pool is greater than or equal to the value of the start position, it means that the storage space between the start position and the end position of the storage pool has been occupied. In order to allocate available space to the operation instruction, it is necessary to check whether there is available space from the end position to the end position. At this time, S203 can be executed.

[0110] S202: When the available space from the end position to the start position is greater than or equal to the space required by the operation instruction, a corresponding memory space is allocated to the operation instruction starting from the end position of the storage pool.

[0111] When the available space from the end position to the start position is less than the space required by the operation instruction, it means that the available space does not meet the space required by the operation instruction. At this time, a new storage pool can be reallocated to the thread.

[0112] When the available space from the end position to the start position is greater than or equal to the space required by the operation instruction, it means that the available space meets the space required by the operation instruction. At this time, the corresponding memory space can be directly allocated to the operation instruction starting from the end position of the storage pool.

[0113] S203: Determine whether the available space from the end position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction.

[0114] If the available space from the end position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction, it means that the available space meets the space required by the operation instruction, and S204 can be executed at this time.

[0115] If the available space from the end position of the storage pool to the end position of the storage pool is less than the space required by the operation instruction, it means that the available space meets the space required by the operation instruction, but the end position of the storage pool cannot be directly moved, and S205 can be executed at this time.

[0116] S204: Allocate corresponding memory space for the operation instruction starting from the end position of the storage pool.

[0117] The end position of the storage pool can be moved to the same size of memory space as the memory space corresponding to the operation instruction.

[0118] S205: Determine whether the available space from the head position of the storage pool to the start position of the storage pool is greater than or equal to the space required by the operation instruction.

[0119] If the available space from the head position of the storage pool to the start position of the storage pool is greater than or equal to the space required by the operation instruction, it means that the available space meets the space required by the operation instruction, and S206 can be executed.

[0120] When the available space from the head position of the storage pool to the start position of the storage pool is less than the space required by the operation instruction, it means that the available space does not meet the space required by the operation instruction. At this time, a new storage pool can be reallocated to the thread.

[0121] S206: Jump the end position to the head position of the storage pool, and allocate corresponding memory space for the operation instruction starting from the end position after the jump.

[0122] If the available space from the head position of the storage pool to the start position of the storage pool is greater than or equal to the space required for the operation instruction, memory space can be selected from the available space from the head position to the start position of the storage pool and allocated to the operation instruction. The memory allocation needs to depend on the end position, so the end position can be jumped to the head position of the storage pool, so as to allocate the corresponding memory space for the operation instruction starting from the end position after the jump.

[0123] In the embodiment of the present application, head can be used to represent the starting position, rear can be used to represent the ending position, and (rear+1)%memory_cache_len can be used to achieve the purpose of jumping from the ending position to the head position of the storage pool. (head+1)%memory_cache_len can be used to achieve the purpose of jumping from the starting position to the head position of the storage pool.

[0124] Among them, % indicates the modulo operation, and memory_cache_len indicates the total memory size of the storage pool.

[0125] In the embodiment of the present application, the start position and the end position are dynamically adjusted based on the change of the memory space usage of the storage pool, so that the start position and the end position can directly and accurately reflect the memory usage of the storage pool. Based on the start position and the end position, the orderly execution of memory space allocation can be guaranteed.

[0126] In an embodiment of the present application, when the available space does not meet the space required by the operation instruction, a memory block matching the storage requirement of the thread can be obtained from the operating system, and the memory block can be used as a new storage pool for the thread. The storage pool whose available space does not meet the space required by the operation instruction is placed in a recycling service linked list. A recycling cycle is set for the storage pool placed in the recycling service linked list; when the storage pool reaches the recycling cycle and no thread is reallocated, the storage pool is released to the operating system.

[0127] Figure 3 A schematic diagram of the structure of a storage allocation device provided in an embodiment of the present application includes a first allocation unit 31, a determination unit 32, a second allocation unit 33, a first adjustment unit 34 and a second adjustment unit 35;

[0128] A first allocation unit 31 is used to allocate a corresponding storage pool to a thread;

[0129] A determination unit 32, configured to determine the available space of the storage pool according to the start position and the end position of the storage pool when the thread receives the operation instruction;

[0130] A second allocation unit 33 is used to allocate corresponding memory space to the operation instruction when the available space meets the space required by the operation instruction;

[0131] A first adjusting unit 34, used for adjusting the end position of the storage pool according to the memory space;

[0132] The second adjusting unit 35 is used to adjust the starting position of the storage pool after completing the operation corresponding to the operation instruction.

[0133] Optionally, the first allocating unit includes a determining subunit, an acting subunit and an acquiring subunit;

[0134] A judgment subunit, used to judge whether there is an available storage pool in the recycling service linked list;

[0135] As a subunit, if there is an available storage pool in the recycling service linked list, an available storage pool is used as the storage pool corresponding to the thread;

[0136] The acquisition subunit is used to obtain a memory block matching the storage requirement of the thread from the operating system if there is no available storage pool in the recycling service linked list, and use the memory block as the storage pool corresponding to the thread.

[0137] Optionally, the second allocation unit includes a sequential allocation subunit and a jump subunit;

[0138] The sequential allocation subunit is used to allocate the corresponding memory space for the operation instruction starting from the end position of the storage pool when the available space is greater than or equal to the space required by the operation instruction and the available space belongs to the storage space opened from the end position of the storage pool;

[0139] The jump subunit is used to jump the end position to the head position of the storage pool when the available space is greater than or equal to the space required by the operation instruction and the available space belongs to the storage space opened from the head position of the storage pool, and allocate corresponding memory space for the operation instruction starting from the end position after the jump.

[0140] Optionally, the sequential allocation subunit is used to allocate corresponding memory space for the operation instruction starting from the end position of the storage pool when the value of the end position of the storage pool is less than the value of the start position and the available space from the end position to the start position is greater than or equal to the space required by the operation instruction;

[0141] In the case where the value of the end position of the storage pool is greater than or equal to the value of the start position, determining whether the available space from the end position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction;

[0142] If the available space from the end position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction, the corresponding memory space is allocated to the operation instruction starting from the end position of the storage pool.

[0143] Optionally, the jump subunit is used to determine whether the available space from the head position of the storage pool to the start position of the storage pool is greater than or equal to the space required by the operation instruction if the available space from the end position of the storage pool to the end position of the storage pool is less than the space required by the operation instruction;

[0144] If the available space from the head position of the storage pool to the start position of the storage pool is greater than or equal to the space required by the operation instruction, the end position is jumped to the head position of the storage pool, and the corresponding memory space is allocated to the operation instruction starting from the end position after the jump.

[0145] Optionally, the second adjustment unit is used to move the starting position of the storage pool according to the memory space corresponding to the operation instruction when the value of the ending position of the storage pool is greater than the value of the starting position;

[0146] When the value of the end position of the storage pool is less than or equal to the value of the start position, determining whether the space from the start position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction;

[0147] If the space from the start position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction, the start position of the storage pool is moved according to the memory space corresponding to the operation instruction;

[0148] If the space from the start position of the storage pool to the end position of the storage pool is less than the space required by the operation instruction, the start position is jumped to the head position of the storage pool, and the jumped start position is moved according to the memory space corresponding to the operation instruction.

[0149] Optionally, it also includes a taking unit, a putting unit, a setting unit and a releasing unit;

[0150] As a unit, it is used to obtain a memory block that matches the storage requirement of the thread from the operating system when the available space does not meet the space required by the operation instruction, and use the memory block as the new storage pool of the thread;

[0151] The putting unit is used to put the storage pool whose available space does not meet the space required by the operation instruction into the recycling service chain list;

[0152] A setting unit, used to set a recycling cycle for the storage pool put into the recycling service linked list;

[0153] The release unit is used to release the storage pool when the storage pool reaches the recycling period and no thread is reallocated.

[0154] Figure 3 The description of the features in the corresponding embodiments can be found in Figure 1 and Figure 2 The relevant descriptions of the corresponding embodiments will not be repeated here one by one.

[0155] It can be seen from the above technical solution that a corresponding storage pool is allocated to the thread; when the thread receives an operation instruction, the available space of the storage pool is determined based on the starting position and the ending position of the storage pool; when the available space meets the space required by the operation instruction, the corresponding memory space is allocated to the operation instruction, and the ending position of the storage pool is adjusted based on the memory space; after the operation corresponding to the operation instruction is completed, the starting position of the storage pool is adjusted. In this technical solution, by allocating a storage pool to a thread, when the thread receives an instruction, there is no need to call a system function to apply for memory, but to directly allocate memory space for the operation instruction from the storage pool, which reduces the pressure of the storage system to allocate memory and effectively improves the read and write performance of the storage system. And based on the execution of the instruction, the starting position and the ending position of the storage pool are dynamically adjusted, which improves the utilization rate of the storage pool while ensuring the normal execution of the instruction.

[0156] Figure 4 A structural diagram of an electronic device provided in an embodiment of the present application, such as Figure 4 As shown, the electronic device includes: a memory 20 for storing a computer program;

[0157] The processor 21 is used to implement the steps of the memory allocation method in the above embodiment when executing a computer program.

[0158] The electronic device provided in this embodiment may include but is not limited to a smart phone, a tablet computer, a laptop computer or a desktop computer.

[0159] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 21 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.

[0160] The memory 20 may include one or more computer-readable storage media, which may be non-transitory. The memory 20 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 20 is at least used to store the following computer program 201, wherein, after the computer program is loaded and executed by the processor 21, the relevant steps of the memory allocation method disclosed in any of the aforementioned embodiments can be implemented. In addition, the resources stored in the memory 20 may also include an operating system 202 and data 203, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 202 may include Windows, Unix, Linux, etc. The data 203 may include, but is not limited to, the start position and end position of the storage pool, etc.

[0161] In some embodiments, the electronic device may further include a display screen 22 , an input / output interface 23 , a communication interface 24 , a power source 25 , and a communication bus 26 .

[0162] Those skilled in the art will understand that Figure 4 The structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure.

[0163] It is understandable that if the memory allocation method in the above embodiment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium to execute all or part of the steps of each embodiment method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), electrically erasable programmable ROM, register, hard disk, removable disk, CD-ROM, magnetic disk or optical disk and other media that can store program codes.

[0164] Based on this, an embodiment of the present invention further 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 above-mentioned memory allocation method are implemented.

[0165] The functions of the functional modules of the computer-readable storage medium described in the embodiment of the present invention can be specifically implemented according to the method in the above method embodiment. The specific implementation process can refer to the relevant description of the above method embodiment, which will not be repeated here.

[0166] The above is a detailed introduction to a memory allocation method, device, equipment and computer-readable storage medium provided in the embodiments of the present application. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.

[0167] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0168] The above is a detailed introduction to a memory allocation method, device, equipment and computer-readable storage medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.

Claims

1. A memory allocation method, characterized in that: include: Allocate the corresponding storage pool for the thread; When the thread receives an operation instruction, determining the available space of the storage pool according to the start position and the end position of the storage pool; In the case where the available space satisfies the space required by the operation instruction, a corresponding memory space is allocated to the operation instruction, and an end position of the storage pool is adjusted according to the memory space; After completing the operation corresponding to the operation instruction, adjusting the starting position of the storage pool; The allocation of a corresponding storage pool to a thread includes: Determine whether there is an available storage pool in the recycling service list; If there is an available storage pool in the recycling service linked list, use an available storage pool as the storage pool corresponding to the thread; If there is no available storage pool in the recycling service linked list, a memory block matching the storage requirement of the thread is obtained from the operating system, and the memory block is used as the storage pool corresponding to the thread; In the case where the available space satisfies the space required by the operation instruction, allocating corresponding memory space to the operation instruction comprises: In a case where the available space is greater than or equal to the space required by the operation instruction, and the available space belongs to the storage space opened from the end position of the storage pool, allocating the corresponding memory space for the operation instruction starting from the end position of the storage pool; In the case where the available space is greater than or equal to the space required by the operation instruction, and the available space belongs to the storage space opened from the head position of the storage pool, the end position is jumped to the head position of the storage pool, and the corresponding memory space is allocated to the operation instruction starting from the end position after the jump; The adjusting the starting position of the storage pool includes: In a case where the value of the end position of the storage pool is greater than the value of the start position, moving the start position of the storage pool according to the memory space corresponding to the operation instruction; In a case where the value of the end position of the storage pool is less than or equal to the value of the start position, determining whether the space from the start position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction; If the space from the start position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction, then moving the start position of the storage pool according to the memory space corresponding to the operation instruction; If the space from the start position of the storage pool to the end position of the storage pool is smaller than the space required by the operation instruction, the start position is jumped to the head position of the storage pool, and the jumped start position is moved according to the memory space corresponding to the operation instruction.

2. The memory allocation method according to claim 1, characterized in that: When the available space is greater than or equal to the space required by the operation instruction, and the available space belongs to the storage space opened from the end position of the storage pool, allocating the corresponding memory space for the operation instruction from the end position of the storage pool includes: When the value of the end position of the storage pool is smaller than the value of the start position, and the available space from the end position to the start position is greater than or equal to the space required by the operation instruction, a corresponding memory space is allocated for the operation instruction starting from the end position of the storage pool; In a case where the value of the end position of the storage pool is greater than or equal to the value of the start position, determining whether the available space from the end position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction; If the available space from the end position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction, the corresponding memory space is allocated to the operation instruction starting from the end position of the storage pool.

3. The memory allocation method according to claim 2, characterized in that: When the available space is greater than or equal to the space required by the operation instruction, and the available space belongs to the storage space opened from the head position of the storage pool, jumping the end position to the head position of the storage pool, and allocating the corresponding memory space for the operation instruction from the end position after the jump includes: If the available space from the end position of the storage pool to the end position of the storage pool is less than the space required by the operation instruction, determining whether the available space from the head position of the storage pool to the start position of the storage pool is greater than or equal to the space required by the operation instruction; If the available space from the head position of the storage pool to the start position of the storage pool is greater than or equal to the space required by the operation instruction, the end position is jumped to the head position of the storage pool, and the corresponding memory space is allocated to the operation instruction starting from the end position after the jump.

4. The memory allocation method according to any one of claims 1 to 3, characterized in that: After determining the available space of the storage pool according to the start position and the end position of the storage pool, the method further includes: When the available space does not satisfy the space required by the operation instruction, a memory block matching the storage requirement of the thread is obtained from the operating system, and the memory block is used as a new storage pool of the thread; Putting the storage pool whose available space does not meet the space required by the operation instruction into a recycling service linked list; Setting a recycling cycle for the storage pool put into the recycling service linked list; When the storage pool reaches a recycling period and no thread is reallocated, the storage pool is released.

5. A memory allocation device, characterized in that: It includes a first allocating unit, a determining unit, a second allocating unit, a first adjusting unit and a second adjusting unit; The first allocation unit is used to allocate a corresponding storage pool to the thread; The determining unit is configured to determine the available space of the storage pool according to the start position and the end position of the storage pool when the thread receives the operation instruction; The second allocation unit is used to allocate corresponding memory space to the operation instruction when the available space meets the space required by the operation instruction; The first adjustment unit is used to adjust the end position of the storage pool according to the memory space; The second adjustment unit is used to adjust the starting position of the storage pool after completing the operation corresponding to the operation instruction; The first allocation unit includes a determination subunit, an acting subunit and an acquisition subunit; The determination subunit is used to determine whether there is an available storage pool in the recycling service linked list; The subunit is used to use an available storage pool as the storage pool corresponding to the thread if there is an available storage pool in the recycling service linked list; The acquisition subunit is used for acquiring a memory block matching the storage requirement of the thread from the operating system if there is no available storage pool in the recycling service linked list, and using the memory block as the storage pool corresponding to the thread; The second allocation unit includes a sequential allocation subunit and a jump subunit; The sequential allocation subunit is configured to allocate the corresponding memory space for the operation instruction starting from the end position of the storage pool when the available space is greater than or equal to the space required by the operation instruction and the available space belongs to the storage space opened from the end position of the storage pool; The jump subunit is used to jump the end position to the head position of the storage pool when the available space is greater than or equal to the space required by the operation instruction and the available space belongs to the storage space opened from the head position of the storage pool, and allocate the corresponding memory space for the operation instruction starting from the end position after the jump; The second adjustment unit is used to move the starting position of the storage pool according to the memory space corresponding to the operation instruction when the value of the ending position of the storage pool is greater than the value of the starting position; In a case where the value of the end position of the storage pool is less than or equal to the value of the start position, determining whether the space from the start position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction; If the space from the start position of the storage pool to the end position of the storage pool is greater than or equal to the space required by the operation instruction, then moving the start position of the storage pool according to the memory space corresponding to the operation instruction; If the space from the start position of the storage pool to the end position of the storage pool is smaller than the space required by the operation instruction, the start position is jumped to the head position of the storage pool, and the jumped start position is moved according to the memory space corresponding to the operation instruction.

6. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to execute the computer program to implement the steps of the memory allocation method as claimed in any one of claims 1 to 4.

7. 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 of the memory allocation method according to any one of claims 1 to 4 are implemented.