Atomic lock management method and device, NUMA system and storage medium
By configuring a local linked list unit for each NUMA node in the NUMA system and managing the atomic lock holding rights in the preset atomic lock rotation order, the problem of unfair application of atomic locks in the NUMA system is solved, and the probability of each node obtaining atomic lock holding rights is achieved, which improves the fairness of the system.
Patent Information
- Application Number
- CN202411803935.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-04-25
AI Technical Summary
In the prior art, different NUMA nodes in NUMA systems are not fair enough to apply for atomic lock holding rights, resulting in a higher probability of obtaining atomic lock holding rights with a node whose access path is closer to the management link list.
In the NUMA system, a local linked list unit is configured for each NUMA node. When any NUMA node needs to access the critical area, it adds information to the local linked list unit that represents the atomic lock holding right and enters spin waiting. When the node that currently occupies the atomic lock delivers the atomic lock holding right in the preset atomic lock rotation order, the NUMA node can obtain the atomic lock holding right.
The local linked list unit manages atomic lock applications to ensure that the access paths experienced by each NUMA node are consistent, and the atomic lock holding rights are rotated in a preset order. Each node has the same chance of obtaining atomic lock holding rights, which significantly improves the fairness of different NUMA nodes in the NUMA system for atomic lock holding rights.
Smart Images

