Method, device and program product for dynamically adjusting cache based on TCMalloc memory allocator

By introducing a dynamically adjusted cache mechanism into the TCMalloc memory allocator, the problem of traditional memory management technology being difficult to adapt to memory requirements in complex application scenarios is solved, efficient and adaptive memory management is achieved, and system performance and resource utilization are improved.

CN118502972BActive Publication Date: 2024-09-27XIAMEN XINGZONG DIGITAL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410968623.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-19
Publication Date
2024-09-27
Estimated Expiration
2044-07-19

AI Technical Summary

Technical Problem

Traditional memory management technology is difficult to adapt to dynamically changing memory requirements when faced with complex and ever-changing application scenarios, resulting in inefficient memory usage, waste or shortage of resources, lack of adaptive adjustment, and impact on system performance.

Method used

Dynamic cache adjustment method based on TCMalloc memory allocator, by regularly monitoring the application's memory usage, dynamically adjusting the cache release mechanism of the idle Span manager and thread cache pool, calculating the application's cache threshold and the system's remaining memory percentage, and automatically releasing Eliminate unnecessary memory, set the maximum cache size of threads, and achieve intelligent and adaptive memory management.

Benefits of technology

It improves the efficiency of memory management and resource utilization, reduces memory fragmentation and performance fluctuations, avoids memory leaks and system crashes, and improves system performance and response time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118502972B
    Figure CN118502972B
Patent Text Reader

Abstract

The present invention provides a method, device and program product for dynamically adjusting cache based on TCMalloc memory allocator, the method comprising: regularly monitoring the memory actually used by the application according to a preset time interval, adjusting the cache release mechanism of the free span manager in the TCMalloc memory allocator and setting the maximum cache size of the threads in the thread cache pool in the TCMalloc memory allocator. By using the above technical solution, the intelligent application of the TCMalloc memory management mechanism is enhanced and expanded, the utilization efficiency of memory resources is significantly improved, and the impact of memory management and memory recycling on system performance is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of system memory management and performance optimization, and in particular to a method, device and program product for dynamically adjusting cache based on a TCMalloc memory allocator. Background Art

[0002] With the increasing number of computationally intensive applications, the impact of memory management on system performance has increased significantly. As a high-performance multi-threaded memory allocator, TCMalloc has been widely used to improve memory allocation performance, but its static configuration method and fixed memory management strategy are not flexible enough when facing complex and changing application scenarios. Traditional memory management technology often cannot adapt well to dynamically changing memory requirements, resulting in inefficient memory use, waste or insufficient resources. Therefore, it is urgent to develop a memory management solution that can be intelligently adjusted according to real-time conditions. Summary of the invention

[0003] The embodiments of the present invention provide a method, device and program product for dynamically adjusting cache based on TCMalloc memory allocator, aiming to improve the efficiency and adaptability of memory management, thereby comprehensively improving system performance and resource utilization.

[0004] In order to achieve the above object, on the one hand, a method for dynamically adjusting cache based on TCMalloc memory allocator is provided, wherein the TCMalloc memory allocator includes: an idle Span manager, a thread common cache pool and a thread cache pool, and the method includes monitoring the memory actually used by the application program at a predetermined time interval, and dynamically adjusting the current system cache by the following steps:

[0005] Adjust the cache release mechanism in the idle Span manager, including:

[0006] Calculate the size of the memory actually occupied by the application, and calculate the cache threshold of the application according to the size of the memory actually occupied by the application, and release the cache in the idle Span manager when the number of cache bytes of the idle Span manager or the number of unmapped bytes in the memory obtained by the idle Span manager from the current system is greater than the cache threshold;

[0007] Calculate the percentage of the current system remaining memory, and when the percentage is less than a predetermined percentage threshold, release the cache in the idle Span manager;

[0008] Set the maximum cache size of threads in the thread cache pool, including:

[0009] Creating a thread memory management container and defining a thread memory statistics structure within the thread memory management container;

[0010] Rewrite the thread creation function in the application, wherein the thread creation function reports the thread id of the thread to the thread memory management container and constructs a thread memory statistics structure of the thread in the thread memory management container;

[0011] Rewrite the memory allocation function in the application, wherein the memory allocation function finds the thread memory management container of the thread according to the thread ID of the thread currently calling the memory allocation function, and counts the memory size applied by the thread and the number of times the thread applies for memory;

