Memory management method and device of thread pool system and thread pool system

By configuring monitoring and worker thread pairs in the thread pool system, periodically detecting and reclaiming idle memory, the problem of memory overflow in the thread pool is solved, thereby improving system stability and task scheduling efficiency.

CN120872601APending Publication Date: 2025-10-31XIAN TONGXING HENGYAO INFORMATION TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511022766.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-23
Publication Date
2025-10-31

AI Technical Summary

Technical Problem

In a thread pool system, because the threads are in a resident state, almost no threads in the system terminate, which fails to trigger the return of free physical memory that can be returned to the operating system, resulting in an OutOfMemoryError (OOM) exception.

Method used

By configuring a monitoring thread and worker thread pair in the memory allocation area, the monitoring thread periodically detects the amount of free physical memory and notifies the worker thread to terminate its task to release free memory when necessary. The monitoring thread is then converted into a worker thread to schedule tasks, ensuring effective memory reclamation.

Benefits of technology

It effectively avoids memory overflow exceptions, improves system stability and task scheduling efficiency, and avoids resource skew and lock contention.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120872601A_ABST
    Figure CN120872601A_ABST
Patent Text Reader

Abstract

The invention provides a memory management method and device of a thread pool system and the thread pool system, and relates to the technical field of computers. The memory management method of the thread pool system comprises the following steps: detecting the quantity of a returnable operating system in a memory allocation area in a preset period by utilizing a monitoring thread in the memory allocation area; if the idle physical memory amount of the returnable operating system is greater than a memory amount threshold value, sending a notification to the working thread, so that the working thread actively ends after completing the current task to release the idle physical memory amount of the returnable operating system; converting the monitoring thread into a working thread used for scheduling and executing a task in a memory allocation area; and creating a monitoring thread for detecting the idle physical memory amount of the returnable operating system for the memory allocation area.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and in particular to a memory management method and apparatus for a thread pool system, and a thread pool system. Background Technology

[0002] In a multithreaded system, multiple memory allocation areas are used. During thread creation, a memory allocation area is selected and bound to the created thread. Therefore, in a multithreaded system, there is a one-to-many relationship between memory allocation areas and threads; that is, a memory allocation area can be bound to multiple threads simultaneously. In this case, if multiple threads in the same memory allocation area simultaneously request / release memory, mutual exclusion must be achieved using a locking mechanism. When a thread terminates, it releases its occupied local cache back to the memory allocation area. If there is still free physical memory available to be returned to the operating system, it will request that free physical memory be returned to the operating system. Summary of the Invention

[0003] The inventors observed that in thread pool systems, threads exist in a persistent state. Tasks are typically managed by a task queue; after a thread completes a task, it retrieves a new task from the queue. When all tasks have been executed, the threads in the thread pool are suspended, waiting for subsequent tasks. Because the threads are in a persistent state, almost no threads terminate in the system, thus preventing the return of free physical memory that can be returned to the operating system. As this free physical memory accumulates, it easily leads to Out of Memory (OOM) exceptions.

[0004] Accordingly, this disclosure provides a memory management method for a thread pool system, which can effectively release free physical memory in the memory allocation area that can be returned to the operating system, and ensure the normal execution of task scheduling, thereby effectively avoiding OOM exceptions and effectively improving system stability.

[0005] In a first aspect of this disclosure, a memory management method for a thread pool system is provided, executed by a memory management device, comprising: using a monitoring thread in a memory allocation area to detect the amount of free physical memory available for returnable operating system in the memory allocation area at predetermined intervals; if the amount of free physical memory available for returnable operating system is greater than a memory threshold, sending a notification to the worker thread so that the worker thread will actively terminate after completing its current task to release the amount of free physical memory available for returnable operating system; converting the monitoring thread into a worker thread in the memory allocation area for scheduling and executing tasks; and creating a monitoring thread for the memory allocation area to detect the amount of free physical memory available for returnable operating system.

