A cache allocation method and apparatus
By calculating the available score of the cache in the switch and allocating the cache according to preset thresholds and adjustment factors, the problem of uneven cache usage is solved, achieving efficient cache utilization and high-speed data transmission, thus improving the performance of the switch.
Patent Information
- Application Number
- CN202511282835.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-09
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2045-09-09
AI Technical Summary
In existing technologies, the cache management strategies of switches are insufficient, resulting in uneven use and low utilization of the cache, which can easily lead to hot spot congestion and affect the performance of the switch.
By obtaining the occupancy and usage of each cache, the available score of each unallocated cache relative to the port is calculated, and appropriate caches are selected and allocated to idle ports according to preset thresholds and adjustment factors, avoiding the phenomenon of multiple caches being used for one purpose and improving cache utilization.
It effectively improves cache utilization, ensures high-speed, high-bandwidth data transmission, reduces data exchange time, and improves switch throughput and overall efficiency.
Smart Images

Figure CN120785850B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of communication, and in particular, to a cache allocation method and device. BACKGROUND
[0002] Multi-port, high bandwidth, and low latency are several performance indicators of a forwarding device (for example, a switch or a router). The cache in the switch can cache a portion of data in the case of network congestion. The scheduling efficiency of the cache by the switch directly affects the forwarding efficiency of the switch and the congestion situation of multiple ports, thereby affecting the bandwidth and latency of the switch. Data exchange of multiple ports requires the switch to reasonably and effectively allocate and schedule multiple caches, so as to achieve effective utilization of the cache, thereby achieving the purposes of high throughput, low latency, and avoiding hot congestion.
[0003] The inventors of the present disclosure find that the cache management strategy in the related art is insufficient, for example, there is a case of one-to-many (that is, multiple ports are allocated the same cache). When data is concentrated in one cache, hot spots of the cache are prone to occur, it is difficult to achieve uniform use and full use of the cache, a portion of the cache has a low utilization rate, and a portion of the cache has hot spots, which causes congestion of the switching path and reduces the performance of the switch. SUMMARY
[0004] Embodiments of the present disclosure provide a cache allocation method and device for reasonably and effectively allocating and scheduling multiple caches in a forwarding device, thereby improving the utilization rate of the cache.
[0005] Based on a first aspect of the embodiments of the present disclosure, a cache allocation method is provided. The method comprises: obtaining an occupation situation and a usage situation of each cache for any port in idle ports. The idle ports include ports that are not allocated a cache. The occupation situation includes whether the cache has been allocated. The usage situation includes the amount of data in the cache. In combination with the occupation situation and the usage situation of each cache, a usable score of each unallocated cache relative to the port is calculated, and a cache with a usable score less than a preset threshold is searched. In the case that the usable score of at least one unallocated cache relative to the port is less than the preset threshold, any cache with a usable score less than the preset threshold is allocated to the port. In the case that the usable scores of all unallocated caches relative to the port are greater than or equal to the preset threshold, a cache corresponding to the minimum usable score among the usable scores of all unallocated caches relative to the port is allocated to the port.
[0006] According to another aspect of the embodiments of the present disclosure, a device is provided, which comprises a management module, a plurality of caches in communication connection with the management module, and a plurality of ports in communication connection with the management module. The management module is configured to: for any one of the idle ports, acquire the occupancy and usage of each cache. The idle port comprises a port that is not assigned a cache; the occupancy comprises whether the cache is assigned; and the usage comprises the amount of data in the cache. In combination with the occupancy and usage of each cache, a usable score of each unassigned cache relative to the port is calculated and a cache with a usable score less than a preset threshold is found. In a case where the usable score of at least one unassigned cache relative to the port is less than the preset threshold, any cache with a usable score less than the preset threshold is assigned to the port. In a case where the usable scores of all unassigned caches relative to the port are all greater than or equal to the preset threshold, a cache corresponding to the smallest usable score among the usable scores of all unassigned caches relative to the port is assigned to the port.
[0007] It should be understood that the general description above and the detailed description below are only exemplary and explanatory and are not restrictive of the present specification. BRIEF DESCRIPTION OF DRAWINGS
[0008] In order to more clearly illustrate the technical solutions of the embodiments of the present application or the prior art, the drawings needed in the description of the embodiments of the present application or the prior art will be briefly introduced. Obviously, the drawings in the following description are only some embodiments described in the present application, and other drawings can also be obtained by those skilled in the art according to these drawings of the embodiments of the present application.
[0009] Figure 1 is a flowchart of a cache allocation method according to an exemplary embodiment of the present specification;
[0010] Figure 2 is a schematic diagram of a switch chip framework according to an exemplary embodiment of the present specification;
[0011] Figure 3 is a schematic diagram of establishing a coordinate system on a switch chip framework according to an exemplary embodiment of the present specification;
[0012] Figure 4 is a schematic diagram of a cache occupancy scoring board according to an exemplary embodiment of the present specification;
[0013] Figure 5 is a schematic diagram of a cache usage table according to an exemplary embodiment of the present specification;
[0014] Figure 6is a flowchart of another cache allocation method according to an example embodiment of the present specification;
[0015] Figure 7 is a schematic diagram of a port corresponding multi-column cache according to an example embodiment of the present specification;
[0016] Figure 8 is a flowchart of another cache allocation method according to an example embodiment of the present specification;
[0017] Figure 9 is a structural schematic diagram of a device according to an example embodiment of the present specification. DETAILED DESCRIPTION
[0018] The following will be described in detail with reference to the drawings. In the following description, the same numbers are used to designate the same elements, unless otherwise specified, and a repeated description of the same elements can be omitted. The embodiments described in the following example embodiments are not representative of all embodiments consistent with the present specification, and they are merely example embodiments of devices and methods consistent with some aspects of the present specification.
[0019] The terminology used in the present specification is for the purpose of describing particular embodiments only and is not intended to limit the present specification. As used in the present specification, the singular forms "a," "an," and "the" are intended to include the plural forms, unless the context clearly indicates otherwise.
[0020] It should be understood that the terms "first", "second", "third", etc. can be used in the present specification to describe various information or structural modules, and the purpose is to make the scheme more clearly described, and it cannot be understood as indicating or implying the relative importance or implicitly indicating the number, order or position of the indicated technical features. Therefore, the features defined as "first", "second", "third", etc. can be explicitly or implicitly included one or more features. In the description of the present specification, unless otherwise specified, the meaning of "a plurality of" is two or more; "if" can be interpreted as "when" or "when" or "in response to determining".
[0021] In the present specification, unless otherwise expressly specified and limited, the term "connection" should be understood broadly, for example, "connection" can be fixed connection, or detachable connection, or integral; can be directly connected, or indirectly connected through an intermediate medium. In addition, the term "coupling" can be direct electrical connection, or indirect electrical connection through an intermediate medium. The term "contact" can be direct contact, or indirect contact through an intermediate medium.
[0022] In the specification, the association relationship between the associated objects is described by "and / or", which means that there can be three kinds of relationships, for example, A and / or B, which can represent the following three cases: A exists alone, A and B exist simultaneously, and B exists alone, where A and B can be singular or plural. The character " / " generally represents an "or" relationship between the associated objects before and after it.
[0023] Next, the embodiments of the present specification will be described in detail.
[0024] As shown in Figure 1 , Figure 1 is a flowchart of a cache allocation method according to an exemplary embodiment of the present specification, comprising the following steps:
[0025] Step 102, for any port in the idle port, get the occupation and usage of each cache.
[0026] In some optional embodiments of the present disclosure, the idle port can include a port that has not been allocated a cache. The occupation can include whether the cache has been allocated. The usage can include the amount of data in the cache.
[0027] In some optional embodiments of the present disclosure, the switch includes a switch chip, and the framework on the switch chip is as shown in Figure 2 The management module, a plurality of caches and a plurality of ports are arranged on the switch chip. The plurality of ports are arranged around the outer periphery of the area where the plurality of caches are located, which has been designed when the layout of the switch chip is designed. The plurality of caches are led to the area where the caches are located by wiring, and the ports are led to the corresponding positions of the ports by wiring. Each cache is generally a physical cache module. Generally, the number of caches is greater than or equal to the number of ports. The plurality of caches are generally regularly distributed in the area where the plurality of caches are located, and the number of rows and the number of columns of the caches in the area where the plurality of caches are located are generally equal. The management module maintains a port allocation table, which records whether each port has been allocated a cache. Each port has a unique identifier, and the management module can confirm whether the port is currently idle by maintaining and querying the port allocation table. One column of the port allocation table can record the identifier of each port, and the other column has an identifier of whether it is idle. For example, 1 can represent that the cache has been allocated, and 0 can represent that the port is idle.
[0028] In some optional embodiments of the present disclosure, the any port can be obtained by polling all idle ports of the switch chip. Alternatively, a port can be randomly selected from all idle ports of the switch chip as the any port. Alternatively, the any port can be selected from all idle ports of the switch chip according to a predetermined rule. The present disclosure does not limit the way to obtain the any port.
[0029] Step 104: Based on the occupancy and usage of each cache, calculate the available score of each unallocated cache relative to the port.
[0030] In some optional embodiments of this disclosure, the location corresponding to the cache can be represented using the coordinates of the cache. Figure 3 For example, taking the bottom left corner of the diagram as the origin O, the horizontal direction to the right is the positive X-axis, and the vertical direction upwards is the positive Y-axis. Then the coordinates of the bottom left corner buffer are (1, 1). Similarly, the location of a port can also be represented using its coordinates. Figure 3 The shaded port has coordinates (5, 2). If position coordinates are used as unique identifiers for caches and ports, then the bottom left cache has a unique identifier of (1, 1), and the shaded port has a unique identifier of (5, 2).
[0031] In some optional embodiments of this disclosure, the management module maintains a cache occupancy scoreboard (ALLOC_SB) and a cache usage table (BUFFER_SB). The cache occupancy scoreboard can be as follows: Figure 4 As shown, each cache location is marked with one bit, reflecting the cache's occupancy status. For example, 1 can indicate that the cache has been allocated, and 0 can indicate that the cache has not been allocated. The cache usage table can be as follows: Figure 5 As shown, each cache location records the amount of data in that cache, reflecting its usage. The cache occupancy scoreboard and cache usage table can also be implemented using the same methods. Figure 3 A similar coordinate definition method ensures that the same coordinate in both the cache occupancy scoreboard and the cache usage table represents the same cache. Ports can include a reporting module. When a port finishes using its cache, it can report to the management module. The management module then reclaims the cache allocated to the port and updates the port allocation table and the cache occupancy scoreboard. The management module can also maintain an allocation record table. One column of this table records the identifier of each port, and the other column records the identifier of the cache allocated to that port. When a port sends data to the cache, it can notify the management module through the reporting module. The management module reclaims the corresponding cache, but the data in the cache may not have been sent out yet. Therefore, the cache occupancy scoreboard may record a cache as unallocated, but the cache usage table may show a non-zero data volume for that cache.
[0032] In some optional embodiments of the present disclosure, before receiving data from the idle port, the management module first allocates a cache for the idle port. When the port receives data, the data is directly sent to the cache that has been allocated, and then the cache sends the data to the corresponding target port, and the data is transmitted out from the target port. The port reports the management module after sending data to the cache once, the management module recycles the cache corresponding to the port, resets the idle identifier corresponding to the port in the port allocation table to the idle identifier, and resets the identifier corresponding to the cache in the cache occupation score board to the unallocated identifier. If the port has not received and sent data, the port will always hold the allocated cache and will not report the management module. For high-speed and large-bandwidth use scenarios, the cache is pre-allocated for the idle port, and when the port receives data, the cache can be directly used for data forwarding, which greatly shortens the entire data exchange time and effectively improves the overall data throughput efficiency.
[0033] Step 106, based on the available score of each unallocated cache relative to the port, determine the cache allocated for the port and allocate the cache to the port.
[0034] In some optional embodiments of the present disclosure, after obtaining the available score of each unallocated cache relative to the port, the cache with the smallest available score can be selected and allocated to the port.
[0035] The above describes a cache allocation method for an idle port, and other idle ports can use the same cache allocation method, which will not be described in detail in the present disclosure.
[0036] In the process of allocating caches for idle ports, the present embodiment fully considers the occupation and use of each cache, and calculates the available score of each cache relative to the port according to the occupation and use, and selects and allocates the cache for the port according to the available score, which greatly improves the utilization efficiency of the cache and has good adaptability to high-speed and large-bandwidth environments.
[0037] As shown in FIG. 1, Figure 6 Figure 6 is a flowchart of another cache allocation method according to an exemplary embodiment of the present disclosure, comprising the following steps:
[0038] Step 102, for any port in the idle port, obtain the occupation and use of each cache;
[0039] Step 1041, in combination with the occupation and use of each cache, calculate the available score of each unallocated cache relative to the port;
[0040] Step 1042, find the cache with an available score less than a preset threshold;
[0041] Step 1061, in the case that at least one of the unassigned caches has an available value less than the preset threshold value, assigning any of the caches having an available value less than the preset threshold value to the port;
[0042] Step 1062, in the case that all of the unassigned caches have an available value greater than or equal to the preset threshold value, assigning the cache corresponding to the minimum available value among the available values of the unassigned caches to the port.
[0043] The contents of steps 102 and 1041 are described above in relation to steps 102 and 104, and will not be described again here. After the available values of each of the unassigned caches relative to the port are calculated in step 1041, step 1042 further finds the caches having an available value less than the preset threshold value.
[0044] In some optional embodiments of the present disclosure, the preset threshold value can be a value set by a person skilled in the art as needed, and can be configured using a register. If there is at least one unassigned cache having an available value less than the preset threshold value, it indicates that all of the unassigned caches having an available value less than the preset threshold value are suitable for being assigned to the port, and any of the caches having an available value less than the preset threshold value can be assigned to the port. The cache having an available value less than the preset threshold value can be the first found cache having an available value less than the preset threshold value, can be the cache having the minimum available value among all of the caches having an available value less than the preset threshold value, or can be any of the first preset number (for example, 3) of caches having an available value less than the preset threshold value in the calculation process, and the present disclosure does not limit this.
[0045] In some optional embodiments of the present disclosure, if all of the unassigned caches have an available value greater than or equal to the preset threshold value, and it is still necessary to assign a cache to the port, the cache corresponding to the minimum available value among the available values of the unassigned caches relative to the port can be assigned to the port.
[0046] The above describes a cache assignment method for a free port, and other free ports can use the same cache assignment method, and the present disclosure will not be described again.
[0047] In the process of assigning a cache to a free port, the embodiments of the present disclosure fully consider the occupation and use of each cache, and calculate the available values of each cache relative to the port, use the preset threshold value to quickly screen suitable caches, even if there is no cache having an available value less than the preset threshold value, the unassigned cache having the minimum available value can still be selected and assigned to the port, so as to ensure that the port has a cache that can be used, and to guarantee high-speed and large-bandwidth data transmission.
[0048] In some alternative embodiments of the present disclosure, the available score includes a usage factor and an adjustment factor. The adjustment factor includes at least one of a random factor and a distance factor. The usage factor can reflect how much the content in the buffer is used. The usage factor can reflect how suitable each buffer is for being allocated to the idle port. The smaller the usage factor, the more suitable it is for being allocated to the idle port. Then, step 1041 can include:
[0049] determining whether the buffer has been allocated based on the occupancy of the buffer;
[0050] if the buffer is an unallocated buffer, taking the amount of data in the unallocated buffer as the usage factor corresponding to the unallocated buffer.
[0051] In some alternative embodiments of the present disclosure, at most one buffer can be allocated to one port, and at most one port can be allocated to one buffer, so as to eliminate the multiple-to-one situation in the related art.
[0052] In some alternative embodiments of the present disclosure, the amount of data in a buffer can be taken as the usage factor corresponding to the buffer. If the occupancy of a buffer indicates that the buffer has been allocated, the buffer can be skipped. If the occupancy of a buffer indicates that the buffer has not been allocated, the usage factor corresponding to the buffer is calculated, so as to greatly reduce the calculation amount of the usage factor. The usage factor can be represented as BUFFER_SB[L], where L is the identifier of the buffer. If the identifier of the buffer uses the position coordinates of the buffer, if the capacity of the buffer (3, 2) is 100, and the buffer (3, 2) uses 85, then the amount of data in the buffer (3, 2) is 85, and the usage factor BUFFER_SB[(3, 2)] = 85.
[0053] In some alternative embodiments of the present disclosure, the usage factor of a buffer can also be calculated first, and then whether to retain the usage factor of the buffer is determined based on the occupancy of the buffer. If the buffer has been allocated, the usage factor of the buffer is discarded. If the buffer has not been allocated, the usage factor of the buffer is retained.
[0054] In some optional embodiments of the present disclosure, the adjustment factor can adjust the result of the usage factor. The introduction of the adjustment factor makes more unallocated buffers have the opportunity to be allocated to the idle port based on the consideration of the usage factor. The random factor can provide each unallocated buffer with a random equal opportunity to be allocated to the port. The random factor well balances the result of the usage factor. The distance factor can refer to the distance between the unallocated buffer and the port. The closer the unallocated buffer is to the port, the higher the chance of being allocated to the port; otherwise, the farther the unallocated buffer is to the port, the smaller the chance. The distance factor can reduce the communication time between the port and the buffer, further improving the throughput of the switch. For the case of multiple logical buffers divided from a physical buffer, since it is actually one physical buffer, the distance factor can not be introduced in this case.
[0055] In some optional embodiments of the present disclosure, when the adjustment factor includes the distance factor, step 1041 further includes:
[0056] For the multiple column buffers corresponding to the port, the column distance between the column where the unallocated buffer is located and the column where the port is located is calculated, and the column distance is taken as the distance factor corresponding to the unallocated buffer.
[0057] In some optional embodiments of the present disclosure, the multiple column buffers corresponding to the port include: performing logical transformation corresponding to the orientation of the port in the region where all the buffers are located on the positions of the port and all the buffers to obtain the multiple column buffers corresponding to the region where all the buffers are located. The orientation of the port in the region where all the buffers are located can be obtained from the coordinates of the port. On the switch chip, the port has four orientations relative to the region where all the buffers are located. It is much easier to perform logical transformation on the position coordinates of the port and the buffer than to make four sets of buffer allocation logic. In order to use one set of buffer allocation logic, the position coordinates of the port and the buffer can be first logically transformed, and then passed to the buffer allocation logic. The input of the buffer allocation logic here is the row and column of the port corresponding to the logical transformation and the row and column of the unallocated buffer corresponding to the logical transformation. Let the number of rows of the buffer be R, the number of columns of the buffer be C, and the coordinates before the logical transformation be (x0, y0).
[0058] In some optional embodiments of the present disclosure, for example Figure 3 The port with coordinates (3, 5) corresponds to the multiple column buffers as follows Figure 7 For the case that the port is above the region where all the buffers are located, the row and column of the port and the unallocated buffer can be made y0 and x0, and then the row and column are passed to the buffer allocation logic. The row of the port (3, 5) is 5, and the column is 3. The row of the buffer (3, 1) is 1, and the column is 3.
[0059] In some alternative embodiments of the present disclosure, for the port with coordinates (0, 0), it can be known that the port (0, 0) is at the top of the region where all the caches are located. For the case that the port is at the top of the region where all the caches are located, the row and the column of the port and the unassigned cache can be made to be x0 and y0 respectively, and then the row and the column are passed to the cache allocation logic. The row of the port (0, 0) is 0, and the column is 0. The row of the cache (3, 1) is 3, and the column is 1. Figure 3 In some alternative embodiments of the present disclosure, for the port with coordinates (3, 0), it can be known that the port (3, 0) is below the region where all the caches are located. For the case that the port is below the region where all the caches are located, the row and the column of the port and the unassigned cache can be made to be R+1-y0 and x0 respectively, and then the row and the column are passed to the cache allocation logic. The row of the port (3, 0) is 5, and the column is 3. The row of the cache (3, 1) is 3, and the column is 4.
[0060] In some alternative embodiments of the present disclosure, for the port with coordinates (0, 2), it can be known that the port (0, 2) is at the left of the region where all the caches are located. For the case that the port is at the left of the region where all the caches are located, the row and the column of the port and the unassigned cache can be made to be x0 and y0 respectively, and then the row and the column are passed to the cache allocation logic. The row of the port (0, 2) is 0, and the column is 2. The row of the cache (3, 1) is 3, and the column is 1. Figure 3 In some alternative embodiments of the present disclosure, for the port with coordinates (5, 2) with the shadow, it can be known from the coordinates that the port is at the right of the region where all the caches are located. For the case that the port is at the right of the region where all the caches are located, the row and the column of the port and the unassigned cache can be made to be x0 and R+1-y0 respectively, and then the row and the column are passed to the cache allocation logic. The row of the port (5, 2) is 5, and the column is 3. The row of the cache (3, 1) is 3, and the column is 4.
[0061] Figure 3 In some alternative embodiments of the present disclosure, after the logical transformation, the cache allocation logic can use the column to calculate. Figure 7
[0062] In some alternative embodiments of the present disclosure, after the logical transformation, the cache allocation logic can use the column to calculate. The cache allocation logic is simplified. Moreover, the logical transformation can be realized by a circuit, which is relatively simple.
[0063] In some alternative embodiments of the present disclosure, for the multi-column cache corresponding to the port, the column distance between the column where the unassigned cache is located and the column where the port is located can be calculated. The column distance can be obtained by using the absolute value of the difference between the column of the port and the column of the cache after the logical transformation. The distance factor can be represented by Distance. The column distance can be directly used as the distance factor. For example, Figure 7 In the above example, the Distance between the port and the cache in the first column on the left is |1-3|=2. It can be seen that the farther the cache is from the port, the greater the distance factor is.
[0064] It should be noted that the logical transformation does not change the actual positions of the port and the cache, and provides a different perspective for viewing the port and the cache. The port corresponds to the multi-column cache, and the disclosure does not limit the logical transformation of the port above all the caches. The port on the left, right, and below all the caches also applies to the method of the disclosure, and the logical transformation rules of each orientation in the whole calculation process correspond to keep consistent. Although the above introduces the multi-column cache, those skilled in the art should understand that the column is relative. If the logical transformation is required to be a multi-row cache, the method of the disclosure is also applicable. Although the above calculates the column spacing, the row spacing between the port and the cache can also contribute a good distance factor. The perspective is different, but it belongs to the same concept and should belong to the protection scope of the disclosure. The calculation should be understood in a broad sense, not limited to numerical calculation, but also can determine a numerical value or conclusion according to the existing information or data.
[0065] In some optional embodiments of the disclosure, when the adjustment factor includes a distance factor, step 1041 further includes:
[0066] For the multi-column cache corresponding to the port, the column spacing between the column where the above unallocated cache is located and the column where the port is located is calculated; a left shift operation of the column spacing by a first preset number of bits is performed to obtain a left shift column spacing; and the left shift column spacing is taken as the distance factor corresponding to the unallocated cache.
[0067] In some optional embodiments of the present disclosure, the distance factor can be represented as Distance<<DISTANCE_COST, where DISTANCE_COST is a first preset numerical value. The first preset numerical value can be a numerical value preset by a person skilled in the art as needed, such as 2. The first preset numerical value can be configured by a register. When the column spacing between the column where the unallocated cache is located and the column where the port is located is 1, the distance factor corresponding to the unallocated cache is 1<<2=4, that is, the binary number 0001 of 1 is left shifted by 2 bits to obtain 0100 corresponding to 4; when the column spacing between the column where the unallocated cache is located and the column where the port is located is 2, the distance factor corresponding to the unallocated cache is 2<<2=8, that is, the binary number 0010 of 2 is left shifted by 2 bits to obtain 1000 corresponding to 8. As can be seen, the column spacing is accelerated and amplified after the left shift operation, resulting in that the farther the distance between the cache and the port, the greater the distance factor, which will make the available score higher in the final available score, so that the cache closer to the port is preferentially allocated. The distance factor can refer to the distance between the unallocated cache and the port. The closer the unallocated cache is to the port, the greater the chance of being allocated to the port, and the farther the unallocated cache is from the port, the smaller the chance. The distance factor can reduce the probability of selecting an unallocated cache far from the port, thereby reducing the data transmission delay. The distance factor can supplement the adjustment of the result of the usage factor, further improving the throughput of the switch.
[0068] In some optional embodiments of the present disclosure, when the adjustment factor includes a random factor, step 1041 further includes:
[0069] calling a preset random number generation method to generate a random number for the unallocated cache, and taking the random number as the random factor corresponding to the unallocated cache.
[0070] In some optional embodiments of the present disclosure, the preset random number generation method can be any random number generation method, such as LFSR (linear feedback shift register), hash function method, etc., as long as the randomness is good, and a person skilled in the art can select it as needed. The order of magnitude of the random number can be comparable to the usage factor and the distance factor. The random factor can be represented as random, for example, the generated random number is 18, and the random factor random=18.
[0071] In some optional embodiments of the present disclosure, when the adjustment factor includes a random factor, step 1041 further includes:
[0072] calling a preset random number generation method to generate a random number for the unallocated cache;
[0073] bitwise AND operation between the random number and the second preset value is performed to obtain the random factor corresponding to the unallocated cache.
[0074] In some optional embodiments of the present disclosure, the random factor random can be LFSR && RAND_MAX_COST. A person skilled in the art can select a polynomial used by the LFSR as needed. The RAND_MAX_COST is the second preset value, which can be a value preset by a person skilled in the art as needed, such as 2. The second preset value can be configured through a register. Then, the calculation process of the random factor random is as follows: a random bit stream is generated by the LFSR, and a bitwise AND operation between the random bit stream and the second preset value RAND_MAX_COST is performed to obtain the random factor.
[0075] Since the random bit stream generated by the LFSR can be relatively long, the last n bits of the random bit stream can be intercepted by performing a bitwise AND operation between the random bit stream and the second preset value RAND_MAX_COST. The value of n depends on the number of bits of the second preset value RAND_MAX_COST, and n is a positive integer. The random factor obtained through the above operation has better randomness.
[0076] In some optional embodiments of the present disclosure, when the adjustment factor includes the random factor, the step 1041 further includes:
[0077] a preset random number generation method is called to generate a random number for the unallocated cache;
[0078] a right shift operation with a dynamic number of bits is performed on the random number to obtain a changed random number;
[0079] a bitwise AND operation between the changed random number and the second preset value is performed to obtain the random factor corresponding to the unallocated cache.
[0080] In some optional embodiments of the present disclosure, the random factor random can be (LFSR >> dynamic) && RAND_MAX_COST. The LFSR can generate a random bit stream. The dynamic is a dynamic number of bits, and the value of the dynamic number of bits can be, for example, any one of the following: the vertical coordinate, the horizontal coordinate, the sum of the horizontal and vertical coordinates, the absolute value of the difference between the horizontal and vertical coordinates, and the like of the unallocated cache. The RAND_MAX_COST is the second preset value, which can be a value preset by a person skilled in the art as needed, such as 2. Then, the calculation process of the random factor is as follows: a random bit stream is generated by the LFSR, the random bit stream is right shifted by the dynamic number of bits to obtain a changed random number, and a bitwise AND operation between the changed random number and the second preset value RAND_MAX_COST is performed to obtain the random factor.
[0081] Since the random factor uses the dynamic bit number to change the initial random number again, the randomness of the final random factor will be higher.
[0082] In some optional embodiments of the present disclosure, the value of the dynamic bit number is the row number of the unallocated buffer in the multi-column cache corresponding to the port. The random factor random can be (LFSR >> row_number) && RAND_MAX_COST. Wherein, row_number is the row number of the unallocated buffer in the multi-column cache corresponding to the port.
[0083] Since the random factor uses the row number of the unallocated buffer in the multi-column cache corresponding to the port to change the initial random number again, because the multi-column cache corresponding to the port has already performed a logical transformation on the position coordinates of the buffer, and the port is located in a different position in the region where all the buffers are located, the logical transformation method is also different, which brings greater randomness to the random factor.
[0084] It should be noted that although the value of the dynamic bit number uses the row number of the unallocated buffer in the multi-column cache corresponding to the port, the row and column can be converted to each other. Therefore, the value of the dynamic bit number can include any of the following: the row number of the unallocated buffer in the multi-column cache corresponding to the port, the column number, the sum of the row number and the column number, the absolute value of the difference between the row number and the column number, and the longitudinal coordinate, the horizontal coordinate, the sum of the horizontal and longitudinal coordinates, the absolute value of the difference between the horizontal and longitudinal coordinates, etc. of the unallocated buffer. These can all contribute to a good random factor, belong to the same concept, and should belong to the protection scope of the present disclosure.
[0085] In some optional embodiments of the present disclosure, if the available score includes the factor BUFFER_SB[L], the distance factor distance << DISTANCE_COST, and the random factor random, the available score Grade[L] can be calculated according to the following formula:
[0086] Grade[L]=BUFFER_SB[L]+distance<<DISTANCE_COST+random
[0087] Those skilled in the art can weight the coefficients of each factor according to the actual scene, or adjust the first preset value DISTANCE_COST in the distance factor and the second preset value RAND_MAX_COST in the random factor, or use the weighted coefficients and the adjusted values in combination, which is not limited in the present disclosure.
[0088] In some optional embodiments of the present disclosure, steps 1041 and 1042 can include:
[0089] For the plurality of columns of caches corresponding to the port, in combination with the occupancy and usage of each cache in the current column, an available score of each unassigned cache in the current column relative to the port is calculated; wherein the current column is initially any column in the plurality of columns of caches;
[0090] If the available score of all unassigned caches in the current column relative to the port is greater than or equal to the preset threshold, the smaller value between the minimum value and the current minimum value is taken to update the minimum value, the next column is taken as the current column, and the search is continued until an unassigned cache with an available score less than the preset threshold is found; wherein the initial value of the minimum value is determined by the minimum value calculated by the first column participating in the calculation;
[0091] In the case that all columns in the plurality of columns of caches are searched and no cache with an available score less than the preset threshold is found, it is determined that the available score of all unassigned caches relative to the port is greater than or equal to the preset threshold.
[0092] In some optional embodiments of the present disclosure, determining the plurality of columns of caches corresponding to the port comprises: performing a logical transformation corresponding to the orientation of the port in the region where all the caches are located on the positions of the port and all the caches to obtain the plurality of columns of caches corresponding to the region where all the caches are located.
[0093] In some optional embodiments of the present disclosure, the first column participating in the calculation in the plurality of columns of caches can be the first column, the last column or a random column of the plurality of columns of caches. Optionally, the next column in the plurality of columns of caches can be adjacent to or separated by several columns from the previous column participating in the calculation. The calculation of each column can be column-by-column calculation or random selection of columns not participating in the calculation. The preset threshold can be a value set by a person skilled in the art as needed, and a register can be used for configuration.
[0094] In some optional embodiments of the present disclosure, the first column participating in the calculation in the plurality of columns of caches is the column where the port is located. That is, the current column is initially the column where the port is located in the plurality of columns of caches. Because the unassigned cache in the column corresponding to the port in the plurality of columns of caches corresponding to the port has the smallest distance factor (0), the column where the port is located is calculated first, and the possibility of finding a cache with an available score less than the preset threshold is also higher, thereby improving the speed and efficiency of assigning caches.
[0095] In some optional embodiments of the present disclosure, there is a mapping relationship between the logical transformed row, column and the horizontal, vertical coordinates before the logical transformation. When calculating the available score of a certain unallocated cache in a certain column of the multi-column cache corresponding to the port, for the usage factor, the mapping relationship can be used to obtain whether the cache has been allocated in the cache occupation score board before the logical transformation and how much data is in the cache usage table, so as to obtain the usage factor corresponding to the cache. For the adjustment factor, the logical transformed row and column can be used to calculate. The usage factor and the adjustment factor can be calculated in parallel, without sequence limitation. In the stage of allocating the cache to the port after the available score is calculated, the coordinates before the logical transformation of the usage port and the cache are used to update the cache occupation score board, the port allocation table and the allocation record table.
[0096] In some optional embodiments of the present disclosure, in the process of calculating the available score of the cache, if the occupation of a cache indicates that the cache has been allocated, the cache can be skipped; if the occupation of a cache indicates that the cache has not been allocated, the available score of the cache is calculated, so as to greatly reduce the calculation amount of the available score. Alternatively, the available score of the cache can be calculated first, and then it is judged whether to keep the available score of the cache according to the occupation of the cache. If the cache has been allocated, the available score of the cache is discarded; if the cache has not been allocated, the available score of the cache is kept.
[0097] In some optional embodiments of the present disclosure, referring to Figure 8 , the cache allocation method of the present disclosure can comprise:
[0098] 201, for any port in the idle port, obtaining the occupation and usage of each cache.
[0099] 202, for the multi-column cache corresponding to the port, combining the occupation and usage of each cache in the current column, calculating the available score of the current unallocated cache relative to the port in the current column. The current unallocated cache is initially any unallocated cache in the current column.
[0100] 203, judging whether the available score of the current unallocated cache relative to the port is less than a preset threshold. If yes, 204, allocating the unallocated cache to the port and ending.
[0101] If no, 205, judging whether the current column is completed. If no, 206, taking the next unallocated cache in the current column as the current unallocated cache, and performing 202. Similarly, the next unallocated cache can be the unallocated cache arranged in order in the current column, or a randomly selected unallocated cache in the current column, which is not limited by the present disclosure.
[0102] If yes, 207, take the minimum value of all unassigned caches in the current column relative to the available score of the port.
[0103] 208, judge whether the current column is the first column in the multi-column cache participating in the calculation. If yes, 209, take the minimum value as the minimum score. If no, 210, take the smaller value of the minimum value and the current minimum score to update the minimum score.
[0104] 211, judge whether all columns of the multi-column cache are calculated. If yes, 212, assign the cache corresponding to the current minimum score to the port. If no, 213, take the next column in the multi-column cache as the new current column, and execute 202.
[0105] In some optional embodiments of the present disclosure, the end refers to the end of the process of assigning caches for the current idle port, and after that, the process of assigning caches for the next idle port will be started.
[0106] The method of the embodiments of the present disclosure can be run by a management module in the switch, for example, can be run by a switch chip on which the management module, multiple ports and multiple caches are disposed. Moreover, the method of the embodiments of the present disclosure is not limited to be applied to the switch, and any device supporting multi-path data switching and using a similar architecture (such as a router, etc.) can use the method of the present disclosure in a high-speed, large-bandwidth environment. Figure 2
[0107] In the process of assigning caches for the idle port, the embodiments of the present disclosure fully consider the occupation and use of each cache, and calculate the available score of each cache relative to the port according to the occupation and use, and select and assign the cache for the port according to the available score, which greatly improves the utilization efficiency of the cache and has good adaptability to the high-speed, large-bandwidth environment.
[0108] Those skilled in the art can flexibly select and combine the contents in the embodiments of the present disclosure according to the needs, so as to combine more schemes. The present disclosure does not list all these recombined schemes, and the schemes formed by various recombination shall be included in the protection scope of the present disclosure.
[0109] In some optional embodiments of the present disclosure, referring to Figure 9 is a schematic diagram of a device according to an exemplary embodiment. The device can include: a management module 10, a plurality of caches 20 in communication connection with the management module 10, and a plurality of ports 30 in communication connection with the management module 10.
[0110] In some optional embodiments of the present disclosure, the management module 10 is configured to:
[0111] For any port 30 in the idle ports 30, obtain the occupancy and usage of each cache 20; wherein the idle ports 30 include ports 30 that are not assigned a cache 20; the occupancy includes whether the cache 20 has been assigned; the usage includes the amount of data in the cache 20;
[0112] In combination with the occupancy and usage of each cache 20, calculate the available score of each unassigned cache 20 relative to the port 30 and find the cache 20 with an available score less than a preset threshold value.
[0113] In the case that at least one unassigned cache 20 relative to the port 30 has an available score less than the preset threshold value, assign any cache 20 with an available score less than the preset threshold value to the port 30.
[0114] In the case that all unassigned caches 20 relative to the port 30 have an available score greater than or equal to the preset threshold value, assign the cache 20 corresponding to the minimum available score among the available scores of all unassigned caches 20 relative to the port 30 to the port 30.
[0115] Since the device embodiments are similar to the foregoing method embodiments, the details are not repeated here, and the relevant parts are referred to the foregoing method embodiments.
[0116] It should be noted that the device in the present disclosure should be understood in a broad sense. The device in the present disclosure can be a switch chip including the above-mentioned management module, cache, and port, or a switch, router, etc. installed with the switch chip. The number of caches and ports in the figure is only illustrative and does not mean that these numbers must be included.
[0117] Corresponding to the foregoing method embodiments, the present specification also provides an embodiment of a cache allocation apparatus. The cache allocation apparatus can include:
[0118] The obtaining module is configured to: for any port in the idle ports, obtain the occupancy and usage of each cache. Wherein the idle ports include ports that are not assigned a cache. The occupancy includes whether the cache has been assigned. The usage includes the amount of data in the cache.
[0119] The calculation module is configured to: in combination with the occupancy and usage of each cache, calculate the available score of each unassigned cache relative to the port and find the cache with an available score less than a preset threshold value.
[0120] The allocation module is configured to: in a case where the available score of at least one unallocated cache with respect to the port is less than the preset threshold, allocate the cache with any available score less than the preset threshold to the port; and in a case where the available scores of all unallocated caches with respect to the port are all greater than or equal to the preset threshold, allocate the cache corresponding to the minimum available score among the available scores of all unallocated caches with respect to the port to the port.
[0121] The implementation process of the functions and roles of the modules in the above apparatus is specifically shown in the implementation process of the corresponding steps in the above method part. Since it basically corresponds to the embodiments of the method, the related parts are described in the embodiment description of the method part, and will not be described here.
[0122] In some optional embodiments of the present disclosure, a terminal is also provided. The terminal includes a processor and a memory for storing processor-executable instructions. When the executable instructions in the memory are executed by the processor, the processor performs the steps in the cache allocation method described in the embodiments of the method part of the present disclosure specification.
[0123] For the terminal embodiments, since they basically correspond to the embodiments of the method, the related parts are described in the embodiment description of the method part.
[0124] The above describes exemplary embodiments of the present disclosure, and it should be understood that in some cases, the modules described in the present disclosure can be divided in a manner different from the embodiments, and the described actions or steps can also be executed in an order different from the embodiments, and the desired results can still be achieved. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multi-task processing and parallel processing are possible or can be advantageous.
[0125] Other embodiments of the present disclosure will be apparent to those skilled in the art upon consideration of the specification and practice of the application disclosed herein. The present disclosure is intended to cover any variations, uses, or adaptations of the present disclosure following the general principles thereof and including such departures from the present disclosure that come within known or customary practice in the art to which the present disclosure pertains.
[0126] The above only describes the preferred embodiments of the present disclosure and does not limit the present disclosure. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A cache allocation method characterized by, The method comprises: acquiring occupancy and usage of each cache for any port in idle ports; wherein the idle ports comprise ports not assigned with caches; the occupancy comprises whether the cache has been assigned; the usage comprises data amount in the cache; calculating available scores of each unassigned cache relative to the port and finding a cache with an available score less than a preset threshold, in combination with the occupancy and usage of each cache; wherein the available score comprises a usage factor and an adjustment factor; the usage factor can reflect how much content in the cache; the adjustment factor can adjust the result of the usage factor; the adjustment factor comprises a random factor and a distance factor; the random factor can provide each unassigned cache with a random equal opportunity to be assigned to the port; the distance factor can refer to the distance between the unassigned cache and the port; in the case that at least one of the unassigned caches has an available score less than the preset threshold relative to the port, assigning any cache with an available score less than the preset threshold to the port; in the case that all the unassigned caches have available scores greater than or equal to the preset threshold relative to the port, assigning the cache corresponding to the minimum available score among the available scores of all the unassigned caches relative to the port to the port.
2. The method according to claim 1, wherein the calculating of the available scores of each unassigned cache relative to the port and the finding of a cache with an available score less than a preset threshold comprise: for a plurality of columns of caches corresponding to the port, calculating the available scores of each unassigned cache in a current column relative to the port in combination with the occupancy and usage of each cache in the current column; wherein the current column is initially any column in the plurality of columns of caches; if all the unassigned caches in the current column have available scores greater than or equal to the preset threshold relative to the port, taking the smaller value between the minimum value and the current minimum value to update the minimum value, taking the next column as the current column, and continuing the finding until an unassigned cache with an available score less than the preset threshold relative to the port is found; wherein the initial value of the minimum value is determined by the minimum value calculated from the first column participating in the calculation; in the case that no cache with an available score less than the preset threshold is found after searching all the columns in the plurality of columns of caches, determining that all the unassigned caches have available scores greater than or equal to the preset threshold relative to the port.
3. The method according to claim 2, wherein the determining of the plurality of columns of caches corresponding to the port comprises: performing a logical transformation corresponding to the orientation of the port in the region where all the caches are located on the positions of the port and all the caches to obtain the plurality of columns of caches corresponding to the region where all the caches are located.
4. The method according to any one of claims 1-3, wherein The method further comprises: determining whether the cache has been allocated based on the occupancy of the cache; if the cache is an unallocated cache, taking the amount of data in the cache as a use factor corresponding to the unallocated cache; in a case where the adjustment factor comprises a distance factor, the method further comprises: for a plurality of columns of caches corresponding to the port, calculating a column distance between a column in which the unallocated cache is located and a column in which the port is located, and taking the column distance as the distance factor corresponding to the unallocated cache; in a case where the adjustment factor comprises a random factor, the method further comprises: calling a preset random number generation method to generate a random number for the unallocated cache, and taking the random number as the random factor corresponding to the unallocated cache.
5. The method of claim 4, wherein the calculation of the column distance between the column in which the unallocated cache is located and the column in which the port is located for the plurality of columns of caches corresponding to the port comprises: calculating the column distance between the column in which the unallocated cache is located and the column in which the port is located for the plurality of columns of caches corresponding to the port; performing a left shift operation on the column distance by a first preset number of bits to obtain a left-shifted column distance; taking the left-shifted column distance as the distance factor corresponding to the unallocated cache.
6. The method of claim 4, wherein the calling of the preset random number generation method to generate a random number for the unallocated cache, and taking the random number as the random factor corresponding to the unallocated cache comprises: calling the preset random number generation method to generate a random number for the unallocated cache; performing a bitwise AND operation on the random number and a second preset number to obtain the random factor corresponding to the unallocated cache.
7. The method of claim 4, wherein the calling of the preset random number generation method to generate a random number for the unallocated cache, and taking the random number as the random factor corresponding to the unallocated cache comprises: calling the preset random number generation method to generate a random number for the unallocated cache; performing a right shift operation on the random number by a state number of bits to obtain a changed random number; performing a bitwise AND operation on the changed random number and a second preset number to obtain the random factor corresponding to the unallocated cache.
8. The method of claim 2 or 3, wherein, The first column of the plurality of columns of caches participating in the calculation is the column in which the port is located.
9. An apparatus, comprising: The device comprises a management module, a plurality of caches in communication connection with the management module, and a plurality of ports in communication connection with the management module; the management module is configured to: for any port in the idle ports, obtain the occupancy and the use of each cache; wherein the idle ports comprise ports to which caches have not been allocated; the occupancy comprises whether the cache has been allocated; and the use comprises the amount of data in the cache. In combination with the occupancy and usage of each cache, a score of availability of each unassigned cache relative to the port is calculated and a cache with a score of availability less than a preset threshold is searched; wherein the score of availability comprises a usage factor and an adjustment factor; the usage factor is capable of reflecting how much content is in the cache; the adjustment factor is capable of adjusting the result of the usage factor; the adjustment factor comprises a random factor and a distance factor; the random factor is capable of providing each unassigned cache with a random equal opportunity of being assigned to the port; the distance factor is capable of referring to the distance between the unassigned cache and the port; In a case where at least one of the unassigned caches has a score of availability relative to the port less than the preset threshold, any cache with a score of availability less than the preset threshold is assigned to the port; In a case where all of the unassigned caches have a score of availability relative to the port greater than or equal to the preset threshold, the cache corresponding to the minimum score of availability among the scores of availability of all of the unassigned caches relative to the port is assigned to the port.
Citation Information
Patent Citations
Multi-port read-write cache management method and device
CN117850666A