A pooling allocation and addressing method and system for processor-localized matrix counters

By organizing shared storage blocks into a matrix structure, efficient counter allocation and addressing are achieved, solving the problems of cache contention and memory fragmentation in high-concurrency write scenarios, and improving the throughput and execution efficiency of the counter.

CN123114744APending Publication Date: 2026-11-17SHANGHAI YINSHENG INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611285871.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-24
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

In high-concurrency write scenarios, global atomic counters lead to increased cache line contention and cache consistency traffic, while shard counters suffer from problems such as excessive allocation of small objects, memory fragmentation, and indirect hot path addressing.

Method used

The shared storage blocks are logically organized into a matrix structure. Each computing unit's local slot occupies a storage span no less than the cache line size, aligned according to the cache line boundaries. Multiple logical counters share the same matrix column, and counter updates and summaries are performed by direct addressing through base address and row mapping parameters.

Benefits of technology

It reduces cache line contention, decreases memory fragmentation, increases count update throughput, improves execution efficiency, simplifies memory management, avoids memory leak risks, and is suitable for high-concurrency scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123114744A_ABST
    Figure CN123114744A_ABST
Patent Text Reader

Abstract

This invention discloses a pooled allocation and addressing method and system for processor-localized matrix counters. The method logically organizes shared memory blocks into a matrix structure, with multiple local slots for computing units aligned to cache row boundaries along the row direction, and multiple logical counting columns along the column direction. In response to a counter allocation request, logical counting columns are allocated from the shared memory block for the counter to be allocated, generating a counter handle containing a base address and row mapping parameters. In response to an update operation, the target row is located based on the execution unit identifier and row mapping parameters, and the target counting slot address is calculated based on the base address, row index, column offset, and storage span, followed by an atomic update. In response to a summary read request, the count value is accumulated by traversing each slot along the column direction with the storage span as the step size. This invention reduces cache row contention for counting operations in multi-core environments, reduces counter memory allocation overhead, and improves system performance in high-concurrency counting scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer concurrent counting and concurrent data structure technology, specifically relating to a pooling allocation and addressing method and system for a processor-localized matrix counter. Background Technology

[0002] Concurrent containers typically need to maintain counting information such as the number of elements, the number of placeholders deleted, and migration progress. The most straightforward approach is to use a global atomic counter.

[0003] While global atomic counters are simple to implement, they present significant problems in high-concurrency write scenarios. Multiple processor cores repeatedly modify the same memory location, causing cache lines to move frequently between different cores. This leads to bus contention, increased cache coherency traffic, and a significant reduction in write throughput.

[0004] Another approach is to use sharded counters. Sharded counters split a logical counter into multiple local slots, with each execution unit updating its own slot, and all slots being aggregated when the total value is read. Sharded counters can reduce write contention, but the common implementation still has the following shortcomings: each logical counter is usually allocated a separate set of local slots; when there are many container instances, a large number of small objects or small arrays are generated; multiple logical counters are allocated separately, making it impossible to reuse the same cache line block; the counter handle may need to store multiple levels of pointers or slice information, and hot path addressing is not direct enough; if the underlying pool references old storage blocks for a long time, the storage blocks may not be reclaimed in time after the old counters are released.

[0005] Therefore, a new counter organization method is needed to merge multiple logical counters into a shared matrix block arranged in processor-local rows, and to allow each counter handle to directly locate its own column. Summary of the Invention

[0006] The purpose of this invention is to provide a pooling allocation and addressing method and system for a processor localized matrix counter, in order to solve the related technical problems in the background art.

[0007] To achieve the above objectives, the present invention adopts the following technical solution:

[0008] A pooling allocation and addressing method for a processor-localized matrix counter includes:

[0009] The shared storage blocks are logically organized into a matrix structure, wherein the row direction of the matrix structure consists of multiple local slots for computing units, the column direction consists of multiple logical counting columns, and the storage span occupied by each local slot for computing units is not less than the cache line size of the target processor, and the starting addresses of adjacent local slots for computing units are aligned according to the cache line boundary.

[0010] In response to a counter allocation request, at least one logical counter column is allocated from the shared memory block for the counter to be allocated, and a counter handle containing the base address of the allocated column in row zero and row mapping parameters is generated.

[0011] In response to an update operation on the target logical count column in the counter handle, the current execution unit identifier is obtained, the current execution unit identifier is mapped to the target row index according to the row mapping parameters, and the address of the target counting slot is calculated according to the base address, the target row index, the column offset of the target logical count column and the storage span, and an atomic update operation is performed on the target counting slot.

[0012] In response to the summary read request, the count values ​​in the local slots of each computing unit are read sequentially along the vertical direction of the target logical count column, with the storage span as the step size, and then accumulated to obtain the summary result.

[0013] In some embodiments, allocating at least one logical count column from the shared storage block for the counter to be allocated includes:

[0014] Enter the allocation mutual exclusion zone;

[0015] Check whether the number of remaining logical counter columns in the current shared storage block meets the requirements of the counter to be allocated;

[0016] If satisfied, allocate the corresponding number of logical count columns from the current shared storage block in ascending order of column number;

[0017] If the conditions are not met, a new shared storage block is created, and the allocation pointer is reset to the starting column of the new shared storage block, from which the corresponding number of logical count columns are allocated.

[0018] In some embodiments, it also includes:

[0019] Multiple counter handles are allocated their respective logical counter columns sequentially from the same shared memory block to enable multiple logical counters to share the underlying storage of the same matrix structure.

[0020] In some embodiments, the row mapping parameter is determined based on the number of local slots of the computing unit, wherein the number of local slots of the computing unit is a power of 2 obtained by rounding up the total number of current concurrent execution units, and the row mapping parameter is the number minus one.

[0021] The step of mapping the current execution unit identifier to the target row index according to the row mapping parameter specifically involves performing a bitwise AND operation between the current execution unit identifier and the row mapping parameter.

[0022] In some embodiments, the counter handle further includes a keep-alive reference to the shared memory block to which it belongs;

[0023] The keep-alive reference is used to keep the shared memory block reachable while the counter handle is alive, thereby preventing the automatic memory management mechanism from reclaiming the shared memory block.

[0024] In some embodiments, it also includes:

[0025] The counting pool only holds references to currently active shared storage blocks;

[0026] When the counter pool creates a new shared storage block and switches references due to insufficient space in the currently active shared storage block, the allocated counter handle maintains the lifecycle of the old shared storage block it belongs to through the keep-alive reference it holds;

[0027] When all counter handles pointing to the old shared memory block become unreachable, the automatic memory management mechanism reclaims the old shared memory block.