[0006] In some embodiments, after receiving the notification, if the worker thread is currently executing a task, it will switch to a recycling thread and terminate the recycling thread upon completing the current task.

[0007] In some embodiments, after receiving the notification, if the worker thread is currently in an idle state, it is converted into a recycling thread and the recycling thread is terminated.

[0008] In some embodiments, if the amount of free physical memory available for returnable operating system is not greater than a memory threshold, it is detected whether the worker thread in the memory allocation area is in the idle state; if the worker thread in the memory allocation area is in the idle state, it is determined whether the duration of the worker thread in the memory allocation area being in the idle state exceeds a duration threshold; if the duration of the worker thread in the memory allocation area being in the idle state exceeds the duration threshold, the worker thread is terminated to release the amount of free physical memory available for returnable operating system; the monitoring thread is converted into a worker thread in the memory allocation area for scheduling and executing tasks; a monitoring thread for detecting the amount of free physical memory available for returnable operating system is created for the memory allocation area.

[0009] In some embodiments, the memory allocation area is configured with a thread pair, the thread pair including a monitoring thread and a worker thread.

[0010] In a second aspect of this disclosure, a memory management device for a thread pool system is provided, comprising: a monitoring module configured to use a monitoring thread in a memory allocation area to detect the amount of free physical memory available for returnable operating system in the memory allocation area at a predetermined period; and a memory management module configured to send a notification to a worker thread if the amount of free physical memory available for returnable operating system is greater than a memory threshold, so that the worker thread will actively terminate after completing its current task to release the amount of free physical memory available for returnable operating system, convert the monitoring thread into a worker thread in the memory allocation area for scheduling and executing tasks, and create a monitoring thread for the memory allocation area to detect the amount of free physical memory available for returnable operating system.

[0011] In some embodiments, after receiving the notification, if the worker thread is currently executing a task, it will switch to a recycling thread and terminate the recycling thread upon completing the current task.

[0012] In some embodiments, after receiving the notification, if the worker thread is currently in an idle state, it is converted into a recycling thread and the recycling thread is terminated.

[0013] In some embodiments, the monitoring module is configured to detect whether the worker threads in the memory allocation area are in the idle state if the amount of free physical memory of the reclaimable operating system is not greater than a memory amount threshold; the memory management module is configured to determine whether the duration of the worker threads in the memory allocation area being in the idle state exceeds a duration threshold when the worker threads in the memory allocation area are in the idle state; if the duration of the worker threads in the memory allocation area being in the idle state exceeds the duration threshold, the worker threads are terminated to release the amount of free physical memory of the reclaimable operating system, the monitoring thread is converted into a worker thread in the memory allocation area for scheduling and executing tasks, and a monitoring thread for detecting the amount of free physical memory of the reclaimable operating system is created for the memory allocation area.

[0014] In some embodiments, the memory allocation area is configured with a thread pair, the thread pair including a monitoring thread and a worker thread.

[0015] In a third aspect of this disclosure, a memory management apparatus is provided, comprising: a memory; and a processor coupled to the memory, the processor being configured to execute instructions stored in the memory to implement the memory management method as described in any of the above embodiments.

[0016] In a fourth aspect of this disclosure, a thread pool system is provided, including a memory management device as described in any of the above embodiments.

[0017] In a fifth aspect of this disclosure, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions that, when executed by a processor, implement the memory management method as described in any of the above embodiments.

[0018] In a sixth aspect of this disclosure, a computer program product is provided, including computer instructions, wherein the computer instructions, when executed by a processor, implement the memory management method as described in any of the above embodiments.

[0019] Other features and advantages of this disclosure will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. Attached Figure Description

[0020] To more clearly illustrate the technical solutions in the embodiments of this disclosure 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 this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0021] Figure 1 This is a schematic diagram illustrating the relationship between threads and memory allocation areas in an embodiment of the prior art.

[0022] Figure 2 This is a schematic diagram illustrating the relationship between threads and memory allocation areas in another embodiment of the prior art.