[0012] The commonly used memory of the thread is obtained through the thread memory statistics structure of the thread and the thread ID of the thread, the sum of the commonly used memory of the thread is counted, and the maximum cache size of the thread is set according to the sum of the commonly used memory of the thread.

[0013] Preferably, the method for dynamically adjusting cache based on TCMalloc memory allocator, wherein the step of calculating the size of memory actually occupied by the application and calculating the cache threshold of the application according to the size of memory actually occupied by the application, comprises:

[0014] S1, obtain the total number of bytes pageheap.system_bytes obtained by the free span manager from the current system and the number of bytes metadata_bytes occupied by the structure of the memory tracked by the TCMalloc memory allocator, and obtain the number of virtual memory bytes of the current system according to the following formula:

[0015] virtual_memory_used = pageheap.system_bytes + metadata_bytes;

[0016] S2, obtaining the number of unmapped bytes in the memory obtained by the free span manager from the current system, pageheap.unmapped_bytes, and obtaining the number of physical memory bytes actually occupied by the TCMalloc memory allocator according to the following formula:

[0017] physical_memory_used = virtual_memory_used - pageheap.unmapped_bytes;

[0018] S3, obtain the cache byte number pageheap.free_bytes of the free Span manager, the cache byte number central_bytes of the thread common cache pool, the cache byte number transfer_bytes that the thread common cache pool is ready to distribute to the thread cache pool, and the cache byte number thread_bytes of the thread cache pool, and obtain the actual memory size allocated to the application by the TCMalloc memory allocator according to the following formula:

[0019] bytes_in_use_by_app = physical_memory_used - metadata_bytes

[0020] - pageheap.free_bytes - central_bytes - transfer_bytes - thread_bytes;

[0021] S4, obtaining the cache threshold of the application according to the following formula:

[0022] threshold = bytes_in_use_by_app / number

[0023] Wherein, number is a pre-set positive integer, and 10≤number≤30.

[0024] Preferably, the method for dynamically adjusting cache based on TCMalloc memory allocator, wherein the calculating the percentage of remaining memory in the current system comprises:

[0025] Get the total memory size MemTotal of the current system, get the free memory size MemFree of the current system, and calculate the percentage of the remaining memory of the current system by the formula MemFree ÷ MemTotal.

[0026] Preferably, the method for dynamically adjusting the cache based on the TCMalloc memory allocator, wherein the thread memory statistics structure includes: a thread application memory statistics structure thread_memory, a file application memory statistics structure file_memory and a line application memory statistics structure line_memory under the file, wherein the thread_memory includes the thread id of the thread and the hash container file_memorys of the thread_memory; the file_memory includes the file name file and the hash container line_memorys of the file_memory; the line_memory includes the line number line, the size size and the count count, wherein the size is used to record the memory size applied by the thread, and the count is used to record the number of times the thread applies for memory.

[0027] Preferably, in the method for dynamically adjusting cache based on TCMalloc memory allocator, the step of rewriting the thread creation function in the application program comprises:

[0028] After creating a thread, the application reports the thread id of the thread to the thread memory management container, and inserts the thread id into the thread memory management container as a key; sets a callback function for the thread, reports the thread id of the thread to the thread memory management container and deletes the thread id from the thread memory management container when the thread exits.

[0029] Preferably, in the method for dynamically adjusting cache based on TCMalloc memory allocator, the step of rewriting the memory allocation function in the application program comprises:

[0030] The memory allocation function adds new parameters and rewrites the memory allocation function logic, wherein the new parameters include: the thread id of the thread that calls the memory allocation function, the file name of the file that calls the memory allocation function, and the line number of the file that specifically calls the memory allocation function;

[0031] The logic of the memory allocation function is: according to the thread id, search the thread_memory of the thread id in the thread memory management container;

[0032] Find the file_memory of the file name in file_memorys under the thread_memory according to the file name;

[0033] Find the line_memory of the line number in line_memorys under the file_memory according to the line number;

[0034] The memory size requested by the thread is recorded in the line_memory, and the number of memory requests by the thread in the line_memory is incremented.

[0035] Preferably, the method for dynamically adjusting cache based on TCMalloc memory allocator, wherein obtaining the common memory of the thread through the thread memory statistics structure of the thread and the thread ID of the thread comprises:

[0036] The commonly used memory of the threads in the current system is counted regularly according to a preset time, wherein the commonly used memory is the memory for which the number of times of applying for memory in the preset time is greater than or equal to a predetermined number.