[0028] In some embodiments, in response to a summary read request, the count values ​​in the local slots of each computing unit are read sequentially along the vertical direction of the target logical count column, with the storage span as the step size, and accumulated to obtain a summary result, including:

[0029] Start from the starting address of the target logical count column described in row zero;

[0030] Each time the address offset of the storage span is increased, the slot value of the same logical count column in the next row is read;

[0031] This continues until all local slots of the compute units in the shared memory block to which the counter handle is bound have been traversed;

[0032] Add up all the slot values ​​read;

[0033] The summary result is an approximate snapshot value obtained within the traversal time window. Concurrent updates that occur during the traversal process may not be fully included in this summary result.

[0034] In some embodiments, a reset operation is also included:

[0035] In response to a reset request for the target logical counter column, atomic swap operations are performed sequentially along the vertical direction of the target logical counter column, with the storage span as the step size, to zero each local slot of the computing unit in the shared storage block to which the counter handle is bound, and the old value before the swap is accumulated, and the accumulation result is returned.

[0036] The reset operation is a non-atomic row-by-row scan process, and the returned accumulation result is an approximate snapshot value. The caller needs to be aware of the counting deviation that may be caused by the interleaving of concurrent updates and scans.

[0037] In some embodiments, it also includes:

[0038] When the number of concurrent execution units increases during operation, and multiple execution units are mapped to the same target row index through the row mapping parameter, the multiple execution units share the same local slot of the computing unit for count updates, and the access address does not exceed the address boundary of the local slot of the computing unit in the shared storage block.

[0039] This embodiment also provides a pooling allocation and addressing system for a processor-localized matrix counter, including:

[0040] A shared storage module is used to provide a storage space that is logically organized into a matrix structure. The matrix structure has multiple local slots for computing units in the row direction and multiple logical counting columns in the column direction. The storage span occupied by each local slot for computing units is not less than the cache line size of the target processor, and the starting addresses of adjacent local slots for computing units are aligned according to the cache line boundary.

[0041] The pool management module is used to, in response to a counter allocation request, allocate at least one logical counter column from the shared storage module for the counter to be allocated, and generate a counter handle containing the base address of the allocated column in row zero and row mapping parameters;

[0042] The direct addressing update module is used to respond to the update operation of the target logical count column in the counter handle, obtain the current execution unit identifier, map the current execution unit identifier to the target row index according to the row mapping parameters, and calculate the address of the target counting slot according to the base address, the target row index, the column offset of the target logical count column and the storage span, and perform an atomic update operation on the target counting slot.

[0043] The summarization module is used to respond to a summary read request by sequentially reading the count values ​​in the local slots of each computing unit along the vertical direction of the target logical count column, using the storage span as the step size, and accumulating them to obtain the summary result.

[0044] In some embodiments, the pool management module includes:

[0045] The mutex submodule is used to serialize the processing of counter allocation requests;

[0046] The space judgment submodule is used to check whether the number of remaining logical count columns of the current shared storage module meets the current allocation request;

[0047] The switching submodule is used to create a new shared storage module when the remaining columns of the current shared storage module are insufficient, and to reset the allocation pointer to the starting column of the new shared storage module.

[0048] In some embodiments, the shared storage module is configured as follows:

[0049] Multiple counter handles can be allocated consecutively in the same shared storage module, allowing multiple logic counters to share the underlying storage area of ​​the same matrix structure.

[0050] In some embodiments, the row mapping parameter is determined based on the number of local slots of the computing unit, wherein the number of local slots of the computing unit is a power of 2 obtained by rounding up the total number of current concurrent execution units, and the row mapping parameter is the number minus one.

[0051] The direct addressing update module maps the current execution unit identifier to the target row index according to the row mapping parameter, specifically by performing a bitwise AND operation between the current execution unit identifier and the row mapping parameter.

[0052] In some embodiments, the counter handle further includes a keep-alive reference to the shared memory module to which it belongs;

[0053] The keep-alive reference is used to keep the shared storage module reachable while the counter handle is alive, thereby preventing the automatic memory management mechanism from reclaiming the shared storage module.

[0054] In some embodiments, the pool management module only holds references to currently active shared storage modules;

[0055] When the pool management module creates a new shared storage module and switches references due to insufficient space in the currently active shared storage module, the allocated counter handle maintains the lifecycle of the old shared storage module it belongs to through the keep-alive reference it holds.

[0056] When all counter handles pointing to the old shared memory module become unreachable, the automatic memory management mechanism reclaims the old shared memory module.

[0057] In some embodiments, the summarization module takes the storage span as the step size, starts from the starting address of the target logical count column in row zero, and reads the slot value of the same logical count column in the next row by increasing the address offset of the storage span each time, until all local slots of the computing unit in the shared storage module bound to the counter handle are traversed, and all the slot values ​​read are added together.

[0058] The summary result is an approximate snapshot value obtained within the traversal time window.

[0059] In some embodiments, a reset module is further included, which, in response to a reset request for the target logical counter column, performs atomic swap operations to zero on each local slot of the computing unit in the shared storage module to which the counter handle is bound, with the storage span as the step size, and accumulates the old value before the swap and returns the accumulation result.

[0060] The reset operation is a non-atomic line-by-line scan process, and the returned accumulation result is an approximate snapshot value.

[0061] In some embodiments, when the number of concurrent execution units increases during operation, and multiple execution units are mapped to the same target row index through the row mapping parameter, the multiple execution units share the same local slot of the computing unit for counting updates, and the access address does not exceed the address boundary of the local slot of the computing unit in the shared storage module.

[0062] This embodiment also provides an electronic device, including a processor and a memory, wherein the memory stores a computer program, and the processor executes the computer program to implement any of the methods described above.

[0063] This embodiment also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the methods described herein.

[0064] Compared with common global counters or ordinary slice counters, the present invention has at least the following advantages:

[0065] 1. Multiple execution units write to different processor local lines. Since each line is arranged according to the cache storage span and the starting address is aligned with the cache line boundary, the write operations of different execution units act on different cache lines, thereby significantly reducing cache line contention for the global atomic counter and improving the count update throughput in high-concurrency scenarios.

[0066] 2. Each row is arranged according to the cache storage span, and there is no risk of address overlap or shared cache lines between adjacent rows. This reduces the false sharing between different execution units and allows the local counting slot of each execution unit to be cached independently without being invalidated by writes from other execution units.

[0067] 3. Multiple logical counters share the same matrix block by column, merging multiple small object allocations into a few large block allocations, reducing the number of allocations for small objects or small arrays, reducing the scanning and reclamation burden on the memory management system, and also reducing memory fragmentation.