[0023] Figure 3 This is a flowchart illustrating a memory management method according to an embodiment of the present disclosure;

[0024] Figure 4 This is a schematic diagram illustrating the relationship between threads and memory allocation areas according to an embodiment of this disclosure;

[0025] Figure 5 This is a schematic diagram of a thread switching process according to an embodiment of the present disclosure;

[0026] Figure 6 This is a flowchart illustrating a memory management method according to another embodiment of the present disclosure;

[0027] Figure 7 This is a schematic diagram of the structure of a memory management device according to an embodiment of the present disclosure;

[0028] Figure 8 This is a schematic diagram of the structure of a memory management device according to another embodiment of the present disclosure;

[0029] Figure 9 This is a schematic diagram of the structure of a thread pool system according to an embodiment of the present disclosure. Detailed Implementation

[0030] The technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this disclosure, and not all embodiments. The following description of at least one exemplary embodiment is merely illustrative and is in no way intended to limit this disclosure or its application or use. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without creative effort are within the scope of protection of this disclosure.

[0031] Unless otherwise specifically stated, the relative arrangement, numerical expressions, and values ​​of the components and steps set forth in these embodiments do not limit the scope of this disclosure.

[0032] At the same time, it should be understood that, for ease of description, the dimensions of the various parts shown in the accompanying drawings are not drawn according to actual scale.

[0033] Techniques, methods, and equipment known to those skilled in the art may not be discussed in detail, but where appropriate, such techniques, methods, and equipment should be considered part of the specification.

[0034] In all examples shown and discussed herein, any specific values ​​should be interpreted as merely exemplary and not as limitations. Therefore, other examples of exemplary embodiments may have different values.

[0035] It should be noted that similar labels and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be discussed further in subsequent figures.

[0036] Figure 1 This is a schematic diagram illustrating the relationship between threads and memory allocation areas in an embodiment of the prior art.

[0037] like Figure 1 As shown, a multithreaded system has multiple memory allocation areas. During thread creation, a memory allocation area is selected and bound to the created thread. Therefore, in a multithreaded system, there is a one-to-many relationship between memory allocation areas and threads; that is, a memory allocation area can be bound to multiple threads simultaneously. In this case, if multiple threads in the same memory allocation area simultaneously request / release memory, mutual exclusion must be achieved using a locking mechanism. When a thread terminates, it releases its occupied local cache back to the memory allocation area. If there is still free physical memory available to be returned to the operating system, it will request that the free physical memory be returned to the operating system.

[0038] It's important to note that as new threads are constantly being created and others are constantly terminating, these newly created threads are bound to different memory allocation areas. The terminating threads trigger the return of free physical memory to the operating system, resulting in a dynamic equilibrium in the system. That is, the number of threads bound to different memory allocation areas is relatively balanced, and the memory allocation areas continuously return free physical memory to the operating system.

[0039] Figure 2 This is a schematic diagram illustrating the relationship between threads and memory allocation areas in another embodiment of the prior art.

[0040] The inventors noticed that some threads do not exit after completing their tasks, but rather persist in a resident state. For example... Figure 2 As shown, tasks are typically managed by a task queue. After a thread completes a task, it retrieves a new task from the task queue. When all tasks have been executed, the threads in the thread pool are suspended, waiting for subsequent tasks.

[0041] Because threads exist in a persistent manner, the total number of threads is significantly reduced. When the number of threads slightly exceeds the number of memory allocation areas, the binding relationship between threads and memory allocation areas becomes skewed, causing resource hotspots. For example, if there are 32 memory allocation areas and 48 threads in the thread pool, 16 memory allocation areas may be bound to 2 threads each, while the other 16 may be bound to only 1 thread each. Consequently, conflicts may arise in memory allocation areas bound to multiple threads, leading to conflicts in memory allocation / deallocation operations between threads.

[0042] Furthermore, because threads are in a persistent state, almost no threads terminate in the system, thus preventing the return of free physical memory that can be returned to the operating system. As this free physical memory accumulates, it can easily lead to an Out of Memory (OOM) exception.