[0037] On the other hand, a device for dynamically adjusting cache based on TCMalloc memory allocator is provided, which includes a memory and a processor, wherein the memory stores at least one program, and the at least one program is executed by the processor to implement any of the methods for dynamically adjusting cache based on TCMalloc memory allocator as described above.

[0038] On the other hand, a computer program product includes a computer program, characterized in that when the computer program is executed by a processor, it implements any of the above methods for dynamically adjusting cache based on TCMalloc memory allocator.

[0039] The above technical solution has the following technical effects:

[0040] The system detects the application's cache threshold, the percentage of system remaining memory, and the system's overall memory status in real time, and dynamically adjusts the memory cache threshold based on these data, thereby achieving immediate response and optimization of system memory usage; when it detects that the system's remaining memory percentage is lower than the predetermined percentage threshold or the free cache in the free Span manager / the unmapped memory in the free Span manager exceeds the set threshold, the system will automatically release this part of the memory to ensure that resources can be quickly released when memory is tight, avoiding memory leaks and system crashes.

[0041] By rewriting the memory allocation function and implementing statistics in each thread, we can accurately count the memory usage pattern of each thread, especially the frequent memory allocation and release operations of the thread. Based on these statistics, we can dynamically set the maximum cache size for the thread to reduce unnecessary memory allocation and release operations, thereby reducing memory fragmentation, improving memory allocation speed and application response time.

[0042] The above technical solutions enhance and expand the intelligent application of TCMalloc memory management mechanism, significantly improve the utilization efficiency of memory resources, reduce the impact of memory management and memory recycling on system performance, and effectively solve the problems of untimely memory recycling, lack of adaptive adjustment, and performance fluctuations in traditional memory allocators. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 A flowchart of a method for dynamically adjusting cache based on TCMalloc memory allocator according to an embodiment of the present invention;

[0044] Figure 2 A schematic flow chart of a method for dynamically adjusting cache based on a TCMalloc memory allocator according to another embodiment of the present invention;

[0045] Figure 3 A flowchart of a method for dynamically adjusting cache based on a TCMalloc memory allocator in another embodiment of the present invention, in which a memory allocation function sets a maximum cache size of threads in a thread cache pool;

[0046] Figure 4 This is a diagram of a device for dynamically adjusting cache based on TCMalloc memory allocator according to another embodiment of the present invention. DETAILED DESCRIPTION

[0047] To further illustrate the various embodiments, the present invention provides drawings. These drawings are part of the disclosure of the present invention, which are mainly used to illustrate the embodiments and can be used in conjunction with the relevant descriptions in the specification to explain the operating principles of the embodiments. With reference to these contents, a person of ordinary skill in the art should be able to understand other possible implementations and advantages of the present invention. The components in the figures are not drawn to scale, and similar component symbols are generally used to represent similar components.

[0048] The present invention will now be further described with reference to the accompanying drawings and specific implementation methods.

[0049] Embodiment 1:

[0050] In order to improve the efficiency and adaptability of system memory management and enhance system performance and resource utilization, an embodiment of the present invention provides a method for dynamically adjusting cache based on TCMalloc memory allocator.

[0051] Figure 1 Flow chart of a method for dynamically adjusting cache based on TCMalloc memory allocator according to an embodiment of the present invention. Figure 1The method for dynamically adjusting cache based on TCMalloc memory allocator in the embodiment of the present invention monitors the memory actually used by the application program according to a preset time interval. The TCMalloc memory allocator includes an idle Span manager, a thread common cache pool and a thread cache pool. The method of this embodiment includes the following steps:

[0052] Adjust the cache release mechanism in the idle Span manager, including:

[0053] Calculate the actual memory size occupied by the application, and calculate the cache threshold of the application based on the actual memory size occupied by the application. When the number of cache bytes of the idle Span manager or the number of unmapped bytes in the memory obtained by the idle Span manager from the current system is greater than the cache threshold, release the cache in the idle Span manager.

[0054] Calculate the percentage of the current system's remaining memory. When the percentage is less than a predetermined percentage threshold, release the cache in the idle Span manager.

[0055] Set the maximum cache size of threads in the thread cache pool, including:

[0056] Create a thread memory management container and define the thread memory statistics structure in the thread memory management container;

[0057] Rewrite the thread creation function in the application, where the thread creation function reports the thread ID of the thread to the thread memory management container and builds the thread memory statistics structure of the thread in the thread memory management container;

[0058] Rewrite the memory allocation function in the application. The memory allocation function finds the thread memory management container of the thread according to the thread ID of the thread that currently calls the memory allocation function, and counts the memory size and number of times the thread applies for memory.