Figure CN119883665A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an atomic lock management method, device, NUMA system and storage medium. Background Art
[0002] In the field of computer technology, atomic lock is a technology used to ensure data consistency and integrity. It is usually used in scenarios where multiple subjects share data. Atomic lock can ensure that certain operations will not be interrupted, thereby avoiding data competition and inconsistency. It is of great significance to ensure the security of accessing shared resources in a multi-threaded environment.
[0003] NUMA (Non-Uniform Memory Access) system is an asymmetric multi-processor architecture. In a NUMA system, it usually includes multiple NUMA nodes, each of which is configured with processors and local memory. The processor in any NUMA node can access the local memory and the processors of other NUMA nodes.
[0004] The prior art ensures the security of each NUMA node accessing shared data (i.e., critical section) through atomic locks. Specifically, the prior art creates a management linked list for each NUMA node, and manages the process of each NUMA node using the atomic lock through the management linked list. When any NUMA node needs to use the atomic lock, it needs to access the management linked list and insert application information into the management linked list to obtain the atomic lock ownership and then occupy the atomic lock.
[0005] The inventors have found that, in actual applications, different NUMA nodes in the same NUMA system have different access path distances experienced in the process of accessing the management linked list. The NUMA nodes that are closer to the management linked list on the access path have a greater probability of obtaining the atomic lock holding right first. Correspondingly, the NUMA nodes that are farther away from the management linked list on the access path have a much lower probability of obtaining the atomic lock holding right. The atomic lock management in the prior art is not fair enough. Summary of the invention
[0006] In view of this, the present application is dedicated to providing an atomic lock management method, device, NUMA system and storage medium to solve the problem in the prior art that different NUMA nodes in the NUMA system apply for atomic lock holding rights unfairly.
[0007] In a first aspect, the present application provides an atomic lock management method, which is applied to a NUMA system including at least two NUMA nodes, and each of the NUMA nodes is configured with a local linked list unit, and the method includes the following steps performed by any of the NUMA nodes:
[0008] When it is necessary to access the critical section, the first information representing the application for the atomic lock ownership is added to the local linked list unit and the spin wait is entered;
[0009] In response to the NUMA node currently occupying the atomic lock delivering the atomic lock holding right according to the preset atomic lock rotation order, the atomic lock holding right is obtained to occupy the atomic lock.
[0010] In an optional implementation manner, obtaining the atomic lock ownership right includes:
[0011] Get the current field value of the first field in the local linked list unit;
[0012] If the current field value is the first field value, determining to obtain the atomic lock holding right;
[0013] If the current field value is the second field value, it is determined that the atomic lock holding right is not obtained.
[0014] In an optional implementation, the linked list unit further includes a second field, and the second field is used to record the first information.
[0015] In an optional implementation, the first field and the second field are the same field.
[0016] In an optional implementation, the atomic lock management method provided in the first aspect of the present application further includes:
[0017] The atomic lock ownership is delivered to the next NUMA node that applies for the atomic lock ownership according to the preset atomic lock rotation order.
[0018] In an optional implementation, delivering the atomic lock ownership to the next NUMA node applying for the atomic lock ownership according to the preset atomic lock rotation order includes:
[0019] Determine the next NUMA node according to the preset atomic lock rotation order;
[0020] Determine whether the next NUMA node applies for atomic lock ownership;
[0021] If the next NUMA node applies for the atomic lock ownership, the atomic lock ownership is delivered to the next NUMA node;
[0022] If the next NUMA node does not apply for the atomic lock holding right, continue to determine whether other NUMA nodes apply for the atomic lock holding right according to the preset atomic lock rotation order until the atomic lock holding right is delivered or the atomic lock is released.
[0023] In an optional implementation, the linked list unit further includes a third field, and the third field is used to indicate the next NUMA node in the preset atomic lock rotation order;
[0024] Determining the next NUMA node according to the preset atomic lock rotation order includes:
[0025] The field value of the third field in the local linked list unit is extracted, and the next NUMA node is determined based on the field value of the third field.
[0026] In an optional implementation, determining whether the next NUMA node applies for atomic lock ownership includes:
[0027] Obtain current information of the linked list unit record of the next NUMA node;
[0028] If the current information includes the first information, determining that the next NUMA node applies for atomic lock holding right;
[0029] If the current information does not include the first information, it is determined that the next NUMA node has not applied for the atomic lock holding right.
[0030] In an optional implementation, the linked list unit includes a first field;
[0031] The delivering the atomic lock holding right to the next NUMA node includes:
[0032] A first field value representing the acquisition of the atomic lock holding right is written into the first field of the linked list unit of the next NUMA node.
[0033] In an optional implementation, the process of releasing the atomic lock includes:
[0034] A second field value indicating that the atomic lock holding right has not been obtained is written into the first field of the local linked list unit.
[0035] In an optional implementation, the atomic lock management method provided in the first aspect of the present application further includes:
[0036] When the atomic lock ownership is obtained, the critical section corresponding to the atomic lock is accessed based on the atomic lock.
[0037] In a second aspect, the present application provides an atomic lock management device, which is applied to a NUMA system including multiple NUMA nodes, and each of the NUMA nodes is configured with a local linked list unit, and the device includes in any of the NUMA nodes:
[0038] An application unit, used for adding first information representing the application for atomic lock ownership in a local linked list unit and entering spin waiting when access to a critical section is required;
[0039] The right confirmation unit is used to obtain the atomic lock holding right in response to the NUMA node currently occupying the atomic lock delivering the atomic lock holding right according to the preset atomic lock rotation order to occupy the atomic lock.
[0040] In a third aspect, the present application provides a NUMA system, comprising: at least two NUMA nodes, wherein:
[0041] Each of the NUMA nodes is locally configured with a linked list unit;
[0042] Any of the NUMA nodes is configured to execute the atomic lock management method as described in any one of the first aspects of the present application.
[0043] In a fourth aspect, the present application provides a computer-readable storage medium storing a computer program, which, when executed, implements the atomic lock management method as described in any one of the first aspects of the present application.
[0044] Based on the above content, the atomic lock management method provided by the present application is applied to a NUMA system, which includes at least two NUMA nodes, and each NUMA node is configured with a local linked list unit. When any NUMA node needs to access a critical section, it adds first information representing the application for atomic lock holding right in the local linked list unit and enters spin waiting. When the NUMA node currently occupying the atomic lock delivers the atomic lock holding right according to the preset atomic lock rotation order, the atomic lock holding right can be obtained, thereby occupying the atomic lock. The present application splits the management linked list in the prior art into linked list units configured locally in each NUMA node. When any NUMA node applies for atomic lock holding right, it only maintains its own linked list unit locally, thereby ensuring that the access path experienced by each NUMA node when applying for atomic lock holding right is consistent. At the same time, the atomic lock holding right is transferred according to the preset atomic lock rotation order, and the probability of each NUMA node obtaining the atomic lock holding right is also consistent. Therefore, compared with the prior art, the present application can significantly improve the fairness of different NUMA nodes in the NUMA system applying for atomic lock holding right. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0046] Figure 1 It is a schematic diagram of the structure of an atomic lock in the prior art.
[0047] Figure 2 This is a schematic diagram of the architecture of a NUMA system in the prior art.
[0048] Figure 3 This is a flow chart of an atomic lock management method provided by this application.
[0049] Figure 4 This is a flow chart of another atomic lock management method provided by this application.
[0050] Figure 5 This is a flow chart of another atomic lock management method provided by this application.
[0051] Figure 6 It is a schematic diagram of the linked list unit provided in this application.
[0052] Figure 7 This is a structural block diagram of an atomic lock management device provided by this application.
[0053] Figure 8 This is a structural block diagram of another atomic lock management device provided by this application.
[0054] Fig. 9 This is a structural block diagram of another atomic lock management device provided by the present application. DETAILED DESCRIPTION
[0055] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0056] In the field of computer technology, atomic lock is a technology used to ensure data consistency and integrity through atomic operations. The so-called atomic operation ensures that instructions are executed in an atomic manner and will not be interrupted during the execution process. It is usually used in scenarios where multiple subjects share data. Atomic locks can ensure that certain operations will not be interrupted, thereby avoiding data competition and inconsistency. It is of great significance to ensure the security of accessing shared resources in a multi-threaded environment.
[0057] In practical applications, atomic locks can effectively protect critical sections and avoid data contention problems caused by multiple threads accessing critical sections at the same time. A critical section refers to a section of code or a code block protected by an atomic lock. The critical section contains access or modification operations to shared resources. Only the processor or thread holding the atomic lock can access the critical section. Other processors or threads that do not hold the atomic lock cannot use the resources in the critical section, thereby avoiding concurrency conflicts and data contention. In practical applications, processors or threads that do not hold the atomic lock will try to hold the atomic lock according to the preset atomic lock rotation mechanism, which means that they will repeatedly check whether the lock is available without being suspended.
[0058] Taking the queue spin lock qspinlock provided by the Linux kernel in the prior art as an example, qspinlock is a lightweight lock suitable for the case where the access time to the critical section is very short. qspinlock performs well in multi-core systems, see Figure 1 As shown, qspinlock uses a union structure, which occupies a total of 32 bits, that is, 4 bytes. The specific structure of qspinlock is as follows:
[0059] The locked field occupies 8 bits from 0 to 7 and is used to indicate whether the lock is occupied. Generally, there are only two values: 1 and 0, where 1 indicates that the lock is occupied and 0 indicates that the lock is not occupied.
[0060] pending field: occupies two bits, 8 and 9, which can be understood as the highest priority lock bit. That is, when the locked field stores 0, the processor indicated by the pending field has the priority to occupy the lock.
[0061] Bits 10-15 are idle and are usually assigned a value of 0.
[0062] Bits 16-31 are the tail field, which indicates the last node (or the last processor) in the qspinlock rotation mechanism. Figure 1 As shown, the tail field is further subdivided into a tail idx field and a tailcpu field.
[0063] Tail idx field: occupies two bits 16 and 17. idx is index, which is used to indicate the node number of any processor that seizes the atomic lock. Therefore, any processor can be configured with a maximum of 4 nodes.
[0064] Tail cpu field: occupies 14 bits from 18 to 31, which are used to indicate which processor (usually using the processor number + 1) is spinning and waiting for the atomic lock. Therefore, a total of 16384 processors can be represented. As for why the processor number + 1 is used, please refer to the relevant technology and will not be described in detail here.
[0065] The locking process of qspinlock can be simply summarized as the following steps:
[0066] S1. If the overall value of qspinlock is 0 (of course, the locked bit is also 0), it means that the lock is idle, then the current processor (that is, the first processor to occupy the lock) sets the locked bit of qspinlock to 1 and directly occupies the lock;
[0067] S2, the first processor waiting for the lock sets the pending bit of qspinlock, indicating that it is the next processor to occupy the lock first, and then enters the spin-wait state, waiting for the locked bit to become 0;
[0068] S3, the second processor waiting for the lock sets the tail field of qspinlock to point to any node of this processor, and then spins and waits for both the locked field and the pending field to become 0;
[0069] S4. The Nth processor waiting for the lock also sets the tail field to point to any node of this processor, and points the next of the previous tail node to itself, and then spins and waits.
[0070] As for the specific locking, unlocking and rotation process of qspinlock, it can be implemented by referring to relevant technologies and will not be described in detail here.
[0071] Furthermore, the NUMA system is an asymmetric multi-processor architecture that allows many servers to operate like a single system while retaining the advantages of small systems that are easy to program and manage. In a NUMA system, it usually includes multiple NUMA nodes, each of which corresponds to its own memory controller and memory. Any NUMA node can access its own corresponding memory, and can also access the memory of any other node in the same NUMA system. According to the relationship between NUMA nodes, NUMA nodes can be divided into local nodes, neighbor nodes, and remote nodes. The speed at which the processor core accesses the memory of different types of nodes is different. The speed of accessing local nodes is the fastest, and the speed of accessing remote nodes is the slowest. That is, the access speed is related to the distance of the access path. The longer the distance, the slower the access speed.
[0072] In actual applications of NUMA systems, there are multiple optional implementations of NUMA nodes.
[0073] exist Figure 2 The NUMA system provided by the illustrated embodiment includes multiple processors (shown as processor 1 and processor 2), each processor includes multiple processor cores, and the processor cores of each processor are divided into different NUMA nodes, for example, NUMA node 1 and NUMA node 2 in processor 1, and NUMA node 3 and NUMA node 4 in processor 2.
[0074] In another optional implementation, the NUMA system includes a processor including multiple processor cores. The processor cores are divided into different groups, each group includes at least one processor core, and each group serves as a NUMA node.
[0075] It should be noted that no matter which method is used, each NUMA node is also configured with an independent memory controller, and the processor cores in the same NUMA node can share the memory controller. At the same time, the corresponding physical memory is configured for each NUMA node. Figure 2 As shown in the example, NUMA node 1 is configured with memory controller 1 and memory 1, NUMA node 2 is configured with memory controller 2 and memory 2, and so on, which will not be described in detail here. Furthermore, the NUMA system is also configured with a disk (such as a hard disk) for storing large amounts of data.
[0076] Each NUMA node can access the memory space of its own configured local memory through its corresponding memory controller, and can also access the memory space of other NUMA nodes. Combining the above content, it can be seen that the efficiency of any NUMA node accessing its own node memory is the highest, the efficiency of accessing the memory of neighboring nodes is second, and the efficiency of accessing remote nodes is the lowest.
[0077] As for the related implementation of the NUMA system which is not expanded in this application, please refer to the related technology and will not be described in detail here.
[0078] Based on the above content, it can be seen that in actual applications, the NUMA system has application requirements for different NUMA nodes to access the same shared resources. Based on this, the existing technology uses atomic locks to ensure the security of each NUMA node accessing shared data (i.e., critical section). Specifically, the existing technology creates a management linked list for each NUMA node, and manages the process of each NUMA node using the atomic lock through the management linked list. When any NUMA node needs to use the atomic lock, it needs to access the management linked list and insert the application information into the management linked list to obtain the atomic lock holding right, and then occupy the atomic lock and access the critical section.
[0079] The inventors have discovered that, in actual applications, different NUMA nodes in the same NUMA system experience different access path distances when accessing the management linked list. NUMA nodes that are closer to the management linked list on the access path have higher access efficiency and are therefore more likely to obtain atomic lock ownership rights first. Correspondingly, NUMA nodes that are farther from the management linked list on the access path have lower access efficiency and are therefore much more likely to obtain atomic lock ownership rights. That is to say, there is an unfairness problem in the atomic lock management in the prior art.
[0080] To solve the above problems, the present application provides a NUMA system including multiple NUAM nodes. It should be noted that the hardware architecture of the NUMA system provided by the present application and the optional configuration of each NUMA node can be found in Figure 2 As shown, it will not be repeated here. Different from the technical solution of creating a unique management linked list for each NUMA node in the prior art, and managing the use of atomic locks by each NUMA node through the management linked list, in the NUMA system provided by the present application, a linked list unit is locally configured for each NUMA node, and each NUMA node applies for atomic lock ownership according to the atomic lock management method provided by the present application. The present application splits the management linked list in the prior art into linked list units configured locally in each NUMA node. When any NUMA node applies for atomic lock ownership, it only maintains its own linked list unit locally, thereby ensuring that the access path experienced by each NUMA node when applying for atomic lock ownership is consistent. At the same time, the atomic lock ownership is transferred according to the preset atomic lock rotation order, and the probability of each NUMA node obtaining the atomic lock ownership is also consistent. Therefore, compared with the prior art, the present application can significantly improve the fairness of different NUMA nodes in the NUMA system applying for atomic lock ownership.
[0081] The atomic lock management method provided in this application is applied to the NUMA system provided in this application, and is specifically applied to any NUMA node in the NUMA system. Figure 3 The atomic lock management method provided in this application includes the following steps.
[0082] S100: When it is necessary to access the critical section, first information representing the application for atomic lock ownership is added to the local linked list unit and a spin wait is entered.
[0083] As mentioned above, in the NUMA system provided in the present application, a linked list unit stored locally is configured for each NUMA node. When the NUMA node needs to access the critical section to obtain shared resources in the critical section, the NUMA node adds first information to the local linked list unit, and uses the first information to represent that the NUMA node applies for atomic lock holding rights.
[0084] In an optional embodiment, the linked list unit carries relevant information by setting different fields. Based on this, the linked list unit includes a second field, and the NUMA node indicates whether to apply for atomic lock holding rights by maintaining the field value of the second field. That is, when the NUMA node writes the first information to the second field of the local linked list unit, it indicates that the NUMA node applies for atomic lock holding rights. Correspondingly, when the NUMA node writes other information or a null value other than the first information to the second field of the local linked list unit, it indicates that the NUMA node does not apply for atomic lock holding rights.
[0085] In an optional embodiment, the first information used to characterize the NUMA node's application for atomic lock holding rights can select the node identifier of the NUMA node, such as the NUMA node number, the processor serial number, or the processor core serial number. In another optional embodiment, the first information can also select a specific value. For example, when the NUMA node needs to access the critical section, the first value representing the application for atomic lock holding rights is written to the second field. When the critical section is not required to be accessed, the second value representing the non-application for atomic lock holding rights is written to the second field. Of course, it can also be other information that can uniquely characterize the corresponding NUMA node, which will not be described in detail here one by one, and it also belongs to the scope of protection of this application without exceeding the core idea of this application.
[0086] After the NUMA node adds the first information in the local linked list unit, it enters the spin wait, waiting for the NUMA node currently occupying the atomic lock to release the atomic lock holding right. In an optional implementation, the NUMA node applying for the atomic lock holding right can query whether the atomic lock holding right is obtained according to the preset self-selected cycle, and will not be suspended. As for the specific process of the NUMA node spin wait, it can be implemented with reference to the relevant technology, and this application does not make specific limitations on this.
[0087] S110 , in response to the NUMA node currently occupying the atomic lock delivering the atomic lock holding right according to a preset atomic lock rotation sequence, the atomic lock holding right is obtained to occupy the atomic lock.
[0088] After the NUMA node currently occupying the atomic lock completes the access to the critical area, it will release the atomic lock holding right. In order to ensure the fairness of each NUMA node in obtaining the atomic lock holding right, this application presets a preset atomic lock rotation order between NUMA nodes for each NUMA node, that is, specifies the order in which each NUMA node obtains the atomic lock holding right. The NUMA node currently occupying the atomic lock delivers the atomic lock holding right to the next NUMA node that applies for the atomic lock holding right specified by the preset atomic lock rotation order according to the preset atomic lock rotation order, so that the NUMA node obtains the atomic lock holding right. As mentioned above, the atomic lock holding right needs to be applied for by adding the first information to the local linked list unit, which means that the atomic lock holding right will only rotate between the NUMA nodes that apply for it, and the NUMA nodes that have not applied for it in the NUMA system will not obtain the atomic lock holding right. That is to say, although the preset atomic lock rotation order specifies the order in which each NUMA node obtains the atomic lock holding right, the rotation order indicates the basis for the rotation of the atomic lock holding right. The actual rotation process also needs to be determined in combination with whether each NUMA node applies for the atomic lock holding right.
[0089] For example, combining Figure 2 As shown, the NUMA system includes NUMA node 1, NUMA node 2, NUMA node 3, and NUMA node 4. The preset atomic lock rotation order is NUMA node 1 →
[0090] NUMA node 2 → NUMA node 3 → NUMA node 4 → NUMA node 1 (forming a closed loop), the atomic lock is currently occupied, that is, the atomic lock holding right is held by NUMA node 1, and at the same time, only NUMA node 3 and NUMA node 4 apply for the atomic lock holding right. In this case, when NUMA node 1 completes the critical section access, it will deliver the atomic lock holding right to NUMA node 3 that applied for the atomic lock holding right, instead of NUMA node 2, according to the preset atomic lock rotation order. As for the delivery process of the atomic lock holding right, it will be specifically expanded in subsequent embodiments and will not be described in detail here.
[0091] In response to the NUMA node currently occupying the atomic lock delivering the atomic lock ownership right according to the preset atomic lock rotation order, the first NUMA node applying for the atomic lock ownership right located after the NUMA node currently occupying the atomic lock according to the preset atomic lock rotation order will obtain the atomic lock ownership right, thereby occupying the atomic lock.
[0092] In an optional embodiment, the linked list unit of the NUMA node also includes a first field, which represents whether the corresponding NUMA node obtains the atomic lock holding right. Based on this, the NUMA node entering the spin-wait state repeatedly obtains the current field value of the first field in the local linked list unit. If the current field value obtained is the first field value, it is determined that it has obtained the atomic lock holding right. Correspondingly, if the current field value obtained is the second field value, it is determined that it has not obtained the atomic lock holding right.
[0093] In an optional implementation, the first field and the second field in the linked list unit can be the same field, which is used to apply for atomic lock ownership and also to receive atomic lock ownership delivered by other NUMA units, that is, when a NUMA node applies for atomic lock ownership, the first information is written to the field, such as the node ID of the NUMA node, and when the NUMA node currently occupying the atomic lock delivers the atomic lock ownership, the aforementioned first field value is written to the field. It can be understood that when the first field and the second field are the same field, the first information and the first field value and the second field value should be different contents, so as to accurately distinguish the information represented by the field in different states.
[0094] Furthermore, in the related art, there is a one-to-one correspondence between the atomic lock and the critical section. Only the critical section corresponding to the atomic lock can be accessed through an atomic lock. Based on this, after the NUMA node obtains the atomic lock ownership, that is, occupies the atom, the critical section corresponding to the atomic lock can be accessed based on the atomic lock. As for the specific implementation process of the NUMA node accessing the corresponding critical section based on the atomic lock to obtain the shared resources in the critical section, it can be implemented with reference to the related technology, and will not be described in detail here.
[0095] To summarize, the present application splits the management linked list in the prior art into linked list units configured locally on each NUMA node. Any NUMA node only maintains its own linked list unit locally when applying for atomic lock ownership, thereby ensuring that the access path experienced by each NUMA node when applying for atomic lock ownership is consistent. At the same time, the atomic lock ownership is transferred according to the preset atomic lock rotation order, and the probability of each NUMA node obtaining the atomic lock ownership is also consistent. Therefore, compared with the prior art, the present application can significantly improve the fairness of different NUMA nodes in the NUMA system applying for atomic lock ownership.
[0096] Furthermore, this application also provides another atomic lock management method, referring to Figure 4 As shown, in Figure 3 Based on the illustrated embodiment, the atomic lock management method provided in this embodiment further includes the following steps.
[0097] S120: Deliver the atomic lock ownership right to the next NUMA node that applies for the atomic lock ownership right according to a preset atomic lock rotation order.
[0098] As mentioned above, the preset atomic lock rotation order defines the rotation order of the atomic lock ownership between the NUMA nodes. After the NUMA node currently occupying the atomic lock completes the access to the critical section based on the obtained atomic lock, the atomic lock ownership is delivered to the next NUMA node that applies for the atomic lock ownership according to the preset atomic lock rotation order.
[0099] In an optional implementation, the delivery process of the atomic lock ownership can refer to Figure 5 shown.
[0100] S1201. Determine the next NUMA node according to a preset atomic lock rotation order.
[0101] Still Figure 2 Take the NUMA system shown in the figure as an example. The NUMA system includes four NUMA nodes. Assume that the preset atomic lock rotation order is NUMA node 1→NUMA node 2→NUMA node 3→
[0102] NUMA node 4, the NUMA node currently occupying the atomic lock is NUMA node 2, then NUMA node 2 will determine the next NUMA node according to the above preset atomic lock rotation order, that is, NUMA node 3. For another example, the NUMA node currently occupying the atomic lock is NUMA node 3, then the next NUMA node determined according to the preset atomic lock rotation order is NUMA node 4.
[0103] Based on the above content, the present application provides a method for carrying a preset atomic lock rotation order. In combination with the above embodiments, a third field is added to the linked list unit of each NUMA node, and the third field is used to indicate the next NUMA node in the preset atomic lock rotation order. Based on this, the NUMA node currently occupying the atomic lock will extract the field value of the third field in the local linked list unit, and determine the next NUMA node based on the record of the third field value.
[0104] As mentioned above, the present application configures a local linked list unit for each NUMA node in the NUMA system, and each NUMA node applies for atomic lock holding rights by maintaining the local linked list unit. Furthermore, in the present embodiment, a third field is added to the linked list unit, and the next NUMA node is indicated by the third field. Any NUMA node can determine the next NUMA node in the preset atomic lock rotation order by querying the local linked list unit. It can be seen that the linked list units of each NUMA node in the NUMA system are combined to realize the management of the atomic lock rotation process between all NUMA nodes in the NUMA system.
[0105] Still Figure 2 Taking the NUMA system shown in the figure as an example, the linked list units of each NUMA node in the system can be constructed as follows Figure 6 The management linked list shown in FIG. 1 manages the rotation process of atomic locks between NUMA nodes. Figure 6 In the illustrated scenario, the first field value, i.e., 1, is recorded in the first field of the linked list unit of NUMA node 1, indicating that the current NUMA node 1 obtains the atomic lock holding right, i.e., occupies the atomic lock. At the same time, the third field of the linked list unit of NUMA node 1 also records the next NUMA node in the preset atomic lock rotation order, i.e., NUMA node 2. Correspondingly, the next NUMA node recorded in the third field of NUMA node 2 is NUMA node 3, and so on. The subsequent rotation order is no longer described in detail. After NUMA node 1 completes access to the critical section based on the atomic lock, it can determine that the next NUMA node is NUMA node 2 by querying the local linked list unit.
[0106] It should be noted that in Figure 6 In the linked list unit shown, the first field and the second field of the linked list unit use the same field, and are both shown as the first field.
[0107] S1202, determine whether the next NUMA node applies for atomic lock ownership, if so, execute S1203, if not, execute S1204.
[0108] As mentioned above, when any NUMA node applies for the right to hold the atomic lock, it is necessary to add the first information representing the application for the right to hold the atomic lock to the local linked list unit. Based on this, after the NUMA node currently occupying the atomic lock determines the next NUMA node in the preset atomic lock rotation order through the aforementioned steps, it is necessary to further determine whether the next NUMA node applies for the right to hold the atomic lock. Specifically, the NUMA node currently occupying the atomic lock obtains the current information of the linked list unit of the next NUMA node. If the obtained current information includes the first information, it indicates that the next NUMA node applies for the right to hold the atomic lock. On the contrary, if the obtained current information does not include the first information, it indicates that the next NUMA node does not apply for the right to hold the atomic lock.
[0109] Continue to use Figure 6In the example shown, NUMA node 1 determines that NUMA node 2 is the next NUMA node in the preset atomic lock rotation order. Further, NUMA node 1 reads the current information of the first field of the linked list unit of NUMA node 2, and the obtained current information is the node identifier "NUMA2" of NUMA node 2. Based on this, it is determined that NUMA node 2 applies for the atomic lock holding right. On the contrary, if the first field in the linked list unit of NUMA node 2 records the empty value NULL, it is determined that NUMA node 2 does not apply for the atomic lock holding right.
[0110] S1203: Deliver the atomic lock ownership to the next NUMA node.
[0111] After determining that the next NUMA node applies for the atomic lock holding right, the NUMA node currently occupying the atomic lock will deliver the atomic lock holding right to the next NUMA node. As mentioned above, the NUMA node indicates whether the atomic lock holding right is obtained through the field value of the first field of the local linked list unit. Based on this, the NUMA node currently occupying the atomic lock writes the first field value, such as 1, into the first field of the local linked list unit of the next NUMA node applying for the atomic lock holding right, that is, the atomic lock holding right is delivered to the next NUMA node. Only when this NUMA node occupies the atomic lock can the critical area be accessed through the atomic lock. As for the specific implementation process of the NUMA node occupying the atomic lock, it can refer to the relevant technical implementation, and this application does not make specific limitations on this.
[0112] Continue to use Figure 6 In the example shown, NUMA node 1 updates the field value of the first field of the local linked list unit in NUMA node 2 from "NUMA2" to "1", that is, delivering the atomic lock ownership to NUMA node 2. It can be understood that, while completing the delivery of the atomic lock ownership, NUMA node 1 should also update the field value of the first field in the local linked list unit to NULL or the aforementioned first information (that is, applying for the atomic lock ownership again).
[0113] S1204, determine whether to traverse all NUMA nodes, if so, execute S1205, if not, return to execute S1201.
[0114] In S1202, if the next NUMA node in the preset atomic lock rotation order does not apply for the atomic lock holding right, the NUMA node currently occupying the atomic lock further determines whether all NUMA nodes in the NUMA system have been traversed. If all NUMA nodes have been traversed, S1205 is executed. If not all NUMA nodes have been traversed, it returns to execute S1201.
[0115] Assumptions Figure 6In the example shown, NUMA node 2 has not applied for the atomic lock ownership right. NUMA node 1 determines that it has not traversed all NUMA nodes, and will continue to determine the next NUMA node 3 according to the record of the linked list unit, and determine whether NUMA node 3 applies for the atomic lock ownership right. This cycle will be repeated until the atomic lock ownership right is delivered to the next NUMA node that applies for the atomic lock ownership right or S1205 is executed.
[0116] In an optional embodiment, the NUMA node currently occupying the atomic lock can count the number of NUMA nodes that have been queried. If the obtained statistical number is less than the total number of all NUMA nodes in the NUMA system, it can be determined that all NUMA nodes have not been traversed. On the contrary, if the obtained statistical number is equal to or greater than the total number of all NUMA nodes in the NUMA system, it is determined that all NUMA nodes have been traversed.
[0117] In another optional implementation, it may be possible to determine whether to traverse all NUMA nodes in conjunction with the linked list units of each NUMA node. Figure 6 As shown, the linked list units of each NUMA node point to the next NUMA node in turn, forming a closed loop order. Based on this, if NUMA node 1 currently occupying the atomic lock finds that the next NUMA node pointed to is itself based on the local linked list units of each NUMA node, that is, through the linked list unit of NUMA node 4, it is determined that the next NUMA node is NUMA node 1, then it can be determined that all NUMA nodes have been traversed.
[0118] S1205: Release the atomic lock.
[0119] After traversing all NUMA nodes, if the remaining NUMA nodes have not applied for the atomic lock ownership, the currently occupied atomic lock has not been able to successfully deliver the atomic lock ownership to other NUMA nodes. In this case, the NUMA node currently occupying the atomic lock will further release the atomic lock so that other NUMA nodes can occupy the atomic lock at any time according to their own needs in the subsequent process. As an optional implementation, the NUMA node currently occupying the atomic lock can write the second field value representing the failure to obtain the atomic lock ownership to the first field of the local linked list unit, thereby releasing the atomic lock. Figure 6 As shown in the example, if NUMA node 1 fails to deliver the atomic lock holding right to other NUMA nodes, "0" is written into the first field of the local linked list unit, and the atomic lock is released.
[0120] It is understandable that after releasing the atomic lock, no NUMA node in the NUMA system occupies the atomic lock. If any subsequent NUMA node needs to use the atomic lock, the first field value can be directly written into the first field of the local linked list unit to directly occupy the atomic lock.
[0121] To sum up, the atomic lock management method provided in this embodiment, based on the previous embodiment, can also realize the orderly delivery of atomic lock holding rights. The delivery process is implemented based on a preset atomic lock rotation order. The probability of each NUMA node obtaining the atomic lock holding right is the same and is not affected by the distance of the access path, which significantly improves the fairness of atomic lock rotation between NUMA nodes.
[0122] Furthermore, a linked list unit is configured in each NUMA node. Any NUMA node can not only apply for atomic lock ownership by maintaining the local linked list unit, but also indicate the next NUMA node based on the linked list unit. The linked list units of each NUMA node cooperate with each other to implement an atomic lock rotation cycle mechanism, which can ensure that the atomic lock rotates in an orderly manner between each NUMA node.
[0123] The atomic lock management device provided by the present invention is introduced below. The atomic lock management device provided by the present invention belongs to the same application concept as the atomic lock management method provided in the embodiment of the present application, and can execute the atomic lock management method provided in any embodiment of the present application, and has the corresponding functional modules and beneficial effects of executing the atomic lock management method. For technical details not described in detail in this embodiment, please refer to the atomic lock management method provided in the embodiment of the present application, and will not be repeated here.
[0124] The atomic lock management device provided by the present application is applied to a NUMA system including multiple NUMA nodes, and each NUMA node is configured with a local linked list unit. Figure 7 As shown, the atomic lock management device provided by this application includes:
[0125] The application unit 10 is used to add first information representing the application for atomic lock ownership in the local linked list unit and enter spin waiting when access to the critical section is required;
[0126] The right confirmation unit 20 is used to obtain the atomic lock holding right in response to the NUMA node currently occupying the atomic lock delivering the atomic lock holding right according to the preset atomic lock rotation sequence to occupy the atomic lock.
[0127] Furthermore, the present application also provides another atomic lock management device, see Figure 8 As shown, in Figure 7 Based on the embodiment shown, the atomic lock management device provided in this embodiment further includes:
[0128] The access unit 30 is used to access the critical section corresponding to the atomic lock based on the atomic lock when obtaining the atomic lock ownership right.
[0129] Furthermore, the present application also provides another atomic lock management device, see Fig. 9 As shown, in Figure 8 Based on the embodiment shown, the atomic lock management device provided in this embodiment further includes:
[0130] The rotation unit 40 is used to access the critical section corresponding to the atomic lock based on the atomic lock when obtaining the atomic lock ownership right.
[0131] In some embodiments, this embodiment further provides a computer-readable storage medium, such as a floppy disk, an optical disk, a hard disk, a flash memory, a USB flash disk, an SD (Secure Digital Memory Card) card, an MMC (Multimedia Card) card, etc., in which one or more instructions for implementing the above steps are stored. When the one or more instructions are executed by one or more processors, the processors execute the atomic lock management method described above. For the relevant specific implementation, please refer to the above description, which will not be repeated here.
[0132] In addition to the above-mentioned methods and devices, an embodiment of the present application may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the atomic lock management method according to various embodiments of the present application described in the above content of this specification.
[0133] The computer program product may be written in any combination of one or more programming languages to write program codes for performing the operations of the embodiments of the present application, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" language or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0134] Those skilled in the art will appreciate that the contents disclosed in this disclosure may be subject to various modifications and improvements. For example, the various devices or components described above may be implemented by hardware, or by software, firmware, or a combination of some or all of the three.
[0135] In addition, although the present disclosure makes various references to certain units in the system according to embodiments of the present disclosure, any number of different units can be used and run on the client and / or server. The units are only illustrative, and different aspects of the system and method can use different units.
[0136] Flowcharts are used in this disclosure to illustrate the steps of the method according to the embodiments of the present disclosure. It should be understood that the preceding or following steps are not necessarily performed precisely in order. On the contrary, various steps may be processed in reverse order or simultaneously. At the same time, other operations may also be added to these processes.
[0137] A person of ordinary skill in the art can understand that all or part of the steps in the above method can be completed by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, such as a read-only memory. Optionally, all or part of the steps in the above embodiment can also be implemented using one or more atomic lock management methods. Accordingly, each module / unit in the above embodiment can be implemented in the form of hardware or in the form of a software functional module. The present disclosure is not limited to any specific form of combination of hardware and software.
[0138] Unless otherwise defined, all terms used herein have the same meaning as commonly understood by those of ordinary skill in the art to which the present disclosure belongs. It should also be understood that terms such as those defined in common dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the relevant technology, and should not be interpreted in an idealized or highly formal sense, unless explicitly defined as such herein.
[0139] The above is an explanation of the present disclosure and should not be considered as a limitation thereof. Although several exemplary embodiments of the present disclosure are described, it will be readily understood by those skilled in the art that many modifications may be made to the exemplary embodiments without departing from the novel teachings and advantages of the present disclosure. Therefore, all such modifications are intended to be included within the scope of the present disclosure as defined in the claims. It should be understood that the above is an explanation of the present disclosure and should not be considered to be limited to the specific embodiments disclosed, and modifications to the disclosed embodiments and other embodiments are intended to be included within the scope of the appended claims. The present disclosure is defined by the claims and their equivalents.
Claims
1. An atomic lock management method, characterized in that: Applied to a NUMA system including at least two NUMA nodes, each of which is configured with a local linked list unit, the method includes the following steps performed by any of the NUMA nodes: When it is necessary to access the critical section, the first information representing the application for the atomic lock ownership is added to the local linked list unit and the spin wait is entered; In response to the NUMA node currently occupying the atomic lock delivering the atomic lock holding right according to the preset atomic lock rotation order, the atomic lock holding right is obtained to occupy the atomic lock.
2. The atomic lock management method according to claim 1, characterized in that: The said obtaining of the atomic lock holding right includes: Get the current field value of the first field in the local linked list unit; If the current field value is the first field value, determining to obtain the atomic lock holding right; If the current field value is the second field value, it is determined that the atomic lock holding right is not obtained.
3. The atomic lock management method according to claim 2, characterized in that: The linked list unit also includes a second field, and the second field is used to record the first information.
4. The atomic lock management method according to claim 3, characterized in that: The first field and the second field are the same field.
5. The atomic lock management method according to any one of claims 1 to 4, characterized in that: The method further comprises: The atomic lock ownership is delivered to the next NUMA node that applies for the atomic lock ownership according to the preset atomic lock rotation order.
6. The atomic lock management method according to claim 5, characterized in that: Delivering the atomic lock ownership right to the next NUMA node applying for the atomic lock ownership right according to the preset atomic lock rotation order includes: Determine the next NUMA node according to the preset atomic lock rotation order; Determine whether the next NUMA node applies for atomic lock ownership; If the next NUMA node applies for the atomic lock ownership, the atomic lock ownership is delivered to the next NUMA node; If the next NUMA node does not apply for the atomic lock holding right, continue to determine whether other NUMA nodes apply for the atomic lock holding right according to the preset atomic lock rotation order until the atomic lock holding right is delivered or the atomic lock is released.
7. The atomic lock management method according to claim 6, characterized in that: The linked list unit further includes a third field, and the third field is used to indicate the next NUMA node in the preset atomic lock rotation sequence; Determining the next NUMA node according to the preset atomic lock rotation order includes: The field value of the third field in the local linked list unit is extracted, and the next NUMA node is determined based on the field value of the third field.
8. The atomic lock management method according to claim 6, characterized in that: Determining whether the next NUMA node applies for atomic lock ownership includes: Obtain current information of the linked list unit record of the next NUMA node; If the current information includes the first information, determining that the next NUMA node applies for atomic lock holding right; If the current information does not include the first information, it is determined that the next NUMA node has not applied for the atomic lock holding right.
9. The atomic lock management method according to claim 6, characterized in that: The linked list unit includes a first field; The delivering the atomic lock holding right to the next NUMA node includes: A first field value representing the acquisition of the atomic lock holding right is written into the first field of the linked list unit of the next NUMA node.
10. The atomic lock management method according to claim 9, characterized in that: The process of releasing an atomic lock includes: A second field value indicating that the atomic lock holding right has not been obtained is written into the first field of the local linked list unit.
11. The atomic lock management method according to any one of claims 1 to 4, characterized in that: The method further comprises: When the atomic lock ownership is obtained, the critical section corresponding to the atomic lock is accessed based on the atomic lock.
12. An atomic lock management device, characterized in that: Applied to a NUMA system including a plurality of NUMA nodes, each of the NUMA nodes being configured with a local linked list unit, the device in any of the NUMA nodes comprising: An application unit, used for adding first information representing the application for atomic lock ownership in a local linked list unit and entering spin waiting when access to a critical section is required; The right confirmation unit is used to obtain the atomic lock holding right in response to the NUMA node currently occupying the atomic lock delivering the atomic lock holding right according to the preset atomic lock rotation order to occupy the atomic lock.
13. A NUMA system, characterized in that: include: At least two NUMA nodes, where Each of the NUMA nodes is locally configured with a linked list unit; Any of the NUMA nodes is configured to execute the atomic lock management method according to any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that: A computer program is stored, and when the computer program is executed, the atomic lock management method according to any one of claims 1 to 11 is implemented.