[0043] Accordingly, this disclosure provides a memory management method that can effectively release free physical memory in the memory allocation area that can be returned to the operating system and ensure the normal execution of task scheduling, thereby effectively avoiding OOM exceptions. Since there is no situation where multiple threads are bound to the same memory allocation area, resource skew is avoided on the one hand, and lock contention caused by parallel memory allocation between multiple threads is avoided on the other hand, thereby effectively improving the stability of the system.

[0044] Figure 3 This is a schematic flowchart illustrating a memory management method according to an embodiment of the present disclosure. In some embodiments, the following memory management method is executed by a memory management device, including steps 31-34.

[0045] In step 31, the monitoring thread in the memory allocation area is used to detect the amount of free physical memory in the memory allocation area that can be returned to the operating system at predetermined intervals.

[0046] In some embodiments, the memory allocation area is configured with a thread pair, which includes a monitor thread and a worker thread. The monitor thread is used to detect the amount of free physical memory in the memory allocation area that can be returned to the operating system at predetermined intervals. The worker thread is used to schedule and execute tasks.

[0047] It's important to note that there's a one-to-one correspondence between memory allocation areas and threads. In a thread pool system, a memory allocation area is configured for each worker thread.

[0048] Furthermore, since the monitoring thread has a single task and does not perform memory allocation / deallocation operations, it can be approximately assumed that the worker thread exclusively occupies the memory resources of the memory allocation area. Therefore, the memory allocation / deallocation operations performed by the worker thread during task execution will not cause lock conflicts.

[0049] In step 32, if the amount of free physical memory that can be returned to the operating system is greater than the memory threshold, a notification is sent to the worker thread so that the worker thread can terminate itself after completing the current task, thereby releasing the amount of free physical memory that can be returned to the operating system.

[0050] In some embodiments, upon receiving a notification, if the worker thread is currently executing a task, it will switch to a recycler thread after completing the current task and then terminate the recycler thread.

[0051] In some embodiments, after receiving a notification, if the worker thread is currently in an idle state, it is converted into a recycling thread and the recycling thread is terminated.

[0052] In other words, when the amount of free physical memory available for return to the operating system in the memory allocation area exceeds a memory threshold, a notification is sent to the worker threads in that memory allocation area. If the worker thread in that memory allocation area is currently executing a task, it will terminate after completing the task, thus triggering the release of the free physical memory available for return to the operating system. If the worker thread in that memory allocation area is not currently executing a task, it will terminate directly, thus triggering the release of the free physical memory available for return to the operating system.

[0053] In step 33, the monitoring thread is converted into a worker thread in the memory allocation area for scheduling and executing tasks.

[0054] It should be noted that since the original worker thread in the memory allocation area has ended, in order not to affect the normal execution of the task, the monitoring thread in the memory allocation area is converted into a worker thread so that the task can be executed immediately.

[0055] In step 34, a monitoring thread is created for the memory allocation area to detect the amount of free physical memory that can be returned to the operating system.

[0056] It should be noted that, since the monitoring thread in the memory allocation area has been converted into a worker thread, a monitoring thread is created in the memory allocation area to detect the amount of free physical memory that can be returned to the operating system. This ensures that after the amount of free physical memory that can be returned to the operating system is released, there is still a thread pair consisting of a monitoring thread and a worker thread in the memory allocation area. Thus, the release of free physical memory that can be returned to the operating system is achieved without affecting the normal execution of task scheduling.

[0057] The memory management method provided in the above embodiments of this disclosure can effectively release the free physical memory in the memory allocation area that can be returned to the operating system and ensure the normal execution of task scheduling, thereby effectively avoiding OOM exceptions. Since there is no situation where multiple threads are bound to the same memory allocation area, resource skew is avoided on the one hand, and lock contention caused by parallel memory allocation between multiple threads is avoided on the other hand, thereby effectively improving the stability of the system.