[0068] 4. The counter handle stores the base address. The hot path directly locates the counting slot through an arithmetic combination of the base address, row mapping, and column offset. This eliminates the need for multi-level pointer indirect addressing or linked list traversal, reducing the number of instructions in the hot path and improving execution efficiency in high-frequency counting scenarios.

[0069] 5. The allocation mutex only exists in the cold path. The hot path does not need to enter the allocation mutex to increase the count. Therefore, the existence of the allocation logic will not cause any blocking or delay to the hot path, and the overall system throughput is not affected by the allocation operation.

[0070] 6. The summary read scans along the fixed cache storage span, and the address shows a regular arithmetic progression pattern, which helps the hardware prefetcher to load subsequent data into the cache in advance, thus improving the efficiency of the summary read.

[0071] 7. The reference pool only retains the current shared storage block, while the old shared storage blocks are kept alive by handles, which reduces the complexity of manual lifecycle management. Developers do not need to maintain an explicit reference count or call a release function for each storage block.

[0072] 8. When the old handle becomes unreachable, the old shared memory block can be reclaimed by the automatic memory management system. The timing of the memory block reclamation is automatically synchronized with the life cycle of the handle, without the need for additional reclamation coordination logic, thus avoiding the risk of memory leaks.

[0073] 9. Multiple counter groups can be stored adjacently in the same local line of the same processor, which is suitable for concurrent containers to maintain multiple statistics at the same time. Multiple related counters have good spatial locality when read.

[0074] 10. When the number of execution units changes, since the row mapping parameter is determined based on the number of rows as a power of 2, any execution unit identifier falls within the range of valid row subscripts after mask mapping, and addressing always remains safe, without out-of-bounds access. Attached Figure Description

[0075] Figure 1 This is a schematic diagram of the system module configuration provided in an embodiment of the present invention.

[0076] Figure 2 This is a flowchart of the core steps of the method of the present invention.

[0077] Figure 3 This is a schematic diagram of the pooling allocation process of the present invention.

[0078] Figure 4 This is a schematic diagram of the summary reading and hardware prefetching mechanism of the present invention. Detailed Implementation

[0079] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.

[0080] In the description of this invention, the term "computing unit" refers to a hardware or software execution context capable of independently executing a stream of instructions, including but not limited to physical processor cores, hardware hyperthreading, operating system threads, coroutines, or any concurrent execution unit managed by a runtime scheduler. The term "memory span" refers to a fixed address distance between the starting addresses of local slots of adjacent computing units, and its value is not less than the cache line size of the target platform. The term "keep-alive reference" refers to a reference type that can prevent the memory region it references from being reclaimed by the automatic memory management mechanism; in managed runtimes, it manifests as a strong reference, and in unmanaged environments, it can manifest as an atomic reference-counting handle. The term "counting pool" refers to the principal object that manages the allocation state and lifecycle of shared memory blocks.

[0081] See Figure 1 and Figure 2 To address cache line contention issues arising from frequent updates of the same global counter by multiple threads in a multi-core processor environment, and to reduce false sharing between different execution units, this invention logically organizes shared memory blocks into a matrix structure. The matrix structure has multiple local slots for multiple computing units along its rows and multiple logical counter columns along its columns. The storage span occupied by each local slot for a computing unit is no less than the cache line size of the target processor, and the starting addresses of adjacent local slots for computing units are aligned with cache line boundaries. Based on this, when the counter needs to be updated, each execution unit operates only on its corresponding matrix row. Since different rows reside in different cache lines, write operations from multiple execution units will not contend for the same cache line, thus eliminating frequent cache line transfers between cores. Aligning row starting addresses with cache line boundaries further ensures that false sharing does not occur between adjacent rows; even if a row is frequently written to, adjacent rows will not be accidentally loaded into the same cache line. Because the storage span is set to be no less than the cache line size, when the storage span equals the cache line size, each row occupies exactly one cache line; when the storage span is greater than the cache line size, each row occupies multiple cache lines. In either case, there is no possibility of sharing the same cache line between local slots of adjacent computing units, thus effectively strengthening the isolation effect.

[0082] In response to a counter allocation request, this invention allocates at least one logical count column from a shared memory block for the counter to be allocated, and generates a counter handle containing the base address of the allocated column in row zero and row mapping parameters. This reduces the number of memory allocations and memory fragmentation during the counter allocation phase. During allocation, multiple counter handles can be allocated their respective logical count columns consecutively from the same shared memory block, meaning that multiple logical counters share the underlying storage area of ​​the same matrix structure. Compared to the traditional method of allocating an array independently for each counter, this invention's column-based allocation method merges multiple small object allocations into a small number of large block allocations, significantly reducing the number of allocations and the scanning burden on the memory management system, while also reducing memory fragmentation.

[0083] This application aims to enable rapid location of the target counter slot in the hot path during counter update operations, avoiding performance overhead caused by multi-level pointer indirect addressing. In response to an update operation on the target logical counter column in the counter handle, the present invention obtains the current execution unit identifier, maps the current execution unit identifier to the target row index according to row mapping parameters, and calculates the address of the target counter slot based on the base address, target row index, column offset of the target logical counter column, and storage span. An atomic update operation is then performed on the target counter slot. This addressing process involves only bitwise operations and addition, avoiding time-consuming operations such as linked list traversal, hash lookup, or pointer dereferencing. The base address stored in the counter handle directly points to the starting position of the allocated column in row zero. The row mapping parameters provide a fast conversion from the execution unit identifier to the row index, and the column offset determines the position of different logical counters within the same row. The combination of these three factors allows each counter update to obtain the final memory address with only a few arithmetic operations, significantly shortening the execution time of the hot path.

[0084] To address the traversal problem of collecting data across multiple shards during summary reads, this invention, in response to a summary read request, sequentially reads and accumulates the count values ​​in the local slots of each computing unit along the vertical direction of the target logical count column, using the storage span as the step size, to obtain the summary result. Since the starting addresses of each row are arranged at equal intervals, when traversing slots in different rows of the same column, the addresses exhibit a regular arithmetic progression pattern. This memory access pattern is highly compatible with the cache prefetching mechanism of modern processors, effectively utilizing the hardware prefetcher to load subsequent data into the cache in advance, thereby improving the efficiency of summary reads. The summary result reflects the count status within the traversal time window, making it suitable for scenarios that do not require strong consistency, such as capacity judgment and statistical indicator monitoring of concurrent containers.

