IP Library Granted Patent US 12,566,646
Granted Patent B2
US 12,566,646 · App. 17/587,663 · Granted Mar 3, 2026

Accessing critical resource in a non-uniform memory access (NUMA) system

Inventors: Chengguang Zheng (Shanghai, CN); Minqi Zhou (Shanghai, CN); Tong Yuan (Xi'an, CN)
Assignee: Huawei Technologies Co., Ltd.
G06F9/526G06F9/4881G06F9/5033
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 12,566,646
App. No.
17/587,663
Filed
Jan 28, 2022
Granted
Mar 3, 2026
Kind
B2
Art Unit
2195
USPC
718/104
Abstract

A method and an apparatus for accessing a critical resource, a computer device, and a readable storage medium are provided, to help reduce a quantity of operations for contending for a lock by a thread, and computing resources, and improve performance of an ARM processor. The method for accessing a critical resource includes: selecting a first thread from the first thread and a second thread to contend for a target lock ( 201 ), where a first task to be executed by the first thread and a second task to be executed by the second thread correspond to the target lock; and if the first thread obtains the target lock through contention, enabling the first thread to execute the first task, and replace the second thread to execute the second task ( 202 ).

Claims (56)

1 . A method for accessing a critical resource, comprising:

selecting a first thread from the first thread and a second thread to contend for a target lock, wherein a first task to be executed by the first thread and a second task to be executed by the second thread correspond to the target lock; and

when the first thread obtains the target lock through contention, enabling the first thread to execute the first task, and to replace the second thread to execute the second task, wherein the enabling the first thread to replace the second thread to execute the second task comprises:

executing, by the first thread, the second task based on an identifier that is of the second task and that is recorded in a data structure, wherein the identifier is an address of a task parameter of the second task, and wherein the task parameter comprises a size of a buffer occupied by a second log fragment for the second task.

2 . The method according to claim 1 , wherein the second thread is a thread that runs to the second task before the first thread obtains the target lock through contention.

3 . The method according to claim 1 , wherein a moment at which the first thread runs to the first task is earlier than a moment at which the second thread runs to the second task.

4 . The method according to claim 1 , wherein the method further comprises:

blocking the second thread.

5 . The method according to claim 4 , wherein the method further comprises:

unblocking the second thread when the first thread replaces the second thread to complete execution of the second task.

6 . The method according to claim 1 , wherein the first thread and the second thread are threads running on a same node of a non-uniform memory access (NUMA) system, the first task and the second task are used to access a buffer of the NUMA system, the buffer comprises a plurality of buffer areas, each buffer area corresponds to one lock, locks corresponding to the plurality of buffer areas are stored on a plurality of nodes in the NUMA system, and the target lock is a lock stored on the node.

7 . A method for accessing a critical resource in a non-uniform memory access (NUMA) system, wherein the method comprises:

running, by a node in the NUMA system, a target thread;

when the target thread runs to a target task, selecting, from a plurality of locks, a target lock stored on the node, wherein the target task is used to access a buffer of the NUMA system, the buffer comprises a plurality of buffer areas, and each of the plurality of locks corresponds to one buffer area, wherein the selecting, from the plurality of locks, the target lock stored on the node further comprises:

determining. based on a correspondence between each of the plurality of locks and a respective node on which the corresponding lock is located, that a particular lock is stored on the same node that runs the target thread, wherein the correspondence is determined based on a hash value of an identifier of each of the plurality of locks and a hash value of a respective node, and the plurality of locks are evenly distributed to a plurality of nodes in the NUMA system based on the hash value of the identifier of each of the plurality of locks and the hash value of each of the plurality of nodes in the NUMA system; and

selecting the particular lock as the target lock based on the determining; and

enabling the target thread to execute the target task when the target thread obtains the target lock through contention.

8 . The method according to claim 7 , wherein the method further comprises:

distributing the plurality of locks to a plurality of nodes in the NUMA system.

9 . The method according to claim 8 , wherein the method further comprises:

recording the correspondence between each of the plurality of locks and a node on which each lock is located.

10 . An apparatus for accessing a critical resource, comprising:

at least one processor; and

one or more memories coupled to the at least one processor and storing programming instructions for execution by the at least one processor to cause the apparatus to:

select a first thread from the first thread and a second thread to contend for a target lock, wherein a first task to be executed by the first thread and a second task to be executed by the second thread correspond to the target lock; and

when the first thread obtains the target lock through contention, enable the first thread to execute the first task, and to replace the second thread to execute the second task, wherein the enabling the first thread to replace the second thread to execute the second task comprises:

executing, by the first thread, the second task based on an identifier that is of the second task and that is recorded in a data structure, wherein the identifier is an address of a task parameter of the second task, and wherein the task parameter comprises a size of a buffer occupied by a second log fragment for the second task.

11 . The apparatus according to claim 10 , wherein the second thread is a thread that runs to the second task before the first thread obtains the target lock through contention.

12 . The apparatus according to claim 10 , wherein a moment at which the first thread runs to the first task is earlier than a moment at which the second thread runs to the second task.

13 . The apparatus according to claim 10 , wherein the programming instructions, when executed by the at least one processor, cause the apparatus to block the second thread.

14 . The apparatus according to claim 13 , wherein the programming instructions, when executed by the at least one processor, cause the apparatus to unblock the second thread when the first thread replaces the second thread to complete execution of the second task.

15 . The apparatus according to claim 10 , wherein the first thread and the second thread are threads running on a same target node of a non-uniform memory access (NUMA) system, the first task and the second task are used to access a buffer of the NUMA system, the buffer comprises a plurality of buffer areas, each buffer area corresponds to one lock, the NUMA system comprises a plurality of nodes, locks corresponding to the plurality of buffer areas are stored on the plurality of nodes in the NUMA system, and the target lock is a lock stored on the target node.

16 . An apparatus for accessing a critical resource in a non-uniform memory access (NUMA) system, wherein the apparatus is disposed on a node in the NUMA system, and the apparatus comprises:

at least one processor; and

one or more memories coupled to the at least one processor and storing programming instructions for execution by the at least one processor to cause the apparatus to:

run a target thread;

when the target thread runs to a target task, select, from a plurality of locks, a target lock stored on the node, wherein the target task is used to access a buffer of the NUMA system, the buffer comprises a plurality of buffer areas, and each of the plurality of locks corresponds to one buffer area, wherein the selecting, from the plurality of locks, the target lock stored on the node further comprises:

determining. based on a correspondence between each of the plurality of locks and a respective node on which the corresponding lock is located, that a particular lock is stored on the same node that runs the target thread, wherein the correspondence is determined based on a hash value of an identifier of each of the plurality of locks and a hash value of a respective node, and the plurality of locks are evenly distributed to a plurality of nodes in the NUMA system based on the hash value of the identifier of each of the plurality of locks and the hash value of each of the plurality of nodes in the NUMA system; and

selecting the particular lock as the target lock based on the determining; and

enable the target thread to execute the target task when the target thread obtains the target lock through contention.

17 . The apparatus according to claim 16 , wherein the programming instructions, when executed by the at least one processor, cause the apparatus to distribute the plurality of locks to a plurality of nodes in the NUMA system.

18 . The apparatus according to claim 17 , wherein the programming instructions, when executed by the at least one processor, cause the apparatus to record the correspondence between each of the plurality of locks and a node on which each lock is located.

19 . A non-uniform memory access (NUMA) system, wherein the NUMA system comprises a plurality of nodes and a plurality of buffer areas, each buffer area corresponds to one lock, and a plurality of locks corresponding to the plurality of buffer areas are stored on the plurality of nodes in the NUMA system; and

a target node of the NUMA system comprises

at least one processor; and

one or more memories coupled to the at least one processor and storing programming instructions for execution by the at least one processor to cause the target node to:

run a first thread, and select a target lock stored on the target node from the plurality of locks when the first thread runs to a to-be-executed first task, wherein the first task is used to access the buffer of the NUMA system, wherein the selecting, from the plurality of locks, the target lock stored on the node further comprises:

determining. based on a correspondence between each of the plurality of locks and a respective node on which the corresponding lock is located, that a particular lock is stored on the same node that runs the target thread, wherein the correspondence is determined based on a hash value of an identifier of each of the plurality of locks and a hash value of a respective node, and the plurality of locks are evenly distributed to a plurality of nodes in the NUMA system based on the hash value of the identifier of each of the plurality of locks and the hash value of each of the plurality of nodes in the NUMA system; and

selecting the particular lock as the target lock based on the determining.

20 . The NUMA system according to claim 19 , wherein the plurality of locks are evenly distributed on the plurality of nodes in the NUMA system.

21 . The NUMA system according to claim 19 , wherein the programming instructions, when executed by the at least one processor, cause the target node to run a second thread, select a target lock stored on the target node from the plurality of locks when the second thread runs to a to be executed second task, and the second task is used to access a buffer of the NUMA system; and

select the first thread from the first thread and the second thread to contend for the target lock, and when the first thread obtains the target lock through contention, enable the first thread to execute the first task, and to replace the second thread to execute the second task.

22 . The NUMA system according to claim 21 , wherein the programming instructions, when executed by the at least one processor, cause the target node to enable the first thread to execute the second task based on an identifier that is of the second task and that is recorded in a data structure.

23 . The NUMA system according to claim 21 , wherein the second thread is a thread that runs to the second task before the first thread obtains the target lock through contention.

24 . The NUMA system according to claim 21 , wherein a moment at which the first thread runs to the first task is earlier than a moment at which the second thread runs to the second task.

25 . The NUMA system according to claim 21 , wherein the programming instructions, when executed by the at least one processor, cause the target node to block the second thread, and unblock the second thread when the first thread replaces the second thread to complete execution of the second task.

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Dec 5, 2022
From: ZHENG, CHENGGUANG; ZHOU, MINQI; YUAN, TONG
To: HUAWEI TECHNOLOGIES CO., LTD.
Reel/Frame 061973/0391 →
Priority Claims (1)
CN 201910690999.X · Jul 29, 2019 · national
Continuity (2)
Continuation PCTCN2020103924 · Jul 24, 2020
Related Publication 20220147404A1 · May 12, 2022
References Cited (46)
US 5612865A · Dasgupta · 1997 [cited by examiner]
US 5699500A · Dasgupta · 1997 [cited by examiner]
US 6499031B1 · Hopmann · 2002 [cited by examiner]
US 6829609B1 · Wagner · 2004 [cited by examiner]
US 7409525B1 · Clark · 2008 [cited by examiner]
US 7509448B2 · Fachan · 2009 [cited by examiner]
US 7774645B1 · Clark · 2010 [cited by examiner]
US 7844973B1 · Dice · 2010 [cited by examiner]
US 8037476B1 · Shavit · 2011 [cited by examiner]
US 8332485B1 · Ben-Shaul · 2012 [cited by examiner]
US 8966491B2 · Calciu · 2015 [cited by examiner]
US 10248420B2 · Mukherjee · 2019 [cited by examiner]
US 10331500B2 · Mukherjee · 2019 [cited by examiner]
US 20040225742A1 · Loaiza · 2004 [cited by examiner]
US 20060129556A1 · Reuter · 2006 [cited by examiner]
US 20060224805A1 · Pruscino · 2006 [cited by examiner]
US 20060225077A1 · Anderson · 2006 [cited by applicant]
US 20060248127A1 · Whitehouse · 2006 [cited by examiner]
US 20080005112A1 · Shavit · 2008 [cited by examiner]
US 20100121865A1 · Vaid · 2010 [cited by examiner]
US 20100312850A1 · Deshpande · 2010 [cited by examiner]
US 20110106778A1 · Chan · 2011 [cited by examiner]
US 20120102501A1 · Waddington · 2012 [cited by examiner]
US 20130047011A1 · Dice · 2013 [cited by examiner]
US 20130290583A1 · Dice · 2013 [cited by examiner]
US 20130290967A1 · Calciu · 2013 [cited by examiner]
US 20140189039A1 · Dalton · 2014 [cited by examiner]
US 20150186057A1 · Das Sharma · 2015 [cited by examiner]
US 20160098303A1 · Balakrishnan · 2016 [cited by examiner]
US 20160224373A1 · Harris · 2016 [cited by examiner]
US 20170039094A1 · Dice · 2017 [cited by examiner]
US 20170220474A1 · Dice · 2017 [cited by examiner]
US 20180107514A1 · Dice · 2018 [cited by examiner]
US 20180198731A1 · Krauss · 2018 [cited by examiner]
US 20190075084A1 · Ding · 2019 [cited by examiner]
US 20190146845A1 · Shen · 2019 [cited by examiner]
US 20200097335A1 · Kogan · 2020 [cited by examiner]
US 20200319939A1 · Kim · 2020 [cited by examiner]
US 20210103576A1 · Chan · 2021 [cited by examiner]
US 20230244604A1 · Chaudhary · 2023 [cited by examiner]
CN 101685408A · 2010 [cited by applicant]
CN 104834505A · 2015 [cited by applicant]
CN 107077425A · 2017 [cited by applicant]
WO WO2017190594A1 · 2017 [cited by examiner]
Hendler et al., “Flat Combining and the Synchronization-Parallelism Tradeoff,” Proceedings of the 22nd Annual ACM Symposium on Parallelism in Algorithms and Architectures, Jun. 2010, 10 pages. [cited by applicant]
PCT International Search Report and Written Opinion issued in International Application No. PCT/CN2020/103924 on Oct. 27, 2020, 17 pages (with English translation). [cited by applicant]