[0058] Figure 4 This is a schematic diagram illustrating the relationship between threads and memory allocation areas according to an embodiment of this disclosure.

[0059] like Figure 4 As shown, each memory allocation area has a thread pair consisting of a monitoring thread and a worker thread. The monitoring thread is used to detect the amount of free physical memory in the memory allocation area that can be returned to the operating system at predetermined intervals. The worker thread is used to schedule and execute tasks.

[0060] Figure 5 This is a schematic diagram of a thread switching process according to an embodiment of the present disclosure.

[0061] First, such as Figure 5 As shown in (A), a memory allocation area has one monitoring thread and one worker thread. The monitoring thread checks the amount of free physical memory available for reclaiming by the operating system in the memory allocation area at predetermined intervals. When the amount of free physical memory available for reclaiming by the operating system exceeds a memory threshold, the monitoring thread sends a notification to the worker thread.

[0062] Then, as Figure 5 As shown in (B), when a worker thread receives a notification, if the worker thread is currently executing a task, it will be converted into a recycling thread after completing the current task, and the recycling thread will be terminated.

[0063] In addition, the monitoring thread is converted into a worker thread in the memory allocation area for scheduling and executing tasks. A monitoring thread is also created for this memory allocation area to detect the amount of free physical memory that can be returned to the operating system.

[0064] Next, as Figure 5 As shown in (C), since the recycling thread has ended, there is only one monitoring thread and one worker thread in this memory allocation area.

[0065] The above processing effectively releases free physical memory in the memory allocation area that can be returned to the operating system, and ensures the normal execution of task scheduling, thereby effectively avoiding OOM exceptions and improving system stability.

[0066] Figure 6This is a schematic flowchart illustrating a memory management method according to an embodiment of the present disclosure. In some embodiments, the following memory management method is executed by a memory management device, including steps 61-66.

[0067] In step 61, the monitoring thread in the memory allocation area is used to detect the amount of free physical memory in the memory allocation area that can be returned to the operating system at predetermined intervals.

[0068] In some embodiments, the memory allocation region is configured with a thread pair, which includes a monitoring thread and a worker thread. The monitoring thread is used to detect the amount of free physical memory in the memory allocation region that can be returned to the operating system at predetermined intervals. The worker thread is used to schedule and execute tasks.

[0069] In step 62, if the amount of free physical memory that can be returned to the operating system is not greater than the memory threshold, check whether the worker threads in the memory allocation area are in an idle state.

[0070] In step 63, if the worker thread in the memory allocation area is in an idle state, it is determined whether the duration of the worker thread in the memory allocation area being in an idle state exceeds the duration threshold.

[0071] In step 64, if the duration of the idle state of the worker thread in the memory allocation area exceeds the duration threshold, the worker thread is terminated to release the amount of free physical memory that can be returned to the operating system.

[0072] In step 65, the monitoring thread is converted into a worker thread in the memory allocation area for scheduling and executing tasks.

[0073] In step 66, a monitoring thread is created for the memory allocation area to detect the amount of free physical memory that can be returned to the operating system.

[0074] It should be noted that if the amount of free physical memory that can be returned to the operating system is not greater than the memory threshold, and the worker threads in the memory allocation area are in an idle state for a long time, it indicates that the physical memory in that memory allocation area is in an idle state for a long time. In this case, releasing the free physical memory that can be returned to the operating system in that memory allocation area can effectively improve the utilization rate of physical memory.

[0075] Figure 7 This is a schematic diagram of the structure of a memory management device according to an embodiment of the present disclosure. Figure 7 As shown, the memory management device includes a monitoring module 71 and a memory management module 72.

[0076] The monitoring module 71 is configured to use a monitoring thread in the memory allocation area to detect the amount of free physical memory in the memory allocation area that can be returned to the operating system at predetermined intervals.

[0077] In some embodiments, the memory allocation region is configured with a thread pair, which includes a monitoring thread and a worker thread. The monitoring thread is used to detect the amount of free physical memory in the memory allocation region that can be returned to the operating system at predetermined intervals. The worker thread is used to schedule and execute tasks.

