Sleep lock optimization method and device, electronic equipment and storage medium
By acquiring system resource parameters and comparing them with preset thresholds, the optimistic spin time of the sleep lock is reduced, thus solving the problem of excessive CPU load caused by the excessive optimistic spin time of the sleep lock and improving system performance.
Patent Information
- Application Number
- CN202211111502.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-13
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2042-09-13
AI Technical Summary
In existing technologies, setting the optimistic spin time of sleep locks to be too long can lead to excessive CPU load and affect system performance.
By acquiring system resource parameters, such as CPU load, memory reclamation pressure, and storage resource pressure, and comparing them with preset parameter thresholds, the optimistic spin time of the sleep lock is reduced if the threshold is met.
This reduces system load and process lock time, avoids excessive CPU load, and improves system performance.
Smart Images

Figure CN115562852B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of computer technology, and specifically relates to a sleep lock optimization method, apparatus, device and readable storage medium. Background Technology
[0002] In system processes, locks such as spin locks and sleep locks consume CPU resources and degrade system performance because the process switches from sleep to wake. To reduce CPU resource consumption and save time, optimistic spin operations can be added to sleep locks. Optimistic spin means that after a system process fails to acquire a lock, it does not immediately enter sleep mode but instead spins and waits for a certain time threshold. Related sleep lock optimization methods often set the optimistic spin time of sleep locks too long, leading to excessive CPU load. Summary of the Invention
[0003] In view of the above problems, this application proposes a sleep lock optimization method, device, electronic device and storage medium to improve the above problems.
[0004] In a first aspect, embodiments of this application provide a sleep lock optimization method, the method comprising: obtaining current system resource parameters, the system resource parameters including at least one of CPU load, memory reclamation pressure and storage resource pressure; if the system resource parameters meet a preset parameter threshold, then reducing the optimistic spin time of the sleep lock.
[0005] Secondly, embodiments of this application provide a sleep lock optimization device, which includes a system resource parameter acquisition unit and a system resource parameter comparison unit. The system resource parameter acquisition unit is used to acquire current system resource parameters, which include at least one of CPU load, memory reclamation pressure, and storage resource pressure; the system resource parameter comparison unit is used to reduce the optimistic spin time of the sleep lock if the system resource parameters meet a preset parameter threshold.
[0006] Thirdly, embodiments of this application provide an electronic device, including one or more processors and a memory; one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to perform the methods described above.
[0007] Fourthly, embodiments of this application provide a computer-readable storage medium storing program code, wherein the above-described method is executed when the program code is run.
[0008] This application provides a sleep lock optimization method, apparatus, electronic device, and storage medium. The sleep lock optimization method includes: first, acquiring current system resource parameters, including at least one of CPU load, memory reclamation pressure, and storage resource pressure; then, if the system resource parameters meet a preset parameter threshold, reducing the optimistic spin time of the sleep lock. By comparing CPU load, memory reclamation pressure, and storage resource pressure with preset parameter thresholds, and reducing the optimistic spin time of the sleep lock only after all three parameters meet the thresholds, the optimistic spin time of the sleep lock can be adjusted, thereby reducing system load and process lock waiting time, and thus avoiding excessive CPU load due to excessively long optimistic spin times. Attached Figure Description
[0009] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0010] Figure 1 A flowchart of a sleep lock optimization method according to an embodiment of this application is shown;
[0011] Figure 2 A flowchart of a sleep lock optimization method according to another embodiment of this application is shown;
[0012] Figure 3 A flowchart illustrating a method for assessing storage resource pressure according to another embodiment of this application is shown;
[0013] Figure 4 A flowchart illustrating a method for obtaining memory reclamation pressure according to another embodiment of this application is shown;
[0014] Figure 5 A flowchart illustrating a method for obtaining CPU load according to another embodiment of this application is shown;
[0015] Figure 6 A flowchart of a sleep lock optimization method according to another embodiment of this application is shown;
[0016] Figure 7 A flowchart of a sleep lock optimization method according to another embodiment of this application is shown;
[0017] Figure 8 A flowchart of a sleep lock optimization method according to another embodiment of this application is shown;
[0018] Figure 9 A structural block diagram of a sleep lock optimization device according to an embodiment of this application is shown;
[0019] Figure 10 This diagram illustrates a structural block diagram of an electronic device used to execute the sleep lock optimization method of the embodiments of this application in real time.
[0020] Figure 11 The present application shows a storage unit for storing or carrying program code that implements the sleep lock optimization method according to the embodiments of the present application. Detailed Implementation
[0021] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0022] In locks required by system processes, such as spin locks and sleep locks, the transition from a sleep state to a wake-up state is time-consuming and consumes system resources, reducing system performance. In a spin lock, when a process needs to acquire the lock, if it finds that the lock is already held by another process, the CPU will continuously run until the process holding the lock unlocks. In a sleep lock, when a process needs to acquire the lock and finds that the lock is already held by another process, the process will enter a sleep state and will not be woken up until the process holding the lock unlocks it.
[0023] The inventors, in their research on related sleep lock optimization methods, discovered that these methods typically involve a process entering a sleep state when a user requests to hold a sleep lock if the lock is already held by another process. The process remains asleep until the holding process releases the lock. However, in these methods, if the process releases the lock after a short period, it may not be able to immediately acquire the lock and will have to wait for a while. Furthermore, switching from sleep to wake-up not only consumes CPU resources but also takes time.
[0024] Therefore, the inventors have proposed a sleep lock optimization method, apparatus, electronic device, and readable storage medium in this application. First, the current system resource parameters are obtained, including at least one of CPU load, memory reclamation pressure, and storage resource pressure. Then, if the system resource parameters meet a preset parameter threshold, the optimistic spin time of the sleep lock is reduced. By comparing the CPU load, memory reclamation pressure, and storage resource pressure with preset parameter thresholds, and reducing the optimistic spin time of the sleep lock only after all three parameters meet the thresholds, the optimistic spin time of the sleep lock can be adjusted, thereby reducing system load and process lock waiting time, and thus avoiding excessive CPU load caused by an excessively long optimistic spin time.
[0025] The embodiments of this application will now be described in detail with reference to the accompanying drawings.
[0026] Please see Figure 1 This application provides a sleep lock optimization method, the method comprising:
[0027] Step S110: Obtain the current system resource parameters, which include at least one of CPU load, memory reclamation pressure, and storage resource pressure.
[0028] As one approach, system resource parameters include at least one of CPU load, memory reclamation pressure, and storage resource pressure. For example, system resource parameters may include any one of CPU load, memory reclamation pressure, and storage resource pressure; or, system resource parameters may include any two of CPU load, memory reclamation pressure, and storage resource pressure; or, system resource parameters may include CPU load, memory reclamation pressure, and storage resource pressure. CPU load characterizes the level of CPU resource strain, memory reclamation pressure characterizes the level of system memory strain, and storage resource pressure characterizes the level of I / O load strain. Optionally, the current CPU load can be obtained through the task scheduling subsystem when the system performs task scheduling; the current memory reclamation pressure can be obtained during memory reclamation; and the current storage resource pressure can be obtained through the task scheduling subsystem when the system performs task scheduling.
[0029] In this embodiment, CPU load can be obtained when the system performs task scheduling. CPU load can be used to display the size of the CPU's operating load over a period of time. The higher the CPU load, the more tasks are running. If the CPU is in a high-load state for a long time, it can easily have an adverse effect on the lifespan of the CPU and other computer hardware. Therefore, by monitoring the size of the CPU load, the CPU can be prevented from operating in a high-load state for a long time.
[0030] As a way to make reasonable use of CPU resources, after obtaining the CPU load status, if the CPU is detected to be in a high load state, some running tasks that consume a lot of CPU resources can be terminated, thereby reducing the CPU load; if the CPU is detected to be in a low load state, some tasks can be scheduled to run.
[0031] As a method, the system performs memory reclamation for two main reasons. First, the system needs to provide enough memory for any sudden memory requests at any time, so that cache and other related memory can be used, and the system's remaining memory will not be in a state of being very low for a long time. Second, when there is a memory request that is greater than the free memory, the system will directly trigger a forced memory reclamation mechanism to try to reclaim memory to solve the problem due to memory shortage. The kernel employs two different mechanisms to address these two reasons. First, the Linux system uses the kswapd background reclamation thread. When the kernel allocates memory to a process, if the system memory level is below the low watermark, the system cannot allocate memory while the memory level is below the low watermark. Therefore, the kswapd background reclamation thread is awakened to asynchronously reclaim memory. Although the kswapd background reclamation thread is created at system startup, it is mostly in a sleep state, only being awakened when a process fails to allocate memory due to insufficient memory. This allows the kswapd background reclamation thread to reclaim memory for the process to use. Second, the Linux system triggers direct memory reclamation. When the kernel calls the page allocation function to allocate memory, if the system memory is insufficient to meet the allocation request, the kernel triggers the page reclamation mechanism to attempt to reclaim memory to resolve the problem. During memory allocation, the kswapd background reclamation thread only works when the watermark is between the low watermark and the minimum watermark; when the watermark is below the minimum watermark, direct memory reclamation is triggered. The kernel is the core of the system. Its main responsibilities include process management, disk management, task scheduling, and memory management. It can translate user-input commands into machine language that the computer hardware can understand, communicate directly with the hardware, and send requests initiated by application software to the hardware.
[0032] In this embodiment, during memory allocation, if the system memory is lower than the preset memory, memory allocation may fail, causing the process to enter a slow path. Once the process enters the slow path, a memory reclamation operation is triggered. The duration of a single memory reclamation operation can be obtained during this process. As one approach, this duration can be used as the memory reclamation pressure to obtain the current memory reclamation pressure.
[0033] When the system memory size is above the low watermark, the system can quickly allocate and acquire memory; this process is the fast path. However, when the system memory size is below the low watermark, the system cannot allocate memory normally and must enter the slow path.
[0034] The categories of memory to be reclaimed can be file-mapped pages and anonymous pages. File-mapped pages can include pagecache, dcache and icache in slabs, code segments of executable programs of user processes, and file-mapped pages. Anonymous pages can include physical memory allocated by processes using various APIs, including heap, stack, shared memory in inter-process communication, pipes, BSS segments, data segments, and TMPFS pages. This part cannot be directly written back; swap areas need to be created for them. These pages are also converted into file-mapped pages, which can be written back to disk. Furthermore, the system handles memory reclamation differently depending on whether the page is dirty. Dirty pages need to be written back to disk before reclamation, while clean pages can be released directly.
[0035] In this embodiment, storage resource pressure can be obtained when the system performs task scheduling. Storage resource pressure can be used to display the magnitude of IO operation pressure over a period of time. Therefore, by detecting the magnitude of IO load, the IO load can be used as the current storage resource pressure, thereby avoiding storage resources from operating in a high-load state for a long time.
[0036] One approach is to begin acquiring the current memory reclamation pressure as soon as it is detected that memory reclamation has just begun. Specifically, the system triggers memory reclamation when memory levels fall below the low watermark. Memory reclamation can include kswapd memory reclamation and direct memory reclamation. The triggering conditions for these two types of reclamation differ; therefore, the memory reclamation method can be determined by detecting the triggering conditions, thereby determining the start time of memory reclamation. After determining the start time of memory reclamation, the current memory reclamation pressure is then acquired.
[0037] As another approach, when the system detects task scheduling through the task scheduling subsystem, the current CPU load can be obtained through the task scheduling subsystem. Specifically, the system can be equipped with a task scheduling subsystem, which can include functions for task scheduling and data reading. In this embodiment, the data reading function of the task scheduling subsystem is mainly used to read the current CPU load. Optionally, a task identifier can be pre-set for each type of task, and then the task identifier can be detected to determine whether the task is being scheduled by the task scheduling subsystem. When the corresponding task identifier is detected, it is determined that the task scheduling subsystem is performing task scheduling, and the current CPU load is then obtained.
[0038] As another approach, when task scheduling is detected through the task scheduling subsystem, the current I / O load can be obtained from the task scheduling subsystem. Specifically, the system can have a task scheduling subsystem, which can include functions for task scheduling and data reading. In this embodiment, the data reading function of the task scheduling subsystem is mainly used to read the current I / O load, which is then used as the system resource pressure at the current moment. Optionally, a task identifier can be pre-set for each type of task, and then the task identifier can be detected to determine whether the task is being scheduled by the task scheduling subsystem. When the corresponding task identifier is detected, it is determined that the task scheduling subsystem is performing task scheduling, and the current I / O load, i.e., the system resource pressure, is obtained.
[0039] Step S120: If the system resource parameters meet the preset parameter threshold, then reduce the optimistic spin time of the sleep lock.
[0040] In this embodiment, the preset parameter threshold is used to characterize the threshold at which the corresponding system resource parameters meet the conditions. The preset parameter threshold may include at least one of a preset load threshold, a preset pressure threshold, and a preset resource threshold, which correspond to CPU load, memory reclamation pressure, and storage resource pressure, respectively.
[0041] Optimistic spinning in sleep locks refers to a process that, after failing to acquire a lock, spins and waits for a certain time threshold before entering a sleep state. This time threshold is a system setting.
[0042] In this embodiment, the system resource parameters obtained by the aforementioned method can be compared with a pre-set preset parameter threshold. If the current system resource parameters meet the preset parameter threshold, the optimistic spin time of the sleep lock can be reduced. The current system resource parameters meeting the preset parameter threshold may include at least one of the following: CPU load meeting a preset load threshold, memory reclamation pressure meeting a preset pressure threshold, and storage resource pressure meeting a preset resource threshold. For example, if the system resource parameters only include CPU load, then the current system resource parameters meeting the preset parameter threshold includes CPU load meeting the preset load threshold; if the system resource parameters include CPU load, memory reclamation pressure, and storage resource pressure, then the current system resource parameters meeting the preset parameter threshold may include CPU load meeting the preset load threshold, memory reclamation pressure meeting the preset pressure threshold, and storage resource pressure meeting the preset resource threshold.
[0043] If the current system resource parameters meet the preset threshold, the optimistic spin time of the sleep lock is reduced. When reducing the optimistic spin time of the sleep lock, the reduction amount is determined based on the magnitude of the current system resource parameters; the larger the current system resource parameters, the greater the reduction in optimistic spin time.
[0044] This application provides a sleep lock optimization method. First, it obtains current system resource parameters, including at least one of CPU load, memory reclamation pressure, and storage resource pressure. Then, if the system resource parameters meet a preset threshold, it reduces the optimistic spin time of the sleep lock. By comparing CPU load, memory reclamation pressure, and storage resource pressure with preset thresholds, and reducing the optimistic spin time of the sleep lock only after all three parameters meet the thresholds, the optimistic spin time of the sleep lock can be adjusted. This reduces system load and process lock waiting time, thereby avoiding excessive CPU load caused by excessively long optimistic spin times.
[0045] Please see Figure 2 This application provides a sleep lock optimization method, the method comprising:
[0046] Step S201: In response to the lock holding request sent by the thread, obtain the current state of the sleep lock.
[0047] In this embodiment of the application, a thread needs to request to hold the lock before it can hold the sleep lock. Therefore, a thread can send a lock request. After receiving the lock request sent by the thread, the system responds to the lock request and obtains the current state of the sleep lock.
[0048] Step S202: If the sleep lock is in a non-idle state, obtain the current lock type of the sleep lock.
[0049] As one approach, if the current sleep lock is detected to be held by another thread, the sleep lock is determined to be in a non-idle state, and the thread acquires the lock type of the current sleep lock. The sleep lock type can include two types: dedicated locks and general locks. Dedicated locks are sleep locks associated with only a single system resource, including but not limited to CPU resources, memory resources, storage resources, or network resources; general locks are sleep locks associated with CPU resources, memory resources, and storage resources.
[0050] Alternatively, if it is detected that the current sleep lock is not held by other threads, the sleep lock is determined to be in an idle state, and the thread directly acquires the lock.
[0051] Step S203: If the sleep lock is a general lock, check whether the system resource parameters meet the preset parameter threshold.
[0052] In this embodiment, the system resource parameters include three parts: CPU load, memory reclamation pressure, and storage resource pressure. The preset parameter thresholds include three parts: a preset load threshold, a preset pressure threshold, and a preset resource threshold. The preset load threshold corresponds to CPU load, the preset pressure threshold corresponds to memory reclamation pressure, and the preset resource threshold corresponds to storage resource pressure. The preset parameter thresholds can be fixed values or adjusted based on the number of threads; no specific limitation is made here.
[0053] As one method, the method for obtaining storage resource pressure is as described in steps S2031 and S2032, the method for obtaining memory reclamation pressure is as described in steps S2033, S2034 and S2035, and the method for obtaining CPU load is as described in steps S2036 and S2037.
[0054] Once the system obtains the CPU load, memory reclamation pressure, and storage resource pressure, it can compare these parameters with preset threshold values to determine whether the system resource parameters meet the preset threshold values.
[0055] Step S2031: Obtain the total system I / O within a preset time period.
[0056] In this embodiment of the application, when the system performs task scheduling, it can obtain the total IO of each IO node within a certain time period. The time period can be set to any value; for example, it can be set to 4ms.
[0057] Meanwhile, each I / O load calculation may increase the system load, thus affecting system performance. Therefore, the total I / O volume can be obtained at preset time intervals to reduce the impact of I / O load calculation on system performance. This preset time interval can be pre-set or configured based on the specific tasks. For example, if the number of scheduled tasks exceeds a preset threshold, the preset time interval is extended; if the number of scheduled tasks is less than or equal to the preset threshold, the preset time interval is shortened. This reduces the number of I / O load calculations, i.e., the number of storage resource pressure calculations, thereby reducing the impact of storage resource pressure calculations on the system.
[0058] Step S2032: Calculate the IO load based on the total IO volume during the preset time period, and use the IO load as the current system resource parameter.
[0059] In this embodiment of the application, the system obtains the total IO of each IO node through task scheduling, and then calculates the current IO load by processing the total IO of each IO node. The calculation formula is as follows: IO load = total IO / time, that is, the value of the IO load is obtained by dividing the total IO by the time.
[0060] After obtaining the current IO load using the above method, the system can detect whether the task has been scheduled and completed. If the task scheduling is completed, the system will proceed with the next task scheduling and end the IO load monitoring.
[0061] For example, the processes described in steps S2031 and S2032 can be as follows: Figure 3 As shown, when the system performs IO load monitoring, it first schedules a subsystem to obtain the total IO volume of the system over a period of time, then calculates the IO load based on the total IO volume, then schedules the next task, and finally ends the monitoring.
[0062] Step S2033: If the current free memory is lower than the preset memory, then start the memory reclamation operation.
[0063] In this embodiment, before performing memory reclamation, the system needs to monitor the relationship between the current system's free memory and the preset memory. If the current system's free memory is lower than the preset memory, the memory reclamation operation is triggered. The preset memory indicates that the current system's free memory is very low. The preset memory can be a specific value set by the user or a memory threshold inherent in the system. The memory threshold inherent in the system can be a low watermark, and no specific limitation is made here.
[0064] Step S2034: Obtain the start time and end time corresponding to the memory reclamation operation.
[0065] In this embodiment of the application, during the memory reclamation operation, the system records the start time when the memory reclamation operation begins and the end time when the memory reclamation operation ends.
[0066] Step S2035: Determine the current memory reclamation pressure based on the start time and the end time.
[0067] In this embodiment, the duration of a single memory reclamation operation can be obtained based on the start and end times of the memory reclamation operation. The duration of a single memory reclamation operation can be calculated by subtracting the start time from the end time, and the magnitude of the duration represents the magnitude of the memory reclamation pressure.
[0068] Once the memory reclamation pressure is obtained using the above method, the system can determine whether the current free memory is greater than the preset memory. If the system detects that the current free memory is still lower than the preset memory after one memory reclamation, it will perform another memory reclamation operation, recording the duration of each reclamation. If the system detects that the current free memory is greater than the preset memory after one memory reclamation, it will set the duration of each reclamation to 0 and end the reclamation operation to prevent misjudgments in memory assessment and avoid errors in monitoring memory reclamation pressure.
[0069] For example, the processes described in steps S2033, S2034, and S2035 can be as follows: Figure 4 As shown, when the system monitors memory load, it first allocates memory. When the system detects that the current free memory is lower than the preset memory, it performs memory reclamation. During memory reclamation, the start time is recorded as timestamp 1, and the end time as timestamp 2. The duration of a single memory reclamation can be calculated using timestamps 1 and 2, and is denoted as STALL_TIME, which is timestamp 2 minus timestamp 1. After each memory reclamation, it first checks if the current free memory is greater than the preset memory. If the current free memory is greater than or equal to the preset memory, the system has sufficient free memory, and STALL_TIME can be set to 0, ending memory reclamation. If the current free memory is less than the preset memory, the system lacks sufficient free memory, and memory reclamation needs to continue.
[0070] Step S2036: Obtain the CPU's running time and idle time within a preset time period.
[0071] In this embodiment, when scheduling tasks, the system can obtain the running time and idle time of each CPU node within a certain time period. The time period can be set to any value; for example, it can be set to 1 second. CPU idle time is mainly caused by a mismatch between the operating speeds of the CPU and I / O devices. To fully utilize CPU resources, the system cannot allow excessive CPU idle time. The system generally proposes solutions from two aspects: utilizing CPU idle time and reducing CPU idle time. Commonly used methods include multiprogramming, DMA, and I / O channels.
[0072] Meanwhile, each CPU load calculation may increase the system load, thus affecting system performance. Therefore, the CPU's runtime and idle time can be obtained at preset time intervals to reduce the impact of CPU load calculation on system performance. This preset time interval can be pre-set or configured according to different tasks. For example, the preset time interval can be simply set to 100ms, or it can be set according to the number of scheduled tasks. For instance, if the number of scheduled tasks exceeds a preset threshold, the preset time interval is extended; if the number of scheduled tasks is less than or equal to the preset threshold, the preset time interval is shortened. This reduces the number of CPU load calculations, thereby reducing the impact of CPU load calculation on the system.
[0073] Step S2037: Determine the current CPU load based on the running time and the idle time.
[0074] In this embodiment of the application, the system obtains the running time and idle time of each CPU node through task scheduling, and then calculates the current CPU load by processing the running time and idle time of each CPU node. The calculation formula is as follows: CPU load = running time / (idle time + running time), that is, the value of the CPU load is obtained by dividing the running time by the sum of the running time and the idle time.
[0075] After obtaining the current CPU load using the above method, the system can monitor whether the task has been scheduled successfully. If the task scheduling is successful, the system will proceed with the next task scheduling and end the current CPU load monitoring.
[0076] For example, the processes described in steps S2036 and S2037 can be as follows: Figure 5 As shown, when the system monitors CPU load, it obtains the system's CPU running time and idle time over a period of time through the scheduling subsystem, calculates the CPU load based on the running time and idle time, schedules the next task after the load calculation is completed, and finally ends the monitoring.
[0077] Step S204: If the system resources meet the preset parameter threshold, then reduce the optimistic spin time of the sleep lock.
[0078] In one approach, if the system resource parameters include CPU load, and the CPU load is greater than a preset load threshold, it is determined that the preset parameter threshold is met, thereby reducing the optimistic spin time of the sleep lock.
[0079] One approach is to compare the current CPU load with a preset load threshold, and reduce the optimistic spin time of the sleep lock if the condition is met. This includes: if the CPU load is greater than the preset load threshold, then the preset parameter threshold is met, and the optimistic spin time of the sleep lock is reduced.
[0080] In this embodiment, before reducing the optimistic spin time of the sleep lock, the system needs to compare system resource parameters with preset parameter thresholds. Only after the conditions are met can the optimistic spin time of the sleep lock be reduced. Since the sleep lock is in a non-idle state after the process requests to hold the lock, it triggers a CPU load acquisition operation. The system obtains the CPU load by acquiring the CPU's running time and idle time, and compares the CPU load with a preset load threshold. If the CPU load is greater than the preset load threshold, the system reduces the optimistic spin time of the sleep lock.
[0081] Alternatively, if the system resource parameters include memory reclamation pressure, and the memory reclamation pressure is greater than a preset pressure threshold, then the preset parameter threshold is satisfied, and the optimistic spin time of the sleep lock is reduced.
[0082] One approach is to compare the current memory reclamation pressure with a preset pressure threshold, and reduce the optimistic spin time of the sleep lock once the condition is met. This includes: if the memory reclamation pressure is greater than the preset pressure threshold, then the preset parameter threshold is met, and the optimistic spin time of the sleep lock is reduced.
[0083] In this embodiment, before reducing the optimistic spin time of the sleep lock, the system needs to compare system resource parameters with preset parameter thresholds. Only after the conditions are met can the optimistic spin time of the sleep lock be reduced. Since the sleep lock is in a non-idle state after a process requests to hold the lock, it triggers a memory reclamation pressure acquisition operation. The system acquires the memory reclamation pressure by acquiring the duration of a single memory reclamation, and compares the memory reclamation pressure with a preset pressure threshold. If the memory reclamation pressure is greater than the preset pressure threshold, the system reduces the optimistic spin time of the sleep lock.
[0084] Optionally, if the system resource parameters include storage resource pressure, and the storage resource pressure is greater than a preset resource threshold, the preset parameter threshold is satisfied, and the optimistic spin time of the sleep lock is reduced.
[0085] One approach is to compare the current storage resource pressure with a preset resource threshold, and reduce the optimistic spin time of the sleep lock once the condition is met. This includes: if the storage resource pressure is greater than the preset pressure threshold, then the preset parameter threshold is met, and the optimistic spin time of the sleep lock is reduced.
[0086] In this embodiment, before reducing the optimistic spin time of the sleep lock, the system needs to compare system resource parameters with a preset parameter threshold. Only after the condition is met can the optimistic spin time of the sleep lock be reduced. Since the sleep lock is in a non-idle state after the process requests to hold the lock, it triggers the operation of acquiring storage resource pressure. The system obtains the IO load by obtaining the total IO of the system over a period of time, uses the obtained IO load as the storage resource pressure, and compares the storage resource pressure with a preset resource threshold. If the storage resource pressure is greater than the preset resource threshold, the system reduces the optimistic spin time of the sleep lock.
[0087] Optionally, if the system resource parameters include CPU load, memory reclamation pressure, and storage resource pressure, and the CPU load is greater than a preset load threshold, the memory reclamation pressure is greater than a preset pressure threshold, and the storage resource pressure is greater than a preset resource threshold, then the preset parameter thresholds are satisfied, and the optimistic spin time of the sleep lock is reduced.
[0088] In this embodiment, before reducing the optimistic spin time of the sleep lock, the system needs to compare system resource parameters with a preset parameter threshold. Only after the condition is met can the optimistic spin time of the sleep lock be reduced. Since the sleep lock is in a non-idle state after the process requests to hold the lock, it triggers operations to obtain CPU load, memory reclamation pressure, and storage resource pressure. The system obtains system resource parameters and compares them with preset parameter thresholds. If the system resource parameters are greater than the preset parameter threshold, it is determined that the preset parameter threshold is met, and the optimistic spin time of the sleep lock is reduced.
[0089] Step S205: If the system resource parameters do not meet the preset parameter threshold, the optimistic spin time of the sleep lock is maintained at the preset time.
[0090] As one approach, system resource parameters are compared with preset parameter thresholds. If the system resource parameters do not meet the preset parameter thresholds, the optimistic spin time of the sleep lock is maintained. Step S205 specifically includes: if the system resource parameters include CPU load, memory reclamation pressure, and storage resource pressure, and the CPU load is less than or equal to a preset load threshold, the memory reclamation pressure is less than or equal to a preset pressure threshold, and the storage resource pressure is less than or equal to a preset resource threshold, then the system resource parameters do not meet the preset parameter thresholds, and the optimistic spin time of the sleep lock is maintained.
[0091] In this embodiment, the system needs to compare system resource parameters with preset parameter thresholds before maintaining the optimistic spin time of the sleep lock. The optimistic spin time of the sleep lock can only be maintained if the conditions are not met. Since the sleep lock is in a non-idle state after the process requests to hold the lock, it triggers the operation of acquiring CPU load, memory reclamation pressure, and storage resource pressure. The CPU load, memory reclamation pressure, and storage resource pressure are compared with preset load thresholds, preset pressure thresholds, and preset resource thresholds. If the CPU load is less than or equal to the preset load threshold, the memory reclamation pressure is less than or equal to the preset pressure threshold, and the storage resource pressure is less than or equal to the preset resource threshold, then the system maintains the optimistic spin time of the sleep lock.
[0092] This application provides a sleep lock optimization method. First, in response to a lock-holding request sent by a thread, the current state of the sleep lock is obtained. Then, if the sleep lock is in an idle state, the lock type of the sleep lock is obtained. If the lock type is a general lock, it is checked whether the system resource parameters meet a preset parameter threshold. If the system resources meet the preset parameter threshold, the optimistic spin time of the sleep lock is reduced. If the system resource parameters do not meet the preset parameter threshold, the optimistic spin time of the sleep lock is maintained at the preset time. By comparing specific resources with preset parameter thresholds and reducing the optimistic spin time after the specific resources meet the preset parameter thresholds, the optimistic spin time of the sleep lock can be adjusted, thereby reducing system load and process lock waiting time, and thus avoiding excessive CPU load caused by excessively long optimistic spin times.
[0093] Please see Figure 6 This application provides a sleep lock optimization method, the method comprising:
[0094] Step S301: In response to the lock holding request sent by the thread, obtain the current state of the sleep lock.
[0095] Step S301 can be referred to in detail in the above embodiments, and therefore will not be repeated in this embodiment.
[0096] Step S302: If the sleep lock is in a non-idle state, obtain the current lock type of the sleep lock.
[0097] Step S302 can be referred to in detail in the above embodiments, and therefore will not be repeated in this embodiment.
[0098] Step S303: If the sleep lock is a dedicated lock, check whether the system resource parameters meet the preset parameter threshold.
[0099] In this embodiment, system resource parameters include CPU load, memory reclamation pressure, and storage resource pressure. The dedicated lock also has other associated system resources, including network resources and USB transmission resources. The system resource parameters differ depending on the system resource associated with the dedicated lock, and the dedicated lock only compares and judges one type of system resource parameter. For example, if the system resource involved in the dedicated lock is CPU resource, the preset parameter threshold is a preset load threshold; if the system resource involved in the dedicated lock is memory reclamation resource, the preset parameter threshold is a preset pressure threshold; and if the system resource involved in the dedicated lock is storage resource, the preset parameter threshold is a preset resource threshold.
[0100] Once the system obtains the system resource parameters based on the different dedicated locks, it can compare the system resource parameters with preset parameter thresholds to determine whether the system resource parameters meet the preset parameter thresholds.
[0101] As one method, the method for obtaining storage resource pressure is as described in steps S2031 and S2032, the method for obtaining memory reclamation pressure is as described in steps S2033, S2034 and S2035, and the method for obtaining CPU load is as described in steps S2036 and S2037.
[0102] For a dedicated lock, if the system resource parameters include any one of CPU load, memory reclamation pressure, or storage resource pressure, and the system resource pressure is less than or equal to a preset parameter threshold, and it is determined that the preset parameter threshold is not met, then the optimistic spin time of the sleep lock is maintained at the preset time.
[0103] In this embodiment, the system resource associated with the dedicated lock involves only one type. This system resource includes, but is not limited to, CPU load, memory reclamation pressure, storage resource pressure, network resources, or USB transmission resources. When the system resource parameter is less than or equal to a preset resource threshold, the system resource parameter does not meet the preset threshold, and the system maintains the optimistic spin time of the sleep lock for a preset time. The preset optimistic spin time is set by the system itself.
[0104] Step S304: If the system resource parameters meet the preset parameter threshold, obtain the type of the thread.
[0105] In this embodiment, if the CPU load exceeds a preset load threshold, or the memory reclamation pressure exceeds a preset pressure threshold, or the storage resource pressure exceeds a preset resource threshold, the system obtains the thread type. The thread type can be divided into background normal threads and background non-normal threads, where background normal threads and background non-normal threads are automatically identified by the system.
[0106] Step S305: If the type of the thread is not a background normal thread, then reduce the optimistic spin time of the sleep lock.
[0107] In this embodiment, if it is a dedicated lock and the system detects that the thread type is not a background ordinary thread, the optimistic spin time of the sleep lock is reduced.
[0108] Step S306: If the type of the thread is a background normal thread, then control the sleep lock to enter sleep mode.
[0109] In this embodiment of the application, if it is a dedicated lock and the system detects that the thread type is a background normal thread, then the sleep lock is controlled to enter a sleep state.
[0110] This application provides a sleep lock optimization method. First, in response to a lock-holding request sent by a thread, the current state of the sleep lock is obtained. Then, if the sleep lock is not idle, the lock type of the sleep lock is obtained. If the lock type is a dedicated lock, it is checked whether the system resource parameters meet a preset parameter threshold. If the system resource parameters meet the preset parameter threshold, the type of the thread is obtained. If the thread type is not a background ordinary thread, the optimistic spin time of the sleep lock is reduced. If the thread type is a background ordinary thread, the sleep lock is controlled to enter sleep mode. By comparing specific resources with preset parameter thresholds and reducing the optimistic spin time after the specific resources meet the preset parameter thresholds, the optimistic spin time of the sleep lock can be adjusted, thereby reducing system load and process lock waiting time, and thus avoiding excessive CPU load caused by excessively long optimistic spin times.
[0111] Please see Figure 7 This application provides a sleep lock optimization method, the method comprising:
[0112] Step S401: The process requests a lock.
[0113] Step S402: Check if the lock is free. If the lock is free, proceed to step S403; if the lock is not free, proceed to step S404.
[0114] Step S403: Process holds lock.
[0115] In this embodiment of the application, if the system detects that the lock is free, the process holds the lock.
[0116] Step S404: Check if it is a special lock. If it is a special lock, proceed to step S405; if it is not a special lock, proceed to step S409.
[0117] Step S405: Obtain a specific resource and check if the specific resource is in short supply. If the specific resource is in short supply, proceed to step S406; if the specific resource is not in short supply, proceed to step S409.
[0118] In the embodiments of this application, specific resources may include CPU resources, memory resources, storage resources, and network resources, without specific limitations. Each specific resource corresponds one-to-one with a dedicated lock; for example, if the dedicated lock is a network lock, then the specific resource corresponds to a network resource.
[0119] Once the system acquires a specific resource, it can compare that resource with a preset parameter threshold to determine whether the resource is scarce, and then decide whether to acquire a background normal thread or maintain the normal optimistic spin time.
[0120] Step S406: Obtain thread attributes and check if it is a background normal thread. If it is a background normal thread, proceed to step S407; otherwise, proceed to step S408.
[0121] Step S407: Sleep.
[0122] Step S408: Reduce optimistic spin time.
[0123] In this embodiment, if it is not a background normal thread, the optimistic spin time of the sleep lock is reduced by a certain amount. The degree of reduction can be a fixed value or can be adjusted according to the special lock type. No specific limitation is made here.
[0124] Step S409: Normal optimistic spin time.
[0125] In the embodiments of this application, the normal optimistic spin time of the sleep lock can be a fixed value or it can be adjusted according to the type of special lock, and no specific limitation is made here.
[0126] This application provides a sleep lock optimization method. First, a process requests a lock. Then, it checks if the lock is free. If the lock is free, the process acquires it. If the lock is not free, it checks if it is a dedicated lock. If it is a dedicated lock, the process acquires the specific resource. If it is not a dedicated lock, the process performs a normal optimistic spin time. Next, it checks if the specific resource is scarce. If the specific resource is scarce, it retrieves the thread attributes. If the specific resource is not scarce, the process performs a normal optimistic spin time. Finally, it checks if the thread is a background thread. If it is a background thread, the process sleeps. If it is not a background thread, the optimistic spin time is reduced. By comparing the specific resource with a preset parameter threshold, and reducing the optimistic spin time after the specific resource meets the preset parameter threshold, the optimistic spin time of the sleep lock can be adjusted, thereby reducing system load and process lock waiting time, and thus avoiding excessive CPU load caused by excessively long optimistic spin times.
[0127] Please see Figure 8 This application provides a sleep lock optimization method, the method comprising:
[0128] Step S501: The process requests a lock.
[0129] Step S501 can be specifically explained in the detailed explanation of the above embodiments, and therefore will not be repeated in this embodiment.
[0130] Step S502: Check if the lock is free. If the lock is free, proceed to step S503; if the lock is not free, proceed to step S504.
[0131] Step S503: Process holds lock.
[0132] Step S503 can be specifically explained in the above embodiments, and therefore will not be repeated in this embodiment.
[0133] Step S504: Check if it is a general lock. If it is a general lock, proceed to step S505; if it is not a general lock, proceed to step S507.
[0134] Step S505: Obtain system resources and check if system resources are scarce. If system resources are scarce, proceed to step S506; if system resources are not scarce, proceed to step S507.
[0135] In this embodiment, system resources include three parameters: CPU resources, memory resources, and storage resources. After the system obtains the CPU resources, memory resources, and storage resources, it can calculate system resource parameters based on these parameters. The system resource parameters include three parameters: CPU load, memory reclamation pressure, and storage resource pressure. The obtained CPU load, memory reclamation pressure, and storage resource pressure are compared with preset parameter thresholds to determine whether the system resource parameters meet the preset parameter thresholds, and then to determine whether to reduce the sleep lock optimistic spin time or maintain the normal optimistic spin time.
[0136] Step S506: Reduce optimistic spin time.
[0137] In this embodiment, the system reduces the optimistic spin time of the sleep lock based on whether the system resource parameters meet the preset parameter thresholds. For example, if one of the CPU load, memory reclamation pressure, and storage resource pressure meets the preset parameter threshold, the normal optimistic spin time of the sleep lock is reduced by one-third. If two of the parameters meet the preset parameter thresholds, the optimistic spin time of the sleep lock is reduced by two-thirds. If all three parameters meet the preset parameter thresholds, the sleep lock directly enters sleep mode.
[0138] Step S507: Normal optimistic spin time.
[0139] Step S507 can be found in the detailed explanation in the above embodiments, and therefore will not be repeated in this embodiment.
[0140] This application provides a sleep lock optimization method. First, the process holds the lock. Then, it checks if the lock is free. If the lock is free, the process holds the lock. If the lock is not free, it checks if it is a generic lock. If it is a generic lock, the process acquires system resources. If it is not a generic lock, it performs normal optimistic spinning. Next, it checks if system resources are scarce. If system resources are scarce, the optimistic spinning time is reduced. If system resources are not scarce, the optimistic spinning time remains normal. By comparing specific resources with preset parameter thresholds and reducing the optimistic spinning time after the specific resource meets the preset parameter thresholds, the optimistic spinning time of the sleep lock can be adjusted. This reduces system load and process lock waiting time, thus avoiding excessive CPU load caused by excessively long optimistic spinning times.
[0141] Please see Figure 9 This application provides a sleep lock optimization device 600, the device 600 comprising:
[0142] The system resource parameter acquisition unit 610 is used to acquire the current system resource parameters, which include at least one of CPU load, memory reclamation pressure and storage resource pressure.
[0143] In one approach, the system resource parameter acquisition unit 610 is used to acquire the total system IO within a preset time period; based on the total IO within the preset time period, the IO load is calculated, and the IO load is used as the current system resource pressure.
[0144] Optionally, the system resource parameter acquisition unit 610 is further configured to: if the current free memory is lower than the preset memory, start a memory reclamation operation; acquire the start time and end time corresponding to the memory reclamation operation; and determine the current memory reclamation pressure based on the start time and the end time.
[0145] Optionally, the system resource parameter acquisition unit 610 is further configured to acquire the CPU's running time and idle time within a preset time period; and determine the current CPU load based on the running time and idle time.
[0146] The system resource parameter comparison unit 620 is used to reduce the optimistic spin time of the sleep lock if the system resource parameters meet the preset parameter threshold.
[0147] In one manner, the system resource parameter comparison unit 620 is configured to: if the system resource parameters include CPU load and the CPU load is greater than a preset load threshold, determine that the preset parameter threshold is met and reduce the optimistic spin time of the sleep lock; or, if the system resource parameters include memory reclamation pressure and the memory reclamation pressure is greater than a preset pressure threshold, determine that the preset parameter threshold is met and reduce the optimistic spin time of the sleep lock; or, if the system resource parameters include storage resource pressure and the storage resource pressure is greater than a preset resource threshold, determine that the preset parameter threshold is met and reduce the optimistic spin time of the sleep lock.
[0148] Optionally, the system resource parameter comparison unit 620 is further configured to maintain the optimistic spin time of the sleep lock at a preset time if the system resource parameters do not meet the preset parameter threshold.
[0149] Optionally, the system resource parameter comparison unit 620 is further configured to, if the system resource parameters include CPU load, memory reclamation pressure, and storage resource pressure, and the CPU load is less than or equal to a preset load threshold, the memory reclamation pressure is less than or equal to a preset pressure threshold, and the storage resource pressure is less than or equal to a preset resource threshold, and if it is determined that the preset parameter threshold is not met, then maintain the optimistic spin of the sleep lock for a preset time.
[0150] Optionally, the system resource parameter comparison unit 620 further includes responding to a lock holding request sent by a thread, obtaining the current state of the sleep lock; if the sleep lock is in an idle state, obtaining the lock type of the current sleep lock; if the lock type of the sleep lock is a dedicated lock, detecting whether the system resource parameters meet the preset parameter threshold.
[0151] Optionally, the system resource parameter comparison unit 620 further includes obtaining the type of the thread if the system resource parameters meet the preset parameter threshold; and reducing the optimistic spin time of the sleep lock if the type of the thread is not a background normal thread.
[0152] Optionally, the system resource parameter comparison unit 620 further includes controlling the sleep lock to enter sleep mode if the type of the thread is a background normal thread.
[0153] Optionally, the system resource parameter comparison unit 620 further includes detecting whether the system resource parameters meet the preset parameter threshold if the lock type of the sleep lock is a general lock.
[0154] It should be noted that the device embodiments in this application correspond to the aforementioned method embodiments. The specific principles in the device embodiments can be found in the content of the aforementioned method embodiments, and will not be repeated here.
[0155] The following will combine Figure 10 This application describes an electronic device.
[0156] Please see Figure 10 Based on the aforementioned sleep lock optimization method and apparatus, this application also provides another electronic device 700 capable of executing the aforementioned sleep lock optimization method. The electronic device 700 includes one or more (only one shown in the figure) processors 702, a memory 704, and a network module 706 coupled together. The memory 704 stores programs capable of executing the contents of the aforementioned embodiments, and the processors 702 can execute the programs stored in the memory 704.
[0157] The processor 702 may include one or more processing cores. The processor 702 connects to various parts within the electronic device 700 using various interfaces and lines, and performs various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 704, and by calling data stored in the memory 704. Optionally, the processor 702 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 702 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the displayed content; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 702 and may be implemented separately using a communication chip.
[0158] The memory 704 may include random access memory (RAM) or read-only memory (ROM). The memory 704 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 704 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as touch functionality, sound playback functionality, image playback functionality, etc.), and instructions for implementing the various method embodiments described below. The data storage area may also store data created by the electronic device 700 during use (such as phonebook data, audio and video data, chat log data, etc.).
[0159] The network module 706 is used to receive and transmit electromagnetic waves, realizing the mutual conversion between electromagnetic waves and electrical signals, thereby communicating with communication networks or other devices, such as audio playback devices. The network module 706 may include various existing circuit elements for performing these functions, such as antennas, radio frequency transceivers, digital signal processors, encryption / decryption chips, user identity modules (SIM cards), memory, etc. The network module 706 can communicate with various networks such as the Internet, corporate intranets, and wireless networks, or communicate with other devices through wireless networks. The aforementioned wireless networks may include cellular telephone networks, wireless local area networks (WLANs), or metropolitan area networks (MANs). For example, the network module 706 can interact with base stations.
[0160] Please refer to Figure 11 This diagram illustrates a structural block diagram of a computer-readable storage medium provided in an embodiment of this application. The computer-readable medium 800 stores program code that can be called by a processor to execute the methods described in the above method embodiments.
[0161] The computer-readable storage medium 800 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read-Only Memory), EPROM, hard disk, or ROM. Optionally, the computer-readable storage medium 800 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 800 has storage space for program code 810 that performs any of the method steps described above. This program code can be read from or written to one or more computer program products. The program code 810 may be compressed, for example, in a suitable form.
[0162] This application provides a sleep lock optimization method, apparatus, electronic device, and storage medium. The sleep lock optimization method includes: first, acquiring current system resource parameters, including at least one of CPU load, memory reclamation pressure, and storage resource pressure; then, if the system resource parameters meet a preset parameter threshold, reducing the optimistic spin time of the sleep lock. By comparing CPU load, memory reclamation pressure, and storage resource pressure with preset parameter thresholds, and reducing the optimistic spin time of the sleep lock only after all three parameters meet the thresholds, the optimistic spin time of the sleep lock can be adjusted, thereby reducing system load and process lock waiting time, and thus avoiding excessive CPU load due to excessively long optimistic spin times.
[0163] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of the present invention without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of the present invention.
Claims
1. A sleep lock optimization method, characterized in that, The method includes: Obtain the current system resource parameters, which include at least one of CPU load, memory reclamation pressure, and storage resource pressure; If the system resource parameters meet the preset parameter threshold, the optimistic spin time of the sleep lock is reduced. The optimistic spin of the sleep lock refers to the process waiting in a certain time threshold after failing to request the lock and before entering the sleep state.
2. The method according to claim 1, characterized in that, If the system resource parameters meet the preset parameter threshold, then reducing the optimistic spin time of the sleep lock includes: If the system resource parameters include CPU load, and the CPU load is greater than a preset load threshold, then the preset parameter threshold is satisfied, and the optimistic spin time of the sleep lock is reduced; or, If the system resource parameters include memory reclamation pressure, and the memory reclamation pressure is greater than a preset pressure threshold, then the preset parameter threshold is satisfied, and the optimistic spin time of the sleep lock is reduced; or, If the system resource parameters include storage resource pressure, and the storage resource pressure is greater than a preset resource threshold, then the preset parameter threshold is satisfied, and the optimistic spin time of the sleep lock is reduced.
3. The method according to claim 1, characterized in that, The method further includes: If the system resource parameters do not meet the preset parameter threshold, the optimistic spin time of the sleep lock is maintained at the preset time.
4. The method according to claim 3, characterized in that, If the system resource parameters do not meet the preset parameter threshold, then maintaining the optimistic spin time of the sleep lock at the preset time includes: If the system resource parameters include CPU load, memory reclamation pressure, and storage resource pressure, and the CPU load is less than or equal to a preset load threshold, the memory reclamation pressure is less than or equal to a preset pressure threshold, and the storage resource pressure is less than or equal to a preset resource threshold, and it is determined that the preset parameter thresholds are not met, then the optimistic spin time of the sleep lock is maintained at the preset time.
5. The method according to claim 1, characterized in that, If the system resource parameters meet the preset parameter threshold, the method further includes the following steps before reducing the optimistic spin time of the sleep lock: In response to a lock request sent by a thread, obtain the current state of the sleep lock; If the sleep lock is not in an idle state, obtain the current lock type of the sleep lock; If the sleep lock is a dedicated lock, check whether the system resource parameters meet the preset parameter threshold.
6. The method according to claim 5, characterized in that, If the system resource parameters meet a preset parameter threshold, then reducing the optimistic spin time of the sleep lock includes: If the system resource parameters meet the preset parameter threshold, obtain the type of the thread; If the type of the thread is not a background normal thread, then reduce the optimistic spin time of the sleep lock.
7. The method according to claim 6, characterized in that, The method further includes: If the thread is a background normal thread, then control the sleep lock to enter sleep mode.
8. The method according to claim 5, characterized in that, The method further includes: If the sleep lock is a general lock, check whether the system resource parameters meet the preset parameter threshold.
9. The method according to claim 1, characterized in that, The process of obtaining the current system resource parameters includes: Get the total system I / O within a preset time period; Based on the total IO volume within the preset time period, the IO load is calculated and used as the current system resource parameter.
10. The method according to claim 1, characterized in that, The process of obtaining the current system resource parameters includes: If the current free memory is lower than the preset memory, then a memory reclamation operation will begin; Obtain the start and end times corresponding to the memory reclamation operation; Based on the start time and the end time, the current memory reclamation pressure is determined.
11. The method according to claim 1, characterized in that, The process of obtaining the current system resource parameters includes: Obtain the CPU's running time and idle time within a preset time period; The current CPU load is determined based on the running time and the idle time.
12. A sleep lock optimization device, characterized in that, The device includes: A system resource parameter acquisition unit is used to acquire current system resource parameters, which include at least one of CPU load, memory reclamation pressure, and storage resource pressure. The system resource parameter comparison unit is used to reduce the optimistic spin time of the sleep lock if the system resource parameters meet the preset parameter threshold. The optimistic spin of the sleep lock refers to the process waiting in a certain time threshold after failing to request the lock and before entering the sleep state.
13. An electronic device, characterized in that, It includes one or more processors and memory, wherein one or more programs are stored in memory and configured to be executed by one or more processors according to any one of claims 1-11.
14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores program code, which includes instructions for performing the method as claimed in any one of claims 1-11.