[0059] The common memory of the thread is obtained through the thread memory statistics structure of the thread and the thread ID of the thread, the sum of the common memory of the thread is counted, and the maximum cache size of the thread is set according to the sum of the common memory of the thread.

[0060] Embodiment 2:

[0061] like Figure 2 As shown, Figure 2The present invention is another embodiment of a method for dynamically adjusting cache based on TCMalloc memory allocator. The TCMalloc memory allocator is divided into three levels of cache: PageHeap level 1 cache, CentralCache level 2 cache, and ThreadCache level 3 cache, wherein PageHeap is an idle Span manager, CentralCache is a common cache pool for each thread, and ThreadCache is a thread cache pool.

[0062] A specific implementation optimizes the mechanism of releasing cache in PageHeap, including:

[0063] Get pageheap.system_bytes, which is the total number of bytes that pageheap obtains from the system; and metadata_bytes, which is the number of bytes occupied by the structure of the TCMalloc memory allocator to track memory; and calculate the number of bytes of virtual memory according to the following formula:

[0064] virtual_memory_used = pageheap.system_bytes + metadata_bytes.

[0065] Get pageheap.unmapped_bytes; pageheap.unmapped_bytes is the number of unmapped bytes in the memory obtained by pageheap from the system; and calculate the number of physical memory bytes actually occupied by the TCMalloc memory allocator according to the following formula:

[0066] physical_memory_used = virtual_memory_used - pageheap.unmapped_bytes.

[0067] Get the number of cache bytes of PageHeap pageheap.free_bytes, the number of cache bytes of CentralCache central_bytes, the number of cache bytes that CentralCache is going to release to ThreadCache transfer_bytes, and the number of cache bytes of ThreadCache thread_bytes; and calculate the actual memory size allocated by TCMalloc for application use according to the following formula:

[0068] bytes_in_use_by_app = physical_memory_used - metadata_bytes - pageheap.free_bytes - central_bytes - transfer_bytes - thread_bytes.

[0069] The number of bytes allowed to be cached by TCMalloc is calculated according to the following formula, that is, the cache threshold:

[0070] threshold = bytes_in_use_by_app / number,

[0071] Preferably, 10≤number≤30; preferably, number=20;

[0072] Check the total system memory size MemTotal and the system free memory size MemFree and calculate the percentage of the current memory remaining according to the following formula: MemFree ÷ MemTotal. In a specific implementation, check MemTotal and MemFree in the / proc / meminfo path. In other implementations, other paths may be used.

[0073] If the current remaining percentage of the system is less than a predetermined percentage threshold, all caches in PageHeap are directly returned to the system; preferably, the predetermined percentage threshold is greater than or equal to 5% and less than or equal to 30%; preferably, when the current remaining percentage of the system is less than 10%, all caches in PageHeap are directly returned to the system.

[0074] If the number of PageHeap cache bytes pageheap.free_bytes is greater than the cache threshold, all PageHeap cache is returned to the system directly;

[0075] If the number of unmapped bytes in the memory obtained by PageHeap from the system, pageheap.unmapped_bytes, is greater than the cache threshold, all unmapped memory in PageHeap is returned to the system, because this part of the memory is actually occupied, but not mapped.

[0076] like Figure 3 As shown, Figure 3 The present invention is a method for dynamically adjusting cache based on TCMalloc memory allocator, in which a memory allocation function sets the maximum cache size of threads in a thread cache pool. Figure 3 , the optimizations for ThreadCache include:

[0077] Create a thread memory management container thread_memorys and define a thread memory statistics structure. The thread memory statistics structure includes:

[0078] thread_memory: a structure used to count the memory requested by threads, which contains the member tid and the hash container file_memorys, where tid is the thread id;

[0079] file_memory: a structure used to count the memory requested under the file, which includes the file name file and the hash container line_memorys;

[0080] line_memory: counts the structure of memory requested for the corresponding line in the file, including: line number line, variable size used to record the memory size, and variable count used to record the number of memory requests.

[0081] Rewrite the creation function of each thread in the application, report the tid after creating the thread, use the tid as the key, insert it into thread_memorys, set the thread callback function, report the tid when the thread exits, and delete the tid from thread_memorys.

[0082] Rewrite the memory allocation function in the application and pass in the thread ID, function line number, file name and other information when allocating memory, for example:

[0083] #define malloc(a)\