[0078] It's important to note that there's a one-to-one correspondence between memory allocation areas and threads. In a thread pool system, a memory allocation area is configured for each worker thread.

[0079] Furthermore, since the monitoring thread has a single task and does not perform memory allocation / deallocation operations, it can be approximately assumed that the worker thread exclusively occupies the memory resources of the memory allocation area. Therefore, the memory allocation / deallocation operations performed by the worker thread during task execution will not cause lock conflicts.

[0080] The memory management module 72 is configured to send a notification to the worker thread if the amount of free physical memory that can be returned to the operating system is greater than the memory threshold, so that the worker thread will actively terminate after completing the current task to release the amount of free physical memory that can be returned to the operating system. The monitoring thread is converted into a worker thread in the memory allocation area for scheduling and executing tasks, and a monitoring thread is created in the memory allocation area to detect the amount of free physical memory that can be returned to the operating system.

[0081] In some embodiments, upon receiving a notification, if the worker thread is currently executing a task, it will switch to a recycler thread after completing the current task and then terminate the recycler thread.

[0082] In some embodiments, after receiving a notification, if the worker thread is currently in an idle state, it is converted into a recycling thread and the recycling thread is terminated.

[0083] In other words, when the amount of free physical memory available for return to the operating system in the memory allocation area exceeds a memory threshold, a notification is sent to the worker threads in that memory allocation area. If the worker thread in that memory allocation area is currently executing a task, it will terminate after completing the task, thus triggering the release of the free physical memory available for return to the operating system. If the worker thread in that memory allocation area is not currently executing a task, it will terminate directly, thus triggering the release of the free physical memory available for return to the operating system.

[0084] It should be noted that since the monitoring thread in the memory allocation area has been converted into a worker thread, a monitoring thread is created in the memory allocation area to detect the amount of free physical memory to be returned to the operating system. This ensures that after the amount of free physical memory to be returned to the operating system is released, there is still a thread pair consisting of a monitoring thread and a worker thread in the memory allocation area. Thus, the release of free physical memory to be returned to the operating system will not affect the normal execution of task scheduling.

[0085] The memory management device provided in the above embodiments of this disclosure can effectively release the free physical memory in the memory allocation area that can be returned to the operating system, and ensure the normal execution of task scheduling, thereby effectively avoiding OOM exceptions and effectively improving the stability of the system.

[0086] In some embodiments, the monitoring module 71 is configured to detect whether the worker threads in the memory allocation area are in an idle state if the amount of free physical memory that can be returned to the operating system is not greater than the memory amount threshold.

[0087] The memory management module 72 is configured to determine whether the duration of the idle state of the worker thread in the memory allocation area exceeds a duration threshold when the worker thread in the memory allocation area is in an idle state. If the duration of the idle state of the worker thread in the memory allocation area exceeds the duration threshold, the worker thread is terminated to release the amount of free physical memory that can be returned to the operating system. The monitoring thread is converted into a worker thread in the memory allocation area for scheduling and executing tasks, and a monitoring thread is created for the memory allocation area to detect the amount of free physical memory that can be returned to the operating system.

[0088] It should be noted that if the amount of free physical memory that can be returned to the operating system is not greater than the memory threshold, and the worker threads in the memory allocation area are in an idle state for a long time, it indicates that the physical memory in that memory allocation area is in an idle state for a long time. In this case, releasing the free physical memory that can be returned to the operating system in that memory allocation area can effectively improve the utilization rate of physical memory.

[0089] Figure 8 This is a schematic diagram of the structure of a memory management device according to another embodiment of the present disclosure;

[0090] like Figure 8 As shown, the memory management device 80 can be represented in the form of a general computing device. The memory management device 80 includes a memory 81, a processor 82, and a bus 83 connecting different system components.

