A method and apparatus for allocating storage addresses for data in a memory
By organizing storage blocks into a tree-like structure with functionally represented data sizes, the method addresses the inefficiencies in managing storage space for variable-sized data in DNNs, enhancing storage efficiency and data access speed.
Patent Information
- Application Number
- CN202010421447.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-05-18
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2040-12-03
AI Technical Summary
There is a lack of effective solutions in the prior art to manage storage space allocation of data of unknown sizes, functionally represented, resulting in insufficient utilization of storage space and a large amount of fragmentation.
A tree structure is used to manage storage blocks, and a tree structure of multi-level nodes is formed by receiving data size requests represented by functions, and the target storage space is allocated, and a new node is created at the physical level to ensure data continuity and space utilization.
It improves the utilization rate of storage space, reduces fragmentation, improves data access efficiency, and retains the integrity of storage records.
Smart Images

Figure CN113688064B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computers, and more particularly, to the management of storage space. Background Art
[0002] Deep neural networks (DNNs) have been widely used in various applications, such as computer vision, speech recognition, machine translation, and robotics, because of their significantly improved accuracy compared to traditional machine learning methods. However, the performance advantages of DNNs come at the cost of extremely high computational and memory complexity, posing challenges to the underlying hardware architecture. To improve the efficiency of DNN processing, various dedicated accelerators have been proposed to provide better performance and efficiency than general-purpose architectures (such as CPUs and GPUs).
[0003] To better utilize storage space, there are various schemes for managing the space of memory, such as best fit (BF) and graph coloring (GC).
[0004] However, in the existing technical solutions, the storage space is allocated in the form of immediate numbers, and there is no suitable solution for variable-sized data. Moreover, the utilization of space in the prior art is not sufficient. Summary of the Invention
[0005] An object of the present disclosure is to allocate appropriate storage space for data represented in a functional manner with an unknown size.
[0006] According to a first aspect of the present disclosure, there is provided a method for allocating a storage address for data in a memory, including: receiving a space allocation request for a storage space in the memory, the allocation request carrying the data size represented by a first function; allocating a target storage space for the data according to the received space allocation request; and allocating a storage address for the data based on the allocated target storage space.
[0007] According to a second aspect of the present disclosure, there is provided a method for managing a storage space, including: forming a plurality of storage blocks, each storage block having a total storage space identifier and an available storage space identifier, where the total storage space identifier is used to indicate the total storage space of the storage block by a total space function, and the available storage space identifier is used to indicate the available storage space of the storage block by a second function; forming a tree structure with the plurality of storage blocks as nodes, the tree structure including multiple levels of nodes, where the total storage space of the upper-level node is the sum of the total storage spaces of the lower-level nodes.
[0008] According to a third aspect of the present disclosure, there is provided a method for allocating storage space for data in a memory, including: receiving a space allocation request for the storage space in the memory, where the allocation request carries the data size represented by a first function; forming a plurality of storage blocks, each storage block having a total storage space identifier and an available storage space identifier, where the total storage space identifier is used to indicate the total storage space of the storage block by a total space function, and the available storage space identifier is used to indicate the available storage space of the storage block by a second function; forming a tree structure with the plurality of storage blocks as nodes, the tree structure including multiple levels of nodes, where the total storage space of a superior node is the sum of the total storage spaces of inferior nodes; and allocating a target storage space for the data according to the received space allocation request and based on the tree structure.
[0009] According to a fourth aspect of the present disclosure, there is provided an electronic device, including: one or more processors; and a memory storing computer-executable instructions, which, when run by the one or more processors, cause the electronic device to execute the method as described above.
[0010] According to a fifth aspect of the present disclosure, there is provided a computer-readable storage medium including computer-executable instructions, which, when run by one or more processors, execute the method as described above. Description of the Drawings
[0011] By referring to the following detailed description with reference to the accompanying drawings, the above and other objects, features, and advantages of the exemplary embodiments of the present disclosure will become readily understandable. In the drawings, several embodiments of the present disclosure are shown in an exemplary but non-limiting manner, and the same or corresponding reference numerals represent the same or corresponding parts, where:
[0012] Figure 1a A general schematic diagram of neural network operations is shown;
[0013] Figure 1b It shows an example of allocating storage space according to the Figure 1a operation process;
[0014] Figure 1c It shows another example of allocating storage space according to the Figure 1a operation process;
[0015] Figure 2 A flowchart of a method for allocating a storage address for data in a memory according to an embodiment of the present disclosure is shown;
[0016] Figure 3 A flowchart of a method for establishing the tree structure is shown;
[0017] Figure 4a Shows a schematic diagram of a tree structure according to an embodiment of the present disclosure;
[0018] Figure 4b Shows a schematic diagram of a tree structure according to an embodiment of the present disclosure;
[0019] Figure 4c Shows a schematic diagram of a tree structure according to an embodiment of the present disclosure;
[0020] Figure 4d Shows a schematic diagram of allocating space for data according to another embodiment of the present disclosure;
[0021] Figure 5 Shows a schematic diagram of allocating target storage space for data according to a preferred embodiment of the present disclosure;
[0022] Figure 6a Shows a flowchart of a method for creating a new node according to an embodiment of the present disclosure;
[0023] Figure 6b Shows according to Figure 6a Schematic diagram of a new node created according to the shown flowchart of the method;
[0024] Figure 6c Shows according to Figure 6a Schematic diagram of a new node created according to the shown flowchart of the method;
[0025] Figure 7a Shows a flowchart of establishing a new node according to an embodiment of the present disclosure;
[0026] Figure 7b Shows a schematic diagram of establishing a new node according to an embodiment of the present disclosure;
[0027] Figure 8 Shows a schematic diagram of allocating an address for a storage space according to an embodiment of the present disclosure;
[0028] Figure 9 Shows a method for managing a storage space according to an embodiment of the present disclosure;
[0029] Figure 10 Shows a method for allocating a storage space for data in a memory according to an embodiment of the present disclosure;
[0030] Figure 11 Shows a schematic block diagram of a combined processing device; and
[0031] Figure 12 Shows a schematic block diagram of a board card. Detailed implementation manners
[0032] The following will clearly and completely describe the technical solutions in the embodiments of the present disclosure in conjunction with the accompanying drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, rather than all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative efforts fall within the protection scope of the present disclosure.
[0033] It should be understood that the terms "first", "second", "third", "fourth", etc. in the claims, the description, and the drawings of the present disclosure are used to distinguish different objects, rather than to describe a specific order. The terms "comprising" and "including" used in the description and claims of the present disclosure indicate the presence of the described features, wholes, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their combinations.
[0034] It should also be understood that the terms used in the description of the present disclosure herein are only for the purpose of describing specific embodiments and are not intended to limit the present disclosure. As used in the description and claims of the present disclosure, unless the context clearly indicates otherwise, the singular forms "a", "an", and "the" are intended to include the plural forms. It should be further understood that the term "and / or" used in the description and claims of the present disclosure refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0035] As used in this specification and the claims, the term "if" can be interpreted as "when", "once", "in response to determining", or "in response to detecting" depending on the context. Similarly, the phrase "if determined" or "if [the described condition or event] is detected" can be interpreted as meaning "once determined", "in response to determining", "once [the described condition or event] is detected", or "in response to detecting [the described condition or event]" depending on the context.
[0036] Figures 1a - 1c A schematic diagram showing various different memory allocation methods, where Figure 1a A schematic diagram showing a general neural network operation is shown.
[0037] Such as Figure 1aAs shown, the convolutional neural network includes data D1 - D4. The symbol Conv represents the convolution operation. Thus, D2 = Conv(D1), D3 = Conv(D2), and D4 = Conv(D3). For example, D1 is 16 bits, D2 is 8 bits, D3 is 24 bits, and D4 is 32 bits. During the continuous convolution operation, it is necessary to allocate storage space for the data participating in the operation and release the space occupied by historical data.
[0038] Figure 1b illustrates an example of allocating storage space according to the Figure 1a operation process, which is called the best fit (BF) method.
[0039] In Figure 1b , first, addresses are allocated for data D1 and D2. When the second convolution operation is performed, the space occupied by D1 can be released, and storage space is allocated for data D3. Similarly, when the third convolution operation is performed, the space of D2 can be released, and further storage space is allocated for D4. In the scheme shown in 1b, a large amount of space fragmentation will occur, thus reducing the utilization rate of the storage space.
[0040] Figure 1c illustrates another example of allocating storage space according to the Figure 1a operation process, which is called graph coloring (GC).
[0041] As Figure 1c shown, the storage space is divided into multiple classes. Regclass32 represents the space with a capacity of 32 bits, Regclass24 represents the space with a capacity of 24 bits, Regclass16 represents the space with a capacity of 16 bits, and Regclass8 represents the space with a capacity of 8 bits. In this case, data D1 - D4 will be divided into different classifications according to their sizes. For example, data D1 is stored in the R 16,0 space in Regclass16, data D2 is stored in the R 8,4 space in Regclass8, data D3 is stored in the R 24,0 space in Regclass24, and data D4 is stored in the R 32,1 space in Regclass32. In this allocation method, a large amount of fragmentation will still occur, especially when the size of a certain data is smaller than a certain class and larger than another class, then the fragmentation of the storage space is more obvious. For example, if the size of a certain data is 20 bits, it should be stored in Regclass24, resulting in a waste of 4 bits of space.
[0042] Figure 2 A method for allocating a storage address for data in a memory according to an embodiment of the present disclosure is shown, including: in operation S210, receiving a space allocation request for a storage space in the memory, the allocation request carrying a data size represented by a first function; in operation S220, allocating a target storage space for the data according to the received space allocation request; and in operation S230, allocating a storage address for the data based on the allocated target storage space.
[0043] It should be understood that, in the above, in addition to the data size, other information may also be carried in the space allocation request, such as the lifespan of the resource, which indicates when the resource is applied for, when it is released, and the order of application and release, etc. Different orders may lead to different results. In the present disclosure, the data is not an immediate number, but is represented by a function, and the function contains unknown variables, and these unknown variables are only determined at runtime, and are not determined values when allocating storage space for these data.
[0044] Taking a four-dimensional data as an example below, its size can be expressed as S = N * H * W * C, where the parameters N, H, W, and C are all positive natural numbers, and at least one of these four parameters is variable. For easier understanding, if the initial network input size is assumed to be 1 * H * W * 3, where H and W are unknown parameters. After passing through multiple layers of the neural network, at the X-th layer, the input size of this layer becomes 1 * f1(H) * f2(W) * 3. At this time, f is determined according to the parameters of the operators from the first layer to the X-th layer. At this time, f1(H)>0 and f2(W)>0. Since in the neural network, both f1 and f2 are polynomials of the highest degree one, we can obtain the conditions for the minimum sizes of the parameters H and W according to this inequality, such as H>x1 and W>x2.
[0045] For the entire network operation, the constraints on HW of the entire neural network are obtained. It can be set that H = h + x1 and W = w + x2, and substituting this into the original network, each data block expression in the original network will only have a + sign. Among them, x1 and x2 are the minimum values constrained by the neural network. Since the network structure needs to ensure that the size at the last layer cannot be 0 during calculation, for the entire network operation, there are constraints on H and W. Thus, the size of the data can be expressed as, for example, P1hw + P2h + P3w + P4, where P1, P2, P3, and P4 are all non-negative integers.
[0046] The following is a set of exemplary space allocation instructions and space release instructions to facilitate a clearer understanding of the technical solution of the present disclosure, where operations 1 to 8 are executed in chronological order.
[0047] Operation 1: Alloc A 10hw+5h+5w+20
[0048] Operation 2: alloc A1 9hw+4h+6w+5
[0049] Operation 3: alloc A2 hw+h+10w+8
[0050] Operation 4: Dealloc A
[0051] Operation 5: alloc B 8hw+10h+10w+100
[0052] Operation 6: alloc C 4hw+20h+20w+50
[0053] Operation 7: dealloc B
[0054] Operation 8: alloc D 12hw+5h+5w+10
[0055] The instruction "alloc" means allocating storage space, while the instruction "dealloc" means releasing storage space. For example, Operation 1 "Alloc A 10hw+5h+5w+20" means allocating a space of size 10hw+5h+5w+20 for data A, Operation 5 "allocB 8hw+10h+10Ww+100" means allocating a space of size 8hw+10h+10Ww+100 for data B, etc., and Operation 4 "Dealloc A" means releasing the space occupied by data A, and Operation 7 "dealloc B" means releasing the space occupied by data B.
[0056] Next, after receiving the space allocation request, an appropriate part or all of the available storage space can be selected as the target storage space to be allocated to the above-mentioned data. It should be explained that the above term "target storage space" refers to the space actually allocated to the data. Such a description is only used to distinguish different spaces referred to in the context for easy understanding, and does not impose any limitation on the technical solution of the present disclosure. It should be understood that the above "available storage space" and "target storage space" are virtual storage spaces, and these virtual storage spaces can be corresponded to the corresponding data, and then these virtual storage spaces are mapped to the actual physical space and address. However, in the context, different names are used to represent the meanings of these virtual storage spaces.
[0057] After determining the storage space, the corresponding storage address is allocated to the data. The storage address can include a starting address and an offset, and the offset can be determined by the size of the data.
[0058] Among them, the process of allocating corresponding storage addresses to data can be a process of mapping virtual storage space to storage addresses in physical space. In the above text, when allocating target storage space for data, available storage space will be searched to allocate an appropriate part of the storage space to the data. During the process of allocating storage space, specific storage addresses are not allocated temporarily. This method of separating space allocation and address allocation is significantly different from the prior art method of allocating storage space and storage addresses to data in one step.
[0059] According to an embodiment of the present disclosure, a tree structure can be established. The tree structure can include multiple nodes, and each node represents a storage space. Suitable nodes can be found to store data by traversing the storage space. The "suitable nodes" described here can be a single node or a combination of multiple nodes.
[0060] It should be understood that establishing the tree relationship between storage blocks can be achieved before the above operation S210, that is, the tree structure to be described in detail below can be established in advance, or it can be achieved after operation S210 and before operation S220, that is, this tree structure is established in real time through space allocation requests and space release operations.
[0061] Figure 3 The flowchart of a method for establishing this tree structure is shown.
[0062] As Figure 3 shown, the method of the present disclosure further includes: in operation S310, forming multiple storage blocks, each storage block having a total storage space identifier and an available storage space identifier, where the total storage space identifier is used to indicate the total storage space of the storage block with a total space function, and the available storage space identifier is used to indicate the available storage space of the storage block with a second function; in operation S320, forming the multiple storage blocks into a tree structure as nodes, the tree structure including multiple levels of nodes, where the total storage space of the upper-level node is the sum of the total storage spaces of the lower-level nodes.
[0063] The above operations 1 - operation 8 and Figures 4a - 4c are used to describe the establishment process of the tree structure.
[0064] As Figure 4a shown, first, initialization is performed, using node 0 as the initial node. Each node represents a storage block, its total storage space is 0, and its available storage space is 0. For ease of description, its storage attribute can be represented as 0(0).
[0065] Next, when the instruction "Alloc A 10hw+5h+5w+20" of operation 1 is received, node 1 is created under node 0 to store data A. Therefore, the total storage space of this node 1 is 10hw+5h+5w+20, the available storage space is 0, and its storage attribute can be expressed as 10hw+5h +5w+20(0).
[0066] When the instruction "alloc A1 9hw+4h+6w+5" of operation 2 is received, node 2 is created under node 0 to store data A1. Therefore, the total storage space of this node 2 is 9hw+4h+6w+5, the available storage space is 0, and its storage attribute can be expressed as 9hw+4h+6w+5(0).
[0067] When the instruction "alloc A2 hw+h+10w+8" of operation 3 is received, node 3 is created under node 0 to store data A2. Therefore, the total storage space of this node 3 is hw+h+10w+8, the available storage space is 0, and its storage attribute can be expressed as hw+h+10w+8(0).
[0068] At this time, the total storage space of the initial node 0 is 20hw+10h+21w+33, its available storage space is 0, and its storage attribute can be expressed as 20hw+10h+21w+33(0).
[0069] It can be understood that the storage space can also be released. According to an embodiment of the present disclosure, in response to receiving a space release request, the corresponding node is released; the available storage space identifier of the released node is updated.
[0070] Take Figure 4b as an example for description. When the instruction "dealloc A" of operation 4 is received, the space of node 1 is released, so that the available storage space of node 1 is 10hw+5h+5w+20, and its storage attribute can be expressed as 10hw+5h+5w+20(10hw+5h+5w+20), as Figure 4b shown. At this time, the total storage space of the initial node 0 is 20hw+10h+21w+33, its available storage space identifier is still 0, and its storage attribute can be expressed as 20hw+10h+21w+33(0).
[0071] In the present disclosure, the released space can be reused to achieve the purpose of full utilization of the space. Thus, according to an embodiment of the present disclosure, allocating a target storage space for data according to the received space allocation request includes: retrieving available storage space in the nodes of the tree structure; in response to finding available storage space in the nodes of the tree structure whose second function has a common function with the first function, using the storage space indicated by the common function as the target storage space. Here, "finding the second function in the nodes of the tree structure" can be the second function corresponding to a single node or the "second function" formed by a combination of more than one consecutive node.
[0072] It should be understood that for the data size represented by functions, there are several cases where two functions have a common part:
[0073] The first case means that the first function and the second function have partial overlap and intersection parts, but do not completely cover each other; the second case is that the first function completely covers and is larger than the second function, that is, the data size included in the space allocation request is completely larger than the size of the available storage space found; the third case is that the second function completely covers and is larger than the first function, and the data size included in its space allocation request is completely smaller than the size of the available storage space found; the fourth case is that the first function and the second function are completely equal.
[0074] Take Figure 4c as an example to illustrate the first case according to universality and complexity. For example, when receiving an instruction of operation 5, alloc B 8hw + 10h + 10w + 100, it means to request to allocate a storage space of size 8hw + 10h + 10w + 100 for data B. At this time, only node 1 has available storage space 10hw + 5h + 5w + 20, and the function 10hw + 5h + 5w + 20 of this available storage space has a common function 8hw + 5h + 5w + 20 with the function of the space to be allocated. After allocating the common part of the space of size 8hw + 5h + 5w + 20 to data B, the available storage space of node 1 is 2hw, and data B still needs a storage space of 5h + 5w + 80.
[0075] In this case, for data B, its common part can be stored in the manner of 8hw + 5h + 5w + 20, and for the other part, that is, the non-common part in the space allocation request, 5h + 5w + 80, a new node can be created (for example Figure 4cIt is stored in the node 5 shown. It should be understood that the common part of data B can be directly stored in the storage space of size 8hw + 5h + 5w + 20 in node 1. In this way, there is no need to create a new node. However, since the storage space in node 1 originally allocated to data A is allocated to the common part of data B, the original corresponding relationship between node 1 and data A will be erased, which is not conducive to the preservation of subsequent storage relationships.
[0076] According to an embodiment of the present disclosure, a new node 4 can be established at the lower level of node 1 so that the total storage space of the new node is equal to the above-mentioned common function. For Figure 4c example, the storage attribute of the new node 4 can be expressed as 8hw + 5h + 5w + 20(0). At this time, the available storage space of node 1 is 2hw, so the storage attribute of node 1 can be expressed as 10hw + 5h + 5w + 20(2hw). In addition, the total storage space identifier of node 0 becomes 20hw + 15h + 26W + 113. As Figure 4c shown. The available storage space 2hw of node 1 can continue to be allocated to other data.
[0077] Thus, according to an embodiment of the present disclosure, at the logical level, the same node can only be allocated once to ensure that the same node corresponds to one data, so that the entire allocation process can be completely recorded, and it is also convenient for subsequent further splitting of sub-nodes. For example, since node 1 has been previously allocated to data A, even if the space occupied by data A is released, when new data (such as data B) needs to occupy the space originally occupied by data A, logically, a new node (such as node 4) still needs to be split. Of course, physically, the newly created node 4 is still within the physical space range of node 1.
[0078] In addition, it should be explained that the newly created node 5 is adjacent to node 4 to try to make data B stored in a continuous space. According to another embodiment of the present disclosure, node 5 can be on the left side of node 1. Thus, node 5 is adjacent to node 4 and has a continuous space. It should be understood that Figure 4c this is just an example, and the creation of the new node will be adjusted according to actual needs to ensure that the same data can be stored in a continuous space. This will be described in more detail later. In addition, the same data being able to be stored in a continuous space is only a preferred situation, rather than a mandatory requirement. For example, the same data can also be stored discontinuously.
[0079] Next, when performing operation 6 "alloc C 4hw+20h+20w+50", the available storage space of 2hw in node 1 can be reused first, and then a new space of 2hw+20h+20w+50 is applied for. Similarly, a new node can be created, and the new node has a total storage space of 2hw+20h+20w+50.
[0080] Next, when performing operation 7 "dealloc B", the space occupied by data B is released, so that the available storage space is 8hw+10h+10w+100.
[0081] Next, when performing operation 8 "alloc D 12hw+5h+5w+10", the space that can be reused is 8hw+5h+5w+10, and an additional space of 4hw needs to be applied for.
[0082] Figure 4d A schematic diagram of allocating space for data according to another embodiment of the present disclosure is shown.
[0083] In Figure 4d the total storage space of node 0 is 14hw+14h+22w+260, which has four subordinate nodes, namely node 1 (2hw+3h+2w+80(2hw+3h+2w+80)), node 2 (3hw+h+5w(3hw+h+5w)), node 3 (4hw+4h+7w+80(0)), and node 4 (5hw+6h+8W+100(5hw+6h+8W+100)). At this time, the operation instruction alloc B14hw+4h+7w+80 is received. Among the above four nodes, the sum of the available spaces of node 1 and node 2 is 5hw+4h+7w+80, which is greater than the size of data B1 and sufficient to accommodate data B1, and the difference from the data size function of data B1 is hw; the available storage space of node 3 is 0 and cannot accommodate data B1; the available storage space of node 4 is 5hw+6h+8W+100, which is greater than the size of data B1 and sufficient to accommodate data B1. In this case, there are multiple scenarios to store the data B1.
[0084] The first solution is to allocate 4hw+4h+7w+80 of storage space for the data B1 from node 4. After the allocation, there will be hw+h+w+20 of available storage space in node 4.
[0085] The second solution is to occupy the available storage space of 2hw+3h+2w+80 in node 1, and then allocate 2hw+h+5w of storage space from node 2 or node 4.
[0086] The third solution is to occupy the available storage space 3hw + h + 5w in Node 2, and then allocate the storage space hw + 3h + 2w + 80 from Node 1 or Node 4.
[0087] The fourth solution is that the storage spaces with sizes of 4hw + 4h + 7w + 80 can be allocated from Node 1, Node 2, and Node 4 respectively. For example, the storage space with a size of 2hw + 2h + 2w + 40 can be allocated from Node 1, the storage space with a size of 2hw + h + 5w can be allocated from Node 2, and the storage space with a size of h + 40 can be allocated from Node 4.
[0088] The beneficial effect of adopting the first solution is that it is easier to make the newly allocated space continuous in address, reduce the address jumps during data access, and thus improve the data access efficiency.
[0089] The beneficial effects of adopting the second and third solutions are that the existence of fragmented space can be minimized. In addition, the method of using Node 1 and Node 2 to allocate storage space for data is also beneficial to storing data in continuous space, thereby reducing the address jumps during data access.
[0090] According to an embodiment of the present disclosure, in response to not finding a single node in the nodes of the tree structure whose available storage space can cover the data, a new node is created so that the sum of the available storage spaces of the single node and the new node is not less than the data.
[0091] Still taking Figure 4d as an example for illustration.
[0092] In the fifth solution, the available storage space of Node 1 cannot completely cover Data B1. First, the available storage space 2hw + 3h + 2w + 80 in Node 1 can be allocated, and then a new storage space 2hw + h + 5w is applied for. Thus, the total storage space is 4hw + 4h + 7w + 80, which is sufficient to accommodate Data B1.
[0093] In the sixth solution, the available storage space of Node 2 cannot completely cover Data B1. First, the available storage space 3hw + h + 5w in Node 2 can be allocated, and then a new storage space hw + 3h + 2w + 80 is applied for. Thus, the total storage space is 4hw + 4h + 7w + 80, which is sufficient to accommodate Data B1.
[0094] Preferably, the new node can form a continuous space with the above single node.
[0095] Compared with the second and third solutions, the beneficial effects of the fifth and sixth solutions are that if the spaces in Node 1 and Node 2 are not continuous, the space jumps during the data access process are likely to cause inefficiency, while the fifth and sixth solutions can form continuous spaces by directly creating new nodes.
[0096] Figure 5 Fig. shows a schematic diagram of allocating target storage space for data according to an embodiment of a preferred embodiment of the present disclosure.
[0097] According to an embodiment of the present disclosure, in response to searching for an available storage space in a node of the tree structure whose second function has the largest common function with the first function, the storage space indicated by the common function is used as the target storage space.
[0098] As Figure 5 shown, Node 0 has six subordinate nodes, namely Node 1 (2hw + 3h + 2w + 80 (2hw + 3h + 2w + 80)), Node 2 (3hw + h + 5w (3hw + h + 5w)), Node 3 (4hw + 4h + 7w + 80 (4hw + 4h + 7w + 80)), Node 4 (4hw + 5h + 7W + 80 (4hw + 5h + 7W + 80)), Node 5 (4hw + 4h + 8w + 80 (4hw + 4h + 8w + 80)), and Node 6 (4hw + 4h + 7w + 90 (4hw + 4h + 7w + 90)). At this time, an operation instruction alloc B1 4hw + 4h + 7w + 80 is received. Among the above six nodes, the sum of the available spaces of Node 1 and Node 2 is 5hw + 4h + 7w + 80, which is greater than the size of data B1 and sufficient to accommodate data B1, and the difference in the function of the data size from data B1 is hw; the available storage space of Node 3 is 4hw + 4h + 7w + 80, just enough to accommodate data B1; the available storage space of Node 4 is 4hw + 5h + 7W + 80, which is greater than the size of data B1 and sufficient to accommodate data B1, and the difference in the function of the data size from data B1 is h; the available storage space of Node 5 is 4hw + 4h + 8w + 80, which is greater than the size of data B1 and sufficient to accommodate data B1, and the difference in the function of the data size from data B1 is w; the available storage space of Node 6 is 4hw + 4h + 7w + 90, which is greater than the size of data B1 and sufficient to accommodate data B1, and the difference in the function of the data size from data B1 is 10; according to an embodiment of the present disclosure, when both the combination of Node 1 and Node 2, Node 3, Node 4, Node 5, and Node 6 are sufficient to accommodate data B1, Node 3 can be preferentially selected to accommodate data B1 because the difference between its available storage space and the size of data B1 is the smallest. The above preferred embodiment is beneficial to reducing the fragmentation of the storage space and improving the utilization efficiency of the storage space.
[0099] Here, we define the difference between the available storage space and the size of the data in the space to be allocated as the cost function. For the combination of nodes 1 and 2, nodes 4, 5, and 6, their differences from the size of data B1 (i.e., the cost function) are hw, h, w, and 10 respectively. When the differences in size are not very different, there are several ways to determine whether there is a maximum common function between the first function and the second function: First, one of the nodes can be randomly selected (e.g., the combination of nodes 1 and 2, node 4, node 5, or node 6) as the node allocated to this data; Second, the node with the smallest term in the difference between its second function and the first function can be used as the node allocated to this data. For example, among the above four items, if the second function with the smallest h term and w term in the size difference is set as the node allocated to this data, then node 6 can be selected to allocate this data. This setting method is flexible and variable, and those skilled in the art can set it according to actual needs.
[0100] According to an embodiment of the present disclosure, the retrieval of available storage space in the nodes of the tree structure is repeated until no available storage space can be retrieved.
[0101] In this embodiment, when the available storage space of a certain node is not sufficient to meet the data size in the space allocation request, all nodes in the tree structure can be traversed to make full use of all space fragments. For example, in Figure 4c , there is still available storage space 2hw in node 1. Therefore, if the data size in the subsequent space allocation request includes an item such as hw, the space 2hw can still be reused. Of course, if no available storage space represented by the second function that has a common function with the first function can be retrieved, a new node can be constructed.
[0102] The above introduced the situation of creating a tree structure. There is also a situation where the sum of the available storage nodes of all current nodes is not sufficient to store the data, that is, the first function completely covers and is greater than the second function, that is, the data size included in the space allocation request is completely greater than the size of the available storage space searched. According to an embodiment of the present disclosure, allocating a target storage space for data according to the received space allocation request includes: in response to not finding available storage space not less than the data size in the nodes of the tree structure, creating a new node so that the available storage space can accommodate the data.
[0103] Below, various embodiments of creating new nodes will be introduced in detail.
[0104] Figure 6a Shows a flowchart of a method for creating a new node according to an embodiment of the present disclosure;Figure 6b and Figure 6c shows a schematic diagram of a new node created according to the Figure 6a method flow diagram shown.
[0105] As Figure 6a shown, creating a new node such that the available storage space can accommodate the data may include: at S610, adjusting a node with available storage space to a lower-level node of the new node; and, at operation S620, creating a new lower-level node under the new node such that the available storage space of the lower-level nodes of the new node can accommodate the data. Wherein, the node with available storage space is not sufficient to store the data.
[0106] Assume that the current tree structure is as Figure 6b shown, where the total storage space of node 0 is 20hw + 15h + 26w + 113, and nodes 1, 2, and 3 are lower-level nodes of node 0. Among them, the total storage space of node 1 is 10hw + 10h + 10w + 100, and the available storage space is 0; the total storage space of node 2 is 9hw + 4h + 6w + 5, and the available storage space is 9hw + 4h + 6w + 5; the total storage space of node 3 is hw + h + 10w + 8, and the available storage space is h + 2w + 5. Node 4 is a lower-level node of node 3, and its total storage space is hw + 8w + 3, and the available storage space is 0. Therefore, the total available storage space at this time is the sum of the available storage spaces of node 2 and node 3: 9hw + 5h + 8w + 10.
[0107] Assume that at this time a space allocation request is received, alloc D5 15hw + 9h + 10w + 40, and the total available storage space 9hw + 5h + 8w + 10 is less than this space allocation request, and 6hw + 4h + 2w + 30 more space is still needed. In this case, a new node needs to be created.
[0108] Thus, as Figure 6c shown, a node 8 at the same level as node 1 is created, and the original nodes 2 and 3 are moved to be the child nodes of the new node 8 as its lower-level nodes. In this case, a new child node 6 can be created, which has a total storage space identifier of 6hw + 5h + 2w + 30, so that the child node 2, the new child node 6, and the child node 3 together have an available storage space of 15hw + 9h + 10w + 40, so that the new node 8 can accommodate the data D5.
[0109] Furthermore, for the child node 3, since the data D3 was stored before, the child node 3 needs to be further divided into a grandchild node 7 and a grandchild node 4, where the grandchild node 4 was originally a lower-level node of the child node 3, and the grandchild node 7 is a newly created grandchild node.
[0110] Furthermore, as described above, preferably, the same node can only be assigned to the same data. Therefore, although node 2 has available storage space of size 9hw + 4h + 6w + 5, since node 2 has been previously assigned to data D2, a new node 5 can be created under node 2 as a child node of node 2. It should be understood that physically in the memory space, node 2 and node 5 are the same, but in the tree structure, they are different nodes.
[0111] After the above creation process, node 5 can provide storage space of size 9hw + 4h + 6w + 5, node 6 can provide storage space of size 6hw + 4h + 2w + 30, and node 7 can provide storage space of size h + 2w + 5, so as to be able to accommodate data D5 of size 15hw + 9h + 10w + 40.
[0112] In the above description for Figure 6b it can be seen that the same data can occupy different nodes. For example, data D5 can occupy node 5, node 6, and node 7, but the same node can only correspond to one data. For example, node 3 has been assigned to data D3. Even if the space occupied by data D3 has been released, if new data such as data D4 and data D5 need to occupy the space originally occupied by data D3, then node D3 still needs to be further divided into nodes 4 and 7. The above solution is beneficial to retaining the correspondence between the entire node and the data.
[0113] According to an embodiment of the present disclosure, creating a new node such that the available storage space can accommodate the data may include: in response to the available storage space of all nodes in the tree structure being zero, creating a new node such that the available storage space of the new node can accommodate the data.
[0114] In this embodiment, since there is no available storage space in the existing nodes, a new node for storing this data can be completely created. Figure 4a The situation in
[0115] is actually the manifestation of this embodiment, so it will not be elaborated here.
[0116] In this embodiment, the timing of the space allocation request can be taken into account. For example, if the existing available storage space is 6hw + 4h + 2w + 30, and at this time the first space allocation request is received and the storage space to be allocated is 15hw + 9h + 10w + 40, then it can be considered whether the second space allocation request after this space allocation request is less than or equal to 6hw + 4h + 2w + 30. If so, a new node can be created first to allocate to the first space allocation request, and the existing available storage space can be reserved for the second space allocation request. This embodiment is advantageous for periodic or predictable space allocation requests.
[0117] According to the present disclosure, in Figure 6c the manner of establishing a new node, Figure 4c the nodes shown can also be established according to Figure 6c the manner of.
[0118] Figure 7a FIG. 7a shows a flowchart of establishing a new node according to an embodiment of the present disclosure, and FIG. 7b shows a schematic diagram of establishing a new node according to an embodiment of the present disclosure, which is Figure 4c another embodiment of.
[0119] As Figure 7a shown, creating a new node according to an embodiment of the present disclosure so that the available storage space can accommodate the data may include: in operation S710, creating a new node in response to both the first function and the second function having non-common parts; in operation S720, adjusting the node whose second function has a common function with the first function to a lower-level node of the new node; and, in operation S730, creating a new lower-level node under the new node so that the available storage space of the lower-level nodes of the new node can accommodate the data.
[0120] In the above text, the fact that both the first function and the second function have non - common parts means that the first function and the second function have partial overlap and intersection parts, but they do not completely cover each other, which has been introduced above. The total storage space of the new node is the total range covered by the two functions. Specifically, the total storage space of the new node is the sum of the larger ones among the respective terms that make up the first function and the second function. Taking node 4b as an example, the second function representing the total storage space of node 1 is 10hw + 5h + 5w + 20, which has four terms: 10hw, 5h, 5w, and 20; the first function representing the data size in the space allocation request is 8hw + 10h + 10w + 100, and its four terms are 8hw, 10h, 10w, and 100. Therefore, the total storage space of the new node to be applied for is 10hw + 10h + 10w + 100. The remaining available storage space in node 1 is the total storage space of the new node minus the first function (for example, 2hw), and the space size of the new child node that needs to be newly applied for this data is the total storage space of the new node minus the second function (for example, 5h + 5w + 80).
[0121] Thus, as Figure 7b shown, a new node 6 can be created, whose total storage space is 10hw + 10h + 10w + 100. This node 6 is at the same level in the tree - like structure as node 2 and node 3; move node 1 under node 6 as a child node of node 6, where the total storage space of node 1 is 10hw + 5h + 5w + 20 and the available storage space is 2hw; create a new node 5 as a child node of node 6, where the total storage space of node 5 is 5h + 5w + 80 and the available storage space is 0; node 4 remains a child node of node 1. In Figure 7b , it should be understood that since both node 5 and node 4 are used to store data B, preferably these two nodes are adjacent to each other, so that the same data can be stored in continuous space, reducing the frequent jumps during space addressing.
[0122] It can be understood that when the nodes with available storage space in the tree - like structure are not sufficient to store the data and new nodes need to be created, the smaller the storage space of the lower - level nodes of the newly created nodes, the better. This can maximize the reuse of the available storage space in the tree - like structure and is conducive to reducing the occurrence of space fragmentation. Optionally, when the nodes with available storage space in the tree - like structure are not sufficient to store the data, the fifth and sixth solutions described in Figure 4d also apply. In this case, new lower - level nodes will inevitably be created. Similar to the fifth and sixth solutions, one of the nodes can be selected to accommodate part of the data, and then new lower - level nodes of the new node can be created to accommodate the remaining part of the data. The newly created lower - level nodes of the new node can form continuous space with the nodes having available storage space, thus reducing the space jumps during data access.
[0123] After the tree structure is established and a new space allocation request is received, the tree structure can be traversed to find the desired available storage space. According to one embodiment of the present disclosure, when traversing the tree structure, a depth-first strategy can be adopted, that is, after retrieving a parent node and all its child nodes, another node at the same level as the parent node is retrieved.
[0124] Take Figure 6c as an example. For example, when a space allocation request is received, node 1 is searched first. When insufficient available storage space is not found in node 1, node 8 is searched, and then nodes 2 and 5 are searched in sequence; node 6 is searched; nodes 3, 7, and 4 are searched. The depth-first method is conducive to storing the same data in continuous space as much as possible, reducing the jump of space addressing during the operation.
[0125] According to one embodiment of the present disclosure, it further includes: adjusting the positions of the nodes so that the spaces of the multiple storage blocks are continuous.
[0126] It should be understood that the node actually corresponds to a virtual storage space. Therefore, it is desired that the same piece of data can be stored in continuous space to reduce the jump of space addressing during the operation and improve the operation efficiency.
[0127] As Figure 6c shown, the node 6 for storing data D5 is inserted between node 2 and node 3, and the establishment of node 7 is adjacent to node 6. Thus, data D5 can be continuously stored in the continuous space adjacent to nodes 5, 6, and 7. Node 6 can also be set after node 3, and node 7 is set after node 4, but such a method is likely to cause space jump.
[0128] Thus, in order to ensure space continuity, according to one embodiment of the present disclosure, it further includes: fixing the arrangement order of the nodes in the tree structure.
[0129] The order of the nodes can be fixed by making a mark in the parent node of the node. For example, as Figure 6c shown, a mark "ordered" can be made in node 8, then the arrangement order of all child nodes under node 8 will be fixed. Another example is that a mark "ordered" can be given to node 3, then the arrangement order of nodes 7 and 4 under node 3 will be fixed.
[0130] Fixing the arrangement order of the nodes helps to store the same data in continuous space and reduces the jump of space addressing.
[0131] Different from the prior art, in the above process, only storage space is allocated, but no address is allocated for the data. Therefore, space allocation and address allocation are separated. In the prior art, address allocation and storage space allocation are simultaneous, which is also a difference between the technical solution of the present disclosure and the prior art solution.
[0132] Figure 8 A schematic diagram of allocating addresses for storage space according to an embodiment of the present disclosure is shown. For ease of understanding, Figure 8 the total storage space size of each node in is represented by specific numbers.
[0133] As Figure 8 shown, the tree structure includes node 0, node 1, node 2, node 3, node 4, and node 5. Node 0 is the root node, with a total storage space of 31, an available storage space of 0, and a storage attribute represented as 31(0). Nodes 1, 2, 3, and 4 are the child nodes of node 0, and their storage attributes are respectively represented as 5(5), 6(6), 10(0), and 11(0). Node 5 is the child node of node 3, and its storage attribute is represented as 10(0).
[0134] When allocating addresses for these nodes, according to the width-first strategy, that is, first allocate addresses for nodes at the same level, and then more specifically allocate addresses for the lower-level nodes of each node.
[0135] As Figure 8 shown, the starting address of node 0 is 0x0000, and its offset can be 31. Then, as the first child node of node 0, the starting address of node 1 can also be 0x0000, and its offset is 5. Therefore, its ending address is 0x0004. Similarly, the starting address of node 2 can be 0x0005, and the offset is 6. The starting address of node 3 can be 0x000B, and the offset is 10. The starting address of node 4 is 0x0015, and the offset is 11. As the child node of node 3, the starting address of node 5 is also 0x000B, and the offset is 10.
[0136] If the above specific numbers are replaced with function representations, assuming that the total storage space size of node 0 is 20hw + 15h + 26w + 113 and its actual address is 0x0000, then the address range of node 0 is 0x0000+(20hw + 15h + 26w + 113)-1.
[0137] It can be seen that through the above arrangements, the spaces for the same data can be kept continuous, so that continuous addresses can also be allocated, which greatly improves the space utilization rate in the memory and reduces the occurrence of fragmentation. In addition, through the technical solution of the present disclosure, the continuity of data storage can also be maintained, thereby avoiding jumps during the addressing process, and thus improving the data throughput speed. Another beneficial effect is that since all node information is retained, all records of data storage during the space allocation and release processes are retained, facilitating subsequent data tracking and the retention of storage records.
[0138] The solution of the present disclosure is particularly applicable to memories with a large storage capacity, such as off-chip memories, hard disks, etc.
[0139] Figure 9 A method for managing a storage space according to an embodiment of the present disclosure is shown, including: in operation S910, forming a plurality of storage blocks, each storage block having a total storage space identifier and an available storage space identifier, where the total storage space identifier is used to indicate the total storage space of the storage block, and the available storage space identifier is used to indicate the available storage space of the storage block; and, in operation S920, forming the plurality of storage blocks into a tree structure as nodes, the tree structure including multiple levels of nodes, where the total storage space of the upper-level node is the sum of the total storage spaces of the lower-level nodes.
[0140] Figure 10 A method for allocating a storage space for data in a memory according to an embodiment of the present disclosure is shown, including: in operation S1010, receiving a space allocation request for the storage space in the memory, the allocation request carrying a data size represented by a first function; in operation S1020, forming a plurality of storage blocks, each storage block having a total storage space identifier and an available storage space identifier, where the total storage space identifier is used to indicate the total storage space of the storage block by a total space function, and the available storage space identifier is used to indicate the available storage space of the storage block by a second function; in operation S1030, forming the plurality of storage blocks into a tree structure as nodes, the tree structure including multiple levels of nodes, where the total storage space of the upper-level node is the sum of the total storage spaces of the lower-level nodes; and, in operation S1040, according to the received space allocation request, allocating a target storage space for the data according to the tree structure.
[0141] The above Figure 9 and Figure 10 The specific implementation manners of each operation in Figures 2 - 8 have been explained in detail, so they will not be elaborated here.
[0142] The present disclosure also provides an electronic device, including: one or more processors; and a memory storing computer-executable instructions, which, when run by the one or more processors, cause the electronic device to execute the method as described above.
[0143] The present disclosure also provides a computer-readable storage medium including computer-executable instructions, which, when run by one or more processors, execute the method as described above.
[0144] The technical solution of the present disclosure can be applied to the field of artificial intelligence, and can be implemented in a host, a server, or implemented as or in an artificial intelligence chip. The chip can exist alone or be included in a computing device.
[0145] Figure 11 There is shown a combined processing device 1100, which includes the above-mentioned computing device 1102, a general-purpose interconnection interface 1104, and other processing devices 1106. According to the present disclosure, the computing device interacts with other processing devices to jointly complete the operations specified by the user. Figure 11 It is a schematic diagram of the combined processing device.
[0146] The other processing devices include one or more processor types among general-purpose / special-purpose processors such as a central processing unit (CPU), a graphics processing unit (GPU), and a neural network processor. The number of processors included in the other processing devices is not limited. The other processing devices serve as an interface for the machine learning computing device to external data and control, including data transfer, and complete basic controls such as starting and stopping the machine learning computing device; the other processing devices can also cooperate with the machine learning computing device to jointly complete computing tasks.
[0147] The general-purpose interconnection interface is used to transfer data and control instructions between a computing device (including, for example, a machine learning computing device) and other processing devices. The computing device obtains the required input data from other processing devices and writes it into the storage device on the chip of the computing device; it can obtain control instructions from other processing devices and write them into the control cache on the chip of the computing device; it can also read the data in the storage module of the computing device and transfer it to other processing devices.
[0148] Optionally, the structure may further include a storage device 1108, which is respectively connected to the computing device and the other processing devices. The storage device is used to store data in the computing device and the other processing devices, and is particularly suitable for data that cannot be completely stored in the internal storage of the computing device or other processing devices and needs to be calculated.
[0149] The combined processing device can be used as a system-on-chip (SOC) for devices such as mobile phones, robots, drones, and video surveillance equipment, effectively reducing the core area of the control part, improving the processing speed, and reducing the overall power consumption. In this case, the general interconnection interface of the combined processing device is connected to certain components of the device. Some components include, for example, cameras, displays, mice, keyboards, network cards, and Wi-Fi interfaces.
[0150] In some embodiments, the present disclosure also discloses a board card that includes the above chip packaging structure. Refer to Figure 12 , which provides an exemplary board card. In addition to including the above chip 1202, the board card may further include other supporting components, which include but are not limited to: a storage device 1204, an interface device 1206, and a control device 1208.
[0151] The storage device is connected to the chip in the chip packaging structure through a bus and is used to store data. The storage device may include multiple groups of storage units 1210. Each group of the storage units is connected to the chip through a bus. It can be understood that each group of the storage units may be a DDR SDRAM (English: Double Data Rate SDRAM, double data rate synchronous dynamic random access memory).
[0152] DDR can double the speed of SDRAM without increasing the clock frequency. DDR allows data to be read on both the rising and falling edges of the clock pulse. The speed of DDR is twice that of standard SDRAM. In one embodiment, the storage device may include 4 groups of the storage units. Each group of the storage units may include multiple DDR4 chips. In one embodiment, the chip may internally include 4 72-bit DDR4 controllers. Among the above 72-bit DDR4 controllers, 64 bits are used for data transmission and 8 bits are used for ECC verification. In one embodiment, each group of the storage units includes multiple double data rate synchronous dynamic random access memories arranged in parallel. DDR can transmit data twice in one clock cycle. A controller for controlling DDR is provided in the chip to control the data transmission and data storage of each of the storage units.
[0153] The interface device is electrically connected to the chip within the chip packaging structure. The interface device is used to implement data transmission between the chip and an external device 1212 (such as a server or a computer). For example, in one embodiment, the interface device may be a standard PCIE interface. For instance, the data to be processed is transmitted from the server to the chip through the standard PCIE interface to achieve data transfer. In another embodiment, the interface device may also be other interfaces. The present disclosure does not limit the specific forms of the above-mentioned other interfaces, as long as the interface unit can implement the transfer function. Additionally, the calculation result of the chip is still transmitted back to the external device (such as a server) by the interface device.
[0154] The control device is electrically connected to the chip. The control device is used to monitor the state of the chip. Specifically, the chip and the control device may be electrically connected through an SPI interface. The control device may include a microcontroller (Micro Controller Unit, MCU). For example, the chip may include multiple processing chips, multiple processing cores, or multiple processing circuits, and can drive multiple loads. Therefore, the chip may be in different working states such as multi-load and light-load. Through the control device, the working states of multiple processing chips, multiple processes, and / or multiple processing circuits in the chip can be regulated.
[0155] In some embodiments, the present disclosure also discloses an electronic device or apparatus, which includes the above-mentioned board.
[0156] The electronic device or apparatus includes a data processing device, a robot, a computer, a printer, a scanner, a tablet computer, a smart terminal, a mobile phone, a driving recorder, a navigator, a sensor, a camera, a server, a cloud server, a camera, a video camera, a projector, a watch, a headset, a mobile storage device, a wearable device, a vehicle, a household appliance, and / or a medical device.
[0157] The vehicle includes an airplane, a ship, and / or a vehicle; the household appliance includes a television, an air conditioner, a microwave oven, a refrigerator, a rice cooker, a humidifier, a washing machine, a light, a gas stove, an oil fume extractor; the medical device includes a nuclear magnetic resonance instrument, a B-ultrasound instrument, and / or an electrocardiogram instrument.
[0158] It should be noted that, for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the present disclosure is not limited by the described action sequence, because according to the present disclosure, certain steps may be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily essential to the present disclosure.
[0159] In the above embodiments, the descriptions of the various embodiments each have their own emphasis. For parts not detailed in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.
[0160] In several embodiments provided by this disclosure, it should be understood that the disclosed device can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the couplings or direct couplings or communication connections shown or discussed with each other can be through some interfaces. The indirect couplings or communication connections of the devices or units can be in electrical, optical, acoustic, magnetic or other forms.
[0161] The units described as separate components may or may not be physically separated. The components shown as units may or may not be physical units, that is, they can be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0162] In addition, in each embodiment of this disclosure, the functional units can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated units can be implemented in the form of hardware or in the form of software program modules.
[0163] If the above integrated unit is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, when the technical solution of this disclosure can be embodied in the form of a software product, the computer software product is stored in a memory and includes several instructions for causing a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of this disclosure. And the aforementioned memory includes: various media such as USB flash drives, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), mobile hard disks, magnetic disks or optical discs that can store program codes.
[0164] The above has introduced the embodiments of the present disclosure in detail. Specific examples are used herein to elaborate on the principles and implementation manners of the present disclosure. The description of the above embodiments is only used to help understand the method and its core idea of the present disclosure; at the same time, for those of ordinary skill in the art, according to the idea of the present disclosure, there will be changes in the specific implementation manners and application scopes. In summary, the content of this specification should not be construed as a limitation to the present disclosure.
[0165] The foregoing can be better understood in accordance with the following terms:
[0166] Clause 1. A method for allocating a storage address for data in a memory, including:
[0167] Receiving a space allocation request for a storage space in the memory, the allocation request carrying the data size represented by a first function;
[0168] Allocating a target storage space for the data according to the received space allocation request; and
[0169] Based on the allocated target storage space, allocating a storage address for the data.
[0170] Clause 2. The method according to Clause 1, further including:
[0171] Forming a plurality of storage blocks, each storage block having a total storage space identifier and an available storage space identifier, where the total storage space identifier is used to indicate the total storage space of the storage block by a total space function, and the available storage space identifier is used to indicate the available storage space of the storage block by a second function;
[0172] Forming a tree structure with the plurality of storage blocks as nodes, the tree structure including multiple levels of nodes, where the total storage space of the upper-level node is the sum of the total storage spaces of the lower-level nodes.
[0173] Clause 3. The method according to Clause 2, where allocating a target storage space for the data according to the received space allocation request includes:
[0174] Retrieving the available storage space in the nodes of the tree structure;
[0175] In response to finding an available storage space in the nodes of the tree structure whose second function has a common function with the first function, taking the storage space indicated by the common function as the target storage space.
[0176] Clause 4. The method according to Clause 3, where, in response to finding an available storage space in the nodes of the tree structure whose second function has the largest common function with the first function, taking the storage space indicated by the common function as the target storage space.
[0177] Clause 5. The method according to Clause 3, wherein retrieving available storage space in the nodes of the tree structure is repeated until no available storage space can be retrieved.
[0178] Clause 6. The method according to Clause 3, wherein allocating target storage space for data according to the received space allocation request includes:
[0179] In response to not finding available storage space not less than the size of the data in the nodes of the tree structure, creating a new node so that the available storage space can accommodate the data.
[0180] Clause 7. The method according to Clause 6, wherein creating a new node so that the available storage space can accommodate the data includes:
[0181] Adjusting the node with available storage space to be a subordinate node of the new node;
[0182] Creating new subordinate nodes under the new node so that the available storage space of the subordinate nodes of the new node can accommodate the data; or
[0183] Creating a new node so that the available storage space can accommodate the data includes:
[0184] In response to the available storage space of all nodes in the tree structure being zero, creating a new node so that the available storage space of the new node can accommodate the data; or
[0185] Creating a new node so that the available storage space can accommodate the data includes:
[0186] In response to not finding current available storage space not less than the size of the data in the nodes of the tree structure, and the data size included in the next space allocation request not being greater than the current available storage space, creating a new node so that the available storage space of the new node can accommodate the data.
[0187] Clause 8. The method according to Clause 6, wherein creating a new node so that the available storage space can accommodate the data includes:
[0188] In response to both the first function and the second function having non - common parts, creating a new node;
[0189] Adjusting the node whose second function has a common function with the first function to be a subordinate node of the new node; and,
[0190] Creating new subordinate nodes under the new node so that the available storage space of the subordinate nodes of the new node can accommodate the data.
[0191] Clause 9. The method according to any one of Clauses 3-8, wherein retrieving available storage space in a node of the tree structure includes:
[0192] After retrieving a parent node and all its child nodes, retrieve another node at the same level as the parent node.
[0193] Clause 10. The method according to any one of Clauses 2-9, further comprising:
[0194] Adjust the positions of the nodes so that the spaces of the multiple storage blocks are continuous.
[0195] Clause 11. The method according to any one of Clauses 2-10, further comprising:
[0196] Fix the arrangement order of the nodes in the tree structure.
[0197] Clause 12. The method according to any one of Clauses 2-11, further comprising:
[0198] In response to receiving a space release request, release the corresponding node;
[0199] Update the available storage space identifier of the released node.
[0200] Clause 13. The method according to any one of Clauses 2-12, allocating a storage address for the data based on the allocated target storage space includes:
[0201] After allocating a storage address for a node, allocate addresses for other nodes at the same level in sequence, where the address of each node covers the addresses of all its child nodes.
[0202] Clause 14. A method for managing storage space, comprising:
[0203] Form multiple storage blocks, each storage block having a total storage space identifier and an available storage space identifier, where the total storage space identifier is used to indicate the total storage space of the storage block as a total space function, and the available storage space identifier is used to indicate the available storage space of the storage block as a second function;
[0204] Form the multiple storage blocks into a tree structure as nodes, the tree structure including multiple levels of nodes, where the total storage space of a parent node is the sum of the total storage spaces of its child nodes.
[0205] Clause 15. A method for allocating storage space for data in a memory, comprising:
[0206] Receive a space allocation request for a storage space in a memory, where the allocation request carries a data size represented by a first function;
[0207] Form a plurality of storage blocks, each storage block having a total storage space identifier and an available storage space identifier, where the total storage space identifier is used to indicate the total storage space of the storage block by a total space function, and the available storage space identifier is used to indicate the available storage space of the storage block by a second function;
[0208] Form the plurality of storage blocks into a tree structure as nodes, the tree structure including multiple levels of nodes, where the total storage space of a superior node is the sum of the total storage spaces of its subordinate nodes;
[0209] According to the received space allocation request, allocate a target storage space for the data according to the tree structure.
[0210] Clause 16. The method according to Clause 14 or 15, further comprising:
[0211] In response to receiving a space allocation request for allocating a target storage space for data, retrieve the available storage space in the nodes of the tree structure;
[0212] In response to finding an available storage space in the nodes of the tree structure whose second function has a common function with the first function, use the storage space indicated by the common function as the target storage space.
[0213] Clause 17. The method according to Clause 16, where, in response to finding an available storage space in the nodes of the tree structure whose second function has the largest common function with the first function, use the storage space indicated by the common function as the target storage space.
[0214] Clause 18. The method according to Clause 16, where repeatedly retrieve the available storage space in the nodes of the tree structure until no available storage space can be retrieved.
[0215] Clause 19. The method according to Clause 16, where, in response to not finding an available storage space not less than the data size in the nodes of the tree structure, create a new node so that the available storage space can accommodate the data.
[0216] Clause 20. The method according to Clause 19, where creating a new node so that the available storage space can accommodate the data includes:
[0217] Adjust a node with available storage space to be a subordinate node of the new node;
[0218] Create a new subordinate node under the new node so that the available storage space of the subordinate nodes of the new node can accommodate the data; or
[0219] Creating a new node so that the available storage space can accommodate the data includes:
[0220] In response to the available storage space of all nodes in the tree structure being zero, create a new node so that the available storage space of the new node can accommodate the data; or
[0221] Creating a new node so that the available storage space can accommodate the data includes:
[0222] In response to not finding current available storage space not less than the size of the data in the nodes of the tree structure, and the data size included in the next space allocation request not being greater than the current available storage space, create a new node so that the available storage space of the new node can accommodate the data.
[0223] Clause 21. The method according to any one of clauses 16 - 20, wherein retrieving available storage space in the nodes of the tree structure includes:
[0224] After retrieving a superior node and all its subordinate nodes, then retrieve another node at the same level as the superior node.
[0225] Clause 22. The method according to any one of clauses 14 - 21, further comprising:
[0226] Adjust the positions of the nodes so that the spaces of the multiple storage blocks are continuous.
[0227] Clause 23. The method according to any one of clauses 14 - 22, further comprising:
[0228] Fix the arrangement order of the nodes in the tree structure.
[0229] Clause 24. An electronic device, comprising:
[0230] One or more processors; and
[0231] A memory storing computer-executable instructions that, when run by the one or more processors, cause the electronic device to perform the method according to any one of clauses 1 - 23.
[0232] Clause 25. A computer-readable storage medium comprising computer-executable instructions that, when run by one or more processors, perform the method according to any one of clauses 1 - 23.
Claims
1. A method for allocating storage addresses for data in a memory, comprising: Receiving a space allocation request for a storage space in the memory, the allocation request carrying a data size represented by a first function, the first function including unknown variables that are only determined at runtime; According to the received space allocation request, traversing a tree structure to allocate a target storage space for the data, wherein the tree structure includes multiple nodes, and each node represents a storage space; And Based on the allocated target storage space, traversing the tree structure in a breadth-first strategy to allocate a storage address for the data.
2. The method according to claim 1, further comprising: Forming multiple storage blocks, each storage block having a total storage space identifier and an available storage space identifier, wherein the total storage space identifier is used to indicate the total storage space of the storage block by a total space function, and the available storage space identifier is used to indicate the available storage space of the storage block by a second function; Forming the multiple storage blocks into a tree structure as nodes, the tree structure including multiple levels of nodes, wherein the total storage space of the upper-level node is the sum of the total storage spaces of the lower-level nodes.
3. The method according to claim 2, wherein, Allocating a target storage space for the data according to the received space allocation request includes: Retrieving available storage space among the nodes of the tree structure; In response to finding available storage space in the nodes of the tree structure whose second function has a common function with the first function, using the storage space indicated by the common function as the target storage space.
4. The method according to claim 3, wherein, In response to finding available storage space in the nodes of the tree structure whose second function has the largest common function with the first function, using the storage space indicated by the common function as the target storage space.
5. The method according to claim 3, wherein Repeating to retrieve available storage space among the nodes of the tree structure until no available storage space can be retrieved.
6. The method according to claim 3, wherein Allocating a target storage space for the data according to the received space allocation request includes: In response to not finding available storage space not less than the data size among the nodes of the tree structure, creating a new node so that the available storage space can accommodate the data.
7. The method according to claim 6, wherein Creating a new node so that the available storage space can accommodate the data includes: Adjusting the node with available storage space to be a lower-level node of the new node; Creating new lower-level nodes under the new node so that the available storage space of the lower-level nodes of the new node can accommodate the data; or Creating a new node so that the available storage space can accommodate the data includes: In response to the available storage space of all nodes in the tree structure being zero, creating a new node so that the available storage space of the new node can accommodate the data; or Creating a new node so that the available storage space can accommodate the data includes: In response to not finding current available storage space not less than the data size among the nodes of the tree structure, and the data size included in the next space allocation request not being greater than the current available storage space, creating a new node so that the available storage space of the new node can accommodate the data.
8. The method according to claim 6, wherein Creating a new node to enable the available storage space to accommodate the data includes: Creating a new node in response to both the first function and the second function having non - common parts; Adjusting a node whose second function has a common function with the first function to be a subordinate node of the new node; and, Creating new subordinate nodes under the new node to enable the available storage space of the subordinate nodes of the new node to accommodate the data.
9. The method according to any one of claims 3-8, wherein, Retrieving available storage space among the nodes of the tree - like structure includes: After retrieving a superior node and all its subordinate nodes, retrieving another node at the same level as the superior node.
10. The method according to claim 2, further comprising: Adjusting the positions of the nodes so that the spaces of the multiple storage blocks are continuous.
11. The method according to claim 2, further comprising: Fixing the arrangement order of the nodes in the tree - like structure.
12. The method according to claim 2, further comprising: Releasing a corresponding node in response to receiving a space release request; Updating the available storage space identifier of the released node.
13. The method according to claim 2, for allocating a storage address for the data based on the allocated target storage space includes: After allocating a storage address for one node, sequentially allocating addresses for other nodes at the same level, where the address of each node covers the addresses of all its subordinate nodes.
14. A method for managing storage space, comprising: Forming a plurality of storage blocks, each storage block having a total storage space identifier and an available storage space identifier, where the total storage space identifier is used to indicate the total storage space of the storage block by a total space function, and the available storage space identifier is used to indicate the available storage space of the storage block by a second function, and the second function includes unknown variables that are only determined at runtime; Forming the plurality of storage blocks into a tree - like structure as nodes, the tree - like structure including multiple levels of nodes, where the total storage space of a superior node is the sum of the total storage spaces of its subordinate nodes.
15. A method for allocating storage space for data in a memory, comprising: Receiving a space allocation request for storage space in the memory, the allocation request carrying the data size represented by a first function, and the first function includes unknown variables that are only determined at runtime; Forming a plurality of storage blocks, each storage block having a total storage space identifier and an available storage space identifier, where the total storage space identifier is used to indicate the total storage space of the storage block by a total space function, and the available storage space identifier is used to indicate the available storage space of the storage block by a second function; Forming the plurality of storage blocks into a tree - like structure as nodes, the tree - like structure including multiple levels of nodes, where the total storage space of a superior node is the sum of the total storage spaces of its subordinate nodes; According to the received space allocation request, allocating a target storage space for the data according to the tree - like structure.
16. The method according to claim 14 or 15, further comprising: In response to receiving a space allocation request for allocating a target storage space for data, retrieve available storage space in the nodes of the tree structure; In response to finding available storage space in the nodes of the tree structure whose second function has a common function with the first function, use the storage space indicated by the common function as the target storage space.
17. The method according to claim 16, wherein, In response to finding available storage space in the nodes of the tree structure whose second function has the maximum common function with the first function, use the storage space indicated by the common function as the target storage space.
18. The method according to claim 16, wherein, Repeat retrieving available storage space in the nodes of the tree structure until no available storage space can be retrieved.
19. The method according to claim 16, wherein, In response to not finding available storage space not less than the size of the data in the nodes of the tree structure, create a new node so that the available storage space can accommodate the data.
20. The method according to claim 19, wherein, Creating a new node so that the available storage space can accommodate the data includes: Adjust the node with available storage space to be a subordinate node of the new node; Create a new subordinate node under the new node so that the available storage space of the subordinate nodes of the new node can accommodate the data; or Creating a new node so that the available storage space can accommodate the data includes: In response to the available storage space of all nodes in the tree structure being zero, create a new node so that the available storage space of the new node can accommodate the data; or Creating a new node so that the available storage space can accommodate the data includes: In response to not finding current available storage space not less than the size of the data in the nodes of the tree structure, and the data size included in the next space allocation request not being greater than the current available storage space, create a new node so that the available storage space of the new node can accommodate the data.
21. The method according to claim 16, wherein Retrieving available storage space in the nodes of the tree structure includes: After retrieving a superior node and all its subordinate nodes, then retrieve another node at the same level as the superior node.
22. The method according to claim 14 or 15, further comprising: Adjust the positions of the nodes so that the spaces of the multiple storage blocks are continuous.
23. The method according to claim 14 or 15, further comprising: Fix the arrangement order of the nodes in the tree structure.
24. An electronic device, comprising: One or more processors; And A memory storing computer-executable instructions, which when run by the one or more processors, cause the electronic device to execute the method according to any one of claims 1-23.
25. A computer-readable storage medium, comprising computer-executable instructions, which when run by one or more processors, execute the method according to any one of claims 1-23.
Citation Information
Patent Citations
Methods and system for reserving storage space for data migration in a redundant hierarchic data storage system by dynamically computing maximum storage space for mirror redundancy
US5659704A
Management method and device of file system
WO2016191964A1