A method and system for preferentially raising the priority of a specified process
By introducing a mapping relationship between a priority bitmap and a waiting queue in process lock scheduling, the problem of not being able to control the priority of a specified process lock in existing technologies is solved, achieving efficient lock resource allocation and real-time performance improvement, and ensuring priority acquisition of critical business processes.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA UNICOM DIGITAL TECNOLOGY CO LTD
- Filing Date
- 2026-04-30
- Publication Date
- 2026-06-02
AI Technical Summary
The existing process lock scheduling mechanism cannot achieve targeted priority control of specified process locks, resulting in critical business processes being unable to acquire lock resources first, low scheduling efficiency in high-concurrency scenarios, delays in scheduling high-priority processes, and insufficient real-time performance.
By maintaining the mapping relationship between the priority bitmap and the waiting queue, and using priority-based waiting lists and bitmap settings, the lock priority of a specified process is increased in a targeted manner. The priority bitmap represents the state of the waiting list through binary values. When the lock is released, the highest priority waiting process is found and the positions of the waiting processes are swapped, reducing the scheduling overhead.
It enables targeted control of specified process lock priorities, improves the real-time performance and operational stability of lock scheduling, reduces scheduling overhead, and ensures efficient allocation of process lock resources.
Smart Images

Figure CN122132199A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of process scheduling technology, and in particular to a method and system for targetedly increasing the priority of a lock for a specified process. Background Technology
[0002] Existing process lock scheduling mechanisms mostly use a single waiting queue to carry all waiting processes, which cannot achieve targeted control of lock priority for specified processes, and critical business processes cannot acquire lock resources first. Some priority-based scheduling schemes need to traverse all waiting processes to find the high-priority target after the lock is released, which is inefficient and prone to problems such as delay in high-priority process scheduling and insufficient real-time lock scheduling in high-concurrency scenarios. They cannot balance the directionality and efficiency of lock scheduling. Summary of the Invention
[0003] One objective of this application is to provide a method for targetedly increasing the lock priority of a specified process, thereby reducing scheduling overhead and improving the real-time performance and operational stability of lock scheduling while ensuring that the specified process acquires lock resources preferentially. Another objective of this application is to provide a system for targetedly increasing the lock priority of a specified process.
[0004] To achieve the above objectives, this application proposes a method for targeted elevation of the priority of a specified process lock, applied to a processor thread, the method comprising: Maintain the mapping relationship between priority bitmap and waiting queue. The waiting queue contains N waiting linked lists divided by priority. The priority bitmap includes multiple bitmap settings, each corresponding to a priority. Each bitmap setting uses a binary value to indicate whether there is a waiting process in the corresponding waiting linked list. When the binary value is the first value, the waiting linked list includes at least one waiting process with the same priority. When the binary value is the second value, the waiting linked list is empty.
[0005] When the process holding the process lock releases the lock, the process finds the binary value of the highest priority bitmap. If it is the first value, the process at the head of the corresponding waiting list is retrieved to hold the process lock.
[0006] Optionally, each bitmap is set according to its priority, and the bitmap with higher priority among two adjacent bitmaps is set as the first bitmap and the bitmap with lower priority is set as the second bitmap.
[0007] Before searching for the binary value of the highest priority bitmap set, the method further includes: For each first and second set bit, if the number of waiting processes already executed in the waiting list corresponding to the first set bit is greater than a set threshold, swap the waiting processes in the first m positions of the waiting lists corresponding to the first and second sets bit, and update the waiting lists of the first and second sets bit again.
[0008] Optionally, maintaining the mapping relationship between the priority bitmap and the waiting queue includes: Based on the total number of priorities preset by the system, a priority bitmap with corresponding bits is generated. The total number of bits set in the priority bitmap is consistent with the total number of priorities and the total number of waiting lists.
[0009] Each bitmap is assigned a unique priority identifier, and an independent waiting list is created for each priority identifier. The waiting list follows a first-in-first-out (FIFO) execution rule.
[0010] Establish a one-to-one binding relationship between the storage location of the bitmap setting, the priority identifier, and the memory starting address of the waiting list, and complete the mapping construction between the priority bitmap and the waiting queue.
[0011] Optionally, after maintaining the mapping relationship between the priority bitmap and the waiting queue, the method further includes: A basic priority matching the business attributes is preset for each process in the system, and the basic priority is uniquely associated with a bit setting in a priority bitmap.
[0012] Receive a priority-oriented configuration request for a specified process, parse the target priority parameter carried in the request, verify the legality of the target priority, update the base priority of the specified process to the target priority, and complete the targeted adjustment of the lock priority of the specified process.
[0013] Optionally, the set threshold and the m value of the first m positions are both dynamically adjusted according to the total number of system priorities and the real-time load of the business.
[0014] When the total number of system priorities increases, the set threshold value is simultaneously lowered and the m value is simultaneously increased. When the system's workload increases, the set threshold value is simultaneously lowered and the m value is simultaneously increased.
[0015] Optionally, swapping the waiting processes located in the first m positions of the waiting linked lists corresponding to the first and second set bits includes: Lock the write permissions of the two waiting lists corresponding to the first and second set bits, and prevent new waiting processes from being enqueued during the swapping process.
[0016] By using kernel atomic pointer operations, the positions of the first m waiting processes in two groups are swapped without modifying the business data and priority flags of the waiting processes themselves.
[0017] After the swap is completed, the write lock on the two waiting lists is released, and the head pointer and node length information of the two waiting lists are updated.
[0018] Optionally, after swapping the waiting processes located in the first m positions of the waiting linked lists corresponding to the first and second set bits, the method further includes: The second bit after the swap is completed is used as the new first bit, and the bitmap bit with a priority one level lower than the new first bit is used as the new second bit.
[0019] Determine whether the number of waiting processes already executed in the waiting list corresponding to the new first set bit is greater than a set threshold. If it is, perform the swap operation of the first m waiting processes in the waiting lists corresponding to the two sets of set bits.
[0020] Optionally, after retrieving the process lock held by the first waiting process in the corresponding waiting list, the method further includes: Remove the waiting process from the corresponding waiting list and complete the reconnection of the list nodes.
[0021] Real-time detection is performed to check if the waiting list is empty after removing the waiting process. If the list is empty, the binary value of the corresponding bitmap is updated to the second value. If the list is not empty, the binary value of the corresponding bitmap is kept as the first value.
[0022] Optionally, the binary value of the bitmap setting with the highest search priority includes: Starting from the highest priority bit in the priority bitmap, read the binary value of the bitmap bit by bit in descending order of priority.
[0023] When the first bitmap with the binary value of the first value is read, the traversal operation is terminated, and the bitmap with the highest priority is determined as the target bitmap with the highest priority.
[0024] Another aspect of this application discloses a system for targeted elevation of the priority of a specified process lock, comprising at least one processor thread and memory.
[0025] The memory stores computer-executable instructions, which, when executed by the processor thread, implement the method described above for targeted elevation of the priority of a specified process lock.
[0026] Beneficial effects: This scheme establishes a mapping relationship between a priority bitmap and a waiting queue containing multiple waiting lists divided according to priority. Each priority matches an independent waiting list and a corresponding bitmap setting. When in use, processes are assigned to the specified bitmap setting according to their preset priority. When a process fails to acquire a lock, it enters the corresponding waiting list based on its preset priority. When the lock is released, the binary value of the bitmap setting is read to locate the highest priority non-empty waiting list, and the process at the head of the list holds the lock. In this way, targeted control and efficient scheduling of lock priorities can be achieved without traversing the entire queue. This ensures that the specified process acquires the lock resource first, reduces scheduling overhead, and improves the real-time performance and operational stability of lock scheduling as a whole. Attached Figure Description
[0027] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In the drawings: Figure 1 A flowchart illustrating the method for targeted improvement of the priority of a specified process lock in this application embodiment.
[0028] Figure 2 This is a flowchart illustrating the process structure for maintaining the mapping relationship between the priority bitmap and the waiting queue in the method for targeted improvement of the priority of a specified process lock in this application embodiment.
[0029] Figure 3 This is a flowchart illustrating the process structure after maintaining the mapping relationship between the priority bitmap and the waiting queue in the method for targeted improvement of the priority of a specified process lock in this application embodiment.
[0030] Figure 4 The flowchart illustrates the process of swapping the first and second set bits in the waiting list corresponding to the first set bit and the second set bit in the method for targetedly increasing the priority of a specified process lock in this application embodiment.
[0031] Figure 5 This is a flowchart illustrating the process structure after swapping the waiting processes in the first m positions of the waiting list corresponding to the first and second set bits in the method for targetedly increasing the priority of a specified process lock in this application embodiment.
[0032] Figure 6 This is a flowchart illustrating the process structure after the waiting process at the head of the corresponding waiting list holds the process lock in the method for targetedly increasing the priority of a specified process lock in this application embodiment.
[0033] Figure 7This diagram illustrates the 10 priority levels in the method for targeted improvement of the priority of a specified process lock in this application embodiment.
[0034] Figure 8 This is a schematic diagram of a process with priority 10 scheduled in the method for targeted improvement of the priority of a specified process lock in this application embodiment.
[0035] Figure 9 This is a schematic diagram showing the state of processes with priority 10 and priority 9 after they are swapped in the method for targeted improvement of the priority of a specified process lock in the embodiments of this application. Detailed Implementation
[0036] Existing process scheduling technologies have many shortcomings and operational defects. On the one hand, they cannot achieve targeted control of lock priorities for specified processes, nor can they configure higher lock scheduling priorities for specified processes according to business needs, thus failing to meet the real-time requirements of critical business processes. On the other hand, after a lock is released, it is necessary to traverse all waiting processes to complete the target search. The computational load of the scheduling process increases with the number of waiting processes, and the scheduling efficiency decreases significantly in high-concurrency scenarios.
[0037] In order to solve at least one of the problems existing in the prior art, according to one aspect of this application, such as Figure 1 As shown in the figure, this embodiment discloses a method for targetedly increasing the priority of a lock for a specified process, the method comprising: S100: Maintain the mapping relationship between the priority bitmap and the waiting queue. The waiting queue contains N waiting lists divided by priority. The priority bitmap includes multiple bitmap settings, each corresponding to a priority. Each bitmap setting represents whether there is a waiting process in the corresponding waiting list through a binary value. When the binary value is the first value, the waiting list includes at least one waiting process with the same priority. When the binary value is the second value, the waiting list is empty.
[0038] In this embodiment of the application, the method for targetedly increasing the priority of a specified process lock first performs a mapping relationship maintenance operation between the priority bitmap and the waiting queue. For example... Figures 7 to 9The illustration shows a priority bitmap and a waiting list under each bit set in a specific embodiment. Not shown in the figure, each bit set in the priority bitmap uses a consecutive binary value to indicate whether a waiting process exists in the waiting list. Thus, the priority bitmap can display the waiting list status for each bit set through ordered binary strings. Specifically, each binary bit is an independent bitmap set, and each bitmap set corresponds to a preset priority level. The binary value of the bitmap set includes two states: a first value of 1, indicating that a waiting process exists in the waiting list corresponding to the corresponding priority; and a second value of 0, indicating that no waiting process exists in the waiting list corresponding to the corresponding priority. The storage length of the priority bitmap is determined by the total number of priorities preset by the system. Each priority level corresponds to a unique bitmap set, and the total number of bitmap sets is consistent with the total number of priorities. There will be no redundant empty bitmap sets, nor will there be a situation where a priority level has no corresponding bitmap set. This application will not elaborate further on this.
[0039] It should be noted that in this application, the first value is 1, indicating that there is a waiting process in the waiting list corresponding to the priority, and the second value is 0, indicating that there is no waiting process in the waiting list corresponding to the priority. Those skilled in the art can select the values according to actual needs. For example, the first value can be set to 0 and the second value can be set to 1. The judgment logic can be adjusted accordingly. This application does not limit this.
[0040] Specifically, the priority bitmap occupies a contiguous storage area in system memory. The starting address and length of this storage area are configured during system initialization. Once configured, the length of the storage area remains constant, only adjusting when the total number of priorities is changed. Each bit in the priority bitmap occupies a fixed position within this contiguous storage area. The position number and priority level value form a preset correspondence, established during the mapping phase. This correspondence remains unchanged, ensuring that during system operation, the corresponding bitmap position can be directly located using the priority level value without additional lookup operations. The wait queue is a storage structure in the system kernel used to hold waiting processes. It contains N priority-based linked lists, where N is the same as the system's preset total number of priorities. Each priority level corresponds to a unique linked list. Wait lists for different priority levels are independent and occupy separate storage areas in memory, preventing overlapping storage of waiting processes and ensuring no memory overlap between different wait lists. Each waiting list uses a kernel-standard doubly linked list structure. The list contains a head node and multiple data nodes. The head node stores the list's control information, including the list's length count, the number of scheduled processes, and the list's operation lock. The data nodes carry information about the waiting processes. Each data node corresponds to a unique waiting process, and there will never be a situation where one data node corresponds to multiple waiting processes.
[0041] S200: When the process holding the process lock releases the lock, find the binary value of the highest priority bitmap. If it is the first value, retrieve the waiting process at the head of the corresponding waiting list to hold the process lock.
[0042] In an optional implementation, each bitmap is set according to its priority, and the bitmap with higher priority among two adjacent bitmaps is set as the first bitmap and the bitmap with lower priority is set as the second bitmap.
[0043] Before searching for the binary value of the highest priority bitmap set, the method further includes: S000: For each first set bit and second set bit, if the number of waiting processes already executed in the waiting list corresponding to the first set bit is greater than a set threshold, swap the waiting processes in the first m positions of the waiting lists corresponding to the first set bit and the second set bit, and update the waiting lists of the first set bit and the second set bit again.
[0044] In this embodiment, after swapping the waiting processes of the first and second positions, the system performs a coordinated swapping operation across all priority levels. The system uses the swapped second position as the new first position, and the bitmap position with a priority one level lower than the new first position as the new second position. In a specific example, after swapping nodes with priority levels 10 and 9, the bitmap position corresponding to priority level 9 is used as the new first position, and the bitmap position corresponding to priority level 8 is used as the new second position. Subsequently, the system reads the scheduling counter value of the waiting list corresponding to the new first position and determines whether the value is greater than a set threshold. If the condition is met, the system performs a swapping operation on the first m waiting processes in the two sets of waiting lists. The swapping operation process is completely consistent with the aforementioned process. Similarly, the swapping operation can start from the highest priority level and pass down level by level until the lowest priority level, completing the linkage swapping of all priority levels. This allows scheduling opportunities to be passed down from the highest priority level to the lowest priority level, ensuring that waiting processes at all priority levels can obtain the corresponding scheduling opportunities and avoiding the starvation problem of low-priority processes.
[0045] Specifically, in the coordinated swapping process across all priority levels, the set threshold and m-value for each priority level can use system-wide uniform values or values configured independently for each level. For lower priority levels, a smaller set threshold and a larger m-value can be configured, allowing lower priority levels to trigger swapping operations with the next-level node more quickly, swapping more waiting processes each time, and further increasing the probability of the lowest priority process obtaining a scheduling opportunity. During the coordinated swapping process, if the waiting list for a certain priority level is empty, or the scheduling counter value has not reached the set threshold, the coordinated swapping process is terminated, and it will not continue to be passed to the next lower priority level, avoiding meaningless system calculations and reducing system resource consumption.
[0046] In alternative implementations, such as Figure 2 As shown, the mapping relationship between the maintenance priority bitmap and the waiting queue includes: S110: Generate a priority bitmap with corresponding bits according to the total number of priorities preset by the system. The total number of bits set in the priority bitmap is consistent with the total number of priorities and the total number of waiting lists.
[0047] In this embodiment, maintaining the mapping relationship between the priority bitmap and the waiting queue involves establishing a unique correspondence between the bitmap setting, the priority level, and the waiting list. This correspondence is implemented through a mapping table structure in the system kernel. The mapping table uses a linear array storage structure, where the array index corresponds one-to-one with the storage position number of the bitmap setting. Each element of the array contains two fields: the first field stores the identifier value of the corresponding priority level, and the second field stores the memory starting address of the corresponding waiting list head node. The mapping table completes memory allocation and data filling during the system initialization phase. After filling, the system can directly read the corresponding priority identifier and the starting address of the waiting list from the mapping table using the bitmap setting position number. The time complexity of the lookup process is constant, eliminating the need to traverse the entire mapping table and improving the efficiency of reading the mapping relationship.
[0048] S120: Assign a unique priority identifier to each bitmap setting bit, and create an independent waiting list for each priority identifier. The waiting list follows the first-in-first-out execution rule.
[0049] Specifically, each waiting list follows a first-in, first-out (FIFO) execution rule. The data node corresponding to a waiting process that fails to acquire the lock first is inserted at the end of the waiting list. Data nodes corresponding to waiting processes that fail to acquire the lock later are inserted after the existing tail node. During lock scheduling, the head node of the waiting list is retrieved first, and the corresponding process is scheduled to hold the lock. This ensures that waiting processes within the same priority level participate in scheduling according to the order in which they acquired the lock, maintaining scheduling fairness within the same priority level. The head node of the waiting list stores a list length counter, used to record the total number of data nodes currently existing in the list. Each time a new data node is inserted, the length counter is incremented by one; each time a scheduled data node is removed, the length counter is decremented by one. The system can directly obtain the total number of waiting processes in the corresponding waiting list by reading the length counter value, without traversing the entire list.
[0050] S130: Establish a one-to-one binding relationship between the storage location of the bitmap setting, the priority identifier and the memory starting address of the waiting list, and complete the mapping construction between the priority bitmap and the waiting queue.
[0051] Specifically, after the mapping relationship is constructed, the system will perform a mapping relationship verification operation. The verification process includes three parts. The first part is to verify whether the total number of bitmap bits set, the total number of priorities, and the total number of waiting lists are consistent. If the three values are inconsistent, the mapping relationship construction is determined to be abnormal, and the system will re-execute the mapping relationship construction process. The second part is to verify whether each bitmap bit set corresponds to a unique priority identifier and waiting list. There will not be a situation where one bitmap bit set corresponds to multiple priority identifiers or multiple waiting lists, nor will there be a situation where multiple bitmap bits set correspond to the same priority identifier or the same waiting list. The third part is to verify whether the memory regions of each waiting list are independent of each other. There will be no overlapping memory addresses. If overlapping occurs, memory space will be reallocated to the waiting lists until the memory regions of all waiting lists are completely separated.
[0052] In alternative implementations, such as Figure 3 As shown, after maintaining the mapping relationship between the priority bitmap and the waiting queue, the process further includes: S140: Preset a basic priority for each process in the system that matches the business attributes. The basic priority is uniquely associated with a bit setting in the priority bitmap.
[0053] S150: Receive a priority-oriented configuration request for a specified process, parse the target priority parameter carried in the request, verify the legality of the target priority, update the base priority of the specified process to the target priority, and complete the targeted adjustment of the lock priority of the specified process.
[0054] In this embodiment, after maintaining the mapping relationship between the priority bitmap and the waiting queue, the system also performs process priority preset and targeted adjustment operations. The system presets a base priority for each process that matches its business attributes. Business attributes include the process's business type, real-time requirements, and run level. Processes with high real-time requirements are preset with higher base priorities, while processes running in the background with low real-time requirements are preset with lower base priorities. The base priority preset operation is performed during process creation. The system automatically assigns a corresponding base priority to the process based on the process creation parameters and business type, and stores the base priority value in the process's process control block. The process control block is a structure in the system kernel used to store all process running information. The system can directly locate the corresponding process's process control block through the process number and read the stored base priority value. Each process's base priority uniquely corresponds to a bit in the priority bitmap. When a process fails to acquire a lock subsequently, it will enter the corresponding priority's waiting list based on the base priority value. It will not enter multiple waiting lists simultaneously, nor will it enter a waiting list that does not match its base priority.
[0055] It should be noted that the system receives priority-oriented configuration requests for a specified process. These requests are sent by upper-layer applications or system management processes via system calls, carrying the process ID of the specified process and the target priority parameter. Upon receiving the request, the system first parses the parameters, extracting the process ID and target priority parameter. Then, it performs a validity check on the target priority. This check includes two parts: first, verifying whether the target priority value is within the system's preset priority range; if it exceeds this range, it is deemed invalid, and a parameter error notification is returned to the request sender; second, verifying whether the request sender has the permission to modify the specified process's priority. Only processes with system management privileges can modify the priorities of other processes; ordinary processes can only modify their own priorities and do not have permission to modify the priorities of other processes. If the permission check fails, a permission deficiency notification is returned to the request sender.
[0056] In an optional implementation, the set threshold and the m value of the first m positions are both dynamically adjusted according to the total number of system priorities and the real-time load of services.
[0057] In this embodiment, a threshold is set as a system-preset scheduling threshold to control the triggering frequency of adjacent priority node swaps. The initial value of the threshold is configured during system initialization and can be modified by the user through the kernel configuration interface. The first m digits represent the system-preset node swap quantity, used to control the number of waiting processes swapped between the two waiting lists in each swap operation. The initial value of m is also configured during system initialization and can be modified through the kernel configuration interface. The initial configuration of the threshold and m value can be adjusted according to the system's hardware resources and business operation requirements. In scenarios with sufficient hardware resources and high real-time requirements, the threshold can be configured to a larger value and the m value to a smaller value to ensure the scheduling priority of high-priority processes. In scenarios with limited hardware resources and high requirements for scheduling balance, the threshold can be configured to a smaller value and the m value to a larger value, allowing low-priority processes to obtain more scheduling opportunities.
[0058] When the total number of system priorities increases, the set threshold value is simultaneously lowered and the m value is simultaneously increased. When the system's workload increases, the set threshold value is simultaneously lowered and the m value is simultaneously increased.
[0059] Specifically, the threshold and the value of m for the top m priorities are dynamically adjusted based on the total number of system priorities and the real-time business load. During system operation, changes in the total number of priorities and the real-time business load are monitored in real time. When a change in the total number of priorities or the real-time business load is detected, the threshold and m values are automatically recalculated and the parameters are updated. When the total number of system priorities increases, the system synchronously lowers the threshold and increases the m value. The more priorities there are, the more low-priority levels there are, and the lower the probability that each low-priority level can obtain a scheduling opportunity. Lowering the threshold allows high-priority levels to trigger node swapping operations faster, while increasing the m value allows more low-priority processes to enter the waiting list of high-priority processes in each swapping operation, increasing the probability that low-priority processes will be scheduled. When the real-time load of the system increases, the system synchronously lowers the value of the set threshold and simultaneously increases the value of m. The increase in real-time load means that the competition for lock resources is more intense, the total number of waiting processes is greater, the probability of high-priority processes continuously entering the waiting list is higher, and low-priority processes are less likely to get scheduling opportunities. Lowering the set threshold and increasing the value of m can allow low-priority processes to get the opportunity to enter the high-priority waiting list more quickly, ensuring the balance of system scheduling.
[0060] It should be noted that the dynamic adjustment of the threshold and the value of m has corresponding upper and lower limits. The minimum value of the threshold is not less than 1, and the maximum value does not exceed twice the initial threshold. This is to prevent the threshold from being too small, which would compromise the scheduling priority of high-priority processes, or from being too large, which would prevent low-priority processes from getting scheduling opportunities. The minimum value of m is not less than 1, and the maximum value does not exceed half the minimum length of the corresponding waiting list. This is to prevent the value of m from being too large, which would cause most processes in the waiting list to be swapped, disrupting the overall scheduling priority of the high-priority level. After the system dynamically calculates the values of the threshold and m, it will first compare them with the upper and lower limits. If the calculated value exceeds the upper or lower limit, the value will be adjusted to the corresponding upper or lower limit value before the parameters are updated.
[0061] In alternative implementations, such as Figure 4 As shown, swapping the waiting processes located in the first m positions of the waiting list corresponding to the first set bit and the second set bit respectively includes: S010: Locks the write permissions of the two waiting lists corresponding to the first and second set bits, and prevents new waiting processes from being enqueued during the swapping process.
[0062] In this embodiment, when swapping the first m waiting processes in the waiting lists corresponding to the first and second set bits, a write permission locking operation is first performed on the waiting lists. The system first acquires the operation lock for the two waiting lists corresponding to the first and second set bits. This operation lock is a kernel spinlock, and acquiring the spinlock is an atomic operation. After successfully acquiring the spinlock, the write permissions of the two waiting lists are locked, preventing new waiting processes from enqueuing during the swap. If other processes fail to acquire the lock, they must wait for the spinlock to be released before inserting the corresponding data node at the end of the waiting list. The purpose of locking the write permissions is to prevent new waiting processes from modifying the structure of the waiting lists during the swap, which could lead to changes in the position of the list nodes, node loss, or list breakage, thus ensuring that the structure of the waiting lists remains stable during the swap operation.
[0063] Specifically, after write permission is locked, the system extracts the storage addresses of the data nodes corresponding to the first m waiting processes in the waiting list corresponding to the first bit, and simultaneously extracts the storage addresses of the data nodes corresponding to the first m waiting processes in the waiting list corresponding to the second bit. During the storage address extraction process, the system first verifies the actual length of the two waiting lists. If the actual length of the waiting list is greater than or equal to m, the system extracts the storage addresses of the first m data nodes in the list; if the actual length of the waiting list is less than m, the system extracts the storage addresses of all data nodes in the list, ensuring that no empty node storage addresses are extracted, thus preventing anomalies in subsequent swapping operations. The two sets of extracted storage addresses are stored in two independent temporary arrays located in the system's kernel stack space, which are not accessible to other processes, ensuring the security of the storage addresses.
[0064] S020: Through kernel atomic pointer operations, the positions of the first m waiting processes in two groups are swapped without modifying the business data and priority flags of the waiting processes themselves.
[0065] S030: After the swap is completed, release the write lock on the two waiting lists and update the head pointer and node length information of the two waiting lists.
[0066] In this embodiment, the system uses kernel atomic pointer operations to swap the positions of the first m waiting processes in two groups. Atomic pointer operations are atomic pointer modification operations provided by the kernel. The operation process is not interrupted by other CPU operations, ensuring the consistency of pointer modification and preventing the occurrence of a half-modified abnormal state. The specific swapping process is as follows: first, the first m data nodes of the waiting list corresponding to the first set bit are completely removed from the original list; then, the first m data nodes of the waiting list corresponding to the second set bit are completely removed from the original list; subsequently, the m data nodes removed from the second set bit are completely inserted into the head of the waiting list of the first set bit in their original order; and finally, the m data nodes removed from the first set bit are completely inserted into the head of the waiting list of the second set bit in their original order, thus completing the swapping of the positions of the two groups of waiting processes. During the swap process, the system only modifies the connection pointers of data nodes in the linked list, without modifying the business data and priority identifiers of the waiting process itself. The business data is the key data required by the waiting process to execute business logic, and modification will cause the process's business execution to be abnormal. The priority identifier is the basic configuration information of the process, and modification will affect the enqueue operation when the process requests a lock later. By only modifying the linked list connection pointers, the scheduling order of the waiting processes can be adjusted without affecting the running state and basic configuration of the process itself.
[0067] In alternative implementations, such as Figure 5 As shown, after swapping the waiting processes in the first m positions of the waiting list corresponding to the first and second set bits, the process further includes: S040: Use the second set bit after the swap as the new first set bit, and use the bitmap set bit with a priority one level lower than the new first set bit as the new second set bit.
[0068] It should be noted that after the position swap operation is completed, the system will release the write locks on both waiting lists, release the previously acquired spinlocks, and allow new waiting processes to be enqueued. Simultaneously, the system will update the head pointers and node length information of both waiting lists. The head pointer will then point to the first data node of the swapped waiting list, ensuring that subsequent list operations can be executed normally. Since the number of data nodes detached and inserted in the two lists is the same during the swap operation, the node length information will not change; the system only needs to verify the accuracy of the length information and does not need to modify the value. After completing the above operations, the system will reset the scheduling counter of the waiting list corresponding to the first set bit, clearing the value of the scheduling counter to zero, and restarting the accumulation of the number of scheduled waiting processes until the set threshold is reached again, triggering the next node swap operation.
[0069] S050: Determine whether the number of waiting processes already executed in the waiting list corresponding to the new first set bit is greater than the set threshold. If it is, perform the swap operation of the first m waiting processes in the waiting lists corresponding to the two sets of set bits.
[0070] In this embodiment, after swapping the waiting processes of the first and second positions, the system performs a coordinated swapping operation across all priority levels. The system uses the swapped second position as the new first position, and the bitmap position with a priority one level lower than the new first position as the new second position. In a specific example, after swapping nodes with priority levels 10 and 9, the bitmap position corresponding to priority level 9 is used as the new first position, and the bitmap position corresponding to priority level 8 is used as the new second position. Subsequently, the system reads the scheduling counter value of the waiting list corresponding to the new first position and determines whether the value is greater than a set threshold. If the condition is met, the system performs a swapping operation on the first m waiting processes in the two sets of waiting lists. The swapping operation process is completely consistent with the aforementioned process. Similarly, the swapping operation can start from the highest priority level and pass down level by level until the lowest priority level, completing the linkage swapping of all priority levels. This allows scheduling opportunities to be passed down from the highest priority level to the lowest priority level, ensuring that waiting processes at all priority levels can obtain the corresponding scheduling opportunities.
[0071] The examples above in this application are merely exemplary. In other embodiments, those skilled in the art may use other numerical values to set priorities, and this application does not limit this.
[0072] In alternative implementations, such as Figure 6 As shown, after retrieving the process lock held by the first waiting process in the corresponding waiting list, the process further includes: S300: Remove the waiting process from the corresponding waiting list and complete the reconnection of the list nodes.
[0073] In this embodiment, after the system completes process scheduling, it performs node update and bitmap state synchronization operations on the waiting list. The system removes the data node corresponding to the scheduled process from the waiting list. This removal process is implemented through the kernel's linked list operation function, and the operation is atomic, without damaging the overall structure of the linked list. After node removal, the system performs a reconnection operation on the linked list nodes, setting the second data node in the original linked list as the new first node, updating the head pointer in the head node of the waiting list to point to the new first data node, and simultaneously updating the linked list length count in the head node by decrementing the length count by one.
[0074] S400: Real-time detection of whether the waiting list is empty after removing the waiting process. If the list is empty, update the binary value of the corresponding bitmap to the second value. If the list is not empty, keep the binary value of the corresponding bitmap as the first value.
[0075] Specifically, after the node removal and reconnection operations are completed, the system will check in real time whether the current waiting list is empty. The detection method is to read the list length count in the head node of the waiting list. If the length count is zero, the waiting list is determined to be empty. At this time, the system will use the kernel's atomic bit operation function to update the binary value of the corresponding bitmap to the second value to ensure that the bitmap's state is consistent with the actual state of the waiting list. If the length count is greater than zero, the waiting list is determined to be not empty. At this time, the system keeps the binary value of the corresponding bitmap unchanged as the first value, and will still prioritize the waiting process at this priority level when the lock is released later.
[0076] In this embodiment, each bitmap setting is sorted according to priority. Among two adjacent bitmap settings, the bitmap setting with higher priority is designated as the first setting, and the bitmap setting with lower priority is designated as the second setting. The criterion for determining two adjacent bitmap settings is that the priority level values are adjacent, not that the storage locations of the bitmap settings are adjacent. For example, a bitmap setting with a priority level value of 10 is adjacent to a bitmap setting with a priority level value of 9, a bitmap setting with a priority level value of 9 is adjacent to a bitmap setting with a priority level value of 8, and so on. Since the system's preset storage locations for bitmap settings correspond one-to-one with the priority level values, bitmap settings corresponding to adjacent priorities are also adjacent binary bits in storage, facilitating system traversal and management.
[0077] In an optional implementation, the binary value of the bitmap set with the highest search priority includes: S060: Starting from the highest priority bit in the priority bitmap, read the binary value of the bitmap bit by bit in descending order of priority.
[0078] S070: When the first bitmap with the binary value of the first value is read, the traversal operation is terminated, and the bitmap is determined as the target bitmap with the highest priority.
[0079] In this embodiment, when the process holding the process lock releases the lock, the system performs priority lookup and process scheduling operations. The process lock is a synchronization mechanism in the system kernel used to coordinate concurrent access to shared resources by multiple processes. Only one process can hold the process lock at a time. The process holding the process lock can access the protected shared resource, while processes not holding the process lock cannot access the shared resource and must wait in a waiting list. After completing the access operation to the shared resource, the process holding the process lock will actively release the process lock. During the release process, the process lock's holding flag will be cleared, and a lock release notification will be sent to the system's lock scheduling module. Upon receiving the lock release notification, the lock scheduling module will initiate the priority lookup and process scheduling process.
[0080] Specifically, after the lock scheduling module starts its process, it first searches for the binary value of the highest-priority bitmap setting. The search begins with the highest-priority bitmap setting in the priority bitmap and proceeds bit-by-bit, reading the binary value of each bitmap setting in descending order of priority. The read operation is implemented using bit manipulation functions provided by the kernel. These functions can directly read the binary value at a specified memory address. The read process is atomic and will not be interrupted by other processes, ensuring that the read value matches the actual state of the bitmap setting. After reading the binary value of each bitmap setting, the system determines if it is the first value. If it is, the traversal operation terminates, and this bitmap setting is designated as the target bitmap setting for this scheduling. If it is the second value, the system continues reading the binary value of the next lower-priority bitmap setting until the first bitmap setting with the first value is found, or until all bitmap settings have been traversed.
[0081] It should be noted that if the system has traversed all bitmaps and all bitmaps have the second binary value, it means that all waiting lists are currently empty, and there are no processes waiting for the lock resource. In this case, the system will terminate the current scheduling process and enter an idle waiting state until it receives a new lock release notification or a new process fails to acquire the lock and enters the waiting list. If the system finds the target bitmap set, it will retrieve the waiting list corresponding to the target bitmap set through a pre-built mapping relationship, read the list length count stored in the head node of the waiting list, confirm that the list is not empty, retrieve the data node at the head of the waiting list, extract the waiting process information stored in the data node, schedule the waiting process to hold the process lock, and complete the lock scheduling operation.
[0082] In practical applications, waiting processes are not evenly distributed according to priority levels, but are randomly distributed based on the business attributes and real-time running status of processes within the system. The number of waiting processes varies across different priority levels. Some high-priority levels that carry critical business functions contain only a small number of processes, while some medium- and low-priority levels that carry ordinary background business functions can contain a large number of processes. There is no fixed order binding relationship between process numbers and priority levels; they are entirely determined by the preset base priority of the process, resulting in a random distribution.
[0083] In a specific example, such as Figure 7In a specific example, the system sets 10 priority levels, with higher priority values indicating higher scheduling priority. Level 10 is the highest priority, and level 1 is the lowest. A 10-bit priority bitmap is used, with each bit representing a priority level. The first binary value is 1, indicating that there are waiting processes in the corresponding waiting list; the second value is 0, indicating that the corresponding waiting list is empty. The system constructs a waiting queue containing 10 independent waiting lists. Each priority level corresponds to its own dedicated waiting list, and all lists follow a first-in, first-out (FIFO) rule: the process that failed to acquire the lock first is placed at the head of the list, and the process that acquired it later is placed at the tail. There are a total of 60 waiting processes, numbered 0-59. The processes are randomly distributed across 10 priority levels based on their preset base priorities. The process allocation for each priority level is as follows: Level 10 (highest priority) corresponds to processes 12, 37, 51, 7, 22, and 44, totaling 6 waiting processes; Level 9 corresponds to processes 4, 19, 58, 3, 28, and 33, totaling 6 waiting processes; Level 8 corresponds to processes 15 and 9, totaling 2 waiting processes; Level 7 corresponds to processes 0, 35, 41, 53, 11, 20, and 30, totaling 7 waiting processes; and Level 6 corresponds to process 25. There is 1 waiting process; Level 5 priority corresponds to processes 47, 59, 2, 10, 17, and 24, totaling 6 waiting processes; Level 4 priority corresponds to processes 32, 39, 46, 55, 5, 14, 36, and 49, totaling 8 waiting processes; Level 3 priority corresponds to processes 1, 8, 13, and 21, totaling 4 waiting processes; Level 2 priority corresponds to processes 29, 38, 42, 50, 56, 18, 34, 45, 26, and 6, totaling 10 waiting processes; and Level 1 lowest priority corresponds to processes 16, 23, 27, 48, 31, 40, 43, 52, 54, and 57, totaling 10 waiting processes.
[0084] During system initialization, the mapping between the priority bitmap and the waiting queue is first established. Based on a preset total of 10 priority levels, a 10-bit priority bitmap is generated, ensuring that the total number of bits set in the bitmap, the total number of priorities, and the total number of waiting lists are all 10, ensuring complete consistency. Next, a unique priority identifier is assigned to each bit in the bitmap. The 10 bits, from high to low, correspond to priorities from level 10 to level 1. Simultaneously, an independent waiting list is created for each priority identifier, with all lists following a first-in, first-out (FIFO) execution rule by default. Finally, a one-to-one binding relationship is established between the storage location of the bitmap bits, the priority identifier, and the memory starting address of the corresponding waiting list, completing the mapping between the priority bitmap and the waiting queue. After mapping, the initial state of the priority bitmap is 0000000000, and all priority-related waiting lists are empty. Specifically, the waiting lists for priority levels 10, 9, 8, 7, 6, 5, 4, 3, 2, and 1 are empty. The 60 processes numbered 0-59 sequentially request process locks. If the lock is currently occupied, all processes fail to acquire the lock and are enqueued. Each process matches its preset priority to the corresponding bit in the priority bitmap. The system modifies the binary values of all waiting processes to 1, updating the priority bitmap state to 1111111111, indicating that waiting processes exist at all priority levels.Next, each process is atomically inserted into the tail of the waiting list corresponding to its priority, according to its own priority. After enqueueing, the processes in the waiting lists for each priority are arranged as follows: For priority level 10, the waiting lists are: processes 12, 37, 51, 7, 22, and 44; for priority level 9, the waiting lists are: processes 4, 19, 58, 3, 28, and 33; for priority level 8, the waiting lists are: processes 15 and 9; for priority level 7, the waiting lists are: processes 0, 35, 41, 53, 11, 20, and 30; for priority level 6, the waiting list is: process 25; and for priority level 5, the waiting list is: ... The waiting lists for priority levels 4 and 2 are as follows: Process 47, Process 59, Process 2, Process 10, Process 17, Process 24; Process 32, Process 39, Process 46, Process 55, Process 5, Process 14, Process 36, Process 49; Process 1, Process 8, Process 13, Process 21; Process 29, Process 38, Process 42, Process 50, Process 56, Process 18, Process 34, Process 45, Process 26, Process 6; Process 16, Process 23, Process 27, Process 48, Process 31, Process 40, Process 43, Process 52, Process 54, Process 57.
[0085] When the lock holder releases the process lock, the system initiates the lock scheduling process. Starting with the highest priority bit in the priority bitmap (level 10), the system reads the binary values of the bitmap bits one by one, in descending order of priority. When the binary value of the level 10 bit is found to be 1, it becomes the first bitmap bit with a value of 1, terminating the traversal and setting the level 10 bit as the target bitmap bit for this scheduling operation. Next, the system retrieves the waiting list corresponding to the level 10 priority, taking the first waiting process (process 12) from the list. Process 12 holds the process lock, completing this lock scheduling. Process 12 is then removed from the waiting list corresponding to the level 10 priority, and the list nodes are reconnected. At this point, the waiting list corresponding to the level 10 priority contains processes 37, 51, 7, 22, and 44, still five waiting processes. Since this is a non-empty list, the binary value of the level 10 bit remains unchanged at 1. As locks are subsequently released, the system repeats the above scheduling process, sequentially scheduling processes 37, 51, and 7 in the waiting list corresponding to priority level 10. After each scheduling cycle, the corresponding process is removed from the list, and the bitmap state remains unchanged. After scheduling process 7, the waiting list corresponding to priority level 10 consists of processes 22 and 44, respectively. Figure 8 As shown.
[0086] In this example, a scheduling threshold of 4 is set. After a high-priority waiting list has accumulated 4 processes scheduled, a node swap is triggered. The swap quantity m=2. Each swap involves the two head waiting processes of adjacent priority waiting lists. In the adjacent bitmap settings, the higher priority bit is set first, and the lower priority bit is set second. For example, if level 10 is set first, level 9 is set second. When the number of processes scheduled in the waiting list corresponding to level 10 priority reaches 4 (processes 12, 37, 51, and 7 have all been scheduled), the number of executed waiting processes exceeds the preset threshold of 4, satisfying the hierarchical swap trigger condition, and the adjacent priority node swap operation is initiated. At this time, the waiting list corresponding to level 10 priority consists of processes 22 and 44, while the waiting list corresponding to level 9 priority has not been scheduled. The process order remains process 4, process 19, process 58, process 3, process 28, and process 33, with level 10 set first and level 9 set second. The system initiates a node swap operation. First, it locks write permissions on the waiting lists corresponding to priorities 10 and 9, preventing new waiting processes from being enqueued during the swap. Next, it extracts the memory addresses of the first two waiting processes (processes 22 and 44) in the priority 10 waiting list, and the memory addresses of the first two waiting processes (processes 4 and 19) in the priority 9 waiting list. Then, through kernel atomic pointer operations, it swaps the positions of the two groups of waiting processes without modifying their business data or preset priority flags. After the swap, it releases the write lock on the two priority waiting lists and updates the head pointers and node length information of both lists.
[0087] like Figure 9As shown, after the swap, the process order of the waiting lists corresponding to the two priorities is updated as follows: the waiting list corresponding to priority level 10 consists of processes 4 and 19; the waiting list corresponding to priority level 9 consists of processes 22, 44, 58, 3, 28, and 33. The system synchronously checks the process storage status of the waiting lists corresponding to the two priorities. Since both lists contain waiting processes, the binary values of the bits set for priority levels 10 and 9 remain unchanged at 1. When the lock is released subsequently, the system will prioritize scheduling processes 4 and 19 at the head of the waiting list corresponding to priority level 10. The originally low-priority processes at priority level 9 can be swapped into the waiting list corresponding to the highest priority, thus acquiring the lock resource first and avoiding starvation of low-priority processes. When the number of processes scheduled in the waiting list corresponding to priority level 9 reaches the threshold of 4 after the swap, the system sets the bit for level 9 as the new first bit and the bit for level 8 as the new second bit, repeating the above swapping process to swap the first two processes in the waiting lists corresponding to priority levels 9 and 8. Similarly, the swapping operation can be passed down from the highest priority level to the next, completing the full-link linkage swapping of 10 priority levels, so that processes of all priorities can obtain lock scheduling opportunities.
[0088] This application is not limited to this. The above examples of this application are merely exemplary. In other embodiments, priority 8, priority 6, etc. may also be used. The number of processes is only the number at a certain moment. At other moments, it may be 79, 86, or 90, etc. The specific number of processes is determined based on the actual situation. This application does not limit this.
[0089] Another aspect of this application discloses a system for targeted elevation of the priority of a specified process lock, comprising at least one processor thread and memory.
[0090] The memory stores computer-executable instructions, which, when executed by the processor thread, implement the method described above for targeted elevation of the priority of a specified process lock.
[0091] Since the principle behind this system's problem-solving is similar to the methods described above, the implementation of this system can be found in the implementation of the methods, and will not be repeated here.
[0092] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0093] The above description is merely an embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principle of this application should be included within the scope of the claims of this application.
Claims
1. A method for targetedly increasing the priority of a lock for a specified process, characterized in that, The method includes: Maintain the mapping relationship between priority bitmap and waiting queue. The waiting queue contains N waiting linked lists divided by priority. The priority bitmap includes multiple bitmap settings, each corresponding to a priority. Each bitmap setting represents whether there is a waiting process in the corresponding waiting linked list through a binary value. When the binary value is the first value, the waiting linked list includes at least one waiting process with the same priority. When the binary value is the second value, the waiting linked list is empty. When the process holding the process lock releases the lock, the process finds the binary value of the highest priority bitmap. If it is the first value, the process at the head of the corresponding waiting list is retrieved to hold the process lock.
2. The method for targeted improvement of the lock priority of a specified process according to claim 1, characterized in that, Each bitmap is set according to its priority, and the bitmap with higher priority is set first, and the bitmap with lower priority is set second. Before searching for the binary value of the highest priority bitmap set, the method further includes: For each first and second set bit, if the number of waiting processes already executed in the waiting list corresponding to the first set bit is greater than a set threshold, swap the waiting processes in the first m positions of the waiting lists corresponding to the first and second sets bit, and update the waiting lists of the first and second sets bit again.
3. The method for targeted improvement of the lock priority of a specified process according to claim 1, characterized in that, The mapping relationship between the maintenance priority bitmap and the waiting queue includes: Based on the total number of priorities preset by the system, a priority bitmap with corresponding bits is generated. The total number of bits set in the priority bitmap is consistent with the total number of priorities and the total number of waiting lists. Each bitmap is assigned a unique priority identifier, and an independent waiting list is created for each priority identifier. The waiting list follows a first-in-first-out execution rule. Establish a one-to-one binding relationship between the storage location of the bitmap setting, the priority identifier, and the memory starting address of the waiting list, and complete the mapping construction between the priority bitmap and the waiting queue.
4. The method for targeted improvement of the lock priority of a specified process according to claim 1, characterized in that, After maintaining the mapping relationship between the priority bitmap and the waiting queue, the following is also included: Each process in the system is given a preset basic priority that matches its business attributes, and the basic priority is uniquely associated with a bit setting in a priority bitmap. Receive a priority-oriented configuration request for a specified process, parse the target priority parameter carried in the request, verify the legality of the target priority, update the base priority of the specified process to the target priority, and complete the targeted adjustment of the lock priority of the specified process.
5. The method for targeted improvement of the lock priority of a specified process according to claim 2, characterized in that, The set threshold and the m value of the first m positions are both dynamically adjusted according to the total number of system priorities and the real-time load of the business. When the total number of system priorities increases, the value of the set threshold is simultaneously lowered and the value of m is simultaneously increased. When the system's business load increases, the value of the set threshold is simultaneously lowered and the value of m is simultaneously increased.
6. The method for targeted improvement of the lock priority of a specified process according to claim 2, characterized in that, The swapping of the waiting processes located in the first m positions of the waiting list corresponding to the first set bit and the second set bit includes: Lock the write permissions of the two waiting lists corresponding to the first and second set bits, and prevent new waiting processes from being enqueued during the swapping process; By using kernel atomic pointer operations, the positions of the first m waiting processes in two groups are swapped without modifying the business data and priority flags of the waiting processes themselves. After the swap is completed, the write lock on the two waiting lists is released, and the head pointer and node length information of the two waiting lists are updated.
7. The method for targeted improvement of the lock priority of a specified process according to claim 2, characterized in that, After swapping the waiting processes in the first m positions of the waiting lists corresponding to the first and second set bits, the process further includes: The second bit after the swap is taken as the new first bit, and the bitmap bit with a priority one level lower than the new first bit is taken as the new second bit. Determine whether the number of waiting processes already executed in the waiting list corresponding to the new first set bit is greater than a set threshold. If it is, perform the swap operation of the first m waiting processes in the waiting lists corresponding to the two sets of set bits.
8. The method for targeted improvement of the lock priority of a specified process according to claim 1, characterized in that, After retrieving the process lock held by the first waiting process in the corresponding waiting list, the process lock is further included as follows: Remove the waiting process from the corresponding waiting list and complete the reconnection of the list nodes; Real-time detection is performed to check if the waiting list is empty after removing the waiting process. If the list is empty, the binary value of the corresponding bitmap is updated to the second value. If the list is not empty, the binary value of the corresponding bitmap is kept as the first value.
9. The method for targeted improvement of the lock priority of a specified process according to claim 1, characterized in that, The binary value of the bitmap set with the highest search priority includes: Starting from the highest priority bit in the priority bitmap, read the binary value of the bitmap bit by bit in descending order of priority. When the first bitmap with the binary value of the first value is read, the traversal operation is terminated, and the bitmap with the highest priority is determined as the target bitmap with the highest priority.
10. A system for targeted elevation of lock priority for a specified process, characterized in that, Includes at least one processor thread and memory; The memory stores computer-executable instructions, which, when executed by the processor thread, implement the method for targeted elevation of the priority of a specified process lock as described in any one of claims 1 to 9.