[0091] The memory 81 may include, for example, system memory, non-volatile storage media, etc. System memory may store, for example, an operating system, application programs, a boot loader, and other programs. System memory may include volatile storage media, such as random access memory (RAM) and / or cache memory. Non-volatile storage media may store, for example, instructions for a corresponding embodiment of a memory management method of at least one thread pool system being executed. Non-volatile storage media include, but are not limited to, disk storage, optical storage, flash memory, etc.

[0092] The processor 82 can be implemented using a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete hardware components such as discrete gates or transistors. Accordingly, each module, such as the acquisition module, the calculation module, and the adjustment module, can be implemented by executing instructions in the central processing unit (CPU) running memory to perform the corresponding steps, or by implementing dedicated circuits that perform the corresponding steps.

[0093] For example, processor 82 is configured for memory-based instruction execution implementation such as Figure 3 , 6 The method involved in any of the embodiments.

[0094] Bus 83 can use any of the various bus architectures. For example, bus architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MCA) bus, and the Peripheral Component Interconnect (PCI) bus.

[0095] The interfaces 84, 85, and 86 of the memory management device 80, as well as the memory 81 and processor 82, can be connected via bus 83. Input / output interface 84 provides a connection interface for input / output devices such as monitors, mice, and keyboards. Network interface 85 provides a connection interface for various networked devices. Storage interface 86 provides a connection interface for external storage devices such as floppy disks, USB flash drives, and SD cards.

[0096] Various aspects of this disclosure are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatus, and computer program products according to embodiments of this disclosure. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations thereof, can be implemented by computer-readable program instructions.

[0097] These computer-readable program instructions are provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable device to produce a machine, such that execution of the instructions by the processor produces means for implementing the functions specified in one or more boxes of the flowchart and / or block diagram.

[0098] These computer-readable program instructions may also be stored in a computer-readable storage medium. These instructions cause a computer to work in a particular manner to produce an article of manufacture, including instructions that implement the functions specified in one or more boxes in a flowchart and / or block diagram.

[0099] This disclosure may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects.

[0100] This disclosure also provides a computer-readable storage medium storing computer instructions that, when executed by a processor, implement... Figure 3 , 6 The method involved in any of the embodiments.

[0101] This disclosure also provides a computer program product, including computer instructions, wherein the computer instructions, when executed by a processor, implement as follows: Figure 3 , 6 The method involved in any of the embodiments.

[0102] Figure 9 This is a schematic diagram of the structure of a thread pool system according to an embodiment of this disclosure. Figure 9 As shown, the thread pool system 90 includes a memory management device 91, which is... Figure 7 or Figure 8 The memory management device involved in any of the embodiments.

[0103] By implementing the above embodiments of this disclosure, the following beneficial effects can be obtained.

[0104] 1) By utilizing worker threads in the thread pool to exclusively occupy resources in the memory allocation area, memory allocation / release without concurrency conflicts can be effectively achieved, ensuring the efficiency of concurrent task execution and preventing resource hotspots.

[0105] 2) By monitoring threads, periodic reclaimable free physical memory of the operating system can be achieved, and memory reclamation will not fail to be triggered due to the excessively long life cycle of worker threads under the thread pool architecture.

[0106] 3) Through the thread pair mechanism and the thread identity switching method, during the thread switching period, an existing thread immediately takes over the task scheduling, and the scheduling will not be interrupted due to the triggering of memory reclamation.

[0107] In some embodiments, the functional units described above may be implemented as general-purpose processors, programmable logic controllers (PLCs), digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or any suitable combination thereof for performing the functions described herein.

[0108] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.

[0109] The description in this disclosure is provided for illustrative and descriptive purposes only and is not intended to be exhaustive or to limit the disclosure to its forms. Many modifications and variations will be apparent to those skilled in the art. The embodiments were chosen and described in order to better illustrate the principles and practical application of this disclosure and to enable those skilled in the art to understand this disclosure and to design various embodiments with various modifications suitable for a particular purpose.

Claims

