A method of sharing buffer space among multiple priority queues
By dynamically adjusting the shared cache space allocation rules, the problem of cache space contention among multiple priority queues is solved, ensuring the caching needs of high-priority queues and improving the utilization rate of shared cache.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-22
- Publication Date
- 2026-04-14
AI Technical Summary
When multiple priority queues compete for shared cache space, high-priority queues are prone to congestion and packet loss due to low-priority queues preempting cache space. At the same time, existing technologies cannot effectively improve the utilization rate of shared cache.
Based on the caching requirements and priorities of each priority queue, the shared cache space allocation rules are dynamically adjusted to ensure the caching space requirements of high-priority queues, and the shared cache space is reasonably allocated and used through the shared cache occupancy rules between priority queues.
While ensuring the high-priority queue cache space, the utilization rate of the shared cache space is improved, avoiding cache space waste and congestion.
Smart Images

Figure CN121365015B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a method for sharing cache space among multiple priority queues, belonging to the technical field of chip shared cache usage methods. Background Technology
[0002] In switching chips such as PCIe (a high-speed serial computer expansion bus standard) and Ethernet, buffering technology is used to receive data traffic. Data packets are typically divided into different data queues and buffered in the buffer space. The buffer space in the chip is divided into non-shared buffer space and shared buffer space. The non-shared buffer space is smaller. If the amount of data received is large, the shared buffer space is needed to store the data traffic of each queue. Queues are usually divided into different priorities so that the shared buffer space can be allocated to higher priority queues first.
[0003] When the system load is heavy, some high-priority traffic queues are prone to insufficient cache space due to the large volume of low-priority queues preempting the cache space, resulting in congestion or even packet loss.
[0004] Therefore, when multiple queues compete for shared cache space, if adjustments are made based on the priority of each queue and the actual usage of cache requirements, the utilization rate of shared cache space can be effectively improved while ensuring the caching of high-priority queues.
[0005] One existing technical solution is a shared cache usage method based on priority queues.
[0006] The shared cache space is divided into different priority blocks, and high-priority queues can use the same or lower-priority cache blocks.
[0007] This approach ensures that the cache space of high-priority queues will not be preempted by low-priority queues. However, when the cache space of high-priority queues is free, it cannot be used by low-priority queues, resulting in low utilization of the shared cache.
[0008] Another existing technical solution is a shared cache usage method based on the number of queues that need to be allocated with shared cache space.
[0009] Traffic data packets are divided into multiple queues, and cache space is allocated to each queue that needs to share cache space. The cache space is also allocated to the corresponding queues according to the change in the number of queues in demand.
[0010] This shared caching method automatically adjusts and allocates cache space based on network traffic, saving hardware resources and improving cache space utilization. However, this method does not prioritize queues, failing to guarantee that more important queues receive sufficient shared cache space first. This is detrimental to storing higher-level data and reduces caching efficiency. Summary of the Invention
[0011] In this invention, when queues with different priorities compete for the same shared cache space, the size of the shared cache space of the priority queues is adjusted according to the current cache requirements and queue priority of each priority queue. This is a mechanism and method for improving the utilization efficiency of cache space by allowing multiple priority queues to share the same cache while ensuring the cache space of the high-priority queue.
[0012] This invention allocates shared cache according to the different needs of different priority queues, sets rules for each priority queue to occupy the shared cache space of other priority queues, so as to dynamically adjust the cache usage mechanism and method, protect the cache space of high priority queues, and improve the cache space utilization rate.
[0013] The specific technical solution of the present invention is as follows:
[0014] A method for sharing cache space among multiple priority queues includes the following steps:
[0015] S1. By dividing the data packets entering and leaving the buffer into multiple queues, and dividing the queues according to their importance, different priority queues are obtained. Different amounts of shared buffer space are allocated to different priorities. The allocation principle is to first ensure that the high priority queues have the need for shared buffer space.
[0016] S2. Allocate corresponding shared cache space according to the shared cache requirements of each priority queue;
[0017] S3. High-priority queues can occupy the free shared cache space of low-priority queues, and the occupancy is based on the principle of low to high priority.
[0018] S4. Set constraints. When the constraints are met, low-priority queues can occupy the shared cache space of high-priority queues. The amount of shared cache space occupied by low-priority queues is constrained.
[0019] A further improvement is made in step S1, where different amounts of shared cache space are allocated to different priorities, including:
[0020] The shared cache space is allocated directly based on the number of queues with shared cache requirements within each priority level.
[0021] If there is no shared cache requirement for this priority level, then no shared cache space will be allocated to it.
[0022] A further improvement is made in step S1, which determines whether the shared cache space currently allocated to the priority is sufficient to accommodate the queue data packets. If it is sufficient, the remaining shared cache space for that priority is calculated. If it is insufficient, the shared cache space of other priorities is occupied according to the shared cache occupancy rules between priority queues.
[0023] Further improvements include rules for shared cache usage between priority queues: high-priority queues can share cache space with low-priority queues, and usage rules can be set as follows:
[0024] Use the lowest priority queue with available shared cache space to share the free area of the cache space;
[0025] Low-priority queues can also use the shared cache space of high-priority queues, with the following usage rules: if the shared cache space of a high-priority queue is used up to the limit of a predetermined condition, a low-priority queue can use the free shared cache space of that high-priority queue; a low-priority queue can use the shared cache space of the lowest-priority queue from the shared cache space of a high-priority queue that meets the usage rules.
[0026] A further improvement is made in step S1, where the process for allocating shared cache space among the priority queues is as follows:
[0027] First, calculate the shared cache space requirements of each priority queue. Then, following the principle of high to low priority, allocate the corresponding shared cache space to each priority queue in order of priority.
[0028] A further improvement, the method for each priority queue to occupy shared cache space includes the following steps:
[0029] Check the size of the shared and non-shared cache space corresponding to the priority of the queue, determine whether the currently allocated shared cache space can meet the caching requirements of the queue, and if it can meet the caching requirements of the queue, store the data packets in the queue into the shared cache space of the corresponding priority, and calculate the remaining shared cache space size.
[0030] If the queue caching requirement cannot be met, check if there is any low-priority queue with remaining shared cache space. If so, occupy the lowest priority queue with remaining shared cache space. If not, check if there is any high-priority queue with free shared cache space that meets the usage rules. If so, occupy the lowest priority queue with remaining shared cache space that can be occupied by the low-priority queue. If not, the queue cache space occupancy fails.
[0031] A further improvement is that if the remaining shared cache space of the priority of a queue is insufficient to store the data packet content of that queue, it can be occupied from the free shared cache space of other priority queues;
[0032] Determine if there is free cache space for the low-priority queue. If such a low-priority queue exists, select the lowest priority queue from all eligible priority queues and occupy its shared cache space.
[0033] In a further improvement, in step S4, the constraint is that the high-priority queue uses no more than a set condition for the shared cache space corresponding to its priority.
[0034] Among all high-priority queues that meet the occupancy rules, select the free shared cache space of the lowest-priority queue for occupancy;
[0035] The constraints on the amount of shared cache space occupied by low-priority queues include:
[0036] The amount of free shared cache space occupied by a low-priority queue from a high-priority queue cannot exceed the specified amount of free shared cache space occupied by that high-priority queue.
[0037] The beneficial effects of this invention are:
[0038] This invention divides the queues received by the chip into different priorities, fully considering the cache requirements of each priority level. Based on the cache requirements of each priority queue, it allocates corresponding shared cache space to each priority level and adjusts the specific usage of each priority queue according to the availability of its shared cache space. Simultaneously, it sets shared cache space occupancy rules between different priorities. While ensuring sufficient cache space for high-priority queues, it further improves the utilization rate of shared cache space. Attached Figure Description
[0039] Figure 1 This is a flowchart of the method for sharing cache space among multiple priority queues according to the present invention;
[0040] Figure 2 This is a diagram illustrating the rules for shared cache usage among priority queues. Detailed Implementation
[0041] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0042] Example 1
[0043] This invention proposes dividing incoming and outgoing data packets into multiple queues. Based on the importance of each queue, these queues are further divided according to priority, resulting in queues of different priorities with varying cache space requirements. Different shared cache spaces are allocated to different priorities based on their shared cache requirements. Furthermore, depending on the queue priority and shared space usage, the shared cache space of lower-priority queues can be used. Conversely, in certain situations, the shared cache space of higher-priority queues can be used. By prioritizing queues and allocating shared cache space according to the shared cache requirements of different priority queues, and by setting shared cache space allocation rules, the cache space for high-priority queues can be guaranteed, while simultaneously improving cache space utilization.
[0044] This invention allocates a corresponding shared cache space to each priority queue based on the cache requirements of each priority queue. Then, based on the current usage of the cache space of each priority queue, it occupies the remaining cache space of other priority queues or accommodates data packets of other priority queues, thereby dynamically adjusting the specific use of the shared cache space by each priority queue.
[0045] This invention divides data packets into queues with different priorities, and simultaneously collects information on the shared cache requirements of each priority queue, allocating corresponding shared cache space for each priority. Since the allocation and specific usage of cache space by priority differ, this invention considers queue priorities and their specific usage of shared cache space, setting methods and strategies for using shared cache between priority queues to improve the utilization rate of shared cache space.
[0046] I. For example Figure 1 As shown, the allocation process in the shared cache space includes:
[0047] The queues are divided into multiple priority levels: the chip's internal cache space includes two types: non-shared cache space and shared cache space. The queues received by the chip are divided into multiple priority levels, and corresponding shared cache space is allocated to different priorities. Different priorities correspond to different non-shared cache spaces and shared cache spaces.
[0048] Priority-based shared cache space allocation: This involves calculating the shared cache requirements of queues at different priorities and allocating corresponding shared cache space to each priority level. Various allocation methods can be used, such as allocating shared cache space directly based on the number of queues with shared cache requirements within each priority level. If a priority level has no shared cache requirements, then no shared cache space will be allocated to it.
[0049] In other words, it determines whether the shared cache space currently allocated to a priority is sufficient to accommodate queue data packets. If it is sufficient, it calculates the remaining shared cache space for that priority. If it is insufficient, it occupies the shared cache space of other priorities according to the shared cache occupancy rules between priority queues.
[0050] Priority queue shared cache usage rules: High-priority queues can share cache space with low-priority queues. Usage rules are set as follows:
[0051] Use the lowest priority queue with available shared cache space to share the free area of the cache space;
[0052] Low-priority queues can also use the shared cache space of high-priority queues, with the following usage rules: if the shared cache space of a high-priority queue is not more than half full (or other conditions), a low-priority queue can use the free shared cache space of that high-priority queue; a low-priority queue can use the shared cache space of the lowest-priority queue from the shared cache space of a high-priority queue that meets the usage rules.
[0053] II. Queue Priority Division
[0054] n is the number of queues, and s is the number of priority levels.
[0055] Queues are divided into different priorities. Multiple queues can be at the same priority. Clearly, n ≤ s. Different priorities correspond to different non-shared cache spaces and shared cache spaces.
[0056] III. Cache Space Allocation Strategy for Priority Queues
[0057] According to the present invention, the process of allocating shared cache space among priority queues is as follows:
[0058] First, calculate the shared cache space requirements of each priority queue. Then, following the principle of high to low priority, allocate the corresponding shared cache space to each priority queue in order of priority.
[0059] IV. Strategies for Priority Queues to Use Shared Cache Space
[0060] like Figure 2As shown, check the size of the shared and non-shared cache space corresponding to the priority of the queue, determine whether the currently allocated shared cache space can meet the caching requirements of the queue, and if it can meet the caching requirements of the queue, store the data packets in the queue into the shared cache space of the corresponding priority, and calculate the remaining shared cache space size;
[0061] If the queue caching requirement cannot be met, check if there is any low-priority queue with remaining shared cache space. If so, occupy the lowest priority queue with remaining shared cache space. If not, check if there is any high-priority queue with free shared cache space that meets the usage rules. If so, occupy the lowest priority queue with remaining shared cache space that can be occupied by the low-priority queue. If not, the queue cache space occupancy fails.
[0062] If some priority queues have free shared cache space while other priority queues are fully occupied, leaving no more free shared cache space to accommodate the data of the corresponding priority queues, and also preventing the use of shared cache space from other priorities, this results in a waste of shared cache space. Therefore, this invention establishes shared cache occupancy rules between priority queues, aiming to improve the utilization efficiency of shared cache space while ensuring the availability of high-priority queues.
[0063] according to Figure 2 The process involves allocating shared cache space to different priorities. The method for a queue to use shared cache space is as follows: if the remaining shared cache space of the priority of the queue is insufficient to store the data packet content of the queue, it can be occupied from the free shared cache space of other priority queues.
[0064] To ensure that high-priority queues have priority access to shared cache space, rules are set for queues to occupy the shared cache space of other priority queues:
[0065] First, determine whether there is free cache space for the low-priority queue. If such a low-priority queue exists, then select the shared cache space of the lowest priority queue among all eligible priority queues and occupy it.
[0066] At the same time, low-priority queues can also occupy space in high-priority queues, but they will take priority over high-priority queues. The rule for low-priority queues occupying free shared cache space in high-priority queues is as follows:
[0067] 1) There are multiple rules for determining whether a low-priority queue can occupy the free shared cache space of a high-priority queue. For example, the shared cache space used for the high-priority queue should not exceed half of its corresponding priority.
[0068] 2) There are multiple constraints on the space occupied by low-priority queues in high-priority queues; for example, the amount of free shared cache space occupied by low-priority queues cannot exceed half of the free shared cache space of the high-priority queue.
[0069] 3) Among all high-priority queues that meet the occupancy rules, select the free shared cache space of the lowest priority queue for occupancy.
[0070] This maximizes the use of shared cache resources while ensuring that high-priority queues utilize the cache space.
[0071] Example 2
[0072] Shared cache space allocation instance
[0073] C1 is the total capacity of the non-shared cache space, C2 is the total capacity of the shared cache space, {N1,N2,…Nn} is the set of all queues, and {S1,S2,…Ss} is the set of all priority queues.
[0074] First, divide the n queues into s priority levels. Assume n=10, s=5, and the 5 priority queues are S1={n1,n2}, S2={n3,n4,n5}, S3={n6,n7}, S4={n8,n9}, and S5={n10}. Let C1 be 10kB and C2 be 70kB. Each of the 5 priority queues has 2kB of non-shared cache space. This example uses a shared cache space allocation rule, allocating shared cache space to each priority based on the number of queues requesting shared cache. The shared cache space sizes for the 5 priority queues are 14kB, 21kB, 14kB, 14B, and 7KB, respectively.
[0075] Example 3
[0076] Each priority queue occupies a cache instance
[0077] Example 1: If the shared cache requirements of n queues are 4kB, 4kB, 4kB, 4kB, 8kB, 12kB, 8kB, 4kB, 4kB, and 5kB respectively, then the shared cache usage of the 5 priority queues is as follows:
[0078] Priority queue S1 has 8kB remaining, priority queue S2 has 7kB remaining, priority queue S3 requires an additional 4kB of space, priority queue S4 has 8kB remaining, and priority queue S5 has 4kB remaining. In priority queue S3, queue n7 cannot cache all its contents; therefore, the priority occupancy strategy of this invention is adopted to utilize the free shared buffer space in other priority queues to store the queue contents. Observation of priority queues S4 and S5 shows that the remaining free buffer space in both S4 and S5 can accommodate the remaining data packets of queue n7. To ensure that high-priority queues utilize the shared buffer space as much as possible, the remaining data of queue n7 is stored in the shared buffer allocated to priority queue S5.
[0079] Example 2: If the shared cache requirements of n queues are 4kB, 4kB, 4kB, 4kB, 8kB, 12kB, 8kB, 8kB, 8kB, and 9kB respectively, then the shared cache usage for the five priorities is as follows:
[0080] Priority queue S1 has 8kB remaining, priority queue S2 has 7kB remaining, priority queue S3 requires an additional 4kB of space, priority queue S4 has 0kB remaining, and priority queue S5 has 0kB remaining. At this moment, priority queue S3's cache space is insufficient. Checking the remaining shared cache space of other priority queues reveals that the cache space of low-priority queues is completely occupied, while the cache space of high-priority queues S1 and S2 is free and can accommodate the remaining data of queue n7. Priority queue S1 has 8kB of free shared cache space, and the total shared cache space is 14kB. The free shared cache space exceeds half of the total shared cache space, meaning that a maximum of 4kB of free cache space in priority queue S1 can be occupied by low-priority queues. Priority queue S2 has 7kB of free shared cache space, and the total shared cache space is 21kB. The remaining shared cache space is less than half of the total shared cache space, failing to meet the condition that it can be occupied by low-priority queues. Therefore, only the free cache space in priority queue S1 can be occupied by queue n7. Allocating the 4kB of priority queue S1 to queue n7, all data in all queues is now stored in the cache under the shared cache space allocation rules set in this invention.
[0081] Example 3: If the shared cache requirements of n queues are 4kB, 4kB, 2kB, 2kB, 2kB, 12kB, 8kB, 8kB, 8kB, and 9kB respectively, then the cache usage of the five priority queues is as follows: Priority queue S1 has 8kB remaining, priority queue S2 has 17kB remaining, priority queue S3 needs an additional 4kB of space, priority queue S4 has 0kB remaining, and priority queue S5 has 0kB remaining. Priority queue S2 has 17kB of free shared cache space, and the total shared cache space is 21kB. The free shared cache space exceeds half of the total shared cache space. The free cache space of priority queue S2 can also be occupied by lower priority queues, with a maximum capacity of 8.5kB. Since the free shared cache space of both priority queues S1 and S2 can be occupied by lower priority queues, the free shared cache space in the lower-priority priority queue S2 is chosen for queue n7 to occupy. At this moment, priority queue S2 has 13kB remaining, and only 4.5kB of free shared cache space can be occupied by lower priority queues. All queue data is stored in the cache under the shared cache space allocation rules set by this invention.
[0082] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for sharing cache space among multiple priority queues, characterized in that, Includes the following steps: S1. By dividing the data packets entering and leaving the buffer into multiple queues, and dividing the queues according to their importance, different priority queues are obtained. Different amounts of shared buffer space are allocated to different priorities. The allocation principle is to first ensure that the high priority queues have the need for shared buffer space. S2. Allocate corresponding shared cache space according to the shared cache requirements of each priority queue; S3. High-priority queues can occupy the free shared cache space of low-priority queues, and the occupancy is based on the principle of low to high priority. S4. Set constraints. When the constraints are met, low-priority queues can occupy the shared cache space of high-priority queues. The amount of shared cache space occupied by low-priority queues is constrained. In step S1, it is determined whether the shared buffer space currently allocated to the priority is sufficient to accommodate the queued data packets. If it is sufficient to accommodate the queued data packets, the remaining shared buffer space for that priority is calculated. If there are not enough packets to hold the queue, the shared cache space of other priority queues will be used according to the shared cache occupancy rules between priority queues. Priority queue shared cache usage rules: High-priority queues can share cache space with low-priority queues. Usage rules are set as follows: Use the lowest priority queue with available shared cache space to share the free area of the cache space; Low-priority queues can also use the shared cache space of high-priority queues, with the following usage rules: if the shared cache space of a high-priority queue is used up to the limit of a predetermined condition, a low-priority queue can use the free shared cache space of that high-priority queue; a low-priority queue can use the shared cache space of the lowest-priority queue from the shared cache space of a high-priority queue that meets the usage rules.
2. The method for sharing cache space among multiple priority queues according to claim 1, characterized in that: In step S1, the allocation methods for allocating different amounts of shared cache space to different priorities include: The shared cache space is allocated directly based on the number of queues with shared cache requirements within each priority level. If there is no shared cache requirement for this priority level, then no shared cache space will be allocated to it.
3. The method for sharing cache space among multiple priority queues according to claim 1, characterized in that: In step S1, the process of allocating shared cache space among priority queues is as follows: First, calculate the shared cache space requirements of each priority queue. Then, following the principle of high to low priority, allocate the corresponding shared cache space to each priority queue in order of priority.
4. The method for sharing cache space among multiple priority queues according to claim 1, characterized in that: The method for each priority queue to occupy shared cache space includes the following steps: Check the size of the shared and non-shared cache space corresponding to the priority of the queue, determine whether the currently allocated shared cache space can meet the caching requirements of the queue, and if it can meet the caching requirements of the queue, store the data packets in the queue into the shared cache space of the corresponding priority, and calculate the remaining shared cache space size. If the queue caching requirement cannot be met, check if there is any low-priority queue with remaining shared cache space. If so, occupy the lowest priority queue with remaining shared cache space. If not, check if there is any high-priority queue with free shared cache space that meets the usage rules. If so, occupy the lowest priority queue with remaining shared cache space that can be occupied by the low-priority queue. If not, the queue cache space occupancy fails.
5. A method for sharing cache space among multiple priority queues according to claim 1, characterized in that: If the remaining shared buffer space of the priority of the queue is insufficient to store the data packet content of the queue, it can be occupied from the free shared buffer space of other priority queues; Determine if there is free cache space for the low-priority queue. If such a low-priority queue exists, select the lowest priority queue from all eligible priority queues and occupy its shared cache space.
6. A method for sharing cache space among multiple priority queues according to claim 1, characterized in that: In step S4, the constraint is that the high-priority queue uses no more than a set condition for the shared cache space corresponding to its priority. Among all high-priority queues that meet the occupancy rules, select the free shared cache space of the lowest-priority queue for occupancy; The constraints on the amount of shared cache space occupied by low-priority queues include: The amount of free shared cache space occupied by a low-priority queue from a high-priority queue cannot exceed the specified amount of free shared cache space occupied by that high-priority queue.
Citation Information
Patent Citations
Shared cache distribution method and device
CN106330770A
Caching method and device
CN110493145A
Cited By
Port-aware shared cache priority allocation method and device and switch chip
CN122395164A