Memory monitoring method and device, equipment and medium
By allocating multiple threads to the functional modules of the autonomous driving system and using preset arrays to monitor the memory size in real time, the problem of locating abnormal memory usage and leaks in the autonomous driving system is solved, and the accuracy and efficiency of memory monitoring are improved.
Patent Information
- Application Number
- CN202410797564.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-19
- Publication Date
- 2024-09-03
AI Technical Summary
In autonomous driving systems, existing technology is difficult to quickly locate and solve abnormal memory usage and memory leaks in functional modules, which affects the normal operation of the system.
By allocating multiple threads to each functional module, using a preset array to monitor the memory size of the thread in real time, adjusting the memory size, and judging whether there is an abnormal memory usage based on the adjusted size, precise monitoring of the functional modules is achieved.
It improves the monitoring accuracy of memory usage of functional modules in the autonomous driving system, quickly locates memory usage abnormalities and memory leaks, and ensures normal operation of the system.
Smart Images

Figure CN118585401A
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence, in particular to the field of autonomous driving, and in particular to a method, device, equipment and medium for memory monitoring. Background Art
[0002] The autonomous driving system can be composed of functional modules such as perception, positioning, prediction, planning, and control. Different functional modules can realize different autonomous driving functions. When each functional module is working, it is necessary to apply for or release memory to ensure the normal operation of the autonomous driving system.
[0003] During the operation of the autonomous driving system, it is necessary to monitor the memory usage in real time so that when the autonomous driving system has abnormal memory usage, the abnormal part can be quickly located. How to accurately monitor the abnormal memory situation for functional modules is an urgent problem that needs to be solved. Summary of the invention
[0004] The present disclosure provides a method, apparatus, device and medium for memory monitoring.
[0005] According to a first aspect of the present disclosure, a memory monitoring method is provided. The method is applied to a preset system. The preset system includes multiple function modules. The function modules are used to implement the functions of the preset system. The same function module corresponds to at least one thread. The thread is used to execute the function corresponding to the function module. Each thread has a unique thread number. The method includes:
[0006] In response to a memory allocation request initiated by a thread, determining the thread number of the thread and the size of the memory requested to be allocated; wherein the memory allocation request is a memory application request or a memory release request;
[0007] According to the thread number of the thread and the memory size requested for allocation, the memory size occupied by the thread is adjusted to obtain an adjusted memory size;
[0008] According to the adjusted memory size occupied by the thread, it is determined whether the functional module has a memory occupation abnormality.
[0009] According to a second aspect of the present disclosure, a memory monitoring device is provided, which is applied to a preset system, wherein the preset system includes a plurality of functional modules, wherein the functional modules are used to implement the function of automatic driving, wherein the same functional module corresponds to at least one thread, wherein the thread is used to execute the function corresponding to the functional module, and each thread corresponds to a unique thread number; the device includes:
[0010] A request allocation unit, configured to determine the thread number of the thread and the size of the memory requested to be allocated in response to a memory allocation request initiated by the thread; wherein the memory allocation request is a memory application request or a memory release request;
[0011] A size adjustment unit, configured to adjust the size of the memory occupied by the thread according to the thread number of the thread and the memory size requested for allocation, to obtain an adjusted memory size;
[0012] The abnormality judgment unit is used to determine whether the functional module has a memory occupancy abnormality according to the adjusted memory size occupied by the thread.
[0013] According to a third aspect of the present disclosure, there is provided an electronic device, including:
[0014] at least one processor; and
[0015] a memory communicatively coupled to the at least one processor;
[0016] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method described in the first aspect.
[0017] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause the computer to execute the method described in the first aspect.
[0018] According to a fifth aspect of the present disclosure, a computer program product is provided, the computer program product comprising: a computer program, which implements the method described in the first aspect when executed by a processor.
[0019] According to the technology disclosed in the present invention, the monitoring accuracy of the memory usage of the functional modules in the autonomous driving system is improved.
[0020] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0022] Figure 1 It is a flowchart of a memory monitoring method provided according to an embodiment of the present disclosure;
[0023] Figure 2It is a flowchart of a memory monitoring method provided according to an embodiment of the present disclosure;
[0024] Figure 3 is a memory schematic diagram of a first target memory size provided according to an embodiment of the present disclosure;
[0025] Figure 4 It is a flowchart of a memory monitoring method provided according to an embodiment of the present disclosure;
[0026] Figure 5 It is a flowchart of a memory monitoring method provided according to an embodiment of the present disclosure;
[0027] Figure 6 is a schematic diagram of a memory change curve of a functional module provided according to an embodiment of the present disclosure;
[0028] Figure 7 It is a flowchart of a memory monitoring method provided according to an embodiment of the present disclosure;
[0029] Figure 8 is a structural block diagram of a memory monitoring device provided according to an embodiment of the present disclosure;
[0030] Fig. 9 is a structural block diagram of a memory monitoring device provided according to an embodiment of the present disclosure;
[0031] Fig.10 is a block diagram of an electronic device for implementing the memory monitoring method of the embodiment of the present disclosure;
[0032] Fig.11 It is a block diagram of an electronic device used to implement the memory monitoring method of the embodiment of the present disclosure. DETAILED DESCRIPTION
[0033] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0034] The autonomous driving system can be composed of functional modules such as perception, positioning, prediction, planning, and control. When the autonomous driving system has memory leaks and abnormal memory usage, it is difficult to quickly locate the problem at the module level, thus affecting the normal operation of the autonomous driving system. In order to ensure the normal operation of the autonomous driving system, it is necessary to count the memory usage of each functional module in real time, so that we have a clearer understanding of the memory resources of the autonomous driving system and promptly discover and solve problems such as excessive memory usage and memory leaks.
[0035] In the related technologies of memory monitoring, a separate process can be created for each functional module, and the memory of each process can be counted in real time. The memory of each process is the memory of each functional module. However, different processes need to communicate to exchange data and information, which will introduce additional communication overhead and increase the complexity and delay of the system. In addition, each process requires independent memory space and system resources, including CPU (Central Processing Unit), memory, etc. If the number of processes is too large, it will lead to waste of resources and increase the load of the system, affecting the normal operation of the system, and then causing errors in memory monitoring, affecting the accuracy and efficiency of memory monitoring.
[0036] The present disclosure provides a method, device, equipment and medium for memory monitoring, which are applied to the field of autonomous driving in the field of artificial intelligence to improve the monitoring accuracy of memory.
[0037] It should be noted that the data in this embodiment is not targeted at a specific user and cannot reflect the personal information of a specific user. It should be noted that the data in this embodiment comes from a public data set.
[0038] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0039] In order to enable readers to more deeply understand the implementation principle of the present disclosure, the following Figure 1-Figure 11 The embodiment is further refined.
[0040] Figure 1 The present invention is a flowchart of a memory monitoring method provided according to an embodiment of the present invention. The method can be executed by a memory monitoring device. The method is applied to a preset system, which includes multiple functional modules, and the functional modules are used to implement the functions of the preset system. The preset system can be an autonomous driving system, which includes multiple functional modules, and the functional modules are used to implement the functions of autonomous driving. The same functional module corresponds to at least one thread, and the thread is used to execute the function corresponding to the functional module. Each thread corresponds to a unique thread number. Figure 1As shown, the method comprises the following steps:
[0041] S101. In response to a memory allocation request initiated by a thread, determine the thread number of the thread and the size of the memory requested to be allocated; wherein the memory allocation request is a memory application request or a memory release request.
[0042] Exemplarily, the autonomous driving system may include multiple functional modules, and different functional modules may be used to implement different functions of the autonomous driving system. For example, the functional modules may include a perception module, a prediction module, a planning module, and a control module. For each functional module, a thread pool is configured, and a thread pool may include multiple threads, that is, a functional module corresponds to multiple threads, and the functions corresponding to the functional modules can be executed by running the threads. The memory of the thread pool can be used to represent the memory occupied by the corresponding functional module, that is, the memory of all threads in the thread pool is the memory occupied by the corresponding functional module.
[0043] For all threads in all thread pools, each thread can issue a memory allocation request. A memory allocation request can be a memory application request or a memory release request, that is, each thread can request memory or release memory. Each thread has a unique thread number, which is the identifier of the thread. For any thread, the thread number of the thread can be determined by responding to the memory allocation request initiated by the thread. The memory allocation request can also include the size of memory requested by the thread, for example, the size of memory requested by the thread or the size of memory to be released by the thread. After responding to the memory allocation request, the size of memory requested by the thread can be obtained from the memory allocation request.
[0044] The preset first array can also be directly obtained. The first array includes multiple elements, and the index of the element is the thread number, that is, each thread has a corresponding element in the first array, and the numerical value of the element represents the memory size occupied by the thread corresponding to the thread number. For example, there are six threads, and the initial memory size occupied by each thread is 0, and the thread numbers are 0, 1, 2, 3, 4, and 5 respectively. Then the first array can be [0, 0, 0, 0, 0, 0], and the index numbers of the elements in the first array are 0, 1, 2, 3, 4, and 5 respectively. The number of elements in the first array can be greater than the number of threads, as long as the index of the last element is the largest thread number among all threads. For example, there are six threads, and the thread numbers are 012567 respectively, then the first array can be expressed as [0, 0, 0, 0, 0, 0, 0], and the indexes of the elements are 0, 1, 2, 3, 4, 5, 6, and 7 respectively, among which the elements with indexes 0, 1, 2, 5, 6, and 7 have corresponding threads, and the numerical values of the elements with indexes 3 and 4 will not change. As the size of the memory occupied by the thread changes, the value of the element corresponding to the thread will also change. That is, the value of the element corresponding to the thread can increase or decrease.
[0045] S102: According to the thread number of the thread and the memory size requested for allocation, the memory size occupied by the thread is adjusted to obtain an adjusted memory size.
[0046] Exemplarily, according to the thread number of the thread, the memory size currently occupied by the thread number is determined, that is, the memory size currently occupied by the thread is determined. According to the memory size requested for allocation, the memory size occupied by the thread is resized to obtain the adjusted memory size. For example, the currently occupied memory size can be increased or decreased.
[0047] In this embodiment, after responding to a memory allocation request initiated by a thread, a preset first array can be obtained; wherein the index of the element in the preset first array is the thread number, and the element in the preset first array represents the memory size occupied by the thread corresponding to the thread number. According to the thread number of the thread and the memory size requested for allocation, the memory size represented by the element in the preset first array corresponding to the thread is adjusted to obtain the adjusted memory size.
[0048] Exemplarily, according to the thread number of the thread, the element corresponding to the thread number is found from the first array, that is, the element corresponding to the thread is found, and the element represents the memory size occupied by the thread. Then, according to the memory size requested for allocation, the numerical value of the element corresponding to the thread is adjusted, that is, the memory size represented by the element is adjusted.
[0049] For example, if a thread applies for 10 bytes of memory, then the current value of the element corresponding to the thread can be added by 10. For another example, if a thread applies for releasing 10 bytes of memory, then the current value of the element corresponding to the thread can be subtracted by 10.
[0050] In this embodiment, the functions for memory application and release can be preset, for example, the malloc function and the free function can be preset, the malloc function is a dynamic memory allocation function, and the free function is a memory space release function. By calling the malloc function, it can be used to increase the memory usage, and by calling the free function, it can be used to reduce the memory usage. In this embodiment, the functions for memory application and release are not specifically limited. When each memory allocation is performed, not only the thread number and memory size can be recorded, but also information such as memory address can be recorded in real time.
[0051] S103: Determine whether a functional module has a memory occupancy abnormality according to the adjusted memory size occupied by the thread.
[0052] Exemplarily, after determining the adjusted memory size corresponding to the thread, it can be determined whether the functional module has a memory occupancy anomaly according to the adjusted memory size. For example, if the adjusted memory size exceeds a preset size threshold, it is considered that the functional module described by the thread has an anomaly.
[0053] In this embodiment, it can be determined whether the functional module has a memory usage abnormality according to the adjusted memory size represented by the element corresponding to the thread to which the functional module belongs in the preset first array.
[0054] For example, it is possible to determine whether each functional module has a memory usage anomaly based on the memory size represented by the elements in the array. The memory usage anomaly may be a memory leak, which means that the memory cannot be released.
[0055] A functional module corresponds to multiple threads, and the thread number of the thread corresponding to the functional module is determined. For any functional module, the elements corresponding to all threads belonging to the functional module can be obtained from the first array in real time or periodically according to the thread number of the thread corresponding to the functional module, that is, the elements under the thread number of all threads corresponding to the functional module are found. For example, there are three threads corresponding to the functional module, and the thread numbers are 0, 1, and 2 respectively, then the elements with indexes of 0, 1, and 2 are searched from the first array. According to the memory size represented by the found elements, determine whether the functional module has abnormal conditions such as memory leaks. For example, the values of the multiple elements found can be added to obtain the memory size currently occupied by the functional module, and it can be determined whether the memory size is greater than the preset size threshold. If so, it is considered that the functional module has an abnormality; if not, it is considered that the functional module does not have an abnormality.
[0056] It is also possible to obtain the elements corresponding to each thread to which the functional module belongs at a fixed time, add the memory sizes represented by the elements corresponding to each thread, and obtain the memory size occupied by the functional module at the current moment. According to the time sequence of different moments, it is determined whether the memory size occupied by the functional module has been increasing without decreasing. If so, it is considered that the functional module has an abnormal memory leak; if not, it is considered that the functional module does not have an abnormal memory leak.
[0057] In the disclosed embodiment, multiple threads are allocated to the functional module, and a first array is preset according to the thread number of the thread. The index of the elements in the first array is the thread number, and the elements in the first array represent the memory size occupied by the thread corresponding to the thread number. In response to the memory allocation request initiated by the thread, the thread number of the thread and the memory size requested to be allocated are determined. According to the thread number of the thread and the memory size requested to be allocated, the memory size represented by the element corresponding to the thread in the first array is resized so that the element in the first array can represent the memory size currently occupied by the corresponding thread. According to the memory size represented by the elements corresponding to the multiple threads to which the functional module belongs, it is determined whether the functional module has a memory occupancy anomaly, which solves the problem that the abnormal situation cannot be located at the module level in the related technology. By obtaining the memory occupancy of each thread in real time, the memory occupancy of the functional module is obtained, which provides an effective means for quickly locating the memory occupancy anomaly and memory leak of each functional module, realizes memory monitoring of the functional module, and effectively improves the accuracy and efficiency of memory monitoring.
[0058] Figure 2 A flowchart of a memory monitoring method provided in an embodiment of the present disclosure.
[0059] In this embodiment, the memory allocation request is a memory application request, which includes the memory size to be applied for; according to the thread number of the thread and the memory size requested for allocation, the memory size represented by the element corresponding to the thread in the preset first array is resized, including: according to the memory size to be applied for, a first target memory size is determined; wherein the first target memory size is the sum of the memory size to be applied for and a preset basic memory size, and the preset basic memory size is used to store the thread number; according to the first target memory size, the memory size represented by the element corresponding to the thread number of the thread in the preset first array is resized.
[0060] like Figure 2 As shown, the method comprises the following steps:
[0061] S201. In response to a memory allocation request initiated by a thread, determine the thread number and the requested memory size of the thread, and obtain a preset first array; wherein the memory allocation request is a memory application request or a memory release request, the index of the element in the preset first array is the thread number, and the element in the preset first array represents the memory size occupied by the thread corresponding to the thread number.
[0062] Exemplarily, this step may refer to the above-mentioned step S101 and will not be described in detail.
[0063] S202. Determine a first target memory size according to the memory size to be applied for; wherein the first target memory size is the sum of the memory size to be applied for and a preset basic memory size, and the preset basic memory size is used to store the thread number.
[0064] Exemplarily, the memory allocation request may be a memory application request, which indicates that the thread applies for memory, and the memory size occupied by the thread will increase. The memory application request may include the memory size to be applied for. That is, after responding to the memory application request of the thread, the memory size to be applied for by the thread can be obtained.
[0065] According to the memory size to be applied for, a memory size can be determined as the first target memory size. The first target memory size is the sum of the memory size to be applied for and the preset basic memory size, that is, the first target memory size is larger than the memory size to be applied for. The memory of the first target memory size is allocated to the thread, that is, the actual memory size allocated to the thread is larger than the memory size applied for by the thread. The preset basic memory size can be used to store the thread number. For example, the memory applied for by the thread is 6 bytes, the preset basic memory size is 4 bytes, the first target memory size is 10 bytes, and the memory size allocated to the thread is 10 bytes. The thread number can be written into the memory allocated to the thread.
[0066] A preset magic word can also be stored in the memory corresponding to the preset basic memory size, for example, the preset magic word is 0b01010101. The magic word and the thread number are both stored in the memory corresponding to the preset basic memory size. For example, 4 bytes are applied for more than the memory size applied for by the thread, that is, the preset basic memory size is 4 bytes. The first byte of the 4 bytes stores the magic word, and the last 3 bytes store the thread number.
[0067] S203: According to the first target memory size, adjust the memory size represented by the element corresponding to the thread number of the thread in the preset first array.
[0068] Exemplarily, an element corresponding to the thread number of the thread is obtained from the first array, and the memory size represented by the element is determined. After the first target memory size is determined, the memory size represented by the element can be resized according to the first target memory size. Since the memory allocation request is a memory application request, when resizing, the memory size represented by the element can be increased, that is, it indicates that the memory occupied by the thread increases.
[0069] In this embodiment, when a thread applies for memory, a larger memory than required is allocated to the thread, and the thread number is written in the memory, so as to facilitate statistics on the destination of the memory and improve the management accuracy of the memory.
[0070] In this embodiment, the memory size represented by the element corresponding to the thread number of the thread in the preset first array is adjusted according to the first target memory size, including: determining the current memory size represented by the element corresponding to the thread number of the thread in the preset first array; adding the first target memory size to the current memory size to obtain the adjusted memory size represented by the element corresponding to the thread number of the thread.
[0071] Specifically, an element corresponding to the thread number of the thread is obtained from the preset first array to obtain the memory size represented by the element, that is, the memory size currently occupied by the thread. For example, the current value of the element is 10, indicating that the thread currently occupies 10 bytes of memory.
[0072] For a memory application request, the memory size represented by the element needs to be increased. Therefore, the memory size currently represented by the element can be added to the first target memory size, and the added value is used as the adjusted memory size represented by the element corresponding to the thread number of the thread. For example, if the original memory size represented by the element is 10 and the first target memory size is 6, the adjusted memory size is 16.
[0073] The beneficial effect of such a setting is that the size of the element corresponding to the thread is increased, indicating that the memory occupied by the thread is increased, thereby improving the efficiency of memory statistics and facilitating the supervision of memory occupancy.
[0074] S204: Determine whether there is a memory usage abnormality in the functional module according to the memory size represented by the element corresponding to the thread to which the functional module belongs in the preset first array.
[0075] Exemplarily, this step may refer to the above-mentioned step S103 and will not be described in detail.
[0076] Figure 3 Memory diagram of the first target memory size. Figure 3The memory allocated to the thread may include the memory requested by the thread, the magic word and the thread number. In the current memory allocation related technology, the memory allocated to the thread only has the memory requested by the thread, without the magic word and the thread number.
[0077] In the disclosed embodiment, multiple threads are allocated to the functional module, and a first array is preset according to the thread number of the thread. The index of the elements in the first array is the thread number, and the elements in the first array represent the memory size occupied by the thread corresponding to the thread number. In response to the memory allocation request initiated by the thread, the thread number of the thread and the memory size requested to be allocated are determined. According to the thread number of the thread and the memory size requested to be allocated, the memory size represented by the element corresponding to the thread in the first array is resized so that the element in the first array can represent the memory size currently occupied by the corresponding thread. According to the memory size represented by the elements corresponding to the multiple threads to which the functional module belongs, it is determined whether the functional module has a memory occupancy anomaly, which solves the problem that the abnormal situation cannot be located at the module level in the related technology. By obtaining the memory occupancy of each thread in real time, the memory occupancy of the functional module is obtained, which provides an effective means for quickly locating the memory occupancy anomaly and memory leak of each functional module, realizes memory monitoring of the functional module, and effectively improves the accuracy and efficiency of memory monitoring.
[0078] Figure 4 A flowchart of a memory monitoring method provided in an embodiment of the present disclosure.
[0079] In this embodiment, the memory allocation request is a memory release request, and the memory release request includes the memory size to be released; according to the thread number of the thread and the memory size requested for allocation, the memory size represented by the element corresponding to the thread in the preset first array is resized, including: according to the memory size to be released, a second target memory size is determined; wherein the second target memory size is the sum of the memory size to be released and a preset basic memory size, and the preset basic memory size is used to store the thread number; according to the second target memory size, the memory size represented by the element corresponding to the thread number of the thread in the preset first array is resized.
[0080] like Figure 4 As shown, the method comprises the following steps:
[0081] S401. In response to a memory allocation request initiated by a thread, determine the thread number and the requested memory size of the thread, and obtain a preset first array; wherein the memory allocation request is a memory application request or a memory release request, the index of the element in the preset first array is the thread number, and the element in the preset first array represents the memory size occupied by the thread corresponding to the thread number.
[0082] Exemplarily, this step may refer to the above-mentioned step S101 and will not be described in detail.
[0083] S402. Determine a second target memory size according to the memory size to be released; wherein the second target memory size is the sum of the memory size to be released and a preset basic memory size, and the preset basic memory size is used to store the thread number.
[0084] Exemplarily, the memory allocation request may be a memory release request, which indicates that the thread requests to release memory, and the memory size occupied by the thread will be reduced, and the memory release request may include the memory size to be released. That is, after responding to the memory release request of the thread, the memory size to be released by the thread can be obtained.
[0085] According to the memory size to be released, a memory size can be determined as the second target memory size. The second target memory size is the sum of the memory size to be released and the preset basic memory size, that is, the second target memory size is larger than the memory size to be released. The memory of the second target memory size is released from the memory occupied by the thread, that is, the memory size actually released by the thread is larger than the memory size requested to be released by the thread. The preset basic memory size can be used to store the thread number. For example, the memory requested to be released by the thread is 6 bytes, the preset basic memory size is 4 bytes, the second target memory size is 10 bytes, the memory size released by the thread is 10 bytes, and the released memory includes the thread number. When the thread applies for memory, the memory containing the thread number is obtained. When releasing the memory, the memory containing the thread number applied for can be released.
[0086] A preset magic word may also be stored in the memory corresponding to the preset basic memory size, for example, the preset magic word is 0b01010101. The magic word and the thread number are both stored in the memory corresponding to the preset basic memory size. For example, when a thread applies for memory, the obtained memory contains the magic word and the thread number, and the memory actually released by the thread may contain the memory previously storing the magic word and the thread number. The composition of the memory applied for by the thread may be the same as the composition of the memory released by the thread.
[0087] In this embodiment, the method also includes: determining all memory application requests initiated by the thread before the memory release request as historical application requests; determining the target application request from the historical application requests; determining the second target memory size based on the memory size to be applied for in the target application request; wherein the second target memory size is the sum of the memory size to be applied for in the target application request plus a preset basic memory size.
[0088] Specifically, the memory initially occupied by each thread is 0. Therefore, when using memory, the thread can apply for it first and then release it. That is, before the thread initiates a memory release request, it must have initiated a memory application request. After responding to the thread's memory release request, it can be determined that the memory application request was initiated before the memory release request was initiated. There can be multiple memory application requests before the memory release request was initiated. The memory application request initiated before the memory release request is determined as a historical application request. A historical application request is determined from multiple historical application requests as the target application request. For example, the historical application request that is closest to the memory release request can be determined as the target application request. That is, the memory application request before the memory release request is used as the target application request.
[0089] Determine the memory size to be applied for by the thread in the target application request, and determine the second target memory size according to the memory size to be applied for in the target application request. The second target memory size can be the sum of the memory size to be applied for in the target application request plus the preset basic memory size, that is, the second target memory size is the first target memory size corresponding to the target application request. In other words, the memory applied for the last time is released. For example, the memory applied for the last time is 10 bytes, and these 10 bytes include magic words and thread numbers. After receiving the memory release request, these 10 bytes of memory are released.
[0090] The beneficial effect of such a setting is that the memory applied for the previous time can be directly released, thereby improving the efficiency of memory release, avoiding errors in memory size calculation, and improving the accuracy and efficiency of memory monitoring.
[0091] S403: According to the second target memory size, adjust the memory size represented by the element corresponding to the thread number of the thread in the preset first array.
[0092] Exemplarily, an element corresponding to the thread number of the thread is obtained from the first array, and the memory size represented by the element is determined. After the second target memory size is determined, the memory size represented by the element can be resized according to the second target memory size. Since the memory allocation request is a memory release request, when resizing, the memory size represented by the element can be reduced, that is, the memory occupied by the thread is reduced.
[0093] In this embodiment, when a thread releases memory, a larger memory than required is allocated to the thread, and the memory containing the thread number is released, thereby avoiding waste of memory occupancy and improving the management accuracy of memory.
[0094] In this embodiment, the memory size represented by the element corresponding to the thread number of the thread in the preset first array is adjusted according to the second target memory size, including: determining the current memory size represented by the element corresponding to the thread number of the thread in the preset first array; subtracting the second target memory size from the current memory size to obtain the adjusted memory size represented by the element corresponding to the thread number of the thread.
[0095] Specifically, an element corresponding to the thread number of the thread is obtained from the preset first array to obtain the memory size represented by the element, that is, the memory size currently occupied by the thread. For example, the current value of the element is 10, indicating that the thread currently occupies 10 bytes of memory.
[0096] For a memory release request, the memory size represented by the element needs to be reduced, so the memory size currently represented by the element can be subtracted from the second target memory size, and the subtracted value is used as the adjusted memory size represented by the element corresponding to the thread number of the thread. For example, if the original memory size represented by the element is 10 and the second target memory size is 6, the adjusted memory size is 4.
[0097] The beneficial effect of such a setting is that the size of the element corresponding to the thread is reduced, indicating that the memory occupied by the thread is reduced, thereby improving the efficiency of memory statistics and facilitating the supervision of memory occupancy.
[0098] S404: Determine whether there is a memory usage abnormality in the functional module according to the memory size represented by the element corresponding to the thread to which the functional module belongs in the preset first array.
[0099] Exemplarily, this step may refer to the above-mentioned step S103 and will not be described in detail.
[0100] In the disclosed embodiment, multiple threads are allocated to the functional module, and a first array is preset according to the thread number of the thread. The index of the elements in the first array is the thread number, and the elements in the first array represent the memory size occupied by the thread corresponding to the thread number. In response to the memory allocation request initiated by the thread, the thread number of the thread and the memory size requested to be allocated are determined. According to the thread number of the thread and the memory size requested to be allocated, the memory size represented by the element corresponding to the thread in the first array is resized so that the element in the first array can represent the memory size currently occupied by the corresponding thread. According to the memory size represented by the elements corresponding to the multiple threads to which the functional module belongs, it is determined whether the functional module has a memory occupancy anomaly, which solves the problem that the abnormal situation cannot be located at the module level in the related technology. By obtaining the memory occupancy of each thread in real time, the memory occupancy of the functional module is obtained, which provides an effective means for quickly locating the memory occupancy anomaly and memory leak of each functional module, realizes memory monitoring of the functional module, and effectively improves the accuracy and efficiency of memory monitoring.
[0101] Figure 5 A flowchart of a memory monitoring method provided in an embodiment of the present disclosure.
[0102] In this embodiment, according to the memory size represented by the element corresponding to the thread to which the functional module belongs in a preset first array, determining whether the functional module has a memory usage abnormality includes: determining the thread to which the functional module belongs; obtaining the size of the element corresponding to the thread to which the functional module belongs in a preset first array according to a preset time period; determining the memory usage size of the functional module according to the size of the element corresponding to the thread to which the functional module belongs; wherein the memory usage size of the functional module is the sum of the memory sizes represented by the elements corresponding to the thread to which the functional module belongs; determining the memory change graph of the functional module; wherein the memory change graph represents the changing trend of the memory usage size of the functional module; and determining whether the functional module has a memory usage abnormality according to the memory change graph of the functional module.
[0103] like Figure 5 As shown, the method comprises the following steps:
[0104] S501. In response to a memory allocation request initiated by a thread, determine the thread number and the requested memory size of the thread, and obtain a preset first array; wherein the memory allocation request is a memory application request or a memory release request, the index of the element in the preset first array is the thread number, and the element in the preset first array represents the memory size occupied by the thread corresponding to the thread number.
[0105] Exemplarily, this step may refer to the above-mentioned step S101 and will not be described in detail.
[0106] S502: Adjust the size of the memory represented by the element corresponding to the thread in the preset first array according to the thread number of the thread and the memory size requested for allocation.
[0107] Exemplarily, this step may refer to the above-mentioned step S102 and will not be described in detail.
[0108] S503: Determine the thread to which the functional module belongs.
[0109] Exemplarily, after adjusting the memory size represented by the elements in the first array, it can be determined whether each module has memory usage anomalies according to the memory size represented by each element in the first array. For each functional module, there are different threads. For any functional module, determine the thread to which the functional module belongs, that is, determine which threads correspond to the functional module.
[0110] S504: According to a preset time period, obtain the size of the element corresponding to the thread to which the functional module belongs in the preset first array.
[0111] Exemplarily, the memory sizes represented by the elements corresponding to different threads can be obtained from the first array at regular intervals according to a preset time period, that is, the memory sizes represented by the elements corresponding to the threads to which the functional modules belong can be obtained. For example, the memory sizes represented by the elements can be obtained once every hour.
[0112] Assuming that there are three threads to which the functional module belongs, and the thread numbers are 1, 2, and 3, the values of the elements corresponding to the three threads can be obtained from the first array at regular intervals. In other words, for the functional module, the values of the three elements can be obtained at regular intervals, that is, the memory size occupied by each thread to which the functional module belongs at different times can be obtained.
[0113] S505 . Determine the memory occupied by the functional module according to the size of the element corresponding to the thread to which the functional module belongs; wherein the memory occupied by the functional module is the sum of the memory sizes represented by the elements corresponding to the thread to which the functional module belongs.
[0114] Exemplarily, the element corresponding to the thread to which the functional module belongs is determined as the element to be processed. The memory size represented by each element to be processed is obtained periodically, and the memory occupied size of the functional module is determined according to the memory size represented by these elements to be processed. The memory occupied size of the functional module represents the memory size currently occupied by the functional module, and the memory occupied size is the sum of the memory sizes represented by the elements corresponding to the thread to which the functional module belongs. That is, the memory sizes represented by the elements to be processed are added to obtain the memory occupied size of the functional module.
[0115] According to the preset time period, the memory usage of the functional module at different times can be obtained. For example, for a certain functional module, the memory usage of the functional module can be obtained every 1 hour.
[0116] S506: Determine a memory change graph of the functional module; wherein the memory change graph represents a change trend of the memory usage size of the functional module.
[0117] Exemplarily, according to the memory usage of the functional module at different times, a memory change graph of the functional module can be obtained. The memory change graph represents the changing trend of the memory usage of the functional module. The memory change graph can be in the form of a curve, and one functional module can correspond to a memory change curve. The horizontal axis of the memory change curve represents time, and the vertical axis represents memory size. The memory usage of the functional module at different times is connected by a curve to obtain the memory change curve of the functional module.
[0118] S507: Determine whether there is abnormal memory usage in the functional module according to the memory change graph of the functional module.
[0119] Exemplarily, according to the curve change trend of the memory change graph, it is determined whether the functional module has abnormal memory usage. For example, if the memory change graph is an increasing curve, it is determined that the functional module has abnormal memory usage.
[0120] Specifically, the direction of the memory change curve can be judged. If the memory change curve increases first and then decreases, or presents a continuous waveform of first increasing and then decreasing, it is considered that the functional module is operating normally and there is no memory usage abnormality; if the memory change curve is an increasing curve, it is considered that the functional module only applies for memory and does not release memory, that is, there is a memory leak abnormality.
[0121] When determining the direction of the memory change curve, the memory usage size at two adjacent moments can be obtained. By comparing the memory usage size at two adjacent moments, the direction of the memory change curve can be determined.
[0122] In this embodiment, the sum of the memory occupied by all threads under the functional module is determined as the memory size occupied by the functional module. The memory size occupied by the functional module is obtained regularly, and a memory change curve is automatically generated. According to the memory change curve, it is automatically determined whether the module has a memory leak, thereby improving the efficiency of memory monitoring and realizing the automation of memory monitoring.
[0123] Figure 6 Schematic diagram of the memory change curve of the functional module. Figure 6 In the figure, the memory change curve shows a continuous upward trend, indicating that the functional module has abnormal memory usage.
[0124] In the disclosed embodiment, multiple threads are allocated to the functional module, and a first array is preset according to the thread number of the thread. The index of the elements in the first array is the thread number, and the elements in the first array represent the memory size occupied by the thread corresponding to the thread number. In response to the memory allocation request initiated by the thread, the thread number of the thread and the memory size requested to be allocated are determined. According to the thread number of the thread and the memory size requested to be allocated, the memory size represented by the element corresponding to the thread in the first array is resized so that the element in the first array can represent the memory size currently occupied by the corresponding thread. According to the memory size represented by the elements corresponding to the multiple threads to which the functional module belongs, it is determined whether the functional module has a memory occupancy anomaly, which solves the problem that the abnormal situation cannot be located at the module level in the related technology. By obtaining the memory occupancy of each thread in real time, the memory occupancy of the functional module is obtained, which provides an effective means for quickly locating the memory occupancy anomaly and memory leak of each functional module, realizes memory monitoring of the functional module, and effectively improves the accuracy and efficiency of memory monitoring.
[0125] Figure 7 A flowchart of a memory monitoring method provided in an embodiment of the present disclosure.
[0126] In this embodiment, the method also includes: responding to a memory application request initiated by a thread, if it is determined that a functional module corresponding to the thread has a memory usage exception, determining a memory address of the memory called to the thread, and recording call stack information; wherein the call stack information includes a function that calls the memory to the thread; responding to a memory release request initiated by the thread, determining a function with a memory usage exception based on the memory address of the memory called to the thread and the call stack information; wherein the function with a memory usage exception is a function that causes the memory usage exception.
[0127] In response to a memory release request initiated by a thread, a function with abnormal memory usage is determined based on a memory address of a memory called to the thread and call stack information, including: in response to a memory release request initiated by a thread, a memory address of a memory released from the thread is determined; if it is determined that within a preset time period, the memory address of the memory called to the thread is not the memory address of the memory released from the thread, then the call stack information of the memory called to the thread is obtained; and based on the call stack information, a function with abnormal memory usage is determined.
[0128] like Figure 7 As shown, the method comprises the following steps:
[0129] S701. In response to a memory allocation request initiated by a thread, determine the thread number and the requested memory size of the thread, and obtain a preset first array; wherein the memory allocation request is a memory application request or a memory release request, the index of the element in the preset first array is the thread number, and the element in the preset first array represents the memory size occupied by the thread corresponding to the thread number.
[0130] Exemplarily, this step may refer to the above-mentioned step S101 and will not be described in detail.
[0131] S702: Adjust the memory size represented by the element corresponding to the thread in the preset first array according to the thread number of the thread and the memory size requested for allocation.
[0132] Exemplarily, this step may refer to the above-mentioned step S102 and will not be described in detail.
[0133] S703: Determine whether there is a memory usage abnormality in the functional module according to the memory size represented by the element corresponding to the thread to which the functional module belongs in the preset first array.
[0134] Exemplarily, this step may refer to the above-mentioned step S103 and will not be described in detail.
[0135] S704. In response to the memory application request initiated by the thread, if it is determined that the functional module corresponding to the thread has a memory usage exception, determine the memory address of the memory called to the thread and record the call stack information; wherein the call stack information includes the function that calls the memory to the thread.
[0136] Exemplarily, after determining that a functional module has a memory usage exception, the exception can be further located at the function level, that is, determining which function has the memory usage exception. For example, it can be determined which function cannot release memory. The function with the memory usage exception can be determined during the process of a thread initiating a memory allocation request.
[0137] When the thread is working normally, it first initiates a memory application request, responds to the memory application request initiated by the thread, and determines the functional module corresponding to the thread. It is determined whether the functional module corresponding to the thread has memory usage anomalies. If so, the memory is called to the thread, and the memory address of the memory called to the thread is determined; if not, the memory is called to the thread. When calling the memory to the thread, the memory size to be distributed to the thread can be determined according to the memory size to be applied for, and the memory of the memory size is sent to the thread, and according to the memory size, the memory size represented by the element corresponding to the thread number of the thread in the first array is resized.
[0138] After determining that the function module corresponding to the thread has a memory usage anomaly, determine the memory address of the memory called to the thread, and record the call stack information. The call stack information can indicate the calling order of the functions called when allocating memory. For example, when allocating memory, first use function a to call function b, then use function b to call function c, and then use function c to allocate memory. The call stack information can indicate the order of abc, and the function that calls memory to the thread is function c. That is, the call stack information can include the function that calls memory to the thread.
[0139] In this embodiment, in response to a memory application request initiated by a thread, if it is determined that a functional module corresponding to the thread has a memory usage exception, then the memory address of the memory called to the thread is determined, including: in response to the memory application request initiated by the thread, determining the thread number of the thread and the size of the memory to be applied for; distributing memory to the thread according to the size of the memory to be applied for; if it is determined that a functional module corresponding to the thread number of the thread has a memory usage exception, then determining the memory address of the distributed memory.
[0140] If it is determined that a functional module corresponding to the thread number of the thread has a memory occupancy abnormality, then the memory address of the distributed memory is determined, including: obtaining a preset second array; wherein the index of an element in the preset second array is the thread number, and the element in the preset second array represents whether a functional module corresponding to the thread has a memory occupancy abnormality; according to the thread number of the thread, determining an element corresponding to the thread from the preset second array; if it is determined that a functional module corresponding to the thread has a memory occupancy abnormality according to the element corresponding to the thread in the preset second array, then determining the memory address of the distributed memory; determining the memory address of the distributed memory as the memory address of the memory called to the thread.
[0141] Specifically, according to the judgment result of whether the functional module has a memory usage anomaly, an array is pre-set as the second array. The index of the elements in the second array is the thread number, and each thread corresponds to an element in the second array. The elements in the second array represent whether the functional module corresponding to the thread has a memory usage anomaly. One functional module corresponds to multiple threads, that is, the values of the elements corresponding to multiple threads may be the same, indicating whether the corresponding functional module has a memory usage anomaly. Preset characters can be used to indicate the presence or absence of a memory usage anomaly. For example, 0 indicates the presence of a memory usage anomaly, and 1 indicates the absence of a memory usage anomaly. That is, the elements in the second array are either 0 or 1.
[0142] In response to the memory application request initiated by the thread, the thread number of the thread and the memory size to be applied for are determined, and a preset second array is obtained. According to the thread number of the thread, the element corresponding to the thread is determined from the second array. According to the element corresponding to the thread in the second array, it is determined whether the functional module corresponding to the thread has a memory occupancy abnormality. If so, the memory is distributed to the thread according to the memory size to be applied for, and the memory address of the distributed memory is obtained. The memory distributed to the thread may include a preset magic word and thread number. For example, the magic word may be 0b01010101. The memory address of the distributed memory is the memory address of the memory called to the thread.
[0143] The beneficial effect of such a setting is that, based on the preset second array, it is possible to quickly determine whether the functional module corresponding to the thread has a memory usage anomaly, thereby further determining the abnormal function for the abnormal functional module, thereby improving the accuracy and efficiency of memory monitoring.
[0144] In this embodiment, memory is distributed to threads according to the memory size to be applied for, including: determining the number of times the thread initiates a memory application request, and if the number of initiations is a preset number, determining a third target memory size according to the memory size to be applied for; wherein the third target memory size is the sum of the memory size to be applied for and a preset basic memory size, and the preset basic memory size is used to store the thread number and a preset exception identifier; and distributing memory of the third target memory size to the threads.
[0145] Specifically, each time a thread initiates a memory application request, it can record the number of times it initiates a memory application request. A preset number is set in advance, the number of times the thread initiates a memory application request is determined, and the number of initiations is compared with the preset number. If the number of initiations is the preset number, the third target memory size is determined according to the memory size to be applied for. For example, a number N can be preset, and the preset number is an integer multiple of N. When the number of initiations is an integer multiple of N, the third target memory size can be determined according to the memory size to be applied for. The third target memory size is the sum of the memory size to be applied for and the preset basic memory size. The preset basic memory size can be used to store the thread number and the preset exception identifier. The preset exception identifier is also a magic word. For example, the preset exception identifier is 0b01010111. The preset basic memory size can be 4 bytes, and the preset exception identifier can be placed in the first byte of the 4 bytes, and the thread number can be placed in the last three bytes of the 4 bytes. The memory of the third target memory size is distributed to the thread to obtain the memory address of the distributed memory. That is, the memory containing the exception identifier and the thread number is distributed to the thread.
[0146] If the number of times the thread is initiated is not the preset number or there is no memory usage exception in the functional module corresponding to the thread, the first target memory size can be determined according to the memory size to be applied for. The first target memory size can be the same as the third target memory size, and the memory of the first target memory size can also contain a magic word, but the magic word is not a preset exception identifier. For example, the magic word in the memory of the first target memory size is 0b01010101, and the magic word in the memory of the third target memory size is 0b01010111.
[0147] The beneficial effect of this setting is that the memory containing the exception representation will be distributed to the thread and the memory address will be printed only when the number of initiations reaches a preset number, which effectively reduces the waste of resources and ensures the normal operation of the system.
[0148] In this embodiment, recording the call stack information includes: determining the number of times the thread initiates the memory application request, and if the number of times is a preset number, recording the call stack information.
[0149] Specifically, it is determined whether the number of thread initiations is a preset number, for example, it can be determined whether the number of initiations is an integer multiple of N. If so, the call stack information of this call to the memory is recorded; if not, the call stack information of this call to the memory does not need to be recorded.
[0150] The beneficial effect of such a setting is that the memory address and stack information will only be printed when the number of initiations reaches a preset number, which effectively reduces the waste of resources and ensures the normal operation of the system.
[0151] S705: In response to the memory release request initiated by the thread, determine a memory address of the memory released from the thread.
[0152] Exemplarily, after a thread has applied for memory, it can release the memory. If a memory release request initiated by a thread is responded to, the memory can be released from the thread. If a memory occupancy exception exists in a functional module corresponding to the thread, it is necessary to determine the memory address of the memory released from the thread. For example, the memory of the third target size just applied for can be released, and the memory address of the released memory is the memory address of the memory just applied for.
[0153] The function module corresponding to the thread may not have abnormal memory usage. When the thread initiates a memory release request, the memory can be released normally, and the memory address may be recorded or not.
[0154] In this embodiment, in response to a memory release request initiated by a thread, a memory address of memory released from the thread is determined, including: in response to the memory release request initiated by the thread, the memory to be released is determined from the memory called to the thread; if the memory to be released includes a preset exception identifier, the memory address of the memory to be released is determined to be the memory address of the memory released from the thread.
[0155] Specifically, in response to a memory release request initiated by a thread, the memory to be released is determined from the memory called to the thread. The memory to be released may be the memory distributed to the thread last time, and the size of the memory to be released may be the size of the memory requested for release plus the preset basic memory size, that is, the memory to be released contains the magic word and the thread number.
[0156] It is determined whether the memory to be released contains a preset exception identifier, that is, it is determined whether the magic word in the memory to be released is a preset exception identifier. If so, the memory address of the memory to be released is obtained, that is, the memory address of the memory released from the thread is obtained; if not, the memory is released normally.
[0157] The beneficial effect of such a setting is that when releasing memory, it is possible to determine whether there is an exception mark in the released memory. Only when there is an exception mark will the memory address of the released memory be printed, so that the memory address printed when applying for memory and the memory printed when releasing memory can correspond to each other, which facilitates the subsequent judgment of whether the applied memory is released normally and improves the accuracy of memory monitoring.
[0158] S706: If it is determined that within the preset time period, the memory address of the memory called to the thread is not the memory address of the memory released from the thread, then obtain call stack information of the memory called to the thread.
[0159] Exemplarily, a time period is preset, for example, the preset time period is 24 hours. The memory address of the memory called to the thread and the memory address of the memory released from the thread within the preset time period are obtained. It is determined whether the memory address of the memory called to the thread corresponds to the memory address of the memory released from the thread, that is, it is determined whether all the memory called to the thread is released. If it is determined that there is a memory address of the memory called to the thread, which is not the memory address of the memory released from the thread, it means that the memory of the memory address is only applied but not released, and the call stack information printed when the memory is called is obtained.
[0160] S707: Determine, based on the call stack information, whether there is a function with abnormal memory usage.
[0161] Exemplarily, the function used when calling the memory is obtained from the call stack information, and the function with the memory usage exception is determined according to the calling order of the function. The last function can be determined as the function with the memory usage exception according to the calling order of the function. For example, if the call stack information is abc, the function with the memory usage exception is function c.
[0162] In this embodiment, for the functional module with memory leak, it is possible to further determine which function has the memory leak, that is, determine the function that is only allocated but not released, locate the memory leak at the function level, and improve the accuracy of memory monitoring.
[0163] In the disclosed embodiment, multiple threads are allocated to the functional module, and a first array is preset according to the thread number of the thread. The index of the elements in the first array is the thread number, and the elements in the first array represent the memory size occupied by the thread corresponding to the thread number. In response to the memory allocation request initiated by the thread, the thread number of the thread and the memory size requested to be allocated are determined. According to the thread number of the thread and the memory size requested to be allocated, the memory size represented by the element corresponding to the thread in the first array is resized so that the element in the first array can represent the memory size currently occupied by the corresponding thread. According to the memory size represented by the elements corresponding to the multiple threads to which the functional module belongs, it is determined whether the functional module has a memory occupancy anomaly, which solves the problem that the abnormal situation cannot be located at the module level in the related technology. By obtaining the memory occupancy of each thread in real time, the memory occupancy of the functional module is obtained, which provides an effective means for quickly locating the memory occupancy anomaly and memory leak of each functional module, realizes memory monitoring of the functional module, and effectively improves the accuracy and efficiency of memory monitoring.
[0164] Figure 8 A structural block diagram of a memory monitoring device provided by an embodiment of the present disclosure. For ease of explanation, only the parts related to the embodiment of the present disclosure are shown. The autonomous driving system includes multiple functional modules, which are used to implement the autonomous driving function. The same functional module corresponds to at least one thread, which is used to execute the function corresponding to the functional module. Each thread has a unique thread number. Figure 8 The memory monitoring device 800 includes: a request allocation unit 801, a size adjustment unit 802 and an abnormality judgment unit 803.
[0165] The request allocation unit 801 is used to determine the thread number of the thread and the size of the memory requested to be allocated in response to the memory allocation request initiated by the thread; wherein the memory allocation request is a memory application request or a memory release request;
[0166] A size adjustment unit 802, configured to adjust the size of the memory occupied by the thread according to the thread number of the thread and the memory size requested for allocation, to obtain an adjusted memory size;
[0167] The abnormality determination unit 803 is used to determine whether the functional module has a memory occupancy abnormality according to the adjusted memory size occupied by the thread.
[0168] Fig. 9 A structural block diagram of a memory monitoring device provided by an embodiment of the present disclosure, such as Fig. 9 As shown, the memory monitoring device 900 includes a request allocation unit 901 , a size adjustment unit 902 and an abnormality determination unit 903 , wherein the size adjustment unit 902 includes an array acquisition module 9021 and a size adjustment module 9022 .
[0169] An array acquisition module 9021 is used to acquire a preset first array; wherein the index of the element in the preset first array is the thread number, and the element in the preset first array represents the memory size occupied by the thread corresponding to the thread number;
[0170] The size adjustment module 9022 is used to adjust the memory size represented by the element corresponding to the thread in the preset first array according to the thread number of the thread and the memory size requested to be allocated, and obtain the adjusted memory size.
[0171] In one example, the memory allocation request is a memory application request, and the memory application request includes the memory size to be applied for; the size adjustment module 9022 includes:
[0172] A first determination submodule, used to determine a first target memory size according to the memory size to be applied for; wherein the first target memory size is the sum of the memory size to be applied for and a preset basic memory size, and the preset basic memory size is used to store the thread number;
[0173] The first adjustment submodule is used to adjust the memory size represented by the element corresponding to the thread number of the thread in the preset first array according to the first target memory size.
[0174] In one example, the first adjustment module includes:
[0175] A size determination submodule, used to determine the current memory size represented by the element corresponding to the thread number of the thread in the preset first array; wherein the current memory size represents the memory size currently occupied by the thread;
[0176] The size increase submodule is used to add the current memory size to the first target memory size to obtain an adjusted memory size represented by an element corresponding to the thread number of the thread.
[0177] In one example, the memory allocation request is a memory release request, and the memory release request includes the size of the memory to be released; the size adjustment module 9022 includes:
[0178] A second determination submodule, used to determine a second target memory size according to the memory size to be released; wherein the second target memory size is the sum of the memory size to be released and a preset basic memory size, and the preset basic memory size is used to store the thread number;
[0179] The second adjustment submodule is used to adjust the memory size represented by the element corresponding to the thread number of the thread in the preset first array according to the second target memory size.
[0180] In one example, the second adjustment submodule includes:
[0181] A size determination submodule, used to determine the current memory size represented by the element corresponding to the thread number of the thread in the preset first array;
[0182] The size reduction submodule is used to subtract the second target memory size from the current memory size to obtain an adjusted memory size represented by an element corresponding to the thread number of the thread.
[0183] In one example, it also includes:
[0184] A history determination unit, used for determining that all memory application requests initiated by the thread before the memory release request are historical application requests;
[0185] a target determination unit, configured to determine a target application request from the historical application requests;
[0186] A memory determination unit is used to determine the second target memory size according to the memory size to be applied for in the target application request.
[0187] In one example, the abnormality determination unit 903 includes:
[0188] The abnormality judgment module is used to determine whether the functional module has a memory usage abnormality according to the adjusted memory size represented by the element corresponding to the thread to which the functional module belongs in the preset first array.
[0189] In one example, the abnormality judgment module includes:
[0190] A thread determination submodule, used to determine the thread to which the functional module belongs;
[0191] An element determination submodule, used for obtaining the size of the element corresponding to the thread to which the functional module belongs in the preset first array according to a preset time period;
[0192] A memory occupancy submodule, used to determine the memory occupancy size of the functional module according to the size of the element corresponding to the thread to which the functional module belongs; wherein the memory occupancy size of the functional module is the sum of the memory sizes represented by the elements corresponding to the thread to which the functional module belongs;
[0193] A graph determination submodule, used to determine a memory change graph of the functional module; wherein the memory change graph represents a change trend of the memory usage size of the functional module;
[0194] The abnormality determination submodule is used to determine whether the functional module has a memory usage abnormality according to the memory change graph of the functional module.
[0195] In one example, the exception determination submodule is specifically used to:
[0196] If the memory change graph is an increasing curve, it is determined that the functional module has a memory occupancy anomaly.
[0197] In one example, it also includes:
[0198] An information recording unit, for responding to a memory application request initiated by a thread, and if it is determined that a function module corresponding to the thread has a memory occupancy abnormality, determining a memory address of a memory called to the thread, and recording call stack information; wherein the call stack information includes a function that calls the memory to the thread;
[0199] A function determination unit is used to respond to a memory release request initiated by the thread, and determine a function with a memory occupancy exception according to a memory address of the memory called to the thread and the call stack information; wherein the function with a memory occupancy exception is a function that causes the memory occupancy exception.
[0200] In one example, the function determination unit includes:
[0201] A memory release module, configured to determine a memory address of memory released from the thread in response to a memory release request initiated by the thread;
[0202] an information acquisition module, configured to acquire call stack information of the memory called to the thread if it is determined that the memory address of the memory called to the thread is not the memory address of the memory released from the thread within a preset time period;
[0203] The function determination module is used to determine the function with abnormal memory usage according to the call stack information.
[0204] In one example, the information recording unit includes:
[0205] A memory application module, used to respond to a memory application request initiated by a thread and determine the thread number of the thread and the memory size to be applied for;
[0206] A memory distribution module, used to distribute memory to the threads according to the memory size to be applied for;
[0207] The address determination module is used to determine the memory address of the distributed memory if it is determined that the function module corresponding to the thread number of the thread has a memory occupancy abnormality.
[0208] In one example, the address determination module includes:
[0209] An array acquisition submodule, used to acquire a preset second array; wherein the index of the element in the preset second array is the thread number, and the element in the preset second array indicates whether there is a memory usage abnormality in the functional module corresponding to the thread;
[0210] An element determination submodule, used to determine the element corresponding to the thread from the preset second array according to the thread number of the thread;
[0211] an abnormality judgment submodule, for determining a memory address of the distributed memory if it is determined that a memory occupancy abnormality exists in the function module corresponding to the thread according to the element corresponding to the thread in the preset second array;
[0212] The address determination submodule is used to determine the memory address of the distributed memory as the memory address of the memory called to the thread.
[0213] In one example, the memory distribution module includes:
[0214] A times determination submodule, used to determine the times of initiation of memory application requests by the thread, and if the times are a preset number, determine a third target memory size according to the memory size to be applied for; wherein the third target memory size is the sum of the memory size to be applied for and a preset basic memory size, and the preset basic memory size is used to store the thread number and a preset exception flag;
[0215] A memory distribution submodule is used to distribute the memory of the third target memory size to the thread.
[0216] In one example, the information recording unit includes:
[0217] The information recording module is used to determine the number of times the thread initiates a memory application request, and if the number of times is a preset number, record the call stack information.
[0218] In one example, the memory release module includes:
[0219] A request release submodule, used for determining the memory to be released from the memory called to the thread in response to the memory release request initiated by the thread;
[0220] The identification judgment submodule is used to determine the memory address of the memory to be released as the memory address of the memory released from the thread if the memory to be released includes a preset exception identification.
[0221] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device.
[0222] Fig.10 This is a structural block diagram of an electronic device provided in an embodiment of the present disclosure. The electronic device may be a terminal device, a processor or a server. Fig.10 As shown, the electronic device 100 includes: at least one processor 1002; and a memory 1001 communicatively connected to the at least one processor 1002; wherein the memory stores instructions executable by the at least one processor 1002, and the instructions are executed by the at least one processor 1002 so that the at least one processor 1002 can execute the memory monitoring method disclosed in the present invention.
[0223] The electronic device 100 further includes a receiver 1003 and a transmitter 1004. The receiver 1003 is used to receive instructions and data sent by other devices, and the transmitter 1004 is used to send instructions and data to external devices.
[0224] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0225] According to an embodiment of the present disclosure, the present disclosure also provides a computer program product, which includes: a computer program, the computer program is stored in a readable storage medium, at least one processor of an electronic device can read the computer program from the readable storage medium, and at least one processor executes the computer program so that the electronic device executes the solution provided by any of the above embodiments.
[0226] Fig.11A schematic block diagram of an example electronic device 1100 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0227] like Fig.11 As shown, the device 1100 includes a computing unit 1101, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 1102 or a computer program loaded from a storage unit 1108 into a random access memory (RAM) 1103. In the RAM 1103, various programs and data required for the operation of the device 1100 can also be stored. The computing unit 1101, the ROM 1102, and the RAM 1103 are connected to each other via a bus 1104. An input / output (I / O) interface 1105 is also connected to the bus 1104.
[0228] A number of components in the device 1100 are connected to the I / O interface 1105, including: an input unit 1106, such as a keyboard, a mouse, etc.; an output unit 1107, such as various types of displays, speakers, etc.; a storage unit 1108, such as a disk, an optical disk, etc.; and a communication unit 1109, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 1109 allows the device 1100 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0229] The computing unit 1101 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 1101 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 1101 performs the various methods and processes described above, such as the method of memory monitoring. For example, in some embodiments, the method of memory monitoring may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 1108. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 1100 via the ROM 1102 and / or the communication unit 1109. When the computer program is loaded into the RAM 1103 and executed by the computing unit 1101, one or more steps of the method of memory monitoring described above may be performed. Alternatively, in other embodiments, the computing unit 1101 may be configured to perform the method of memory monitoring in any other appropriate manner (e.g., by means of firmware).
[0230] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0231] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0232] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0233] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0234] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0235] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services ("Virtual Private Server", or "VPS" for short). The server may also be a server of a distributed system, or a server combined with a blockchain.
[0236] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0237] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A memory monitoring method, the method is applied to a preset system, the preset system includes multiple function modules, the function modules are used to implement the functions of the preset system, the same function module corresponds to at least one thread, the thread is used to execute the function corresponding to the function module, and each thread has a unique thread number; the method include: In response to a memory allocation request initiated by a thread, determining the thread number of the thread and the size of the memory requested to be allocated; wherein the memory allocation request is a memory application request or a memory release request; According to the thread number of the thread and the memory size requested for allocation, the memory size occupied by the thread is adjusted to obtain an adjusted memory size; According to the adjusted memory size occupied by the thread, it is determined whether the functional module has a memory occupation abnormality.
2. The method according to claim 1, in, The step of adjusting the memory size occupied by the thread according to the thread number of the thread and the memory size requested for allocation to obtain the adjusted memory size includes: Obtain a preset first array; wherein the index of the element in the preset first array is the thread number, and the element in the preset first array represents the memory size occupied by the thread corresponding to the thread number; According to the thread number of the thread and the memory size requested for allocation, the memory size represented by the element corresponding to the thread in the preset first array is adjusted to obtain an adjusted memory size.
3. The method according to claim 2, in, The memory allocation request is a memory application request, and the memory application request includes a memory size to be applied for; and adjusting the memory size represented by the element corresponding to the thread in the preset first array according to the thread number of the thread and the memory size requested for allocation, including: Determine a first target memory size according to the memory size to be applied for; wherein the first target memory size is the sum of the memory size to be applied for and a preset basic memory size, and the preset basic memory size is used to store the thread number; According to the first target memory size, the memory size represented by the element corresponding to the thread number of the thread in the preset first array is resized.
4. The method according to claim 3, wherein the memory size represented by the element corresponding to the thread number of the thread in the preset first array is adjusted according to the first target memory size, include: Determine the current memory size represented by the element corresponding to the thread number of the thread in the preset first array; wherein the current memory size represents the memory size currently occupied by the thread; The current memory size is added to the first target memory size to obtain an adjusted memory size represented by an element corresponding to the thread number of the thread.
5. The method according to any one of claims 2 to 4, in, The memory allocation request is a memory release request, and the memory release request includes the size of the memory to be released; and the size of the memory represented by the element corresponding to the thread in the preset first array is adjusted according to the thread number of the thread and the size of the memory requested to be allocated, including: Determine a second target memory size according to the memory size to be released; wherein the second target memory size is the sum of the memory size to be released and a preset basic memory size, and the preset basic memory size is used to store the thread number; According to the second target memory size, the memory size represented by the element corresponding to the thread number of the thread in the preset first array is resized.
6. The method according to claim 5, in, The step of adjusting the memory size represented by the element corresponding to the thread number of the thread in the preset first array according to the second target memory size includes: Determine a current memory size represented by an element corresponding to the thread number of the thread in the preset first array; The second target memory size is subtracted from the current memory size to obtain an adjusted memory size represented by an element corresponding to the thread number of the thread.
7. The method according to claim 5, further comprising: include: Determine that all memory application requests initiated by the thread before the memory release request are historical application requests; Determine a target application request from the historical application requests; The second target memory size is determined according to the memory size to be applied for in the target application request.
8. The method according to any one of claims 2 to 7, in, The determining, according to the adjusted memory size occupied by the thread, whether the functional module has a memory occupancy abnormality comprises: According to the adjusted memory size represented by the element corresponding to the thread to which the functional module belongs in the preset first array, it is determined whether the functional module has a memory occupancy abnormality.
9. The method according to claim 8, in, The determining whether the functional module has a memory occupancy abnormality according to the adjusted memory size represented by the element corresponding to the thread to which the functional module belongs in the preset first array includes: Determine the thread to which the functional module belongs; According to a preset time period, obtaining the size of the element corresponding to the thread to which the functional module belongs in the preset first array; Determine the memory size occupied by the functional module according to the size of the element corresponding to the thread to which the functional module belongs; wherein the memory size occupied by the functional module is the sum of the memory sizes represented by the elements corresponding to the thread to which the functional module belongs; Determine a memory change graph of the functional module; wherein the memory change graph represents a change trend of the memory usage size of the functional module; According to the memory change graph of the functional module, it is determined whether the functional module has a memory usage abnormality.
10. The method according to claim 9, in, Determining whether the functional module has a memory usage abnormality according to the memory change graph of the functional module includes: If the memory change graph is an increasing curve, it is determined that the functional module has a memory occupancy anomaly.
11. The method according to any one of claims 1 to 10, further comprising: include: In response to a memory application request initiated by a thread, if it is determined that a functional module corresponding to the thread has a memory occupancy exception, a memory address of the memory called to the thread is determined, and call stack information is recorded; wherein the call stack information includes a function that calls the memory to the thread; In response to a memory release request initiated by the thread, a function with a memory occupancy exception is determined according to a memory address of the memory called to the thread and the call stack information; wherein the function with a memory occupancy exception is a function that causes the memory occupancy exception.
12. The method according to claim 11, in, The step of responding to the memory release request initiated by the thread and determining the function with abnormal memory usage according to the memory address of the memory called to the thread and the call stack information includes: In response to a memory release request initiated by the thread, determining a memory address of a memory released from the thread; If it is determined that within a preset time period, the memory address of the memory called to the thread is not the memory address of the memory released from the thread, then obtaining call stack information of the memory called to the thread; According to the call stack information, a function with abnormal memory usage is determined.
13. The method according to claim 11, in, The step of responding to the memory application request initiated by the thread, if it is determined that a memory usage exception exists in a function module corresponding to the thread, then determining a memory address of a memory called to the thread includes: In response to a memory application request initiated by a thread, determining a thread number of the thread and a memory size to be applied for; Allocate memory to the thread according to the memory size to be applied for; If it is determined that a memory usage abnormality exists in the function module corresponding to the thread number of the thread, a memory address of the distributed memory is determined.
14. The method according to claim 13, in, If it is determined that a memory occupancy abnormality exists in a function module corresponding to the thread number of the thread, determining a memory address of the distributed memory includes: Obtain a preset second array; wherein the index of the element in the preset second array is the thread number, and the element in the preset second array indicates whether there is a memory usage abnormality in the functional module corresponding to the thread; According to the thread number of the thread, determining the element corresponding to the thread from the preset second array; If it is determined that the function module corresponding to the thread has a memory occupancy abnormality according to the element corresponding to the thread in the preset second array, then the memory address of the distributed memory is determined; The memory address of the distributed memory is determined as the memory address of the memory called to the thread.
15. The method according to claim 13, in, The allocating memory to the thread according to the memory size to be applied for includes: Determine the number of times the thread initiates a memory application request, and if the number of times is a preset number, determine a third target memory size according to the memory size to be applied for; wherein the third target memory size is the sum of the memory size to be applied for and a preset basic memory size, and the preset basic memory size is used to store the thread number and the preset exception identifier; Distribute the memory of the third target memory size to the thread.
16. The method according to claim 15, in, The recorded call stack information includes: The number of times the thread initiates a memory application request is determined, and if the number of times is a preset number, the call stack information is recorded.
17. The method according to claim 16, in, The step of determining a memory address of a memory released from the thread in response to a memory release request initiated by the thread comprises: In response to a memory release request initiated by the thread, determining memory to be released from the memory called to the thread; If the memory to be released includes a preset exception identifier, the memory address of the memory to be released is determined to be the memory address of the memory released from the thread.
18. A memory monitoring device, the device is applied to a preset system, the preset system includes multiple function modules, the function modules are used to implement the functions of the preset system, the same function module corresponds to at least one thread, the thread is used to execute the function corresponding to the function module, and each thread has a unique thread number; the device include: A request allocation unit, configured to determine the thread number of the thread and the size of the memory requested to be allocated in response to a memory allocation request initiated by the thread; wherein the memory allocation request is a memory application request or a memory release request; A size adjustment unit, configured to adjust the size of the memory occupied by the thread according to the thread number of the thread and the memory size requested for allocation, to obtain an adjusted memory size; The abnormality judgment unit is used to determine whether the functional module has a memory occupancy abnormality according to the adjusted memory size occupied by the thread.
19. The device according to claim 18, in, The size adjustment unit includes: An array acquisition module, used to acquire a preset first array; wherein the index of the element in the preset first array is the thread number, and the element in the preset first array represents the memory size occupied by the thread corresponding to the thread number; The size adjustment module is used to adjust the memory size represented by the element corresponding to the thread in the preset first array according to the thread number of the thread and the memory size requested for allocation, so as to obtain the adjusted memory size.
20. The device according to claim 19, in, The memory allocation request is a memory application request, and the memory application request includes the memory size to be applied for; the size adjustment module includes: A first determination submodule, used to determine a first target memory size according to the memory size to be applied for; wherein the first target memory size is the sum of the memory size to be applied for and a preset basic memory size, and the preset basic memory size is used to store the thread number; The first adjustment submodule is used to adjust the memory size represented by the element corresponding to the thread number of the thread in the preset first array according to the first target memory size.
21. The device according to claim 20, in, The first adjustment submodule includes: A size determination submodule, used to determine the current memory size represented by the element corresponding to the thread number of the thread in the preset first array; wherein the current memory size represents the memory size currently occupied by the thread; The size increase submodule is used to add the current memory size to the first target memory size to obtain an adjusted memory size represented by an element corresponding to the thread number of the thread.
22. The device according to any one of claims 19 to 21, in, The memory allocation request is a memory release request, and the memory release request includes the size of the memory to be released; The size adjustment module comprises: A second determination submodule, used to determine a second target memory size according to the memory size to be released; wherein the second target memory size is the sum of the memory size to be released and a preset basic memory size, and the preset basic memory size is used to store the thread number; The second adjustment submodule is used to adjust the memory size represented by the element corresponding to the thread number of the thread in the preset first array according to the second target memory size.
23. The device according to claim 22, in, The second adjustment submodule includes: A size determination submodule, used to determine the current memory size represented by the element corresponding to the thread number of the thread in the preset first array; The size reduction submodule is used to subtract the second target memory size from the current memory size to obtain an adjusted memory size represented by an element corresponding to the thread number of the thread.
24. The device according to claim 22, further comprising: include: A history determination unit, used for determining that all memory application requests initiated by the thread before the memory release request are historical application requests; A target determination unit, configured to determine a target application request from the historical application requests; A memory determination unit is used to determine the second target memory size according to the memory size to be applied for in the target application request.
25. The device according to any one of claims 19 to 24, in, The abnormality judgment unit comprises: The abnormality judgment module is used to determine whether the functional module has a memory usage abnormality according to the adjusted memory size represented by the element corresponding to the thread to which the functional module belongs in the preset first array.
26. The device according to claim 25, in, The abnormality judgment module comprises: A thread determination submodule, used to determine the thread to which the functional module belongs; An element determination submodule, used for obtaining the size of the element corresponding to the thread to which the functional module belongs in the preset first array according to a preset time period; A memory occupancy submodule, used to determine the memory occupancy size of the functional module according to the size of the element corresponding to the thread to which the functional module belongs; wherein the memory occupancy size of the functional module is the sum of the memory sizes represented by the elements corresponding to the thread to which the functional module belongs; A graph determination submodule, used to determine a memory change graph of the functional module; wherein the memory change graph represents a change trend of the memory usage size of the functional module; The abnormality determination submodule is used to determine whether the functional module has a memory usage abnormality according to the memory change graph of the functional module.
27. The device according to claim 26, in, The abnormality determination submodule is specifically used for: If the memory change graph is an increasing curve, it is determined that the functional module has a memory occupancy anomaly.
28. The device according to any one of claims 18 to 27, further comprising: include: An information recording unit, for responding to a memory application request initiated by a thread, and if it is determined that a function module corresponding to the thread has a memory occupancy abnormality, determining a memory address of a memory called to the thread, and recording call stack information; wherein the call stack information includes a function that calls the memory to the thread; A function determination unit is used to respond to a memory release request initiated by the thread, and determine a function with a memory occupancy exception according to a memory address of the memory called to the thread and the call stack information; wherein the function with a memory occupancy exception is a function that causes the memory occupancy exception.
29. The device according to claim 28, in, The function determination unit comprises: A memory release module, configured to determine a memory address of memory released from the thread in response to a memory release request initiated by the thread; an information acquisition module, configured to acquire call stack information of the memory called to the thread if it is determined that the memory address of the memory called to the thread is not the memory address of the memory released from the thread within a preset time period; The function determination module is used to determine the function with abnormal memory usage according to the call stack information.
30. The device according to claim 28, in, The information recording unit comprises: A memory application module, used to respond to a memory application request initiated by a thread and determine the thread number of the thread and the memory size to be applied for; A memory distribution module, used to distribute memory to the threads according to the memory size to be applied for; The address determination module is used to determine the memory address of the distributed memory if it is determined that the function module corresponding to the thread number of the thread has a memory occupancy abnormality.
31. The device according to claim 30, in, The address determination module comprises: An array acquisition submodule, used to acquire a preset second array; wherein the index of the element in the preset second array is the thread number, and the element in the preset second array indicates whether there is a memory usage abnormality in the functional module corresponding to the thread; An element determination submodule, used to determine the element corresponding to the thread from the preset second array according to the thread number of the thread; an abnormality judgment submodule, for determining a memory address of the distributed memory if it is determined that a memory occupancy abnormality exists in the function module corresponding to the thread according to the element corresponding to the thread in the preset second array; The address determination submodule is used to determine the memory address of the distributed memory as the memory address of the memory called to the thread.
32. The device according to claim 30, in, The memory distribution module includes: A times determination submodule, used to determine the times of initiation of memory application requests by the thread, and if the times are a preset number, determine a third target memory size according to the memory size to be applied for; wherein the third target memory size is the sum of the memory size to be applied for and a preset basic memory size, and the preset basic memory size is used to store the thread number and a preset exception flag; A memory distribution submodule is used to distribute the memory of the third target memory size to the thread.
33. The device according to claim 32, in, The information recording unit comprises: The information recording module is used to determine the number of times the thread initiates a memory application request, and if the number of times is a preset number, record the call stack information.
34. The device according to claim 33, in, The memory release module comprises: A request release submodule, used for determining the memory to be released from the memory called to the thread in response to the memory release request initiated by the thread; The identification judgment submodule is used to determine the memory address of the memory to be released as the memory address of the memory released from the thread if the memory to be released includes a preset exception identification.
35. An electronic device, include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 17.
36. A non-transitory computer-readable storage medium storing computer instructions, in, The computer instructions are used to cause the computer to execute the method according to any one of claims 1-17.
37. A computer program product, in, The invention comprises a computer program, which implements the steps of the method according to any one of claims 1 to 17 when being executed by a processor.
Citation Information
Cited By
Memory processing method, product, electronic equipment and medium
CN119376961A
Resource processing method and device for large language model service, equipment and storage medium
CN121349656A
Resource processing methods, devices, equipment, and storage media for large language model services
CN121349656B