[0085] To separate the cold path of counter allocation from the hot path of counter update in the code execution path, ensuring the hot path is unaffected by allocation logic, this invention, when allocating logical count columns for the counter to be allocated from the shared memory block, first enters the allocation mutex area, then checks whether the number of remaining logical count columns in the current shared memory block meets the needs of the counter to be allocated. If it does, the corresponding number of logical count columns are allocated from the current shared memory block in ascending order of column number. If not, a new shared memory block is created, and the allocation pointer is reset to the starting column of the new shared memory block, starting the allocation of the corresponding number of logical count columns from the starting column. The allocation process only occurs when creating a new counter, and its frequency is much lower than that of the counter update operation. Therefore, even if the allocation process is serialized using a mutex lock, it will not affect the high-frequency counter update hot path. By placing the allocation logic under the protection of the mutex area, column number conflicts and out-of-bounds allocation problems that may occur during multi-threaded concurrent allocation are avoided. Since the counter update operation does not access the allocation mutex area, it will not be blocked due to allocation conflicts. This cold and hot path separation design ensures that the overall throughput of the system will not decrease due to the presence of allocation logic.

[0086] To ensure continued operation of existing counters even after a single shared memory block is full, this invention utilizes a counting pool that only holds references to currently active shared memory blocks. When the counting pool creates a new shared memory block and switches references due to insufficient space in the currently active shared memory block, the allocated counter handle maintains the lifecycle of its associated old shared memory block through its keep-alive reference. Each counter handle stores a keep-alive reference to its associated shared memory block during allocation. This reference ensures the shared memory block remains reachable during the counter handle's lifetime, preventing the automatic memory management mechanism from reclaiming the shared memory block. When all counter handles pointing to the old shared memory block become unreachable, the automatic memory management mechanism reclaims the old shared memory block. This mechanism eliminates the need to maintain explicit reference counting for each memory block and requires no manual call to the release function by the developer. Instead, it leverages the reachability analysis capabilities of the underlying automatic memory management system to achieve automatic memory block reclamation while ensuring data security, thus reducing the memory management burden on developers.

[0087] To clarify the traversal range and declare its approximation during summary reading, this application, in response to a summary read request, starts from the starting address of the target logical count column in row zero, increments by an address offset of one storage span each time, and reads the slot value of the same logical count column in the next row until all local slots of the computing unit in the shared storage block bound to the counter handle have been traversed. All read slot values ​​are then summed to obtain the summary result. This traversal range is limited to the shared storage block bound to the counter handle, meaning that cross-block summarization is not performed between different shared storage blocks, and each handle independently manages the data within its own block. Since other execution units may be concurrently updating certain slots during the summary traversal, the summary result obtained within the traversal time window is an approximate snapshot value; concurrent updates occurring during the traversal may not be fully included in the summary result. This approximation is acceptable in the capacity estimation scenario of concurrent containers, and this declaration helps the caller correctly understand and use the summary result, avoiding its misuse in business logic with strong consistency requirements.

[0088] This application aims to clear the count values ​​in all slices and return the total count before clearing when resetting a logical counter. It also clearly defines the non-atomic boundaries of this operation in the specification to guide the caller in correct use. In response to a reset request for a target logical counter column, the invention performs atomic swap-to-zero operations on each local slot of the computing unit in the shared memory block bound to the counter handle, with the storage span as the step size, along the vertical direction of the target logical counter column. The old value before the swap is then accumulated, and the accumulated result is returned. The atomic swap-to-zero operation ensures that reading and clearing a single slot are indivisible at the hardware level; that is, the old value read must be the value that existed in that slot at the moment before clearing. However, this reset operation itself is a row-by-row scanning serialization process. The entire scanning process is not atomic; there may be a time window between scanning the first and last rows, during which other execution units may be concurrently updating rows that have not yet been scanned or have already been scanned. Therefore, the returned accumulated result is an approximate snapshot value, and the caller needs to be aware of the counting deviation that may be caused by the interleaving of concurrent updates and scanning. For business scenarios that require precise reset, the caller should use a synchronization mechanism in conjunction with the reset operation.

[0089] To ensure addressing safety when the number of concurrent execution units dynamically increases during runtime, this application proposes a safety mechanism. When multiple execution units are mapped to the same target row index via row mapping parameters, they share the same local slot for counting updates, and the accessed address does not exceed the address boundary of that local slot in the shared storage block. The row mapping parameters are determined during the initialization of the counting pool and remain unchanged throughout the pool's lifetime. This ensures that addressing operations are always based on a fixed number of rows, preventing out-of-bounds access due to changes in the number of execution units. When multiple execution units are mapped to the same row, they share the cache line for that row. While some cache contention may occur, the system still operates correctly without memory out-of-bounds errors. This safety fallback mechanism ensures the stability and reliability of the system under various operating conditions.

[0090] To implement the above method, this application also provides a pooling allocation and addressing system for a processor localized matrix counter, including a shared storage module, a pool management module, a direct addressing update module, and a summarization module. The shared storage module provides a storage space logically organized in a matrix structure. The matrix structure has multiple local slots for computing units along its rows and multiple logical counter columns along its columns. Each local slot for a computing unit occupies a storage span no less than the cache line size of the target processor, and the starting addresses of adjacent local slots for computing units are aligned according to the cache line boundaries. The pool management module, in response to a counter allocation request, allocates at least one logical counter column from the shared storage module for the counter to be allocated, and generates a counter handle containing the base address of the allocated column in row zero and row mapping parameters. The direct addressing update module, in response to an update operation on the target logical counter column in the counter handle, obtains the current execution unit identifier, maps the current execution unit identifier to the target row index according to the row mapping parameters, calculates the address of the target counter slot based on the base address, target row index, column offset of the target logical counter column, and storage span, and performs an atomic update operation on the target counter slot. The summarization module, in response to a summarization read request, reads and accumulates the count values ​​in each local slot of the computing unit along the vertical direction of the target logical counter column, with the storage span as the step size, to obtain the summarization result. The connection relationships between the modules are as follows: the pool management module connects to the shared storage module to perform storage space allocation and management; the direct addressing update module connects to both the shared storage module and the pool management module to obtain storage space access permissions and handle information; and the aggregation module connects to the shared storage module to perform cross-row data reading and accumulation operations.

[0091] To achieve serialized processing of cold path allocation and automatic switching when storage space is insufficient at the system level, this application includes an allocation mutex submodule, a space judgment submodule, and a switching submodule in the pool management module. The allocation mutex submodule serializes the processing of counter allocation requests, ensuring that only one allocation operation modifies the allocation status of a shared storage module at any given time. The space judgment submodule checks whether the remaining logical count columns of the current shared storage module meet the current allocation request. The switching submodule creates a new shared storage module and resets the allocation pointer to the starting column of the new shared storage module when the remaining columns of the current shared storage module are insufficient. The three submodules work collaboratively: the allocation mutex submodule first obtains allocation permission, then the space judgment submodule evaluates whether the current block meets the requirements; if not, the switching submodule creates a new block and resets the allocation pointer, finally completing the column allocation under the same mutex protection.