[0084] __my_malloc(a,syscall(SYS_gettid),__FILE__,__LINE__,__PRETTY_FUNCTION__)

[0085] Define the memory allocation function, use tid as the key of thread_memory, and search the structure thread_memory for statistical thread memory in thread_memorys;

[0086] According to file (file name) as the key of file_memory, find file_memory in the hash container file_memorys under thread_memory;

[0087] According to line (line number) as the key of line_memory, find line_memory in the hash container line_memorys under file_memory;

[0088] Record the size of the memory requested under file_memory, as well as count+1, which is the number of times the row is requested.

[0089] In the memory cached by the TCMalloc memory allocator, for example, the high-frequency memory size under each thread is counted every 60 seconds, that is, the memory with count under file_memory greater than or equal to 30 times in 60 seconds, the sum of the high-frequency memory size under the thread is calculated, and the maximum cache size allowed for each thread is set according to the sum of the high-frequency memory size. In other implementations, the time interval for the timed statistics can be a predetermined time other than 60 seconds.

[0090] The present invention allows each thread to set the maximum allowed memory based on TCMalloc, counts the commonly used memory of each thread, and sets the maximum cache size of each thread according to the counted commonly used memory. Compared with only allocating cache for the maximum memory required by the current thread, the present invention further optimizes the cache performance.

[0091] Embodiment three:

[0092] The present invention also provides a device for dynamically adjusting cache based on TCMalloc memory allocator, such as Figure 4 As shown, the device includes a processor 401, a memory 402, a bus 403, and a computer program stored in the memory 402 and executable on the processor 401. The processor 401 includes one or more processing cores. The memory 402 is connected to the processor 401 via the bus 403. The memory 402 is used to store program instructions. When the processor executes the computer program, the steps in the method embodiment for dynamically adjusting the cache based on the TCMalloc memory allocator of the first embodiment of the present invention are implemented.

[0093] Further, as an executable solution, the device for dynamically adjusting the cache based on the TCMalloc memory allocator can be a computer unit, which can be a computing device such as a desktop computer, a notebook, a PDA, and a cloud server. The computer unit may include, but is not limited to, a processor and a memory. Those skilled in the art will understand that the composition structure of the above-mentioned computer unit is only an example of a computer unit and does not constitute a limitation on the computer unit. It may include more or less components than the above, or a combination of certain components, or different components. For example, the computer unit may also include input and output devices, network access devices, buses, etc., which are not limited in the embodiments of the present invention.

[0094] Further, as an executable solution, the processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the computer unit, and various interfaces and lines are used to connect various parts of the entire computer unit.

[0095] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the computer unit by running or executing the computer program and / or module stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system and at least one application required for a function; the data storage area can store data created according to the use of the mobile phone, etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0096] Embodiment 4:

[0097] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the steps of the method described above are implemented.

[0098] Although the present invention has been specifically shown and described in conjunction with the preferred embodiments, it should be understood by those skilled in the art that various changes may be made to the present invention in form and details without departing from the spirit and scope of the present invention as defined by the appended claims, all of which are within the scope of protection of the present invention.

Claims