1. A memory management method for a thread pool system, executed by a memory management device, comprising: The amount of free physical memory that can be returned to the operating system in the memory allocation area is detected at predetermined intervals using a monitoring thread in the memory allocation area. If the amount of free physical memory of the reclaimable operating system is greater than the memory threshold, a notification is sent to the worker thread so that the worker thread can terminate itself after completing the current task, thereby releasing the amount of free physical memory of the reclaimable operating system. The monitoring thread is converted into a worker thread in the memory allocation area for scheduling and executing tasks. A monitoring thread is created for the memory allocation area to detect the amount of free physical memory that can be returned to the operating system.

2. The memory management method according to claim 1, wherein, Upon receiving the notification, if the worker thread is currently executing a task, it will switch to a recycling thread after completing the current task and then terminate the recycling thread.

3. The memory management method according to claim 2, wherein, Upon receiving the notification, if the worker thread is currently in an idle state, it will be converted into a recycling thread and the recycling thread will be terminated.

4. The memory management method according to claim 1 further includes: If the amount of free physical memory of the reclaimable operating system is not greater than the memory threshold, detect whether the working threads in the memory allocation area are in the idle state; When a worker thread in the memory allocation area is in the idle state, determine whether the duration of the worker thread in the memory allocation area being in the idle state exceeds a duration threshold. If the duration of the idle state of the working thread in the memory allocation area exceeds the duration threshold, the working thread is terminated to release the amount of free physical memory that can be returned to the operating system. The monitoring thread is converted into a worker thread in the memory allocation area for scheduling and executing tasks. A monitoring thread is created for the memory allocation area to detect the amount of free physical memory that can be returned to the operating system.

5. The memory management method according to any one of claims 1-4, wherein, The memory allocation area is configured with a thread pair, which includes a monitoring thread and a worker thread.

6. A memory management device for a thread pool system, comprising: The monitoring module is configured to use a monitoring thread in the memory allocation area to detect the amount of free physical memory in the memory allocation area that can be returned to the operating system at predetermined intervals. The memory management module is configured to send a notification to the worker thread if the amount of free physical memory available for return to the operating system is greater than a memory threshold, so that the worker thread will actively terminate after completing the current task to release the amount of free physical memory available for return to the operating system, convert the monitoring thread into a worker thread in the memory allocation area for scheduling and executing tasks, and create a monitoring thread in the memory allocation area for detecting the amount of free physical memory available for return to the operating system.

7. The memory management device according to claim 6, wherein, Upon receiving the notification, if the worker thread is currently executing a task, it will switch to a recycling thread after completing the current task and then terminate the recycling thread.

8. The memory management device according to claim 7, wherein, Upon receiving the notification, if the worker thread is currently in an idle state, it will be converted into a recycling thread and the recycling thread will be terminated.

9. The memory management device according to claim 6, wherein, The monitoring module is configured to detect whether the working threads in the memory allocation area are in the idle state if the amount of free physical memory of the reclaimable operating system is not greater than the memory amount threshold. The memory management module is configured to, when a worker thread in the memory allocation area is in the idle state, determine whether the duration of the idle state exceeds a duration threshold. If the duration of the idle state exceeds the duration threshold, the worker thread is terminated to release the amount of free physical memory that can be returned to the operating system. The monitoring thread is then converted into a worker thread in the memory allocation area for scheduling and executing tasks, and a monitoring thread is created for the memory allocation area to detect the amount of free physical memory that can be returned to the operating system.

10. The memory management device according to any one of claims 6-9, wherein, The memory allocation area is configured with a thread pair, which includes a monitoring thread and a worker thread.

11. A memory management device for a thread pool system, comprising: Memory; A processor, coupled to memory, is configured to implement the memory management method as described in any one of claims 1-5, based on the memory-stored instruction execution.

12. A thread pool system, comprising the memory management apparatus as described in claim 11.

13. A computer-readable storage medium, wherein, The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the memory management method as described in any one of claims 1-5.

14. A computer program product comprising computer instructions, wherein the computer instructions, when executed by a processor, implement the memory management method as described in any one of claims 1-5.