[0092] To reduce memory allocation frequency by enabling multiple logic counters to share the underlying storage area of ​​the same matrix structure, this application configures the shared storage module to allow multiple counter handles to be allocated consecutively column-wise within the same shared storage module. This configuration is achieved by maintaining a monotonically increasing column allocation pointer in the shared storage module. Each allocation starts from the current pointer position and continuously allocates the required number of columns, then advances the pointer by the corresponding step. Each counter handle holds the base address of its allocated column, which points to the position of that column in the zero row of the matrix. Different handles are distinguished by column numbers and do not overlap.

[0093] To replace division or modulo operations with efficient bitwise operations when mapping execution unit identifiers to matrix row indices, this application uses efficient bitwise operations instead of division or modulo operations. The row mapping parameter is determined based on the number of local slots in the computing unit, which is a power of 2 (rounded up from the total number of concurrent execution units). The row mapping parameter is this number minus one. The direct addressing update module maps the current execution unit identifier to the target row index according to the row mapping parameter, specifically by performing a bitwise AND operation between the current execution unit identifier and the row mapping parameter. Since the number of rows is a power of 2, the binary form of the row mapping parameter (number of rows minus one) is all 1s in the lower bits. The result of the bitwise AND operation is equivalent to taking the modulo of the number of rows, but bitwise operations are much faster than division or modulo operations. This design saves several CPU instructions during each count update, resulting in significant performance gains in high-frequency counting scenarios.

[0094] To achieve lifecycle management of shared storage modules at the system level through a keep-alive reference mechanism, avoiding the complexity of manual reference counting, this application provides a keep-alive reference to the shared storage module it belongs to, as part of a counter handle. This keep-alive reference ensures the shared storage module remains reachable during the counter handle's lifetime, preventing the automatic memory management mechanism from reclaiming it. This keep-alive reference is set during handle allocation and points to the underlying storage area of ​​the shared storage module to which the handle belongs. As long as the handle itself is reachable, its keep-alive reference ensures the corresponding shared storage module remains reachable during the automatic memory management mechanism's reachability analysis, thus preventing its reclamation. This mechanism fully utilizes the memory management capabilities of the managed runtime, eliminating the need for developers to explicitly maintain reference counting or manually release memory.

[0095] To achieve a smooth transition between old and new shared storage blocks and automatic reclamation of old blocks at the system level, this application proposes a pool management module that only holds references to currently active shared storage modules. When the pool management module creates a new shared storage module and switches references due to insufficient space in the currently active shared storage module, the allocated counter handles maintain the lifecycle of their respective old shared storage modules through their keep-alive references. When all counter handles pointing to old shared storage modules become unreachable, the automatic memory management mechanism reclaims the old shared storage modules. During this process, the pool management module releases references to the old blocks, but the old blocks are not immediately reclaimed because the keep-alive references of the allocated handles keep them reachable. As business logic progresses, when all counter handles using the old blocks are destroyed or become unreachable, the old blocks lose all references, and the automatic memory management mechanism reclaims them. This design automatically synchronizes the timing of storage block reclamation with the lifecycle of the handles, eliminating the need for additional reclamation coordination logic.

[0096] To limit the traversal range and declare approximation in system-level summary readings, this application describes a summary module that uses a storage span as the step size. Starting from the beginning address of the target logical count column in row zero, it reads the slot value of the same logical count column in the next row, increasing the address offset by one storage span each time, until all local slots of the computing units in the shared storage module bound to the counter handle have been traversed. All read slot values ​​are then summed. The summary result output by this module is an approximate snapshot value obtained within the traversal time window; concurrent updates occurring during the traversal may not be fully included in this summary result. This approximation declaration helps system callers correctly understand the semantic boundaries of the interface.

[0097] To provide reset capabilities at the system level, this invention also includes a reset module. This module, in response to a reset request for a target logical counter column, performs atomic swaps to zero operations sequentially along the vertical direction of the target logical counter column, using the storage span as a step, on each local slot of the computing unit in the shared storage module to which the counter handle is bound. It then accumulates the old value before the swap and returns the accumulated result. The reset operation is a non-atomic row-by-row scan process, and the returned accumulated result is an approximate snapshot value. This reset module shares the same row traversal logic as the summarization module, the difference being that the reset module performs atomic swaps to zero on each slot during the traversal process instead of simply reading it.

[0098] To ensure addressing safety at the system level when the number of execution units dynamically increases, this invention addresses this issue. When the number of concurrent execution units increases during operation, and multiple execution units are mapped to the same target row index through row mapping parameters, these units share the same local slot of the computing unit for counting updates. Furthermore, the access address does not exceed the address boundary of the local slot of that computing unit in the shared storage module. This safety guarantee stems from the fact that the row mapping parameters are fixed during system initialization and remain unchanged. All addressing operations are based on these fixed parameters; therefore, regardless of changes in the execution unit identifier, the mapping result always falls within the valid row index range.

[0099] This application also provides an electronic device, including a processor and a memory, wherein a computer program is stored in the memory, and the processor executes the computer program to implement the above-described method. This electronic device can be a server, a personal computer, an embedded device, or any computing device requiring high concurrency counting capabilities.

[0100] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described method. The storage medium may be a read-only memory, a random access memory, a solid-state drive, a hard disk drive, or any other form of computer-readable storage medium.

[0101] The following detailed explanation will be illustrated with several specific embodiments.

[0102] Example 1

[0103] See Figure 1 and Figure 3 This embodiment describes a basic implementation of a pooling allocation and addressing method for a processor localized matrix counter.

[0104] The shared memory blocks are logically organized as a matrix. This matrix has N rows and M columns, where the rows correspond to multiple local slots for computing units, and the columns correspond to multiple logical count columns. Each row occupies a contiguous storage space of one cache line size (e.g., 64 bytes), and the starting address of each row is aligned to the cache line boundary. In this embodiment, assuming the target processor is an x86 architecture, the cache line size is 64 bytes, and the count slot width is 8 bytes (corresponding to a 64-bit atomic integer), then each row can accommodate 8 logical count columns.

[0105] When the system starts, the counting pool has not yet allocated any storage blocks. When the first counter request arrives, the pool management module first determines the number of local slots for the computing unit. In this embodiment, assuming the current system has 8 physical cores, the number of rows is 8, and the row mask is 7 (binary 0111). Subsequently, the counting pool creates a shared storage block with a size of 8 rows multiplied by 64 bytes per row, i.e., 512 bytes, with an additional 64 bytes reserved for alignment. After allocation, the starting column number of the current storage block is 0, available for subsequent allocation.