1. A method for dynamically adjusting cache based on a TCMalloc memory allocator, the TCMalloc memory allocator comprising: Idle Span manager, thread common cache pool and thread cache pool, characterized in that the method includes regularly monitoring the memory actually used by the application according to a preset time interval, and dynamically adjusting the current system cache through the following steps: Adjust the cache release mechanism in the idle Span manager, including: Calculate the size of the memory actually occupied by the application, and calculate the cache threshold of the application according to the size of the memory actually occupied by the application, and release the cache in the idle Span manager when the number of cache bytes of the idle Span manager or the number of unmapped bytes in the memory obtained by the idle Span manager from the current system is greater than the cache threshold; Calculate the percentage of the current system remaining memory, and when the percentage is less than a predetermined percentage threshold, release the cache in the idle Span manager; Set the maximum cache size of threads in the thread cache pool, including: Creating a thread memory management container and defining a thread memory statistics structure within the thread memory management container; Rewrite the thread creation function in the application, wherein the thread creation function reports the thread id of the thread to the thread memory management container and constructs a thread memory statistics structure of the thread in the thread memory management container; Rewrite the memory allocation function in the application, wherein the memory allocation function finds the thread memory management container of the thread according to the thread ID of the thread currently calling the memory allocation function, and counts the memory size applied by the thread and the number of times the thread applies for memory; Obtaining the common memory of the thread through the thread memory statistics structure of the thread and the thread ID of the thread, counting the sum of the common memory of the thread, and setting the maximum cache size of the thread according to the sum of the common memory of the thread; The step of calculating the size of the memory actually occupied by the application program, and calculating the cache threshold of the application program according to the size of the memory actually occupied by the application program, comprises: S1, obtain the total number of bytes pageheap.system_bytes obtained by the free span manager from the current system and the number of bytes metadata_bytes occupied by the structure of the memory tracked by the TCMalloc memory allocator, and obtain the number of virtual memory bytes of the current system according to the following formula: virtual_memory_used = pageheap.system_bytes + metadata_bytes; S2, obtaining the number of unmapped bytes in the memory obtained by the free span manager from the current system, pageheap.unmapped_bytes, and obtaining the number of physical memory bytes actually occupied by the TCMalloc memory allocator according to the following formula: physical_memory_used = virtual_memory_used - pageheap.unmapped_bytes; S3, obtain the cache byte number pageheap.free_bytes of the free Span manager, the cache byte number central_bytes of the thread common cache pool, the cache byte number transfer_bytes that the thread common cache pool is ready to distribute to the thread cache pool, and the cache byte number thread_bytes of the thread cache pool, and obtain the actual memory size allocated to the application by the TCMalloc memory allocator according to the following formula: bytes_in_use_by_app = physical_memory_used - metadata_bytes - pageheap.free_bytes - central_bytes - transfer_bytes - thread_bytes; S4, obtaining the cache threshold of the application according to the following formula: threshold = bytes_in_use_by_app / number Wherein, number is a pre-set positive integer, and 10≤number≤30.

2. The method for dynamically adjusting cache based on TCMalloc memory allocator according to claim 1, characterized in that: The calculating the percentage of the current system remaining memory includes: Get the total memory size MemTotal of the current system, get the free memory size MemFree of the current system, and calculate the percentage of the remaining memory of the current system by the formula MemFree ÷ MemTotal.

3. The method for dynamically adjusting cache based on TCMalloc memory allocator according to claim 1, characterized in that: The thread memory statistics structure includes: a thread application memory statistics structure thread_memory, a file application memory statistics structure file_memory and a line application memory statistics structure line_memory under the file, wherein the thread_memory includes the thread id of the thread and the hash container file_memorys of the thread_memory; the file_memory includes the file name file and the hash container line_memorys of the file_memory; the line_memory includes the line number line, the size size and the count count, wherein the size is used to record the memory size applied by the thread, and the count is used to record the number of times the thread applies for memory.

4. The method for dynamically adjusting cache based on TCMalloc memory allocator according to claim 3, characterized in that: The step of rewriting the thread creation function in the application program comprises: After creating a thread, the application reports the thread id of the thread to the thread memory management container, and inserts the thread id into the thread memory management container as a key; sets a callback function for the thread, reports the thread id of the thread to the thread memory management container and deletes the thread id from the thread memory management container when the thread exits.

5. The method for dynamically adjusting cache based on TCMalloc memory allocator according to claim 4, characterized in that: The step of rewriting the memory allocation function in the application program comprises: The memory allocation function adds new parameters and rewrites the memory allocation function logic, wherein the new parameters include: the thread id of the thread that calls the memory allocation function, the file name of the file that calls the memory allocation function, and the line number of the file that specifically calls the memory allocation function; The logic of the memory allocation function is: according to the thread id, search the thread_memory of the thread id in the thread memory management container; Find the file_memory of the file name in file_memorys under the thread_memory according to the file name; Find the line_memory of the line number in line_memorys under the file_memory according to the line number; The memory size requested by the thread is recorded in the line_memory, and the number of memory requests by the thread in the line_memory is incremented.

6. The method for dynamically adjusting cache based on TCMalloc memory allocator according to claim 1, characterized in that: The obtaining the common memory of the thread through the thread memory statistics structure of the thread and the thread ID of the thread includes: The commonly used memory of the threads in the current system is counted regularly according to a preset time, wherein the commonly used memory is the memory for which the number of times of applying for memory in the preset time is greater than or equal to a predetermined number.

7. A device for dynamically adjusting cache based on TCMalloc memory allocator, characterized in that: It includes a memory and a processor, the memory stores at least one program, and the at least one program is executed by the processor to implement the method for dynamically adjusting cache based on TCMalloc memory allocator as described in any one of claims 1 to 6.

8. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method for dynamically adjusting cache based on a TCMalloc memory allocator as described in any one of claims 1 to 6 is implemented.