[0106] Suppose three counter allocation requests arrive sequentially: the first request allocates 1 column, the second allocates 2 columns, and the third allocates 1 column. The counter pool enters the allocation mutex area and processes these three requests in turn: the first handle obtains column 0, with its base address pointing to row 0, column 0; the second handle obtains columns 1 to 2, with its base address pointing to row 0, column 1; and the third handle obtains column 3, with its base address pointing to row 0, column 3.

[0107] Taking the second counter handle (with columns 1 and 2) as an example, assume the current execution unit identifier is 3. When an increment operation is needed on column 1 of this handle, the direct addressing module first calculates the row index using the row mapping parameters: a bitwise AND operation between 3 and 7, resulting in 3. Then, it calculates the target address: base address + 3 multiplied by 64 bytes + 1 multiplied by 8 bytes. An atomic addition operation is then performed on this address. Since the execution unit with identifier 3 only operates on row 3, while other execution units operate on other rows, and different rows reside in different cache lines, no cache line contention occurs.

[0108] When it is necessary to summarize the reading of column 1 of the handle, the summarization module starts from the address of row 0, column 1, and reads row 1, column 1, row 2, column 1, row 3, column 1, ... up to row 7, column 1, adds the eight values ​​read, and returns them. The summary result is an approximate snapshot value.

[0109] When a row in a shared memory block can hold 8 columns, and the current shared memory block has already been allocated 8 columns (columns 0 to 7), a new counter request requires 2 columns. The counter pool enters the allocation mutex area. The space judgment submodule checks that the current shared memory block has 0 remaining columns, less than 2 columns. Therefore, the switching submodule creates a new shared memory block with the same number of rows as the old block (still 8 rows), and resets the allocation pointer to row 0, column 0 of the new block. Subsequently, columns 0 to 1 are allocated from the new block to a new counter handle, whose base address points to row 0, column 0 of the new block. At this time, the old handle still holds a keep-alive reference to the old block, and the old block remains valid; the new handle holds a keep-alive reference to the new block, and the new block is referenced by the counter pool as the current block. When all old handles become unreachable, the old block is automatically reclaimed.

[0110] In this embodiment, the keep-alive reference is represented as a regular object reference (i.e., a strong reference) in the Java implementation, as a std::shared_ptr in the C++ implementation, and as an Arc in the Rust implementation. The automatic memory management mechanism is a garbage collector in Java, the destructor of shared_ptr in C++, and the memory release when the reference count of Arc drops to zero in Rust.

[0111] Example 2

[0112] This embodiment describes a specific implementation method for determining the number of rows, focusing on the number of rows raised to the power of 2 and its bitwise operation mapping mechanism.

[0113] Assuming the current system has 6 physical cores, rounding up to the power of 2 gives 8, the number of rows is set to 8, and the row mask is set to 7. The advantage of this design is that, regardless of whether the execution unit identifier is an incrementing integer or a sparsely distributed hardware identifier, any execution unit identifier can be mapped to a row index in the range of 0 to 7 through a bitwise AND operation.

[0114] Assume the system provides 12 logical execution units during runtime using hyper-threading. New execution unit identifiers (e.g., 10, 11) are bitwise ANDed using row mask 7: 10 ANDed with 7 yields 2, and 11 ANDed with 7 yields 3. Execution units with identifiers 10 and 2 are mapped to the same row (row 2), and execution units with identifiers 11 and 3 are mapped to the same row (row 3). At this point, rows 2 and 3 are shared by two execution units each. These execution units may experience cache line contention, but all addressing operations remain within the valid row index range, preventing out-of-bounds access. This safety fallback mechanism ensures stable system operation even when the number of execution units changes dynamically.

[0115] Example 3

[0116] This embodiment describes the specific working principle of the summary read operation, focusing on the utilization of the hardware prefetch mechanism by regular step-size access.

[0117] like Figure 4 As shown, assume the handle has a single column (column 0), 8 rows, and a storage span of 64 bytes. The aggregation module performs the following operations: initializes the total value to 0, sets the current address as the handle's base address (i.e., the address of row 0, column 0), and then executes a loop 8 times. In each loop iteration, it reads the 64-bit integer value at the current address and adds it to the total value, then increments the current address by 64 bytes. After the loop completes, it returns the total value.

[0118] During this process, because the addresses read between two adjacent reads differ by 64 bytes, the memory access pattern exhibits a regular arithmetic progression. The hardware prefetcher can recognize this pattern and preload data from subsequent rows into the L2 or L3 cache, thereby reducing cache misses. When the number of rows is large (e.g., 64 or 128 rows), the performance improvement brought by hardware prefetching is more significant. This effect is particularly pronounced on high-performance processors with strong hardware prefetching capabilities (such as the Intel Core series and AMD Zen series).

[0119] Example 4

[0120] This embodiment describes the specific working principle of the reset operation, focusing on illustrating its non-atomic semantic boundary through numerical simulation.

[0121] Suppose we need to perform a reset operation on column 1 of a handle, with 8 rows and a storage span of 64 bytes. The reset module performs the following operations: initializes the total value to 0, sets the current address to the handle base address + 1 multiplied by 8 bytes (i.e., the address of row 0, column 1), then executes a loop 8 times. In each loop, it performs an atomic swap operation to zero on the current address, adds the swapped old value to the total value, and then increments the current address by 64 bytes.

[0122] Taking specific numerical values ​​as an example, suppose the values ​​of column 1 in each row before the reset are: row 0 is 5, row 1 is 3, row 2 is 8, row 3 is 0, row 4 is 2, row 5 is 7, row 6 is 1, and row 7 is 4. The reset process scans from row 0 to row 7. When row 3 is scanned, its value is 0. After performing an atomic swap to zero, the return value is 0, and the total value remains unchanged. However, if, after scanning row 3 and before scanning row 4, an execution unit increases the value of row 3 from 0 to 1, since row 3 has already been cleared, this increase operation will make row 3 become 1. This 1 will not be included in the return value of this reset (because the old value was 0 when scanning row 3), but will be retained as the new value in row 3. This is a typical effect caused by the non-atomicity of the reset operation. The caller needs to be aware of this behavior when using the reset function. For reset scenarios that require precise totals, a synchronization mechanism should be used in conjunction with the reset operation.

[0123] Example 5

[0124] This embodiment describes an application scenario of multiple logic counter groups in a concurrent container.

[0125] In a concurrent hash table, three counters need to be maintained simultaneously: the number of occupied slots, the number of deleted tombstones, and the current migration progress. In this embodiment, these three counters are allocated consecutively from the same shared storage block, occupying columns 0, 1, and 2 respectively, forming three logical columns in the same counter handle.

[0126] When a hash table insertion operation occurs, the execution unit needs to increment both the occupied slot count and the migration progress count simultaneously. Since these two columns are located adjacent to each other in the same row (separated by column 1), their addresses are base address + row offset × 64 bytes + 0 × 8 bytes and base address + row offset × 64 bytes + 2 × 8 bytes respectively. Because both addresses reside within the same cache line, updating these two counters will hit the same cache line, exhibiting excellent spatial locality.

[0127] When the load factor of the current hash table needs to be read, the system calls a summary read operation to read the total values ​​of column 0 (number of occupied slots) and column 1 (number of deleted placeholders), calculates the effective number of slots = total value of column 0 - total value of column 1, and then compares it with the total capacity of the hash table to obtain the load factor. This load factor is an approximation, but it is sufficient for expansion decisions. Even with a small counting deviation, it will not affect the correctness of the expansion—expansion is usually triggered when the load factor reaches a threshold, and a small deviation only affects the timing of the expansion trigger, not the final correctness.

[0128] Example 6

[0129] This embodiment describes implementations of electronic devices and computer-readable storage media.

[0130] An electronic device includes a processor and a memory, wherein a computer program is stored in the memory. When executed by the processor, the computer program implements the method described in this invention. The electronic device can be a multi-core server, a cloud computing node, an edge computing device, or an embedded system. In a multi-core server scenario, the device typically has tens to hundreds of physical cores, with a corresponding number of rows, and the matrix storage space is allocated in shared memory, accessible to all cores.

[0131] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the methods described in this invention. The storage medium may be a solid-state drive, a hard disk drive, an optical disc, a USB flash drive, or an embedded multimedia card. The computer program may be stored in source code, bytecode, or machine code form, as long as it can be loaded and executed by a processor.

[0132] Example 7

[0133] This embodiment describes the specific structure of a processor-localized matrix counter pooling allocation and addressing system and the collaborative working principle between its modules.

[0134] The physical layout parameters (number of rows, storage span, column width) and initialization method of the shared storage module 100 and its internal storage blocks described in this embodiment are completely consistent with the matrix layout described in the aforementioned method embodiments one to six. The specific values ​​will not be repeated below, only the dynamic collaborative relationship between modules will be described.

[0135] like Figure 1 As shown, the system logically includes a shared storage module 100, a pool management module 200, a direct addressing update module 300, a aggregation module 400, and a reset module 500. The pool management module 200 further includes an allocation mutex submodule 210, a space judgment submodule 220, and a switching submodule 230.

[0136] The connection locations and data flow directions of each module are as follows:

[0137] The shared storage module 100 is the underlying storage foundation of the system. Internally, it maintains a dynamically allocated contiguous memory region, which is divided into one or more shared storage blocks (Block 0, Block 1, ...). Each shared storage block is organized in a matrix format, with the number of rows being a fixed power of 2, and the storage span being the size of a cache line. The pool management module 200 establishes a one-way reference connection with the currently active shared storage block in the shared storage module 100 through block reference pointers. Simultaneously, the pool management module 200 maintains a column allocation cursor to indicate the starting position of the next allocatable logical column in the currently active block.

[0138] The pool management module 200 is connected to the direct addressing update module 300, the aggregation module 400, and the reset module 500 via the control bus. It provides these three working modules with initialization data (including base address and row mask) of the allocated counter handles during counter allocation. The specific connection timing is as follows: After the pool management module 200 successfully allocates a new counter handle, it passes the handle's reference to the upper-layer application through the handle distribution interface. Simultaneously, the handle internally stores a keep-alive reference (strong reference / Arc) pointing to its corresponding shared storage block. This keep-alive reference establishes a two-way lifecycle binding relationship with the corresponding old or current block in the shared storage module 100—that is, if the handle holds the block, the block will not be reclaimed; even after the block is released by the pool, the handle can still maintain the block's survival.

[0139] The direct addressing update module 300 connects to the runtime environment interface of the current execution unit during operation to obtain the current execution unit identifier (such as CPU core ID or thread ID) in real time. When the upper-layer application calls the atomic update interface of this module, the direct addressing update module 300 first reads the base address and row mask of the target counter handle from the handle register connected to it; then, through the built-in bitwise operation logic unit, it performs a bitwise AND operation on the execution unit identifier and the row mask to generate the target row index; subsequently, it calculates "base address + row index × storage span + column number × slot width" through the address adder to obtain the final physical memory address; finally, it initiates an atomic addition instruction supported by the bus lock or cache coherency protocol at this address through the atomic operation execution engine. This module is directly connected to the shared storage module 100 through the memory bus, and all counter update operations are direct memory read and write operations, without going through the pool management module 200, thereby achieving physical isolation between hot and cold paths.

[0140] Both the summarization module 400 and the reset module 500 share the same address calculation logic as the direct addressing update module 300, but their execution modes differ. The summarization module 400 includes a step accumulator, whose input receives the target column number and handle base address, and whose control receives the row count parameter. Upon receiving the summarization trigger signal, the summarization module 400 generates a traversal address sequence in steps of storage span, reads the slot values ​​of each row from the shared storage module 100 through a read-only data channel, sums them in the internal accumulator register, and finally outputs the approximate snapshot value to the upper-layer callback interface.

[0141] The structure of the reset module 500 is similar to that of the summary module 400, but each of its read ports has an atomic swap execution unit connected in series. When the reset module 500 traverses to a certain row, this execution unit simultaneously performs two operations: reading the old value and writing zero, and then writes the zero value back to the corresponding slot in the shared memory module 100 through the write-back channel. The reset module 500 also includes an accumulator register to accumulate all the swapped old values, and returns the accumulated value after the traversal is complete.

[0142] The collaborative working mechanism of the allocation mutex submodule 210, the space judgment submodule 220, and the switching submodule 230 is as follows:

[0143] When the pool management module 200 receives an allocation request from an external counter, the request is first routed to the allocation mutex submodule 210. The allocation mutex submodule 210 interacts with the operating system scheduler through a mutex lock to ensure that only one allocation thread enters the critical section at a time. After successfully acquiring the lock, the space judgment submodule 220 is activated. It reads the column allocation cursor value of the currently active shared storage block and calculates the remaining column number by subtracting the current cursor value from the maximum number of columns per row. It then compares this remaining column number with the requested column number.

[0144] If the remaining number of columns meets the requirement, the space judgment submodule 220 directly updates the cursor value (increasing the requested number of columns) and refreshes the cursor update result through a memory barrier instruction to ensure that it is visible to other cores. If the remaining number of columns is insufficient, the space judgment submodule 220 sends a block switching trigger signal to the switching submodule 230. After receiving the signal, the switching submodule 230 requests a new contiguous memory region from the operating system memory manager, the size of which is "number of rows × storage span + cache line size". Then, it calculates the alignment base address of the memory region and creates a new shared storage block object. The switching submodule 230 atomically switches the active block pointer inside the pool management module 200 to point to the new shared storage block and resets the column allocation cursor to 0. While the switching submodule 230 modifies the active block pointer, it removes the reference to the old shared storage block from the internal reference count table of the pool management module 200. However, the keep-alive reference held by the already distributed counter handle remains valid, thus ensuring that neither the old nor the new block will be accidentally reclaimed prematurely during the switching process, achieving a safe switching with zero interruption.

[0145] Through the fixed connections and deterministic collaborative timing between the modules mentioned above, the system fully implements matrix layout, pooling allocation, direct addressing update, approximate aggregation, and automatic recycling based on keep-alive references at the physical level.

[0146] The above description is merely 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 pooling allocation and addressing method for a processor-localized matrix counter, characterized in that, include: The shared storage blocks are logically organized into a matrix structure, wherein the row direction of the matrix structure consists of multiple local slots for computing units, the column direction consists of multiple logical counting columns, and the storage span occupied by each local slot for computing units is not less than the cache line size of the target processor, and the starting addresses of adjacent local slots for computing units are aligned according to the cache line boundary. In response to a counter allocation request, at least one logical counter column is allocated from the shared memory block for the counter to be allocated, and a counter handle containing the base address of the allocated column in row zero and row mapping parameters is generated. In response to an update operation on the target logical count column in the counter handle, the current execution unit identifier is obtained, the current execution unit identifier is mapped to the target row index according to the row mapping parameters, and the address of the target counting slot is calculated according to the base address, the target row index, the column offset of the target logical count column and the storage span, and an atomic update operation is performed on the target counting slot. In response to the summary read request, the count values ​​in the local slots of each computing unit are read sequentially along the vertical direction of the target logical count column, with the storage span as the step size, and then accumulated to obtain the summary result.

2. The method according to claim 1, characterized in that, The step of allocating at least one logical count column from the shared storage block for the counter to be allocated includes: Enter the allocation mutual exclusion zone; Check whether the number of remaining logical counter columns in the current shared storage block meets the requirements of the counter to be allocated; If satisfied, allocate the corresponding number of logical count columns from the current shared storage block in ascending order of column number; If the conditions are not met, a new shared storage block is created, and the allocation pointer is reset to the starting column of the new shared storage block, from which the corresponding number of logical count columns are allocated.

3. The method according to claim 1, characterized in that, Also includes: Multiple counter handles are allocated their respective logical counter columns sequentially from the same shared memory block to enable multiple logical counters to share the underlying storage of the same matrix structure.

4. The method according to claim 1, characterized in that, The row mapping parameter is determined based on the number of local slots of the computing unit. The number of local slots of the computing unit is a power of 2 obtained by rounding up the total number of current concurrent execution units. The row mapping parameter is the number minus one. The step of mapping the current execution unit identifier to the target row index according to the row mapping parameter specifically involves performing a bitwise AND operation between the current execution unit identifier and the row mapping parameter.

5. The method according to claim 1, characterized in that, The counter handle also contains a keep-alive reference to the shared memory block to which it belongs; The keep-alive reference is used to keep the shared memory block reachable while the counter handle is alive, thereby preventing the automatic memory management mechanism from reclaiming the shared memory block.

6. The method according to claim 5, characterized in that, Also includes: The counting pool only holds references to currently active shared storage blocks; When the counter pool creates a new shared storage block and switches references due to insufficient space in the currently active shared storage block, the allocated counter handle maintains the lifecycle of the old shared storage block it belongs to through the keep-alive reference it holds; When all counter handles pointing to the old shared memory block become unreachable, the automatic memory management mechanism reclaims the old shared memory block.

7. The method according to claim 1, characterized in that, In response to the summary read request, the count values ​​in the local slots of each computing unit are read sequentially along the vertical direction of the target logical count column, using the storage span as the step size, and accumulated to obtain the summary result, including: Start from the starting address of the target logical count column described in row zero; Each time the address offset of the storage span is increased, the slot value of the same logical count column in the next row is read; This continues until all local slots of the compute units in the shared memory block to which the counter handle is bound have been traversed; Add up all the slot values ​​read; The summary result is an approximate snapshot value obtained within the traversal time window. Concurrent updates that occur during the traversal process may not be fully included in this summary result.

8. The method according to claim 1, characterized in that, Also includes a reset operation: In response to a reset request for the target logical counter column, atomic swap operations are performed sequentially along the vertical direction of the target logical counter column, with the storage span as the step size, to zero each local slot of the computing unit in the shared storage block to which the counter handle is bound, and the old value before the swap is accumulated, and the accumulation result is returned. The reset operation is a non-atomic row-by-row scan process, and the returned accumulation result is an approximate snapshot value. The caller needs to be aware of the counting deviation that may be caused by the interleaving of concurrent updates and scans.

9. The method according to claim 1, characterized in that, Also includes: When the number of concurrent execution units increases during operation, and multiple execution units are mapped to the same target row index through the row mapping parameter, the multiple execution units share the same local slot of the computing unit for count updates, and the access address does not exceed the address boundary of the local slot of the computing unit in the shared storage block.

10. A pooling allocation and addressing system for a processor-localized matrix counter, characterized in that, include: A shared storage module is used to provide a storage space that is logically organized into a matrix structure. The matrix structure has multiple local slots for computing units in the row direction and multiple logical counting columns in the column direction. The storage span occupied by each local slot for computing units is not less than the cache line size of the target processor, and the starting addresses of adjacent local slots for computing units are aligned according to the cache line boundary. The pool management module is used to, in response to a counter allocation request, allocate at least one logical counter column from the shared storage module for the counter to be allocated, and generate a counter handle containing the base address of the allocated column in row zero and row mapping parameters; The direct addressing update module is used to respond to the update operation of the target logical count column in the counter handle, obtain the current execution unit identifier, map the current execution unit identifier to the target row index according to the row mapping parameters, and calculate the address of the target counting slot according to the base address, the target row index, the column offset of the target logical count column and the storage span, and perform an atomic update operation on the target counting slot. The summarization module is used to respond to a summary read request by sequentially reading the count values ​​in the local slots of each computing unit along the vertical direction of the target logical count column, using the storage span as the step size, and accumulating them to obtain the summary result.