Core dump method, device and computer device based on embedded device
By responding to the core dump event of the core process in the embedded device and selecting an appropriate memory strategy to perform core dumps when memory is tight, the problem of failure of error analysis due to device restart is solved and the smooth progress of error analysis is ensured.
Patent Information
- Application Number
- CN202410976003.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-19
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2044-07-19
AI Technical Summary
When the memory in an embedded device is tight, restarting the device directly makes error analysis impossible, and the existing technology lacks an effective solution.
By responding to the core dump event of the core process, memory application is triggered, and when the memory is insufficient, the OOM policy or the reserved memory policy is selected according to the preset configuration file. When selecting the OOM policy, the process is selected to be terminated based on the evaluation score and incoming parameters. For the target process, when the reserved memory policy is selected, the minimum reserved memory is released to re-trigger the memory application.
It realizes the core dump of the core process when the memory is tight, ensuring the smooth progress of error analysis, avoiding the direct restart of the device, and ensuring the possibility of error analysis.
Smart Images

Figure CN118519783B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a core dump method, device and computer device based on an embedded device. Background Art
[0002] In embedded devices, the memory space available to the embedded operating system is often very limited, so programmers need to make a detailed allocation of the memory space of the embedded operating system to ensure the security of memory access. However, even so, some unpredictable errors will still occur during the program operation. When the system core process generates an unrecoverable error, in order to avoid greater damage to system-related resources, the operating system will forcibly stop running. Similarly, when an application process generates an error, the operating system can terminate the operation of this process without affecting other processes. In these cases, for embedded operating system developers or application personnel, a method is needed to obtain various structures and other important information in the memory at the scene of the error and save them, so as to analyze the cause of the error. In this way, in order to quickly and effectively locate program errors and improve the efficiency of fault debugging, relevant research on core dump technology came into being.
[0003] Core dump technology is a technology that obtains and saves relevant information when an embedded operating system generates an error. Error analysis can be performed through the saved information related to the business process. In embedded devices, the current core dump solution is to directly restart the device when memory is tight, which makes it impossible to retain the abnormal scene of the business process, resulting in the inability to perform error analysis.
[0004] There is no effective solution to the problem in the related art that when the memory is tight, the device is directly restarted, which makes error analysis impossible. Summary of the invention
[0005] In this embodiment, a core dump method, apparatus and computer device based on an embedded device are provided to solve the problem in the related art that when the memory is tight, the device is directly restarted, resulting in the inability to perform error analysis.
[0006] In a first aspect, a core dump method based on an embedded device is provided in this embodiment, comprising:
[0007] Respond to core dump events for the core processes of embedded devices and trigger memory requests;
[0008] When the memory is insufficient, an OOM strategy or a reserved memory strategy is selected according to a preset configuration file;
[0009] When selecting the OOM strategy, a first target process to be terminated is selected according to the evaluation scores corresponding to each process and the preset input parameters; the first target process is terminated to release the corresponding memory; the input parameters are used to protect the specified process;
[0010] When selecting the reserved memory strategy, the corresponding memory is released based on the minimum reserved memory; the minimum reserved memory is the minimum amount of free memory reserved before allocating memory;
[0011] Based on the released memory, the memory request is re-triggered.
[0012] In some of the embodiments, when selecting the OOM strategy, the first target process to be terminated is selected according to the evaluation score corresponding to each process and the preset input parameters, including:
[0013] When selecting the OOM strategy, based on the preset input parameters, the processes to be protected are eliminated from each process to obtain the processes to be evaluated;
[0014] Calling a scoring function to determine an evaluation score of the process to be evaluated according to the resource usage of the process to be evaluated;
[0015] The process to be evaluated with the highest evaluation score is used as the first target process.
[0016] In some of the embodiments, when selecting the reserved memory policy, releasing the corresponding memory based on the minimum reserved memory includes:
[0017] When the reserved memory policy is selected, a processing signal is sent to the target user state process;
[0018] causing the target user state process to release minimum reserved memory in response to the processing signal;
[0019] The kernel of the embedded device is caused to enter a reserved memory release process.
[0020] In some embodiments, causing the kernel of the embedded device to enter a reserved memory release process includes:
[0021] When the interval time does not meet the preset time threshold, the memory application is re-triggered; the interval time is the time difference between two memory shortages;
[0022] When the interval time meets a preset time threshold, a minimum reserved memory is obtained; the minimum reserved memory is adjusted, and memory is released according to the adjusted minimum reserved memory.
[0023] In some embodiments, the method further comprises:
[0024] When the memory application fails to be re-triggered, the OOM strategy is selected to terminate the second target process with the highest evaluation score among the processes and release the corresponding memory.
[0025] In some embodiments, the method further comprises:
[0026] After triggering the memory request, determining whether the memory of the embedded device is sufficient;
[0027] When the memory is sufficient, allocating a first memory page based on the memory; generating a core dump file corresponding to the core process based on the first memory;
[0028] When the memory is insufficient, page recycling is triggered to determine whether the memory after recycling is sufficient;
[0029] When the reclaimed memory is sufficient, a second memory page is allocated based on the reclaimed memory; and a core dump file corresponding to the core process is generated based on the second memory page.
[0030] In some of the embodiments, when the memory is insufficient, selecting an OOM strategy or a reserved memory strategy according to a preset configuration file includes:
[0031] When the memory after recycling is insufficient, the OOM strategy or the reserved memory strategy is selected according to the preset configuration file.
[0032] In a second aspect, a core dump device based on an embedded device is provided in this embodiment, comprising: a trigger module, a selection module, a first execution module, a second execution module and a third execution module;
[0033] The trigger module is used to respond to a core dump event of a core process of the embedded device and trigger a memory request;
[0034] The selection module is used to select the OOM strategy or the reserved memory strategy according to a preset configuration file when the memory is insufficient;
[0035] The first execution module is used to select the first target process to be terminated according to the evaluation score corresponding to each process and the preset input parameter when selecting the OOM strategy; terminate the first target process and release the corresponding memory; the input parameter is used to protect the specified process;
[0036] The second execution module is used to release the corresponding memory based on the minimum reserved memory when selecting the reserved memory strategy; the minimum reserved memory is the minimum amount of free memory reserved before allocating memory;
[0037] The third execution module is used to re-trigger the memory application based on the released memory.
[0038] In a third aspect, a computer device is provided in this embodiment, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the core dump method based on an embedded device described in the first aspect is implemented.
[0039] In a fourth aspect, a storage medium is provided in this embodiment, on which a computer program is stored, and when the program is executed by a processor, the core dump method based on an embedded device described in the first aspect is implemented.
[0040] Compared with the related art, the core dump method, apparatus and computer device based on embedded devices provided in this embodiment trigger memory application by responding to the core dump event of the core process of the embedded device; when the memory is insufficient, the OOM strategy or the reserved memory strategy is selected according to the preset configuration file; when the OOM strategy is selected, the first target process to be ended is selected according to the evaluation score corresponding to each process and the preset input parameters; the first target process is ended and the corresponding memory is released; the input parameters are used to protect the specified process; when the reserved memory strategy is selected, the corresponding memory is released based on the minimum reserved memory; the minimum reserved memory is the minimum amount of free memory reserved before allocating memory; based on the released memory, the memory application is re-triggered, which solves the problem in the related art that when the memory is tight, the device is directly restarted, resulting in the inability to perform error analysis. The OOM strategy or the reserved memory strategy is selected through the configuration file to realize the core dump of the core process when the memory is tight, thereby ensuring the smooth progress of the error analysis.
[0041] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0043] Figure 1 It is a hardware structure block diagram of a terminal device of a core dump method based on an embedded device provided in an embodiment of the present application;
[0044] Figure 2 is a flow chart of a core dump method based on an embedded device provided by an embodiment of the present application;
[0045] Figure 3 yes Figure 2 Flow chart of step S230;
[0046] Figure 4 It is a flowchart of a core dump method based on an embedded device provided in a preferred embodiment of the present application;
[0047] Figure 5 This is a structural block diagram of a core dump device based on an embedded device provided in one embodiment of the present application.
[0048] In the figure: 102, processor; 104, memory; 106, transmission device; 108, input and output device; 210, trigger module; 220, selection module; 230, first execution module; 240, second execution module; 250, third execution module. DETAILED DESCRIPTION
[0049] In order to more clearly understand the purpose, technical solutions and advantages of the present application, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments.
[0050] Unless otherwise defined, the technical terms or scientific terms involved in this application shall have the general meaning understood by people with general skills in the technical field to which this application belongs. The words "one", "a", "the", "these" and the like in this application do not indicate a quantitative limitation, and they may be singular or plural. The terms "include", "comprise", "have" and any variants thereof involved in this application are intended to cover non-exclusive inclusions; for example, a process, method and system, product or device comprising a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there may be three relationships, for example, "A and / or B" may mean: A exists alone, A and B exist at the same time, and B exists alone. Generally, the character " / " indicates that the objects associated with each other are in an "or" relationship. The terms "first", "second", "third", etc. in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.
[0051] The method embodiment provided in this embodiment can be executed in a terminal, a computer or a similar computing device. For example, running on a terminal, Figure 1is a hardware structure block diagram of a terminal of the core dump method based on an embedded device in this embodiment. Figure 1 As shown, the terminal may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 and a memory 104 for storing data, wherein the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA. The above terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.
[0052] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the core dump method based on the embedded device in the present embodiment. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0053] The transmission device 106 is used to receive or send data via a network. The above network includes a wireless network provided by the communication provider of the terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (Radio Frequency, referred to as RF) module, which is used to communicate with the Internet wirelessly.
[0054] In this embodiment, a core dump method based on an embedded device is provided. Figure 2 is a flow chart of the core dump method based on embedded device in this embodiment. Figure 2 As shown, the process includes the following steps:
[0055] Step S210, responding to a core dump event of a core process of the embedded device, triggering a memory request;
[0056] Step S220, when the memory is insufficient, selecting the OOM strategy or the reserved memory strategy according to the preset configuration file;
[0057] Step S230, when selecting the OOM strategy, the first target process to be terminated is selected according to the evaluation scores corresponding to each process and the preset input parameters; the first target process is terminated and the corresponding memory is released; the input parameters are used to protect the specified process;
[0058] Step S240, when selecting the reserved memory strategy, releasing the corresponding memory based on the minimum reserved memory; the minimum reserved memory is the minimum amount of free memory reserved before allocating memory;
[0059] Step S250: re-triggering memory request based on the released memory.
[0060] Specifically, in an embedded operating system of an embedded device, a core dump refers to when a core process terminates execution due to an error or a "signal", the embedded operating system writes the core image to a file for debugging purposes. The core process corresponds to the main memory; wherein the core image is the memory content at the time of the "core process" execution. A core dump event refers to an event in which a core process terminates execution due to an error or a "signal". In response to a core dump event, a memory request is triggered to allocate memory for writing to the core image. Since the memory required for each core dump is different, the memory requested each time shall prevail. If there is enough memory allocated to write to the core image, the memory is considered sufficient; otherwise, the memory is considered insufficient.
[0061] The configuration file may be pre-configured, for example, the configuration file for the OOM policy may be proc / XXX / oom_reserve. The configuration file for the reserved memory policy may be proc / XXX / mem_reserve. Different execution policies are selected according to different configuration files. In an embedded device, the policy selection is completed according to different configuration files. If the configuration file includes the above two, then any one of the policies may be selected to execute to release the corresponding memory, so that sufficient memory resources are allocated to the core image writing, thereby completing the core dump.
[0062] Among them, the OOM strategy refers to ending the first target process, which is the process with the highest score among all processes. In this way, ending the first target process can release the largest amount of memory to minimize the loss caused by ending the process. The incoming parameters are used to protect the specified process from being ended. The incoming parameters can be the parameters corresponding to the configuration file. For example: the incoming parameter corresponding to oom_reserve is oom hello_world, which means that the OOM strategy is used and the hello_world process is protected from being ended. Among them, the reserved memory strategy refers to the minimum amount of free memory reserved before releasing the allocated memory, so as to ensure that there is enough memory allocated to the core image for writing.
[0063] Through the above steps, a core dump event for a core process of an embedded device is responded to, and a memory application is triggered; when the memory is insufficient, an OOM strategy or a reserved memory strategy is selected according to a preset configuration file; when the OOM strategy is selected, the first target process to be terminated is selected according to the evaluation score corresponding to each process and the preset input parameters; the first target process is terminated and the corresponding memory is released; the input parameters are used to protect the specified process; when the reserved memory strategy is selected, the corresponding memory is released based on the minimum reserved memory; the minimum reserved memory is the minimum amount of free memory reserved before allocating memory; based on the released memory, a memory application is re-triggered, which solves the problem in the related art that when the memory is tight, the device is directly restarted, resulting in the inability to perform error analysis. The OOM strategy or the reserved memory strategy is selected through the configuration file to achieve the core dump of the core process when the memory is tight, thereby ensuring the smooth progress of the error analysis.
[0064] The above steps are described in detail below:
[0065] In some of the embodiments, Figure 3 As shown, when selecting the OOM strategy in step S230, the first target process to be terminated is selected according to the evaluation scores corresponding to each process and the preset input parameters, including the following steps:
[0066] Step S231, when selecting the OOM strategy, based on the preset input parameters, the processes to be protected are eliminated from each process to obtain the processes to be evaluated;
[0067] Step S232, calling the scoring function to determine the evaluation score of the process to be evaluated according to the resource usage of the process to be evaluated;
[0068] Step S233: The process to be evaluated with the highest evaluation score is taken as the first target process.
[0069] Specifically, the process to be protected refers to the process to be protected by the input parameters. First, the processes to be protected are listed according to the input parameters, and then the processes to be protected are removed from all processes to obtain the processes to be evaluated, so that the processes to be protected do not participate in the scoring. Then the scoring function is called to determine the evaluation score of the process to be evaluated based on the resource usage of the process to be evaluated. Finally, the process to be evaluated with the highest evaluation score is used as the first target process.
[0070] Among them, the scoring function can be set in the kernel. After selecting the OOM strategy, the scoring function is called to calculate the resource usage of all processes to be evaluated and obtain the corresponding scores. For example, the expression of the scoring function is: evaluation score = get_mm_rss + get_mm_counter + mm_pgtables_bytes / PAGE_SIZE;
[0071] In the formula, get_mm_rss represents physical memory, get_mm_counter represents swap page size, mm_pgtables_bytes represents the memory occupied by page table, and PAGE_SIZE represents the total memory size of embedded device.
[0072] Through this embodiment, the process to be protected is first eliminated, and then the scoring function is called to obtain the evaluation score of the process to be evaluated, thereby improving the response efficiency of the core dump while protecting the process to be protected.
[0073] In some embodiments, when selecting the OOM strategy in step S230, selecting the first target process to be terminated according to the evaluation score corresponding to each process and the preset input parameters includes the following steps:
[0074] When selecting the OOM strategy, the scoring function is called to determine the evaluation score of each process based on the resource usage of each process;
[0075] Based on the preset input parameters, the processes to be protected are eliminated from each process to obtain the processes to be evaluated;
[0076] The process to be evaluated with the highest evaluation score is taken as the first target process.
[0077] Through this embodiment, the scoring function is first called to obtain the evaluation score of each process, then the processes to be protected are eliminated from each process to obtain the processes to be evaluated, and finally the first target process is determined, thereby preventing the processes to be protected from being mistakenly killed.
[0078] In some embodiments, when selecting the reserved memory policy in step S240, releasing the corresponding memory based on the minimum reserved memory includes the following steps:
[0079] Step S241, when selecting the reserved memory policy, sending a processing signal to the target user state process;
[0080] Step S242, causing the target user state process to release the minimum reserved memory in response to the processing signal;
[0081] Step S243, causing the kernel of the embedded device to enter a reserved memory release process.
[0082] Specifically, the reserved memory strategy can be considered to have two processes, which are step S242 and step S243. Among them, the target user state process can be specified in advance by the input parameters. The process of step S242 is: after receiving the processing signal, the target user state process responds to the processing signal, triggers coredump, releases the minimum reserved memory, and generates a core dump file; at the same time, step S243 is executed to make the kernel start to enter the reserved memory release process.
[0083] Through this embodiment, without relying on external hardware and resources, the memory resources of the embedded device can be fully utilized, thereby improving the utilization rate of the memory resources.
[0084] In some embodiments, the step S243 of causing the kernel of the embedded device to enter the reserved memory release process includes the following steps:
[0085] When the interval time does not meet the preset time threshold, the memory request is re-triggered; the interval time is the time difference between two memory shortages;
[0086] When the interval time meets the preset time threshold, the minimum reserved memory is obtained; the minimum reserved memory is adjusted, and the memory is released according to the adjusted minimum reserved memory.
[0087] Specifically, the interval time is the time difference between two insufficient memory. If the interval time does not meet the preset time threshold, that is, the insufficient memory exception occurs frequently in a short period of time, the memory application will be directly re-triggered, and the process returns to step S210. If the memory application fails to be re-triggered, the OOM strategy is selected to terminate the second target process with the highest evaluation score among all processes and release the corresponding memory. At this time, the input parameters are no longer used to protect the process to be protected, thereby releasing a large amount of memory and ensuring the smooth implementation of core dump.
[0088] If the interval time meets the preset time threshold, the minimum reserved memory will be recorded as the historical value of the reserved memory. Then refer to the memory size of the operating system itself, and calculate the new reserved memory value in proportion. The new reserved memory value calculation formula is as follows:
[0089] new_min_free_kbytes=pre_min_free_kbytes-(total_memory) / (1024×1014)×4K;
[0090] In the formula, new_min_free_kbytes represents the new reserved memory value; pre_min_free_kbytes represents the historical value of reserved memory; and total_memory represents the total amount of memory.
[0091] If the new reserved memory value new_min_free_kbytes is greater than the preset reserved memory minimum threshold, the new reserved memory value is set as the current minimum reserved memory to complete the adjustment of the minimum reserved memory. It should be noted that the default minimum reserved memory is generally large, and the adjusted minimum reserved memory will not be small, so the released memory can meet the needs of core dumps, but will not affect system operation.
[0092] The memory requirement for core dump is met by adjusting the minimum reserved memory; when the device's memory cannot be allocated at all, core dump is actively executed to protect the scene.
[0093] In some of the embodiments, the core dump method based on the embedded device further includes the following steps:
[0094] After triggering the memory request, determine whether the embedded device has sufficient memory;
[0095] When the memory is sufficient, allocating a first memory page based on the memory; generating a core dump file corresponding to the core process based on the first memory;
[0096] When the memory is insufficient, page recycling is triggered to determine whether the recycled memory is sufficient;
[0097] When the reclaimed memory is sufficient, a second memory page is allocated based on the reclaimed memory; and a core dump file corresponding to the core process is generated based on the second memory page.
[0098] Specifically, after triggering the memory request in step S210, the slowpath allocator will call the __alloc_pages_nodemask() function to perform parameter sorting and memory allocation to determine whether the remaining memory in the embedded device is sufficient; if the memory is sufficient, the first memory page is directly allocated; based on the first memory, a core dump file corresponding to the core process is generated. If the memory is insufficient, the kernel wakes up the kswapd thread to trigger page recovery to determine whether the recovered memory is sufficient. If the recovered memory is sufficient, a second memory page is allocated based on the recovered memory; based on the second memory page, a core dump file corresponding to the core process is generated. If the recovered memory is still insufficient, proceed to step S220, that is, when the recovered memory is insufficient, select the OOM policy or the reserved memory policy according to the preset configuration file. Among them, the kswapd thread is the thread in Linux responsible for reclaiming pages when memory is insufficient.
[0099] Through this embodiment, cache memory resources are fully utilized based on page recycling, thereby improving resource utilization.
[0100] The present embodiment is described and illustrated below through preferred embodiments.
[0101] Figure 4 It is a flowchart of the core dump method based on embedded device according to the preferred embodiment.
[0102] S41, respond to the core dump event for the core process of the embedded device and trigger the memory application. S42, the kernel will enter the slowpath application of the memory page. S43, determine whether the memory can be applied from the free page corresponding to the remaining memory. S44, if the memory is sufficient at this time, directly allocate the memory page (first memory page) in the free page; based on the memory page, generate the core dump file corresponding to the core process. S45, if the memory is insufficient at this time, make the kernel wake up the kswapd thread and trigger page recycling (including memory regularization operation for tidying up memory fragments; and, page recycling operation for recycling memory pages that have been allocated but no longer used); if the memory after recycling is sufficient, enter step S44, allocate memory pages (second memory pages) based on the memory after recycling; based on the memory page, generate the core dump file corresponding to the core process. S46, if the memory after recycling is still insufficient, select the OOM policy or the reserved memory policy according to the preset configuration file. S47, when selecting the OOM strategy, select the first target process to be terminated according to the evaluation scores corresponding to each process and the preset input parameters; terminate the first target process and release the corresponding memory; enter step S44, allocate memory pages based on the recovered memory; based on the memory pages, generate a core dump file corresponding to the core process. S48, when selecting the memory retention strategy, send a processing signal to the target user state process through send_sig; the target user state process can be specified by the input parameters.
[0103] The target user-mode process is made to respond to the processing signal, trigger coredump, release the minimum reserved memory, and generate a core dump file; at the same time, the kernel of the embedded device is made to enter the reserved memory release process.
[0104] Among them, the process of making the kernel of the embedded device enter the reserved memory release is:
[0105] S49, determine whether the interval time meets the preset time threshold. S52, when the interval time does not meet the preset time threshold, re-trigger the slowpath memory application. S53, determine whether the lowpath memory application at this time is successful; if successful, return to step S44. S54, if failed, select the OOM strategy, end the second target process with the highest evaluation score among all processes, and release the corresponding memory (at this time, there is no process to be protected, and a large amount of memory will be released).
[0106] S50, when the interval time meets the preset time threshold, record the minimum reserved memory as the reserved memory history value. S51, refer to the memory size of the operating system itself, calculate the new reserved memory value in proportion; and return to step S52; the new reserved memory value calculation formula is as follows:
[0107] new_min_free_kbytes=pre_min_free_kbytes-(total_memory) / (1024×1014)×4K;
[0108] In the formula, new_min_free_kbytes represents the new reserved memory value; pre_min_free_kbytes represents the historical value of reserved memory; and total_memory represents the total amount of memory.
[0109] If the new reserved memory value new_min_free_kbytes is greater than the preset reserved memory minimum threshold, the new reserved memory value is set as the current minimum reserved memory to complete the adjustment of the minimum reserved memory. It should be noted that the default minimum reserved memory is generally large, and the adjusted minimum reserved memory will not be small, so the released memory can meet the needs of core dumps, but will not affect system operation. After the new reserved memory value is set, the slowpath memory request is retriggered, and the memory at this time is sufficient for the slowpath allocator, so that the core dump is successfully completed.
[0110] The process of making the target user-mode process respond to the processing signal, triggering coredump, releasing the minimum reserved memory, and generating a core dump file is as follows:
[0111] S55, make the target user state process respond to the processing signal and trigger coredump. S56, determine whether the minimum reserved memory is released. S57, if the minimum reserved memory has been released, generate a core dump file. S58, restore the new reserved memory value to the original reserved memory history value pre_min_free_kbytes. If the minimum reserved memory has not been released, directly return to step S58.
[0112] Through this embodiment, without relying on external hardware and resources, the memory resources of the embedded device can be fully utilized to improve the utilization rate of memory resources. In addition, different strategies are selected through the configuration file, and the processes that need to be protected are protected in combination with the input parameters, so as to improve the memory utilization rate while ensuring the stability of operation; different strategy options are provided to increase flexibility and adapt to more scenarios.
[0113] It should be noted that the steps shown in the above process or the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0114] It should be noted that the steps shown in the above process or the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0115] In this embodiment, a core dump device based on an embedded device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. The terms "module", "unit", "subunit" and the like used below can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0116] Figure 5 is a structural block diagram of the core dump device based on embedded devices in this embodiment, such as Figure 5 As shown, the device includes: a trigger module 210, a selection module 220, a first execution module 230, a second execution module 240 and a third execution module 250;
[0117] A trigger module 210, for responding to a core dump event of a core process of an embedded device, and triggering a memory request;
[0118] A selection module 220 is used to select an OOM strategy or a reserved memory strategy according to a preset configuration file when the memory is insufficient;
[0119] The first execution module 230 is used to select the first target process to be terminated according to the evaluation scores corresponding to each process and the preset input parameters when selecting the OOM strategy; terminate the first target process and release the corresponding memory; the input parameters are used to protect the specified process;
[0120] The second execution module 240 is used to release the corresponding memory based on the minimum reserved memory when selecting the reserved memory strategy; the minimum reserved memory is the minimum amount of free memory reserved before allocating memory;
[0121] The third execution module 250 is used to re-trigger the memory request based on the released memory.
[0122] Through the above-mentioned device, the problem in the related technology that directly restarting the device when the memory is tight, resulting in the inability to perform error analysis, is solved. The OOM strategy or the memory retention strategy is selected through the configuration file to achieve core dump of the core process when the memory is tight, thereby ensuring the smooth progress of error analysis.
[0123] In some of the embodiments, the first execution module 230 is further used to remove the processes to be protected from each process based on the preset input parameters when selecting the OOM strategy, and obtain the processes to be evaluated;
[0124] Call the scoring function to determine the evaluation score of the process to be evaluated based on the resource usage of the process to be evaluated;
[0125] The process to be evaluated with the highest evaluation score is taken as the first target process.
[0126] In some of the embodiments, the second execution module 240 is further configured to send a processing signal to the target user state process when selecting the reserved memory policy;
[0127] causing the target user-mode process to release the minimum reserved memory in response to the processing signal;
[0128] Make the kernel of the embedded device enter the reserved memory release process.
[0129] In some of the embodiments, the second execution module 240 is further used to re-trigger the memory application when the interval time does not meet the preset time threshold; the interval time is the time difference between two memory shortages;
[0130] When the interval time meets the preset time threshold, the minimum reserved memory is obtained; the minimum reserved memory is adjusted, and the memory is released according to the adjusted minimum reserved memory.
[0131] In some of the embodiments, the second execution module 240 is further used to select the OOM strategy when the memory application fails to be re-triggered, terminate the second target process with the highest evaluation score among the processes, and release the corresponding memory.
[0132] In some of the embodiments, the core dump apparatus based on the embedded device further includes: a judgment module;
[0133] A judgment module, used to judge whether the memory of the embedded device is sufficient after triggering the memory application;
[0134] When the memory is sufficient, allocating a first memory page based on the memory; generating a core dump file corresponding to the core process based on the first memory;
[0135] When the memory is insufficient, page recycling is triggered to determine whether the recycled memory is sufficient;
[0136] When the reclaimed memory is sufficient, a second memory page is allocated based on the reclaimed memory; and a core dump file corresponding to the core process is generated based on the second memory page.
[0137] In some of the embodiments, the judgment module is also used to select an OOM strategy or a memory retention strategy according to a preset configuration file when the memory after recycling is insufficient.
[0138] It should be noted that the above modules can be functional modules or program modules, and can be implemented by software or hardware. For modules implemented by hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.
[0139] In this embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0140] Optionally, the computer device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0141] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0142] S1, responds to a core dump event for a core process of an embedded device and triggers a memory request;
[0143] S2, when the memory is insufficient, select the OOM strategy or the memory retention strategy according to the preset configuration file;
[0144] S3, when selecting the OOM strategy, select the first target process to be terminated according to the evaluation score corresponding to each process and the preset input parameters; terminate the first target process and release the corresponding memory; the input parameters are used to protect the specified process;
[0145] S4, when selecting the reserved memory strategy, release the corresponding memory based on the minimum reserved memory; the minimum reserved memory is the minimum amount of free memory reserved before allocating memory;
[0146] S5, re-trigger memory request based on the released memory.
[0147] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and will not be repeated in this embodiment.
[0148] In addition, in combination with the core dump method based on an embedded device provided in the above embodiment, a storage medium can also be provided in this embodiment to implement the core dump method based on an embedded device. The storage medium stores a computer program; when the computer program is executed by a processor, any one of the core dump methods based on an embedded device in the above embodiment is implemented.
[0149] It should be understood that the specific embodiments described herein are only used to explain the application, rather than to limit it. Based on the embodiments provided in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the protection scope of this application.
[0150] Obviously, the drawings are only some examples or embodiments of the present application. For ordinary technicians in the field, the present application can also be applied to other similar situations based on these drawings without creative work. In addition, it is understandable that although the work done in this development process may be complicated and lengthy, for ordinary technicians in the field, certain changes in design, manufacturing or production based on the technical content disclosed in this application are only conventional technical means and should not be regarded as insufficient content disclosed in this application.
[0151] The term "embodiment" in this application refers to a specific feature, structure or characteristic described in conjunction with the embodiment that can be included in at least one embodiment of the present application. The appearance of this phrase in various locations in the specification does not necessarily mean the same embodiment, nor does it mean that it is mutually exclusive with other embodiments and is independent or optional. It is clearly or implicitly understood by those of ordinary skill in the art that the embodiments described in this application can be combined with other embodiments without conflict.
[0152] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of patent protection. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the scope of protection of the present application. Therefore, the scope of protection of the present application shall be subject to the attached claims.
Claims
1. A core dump method based on an embedded device, characterized in that: include: Respond to core dump events for the core processes of embedded devices and trigger memory requests; When the memory is insufficient, an OOM strategy or a reserved memory strategy is selected according to a preset configuration file; When selecting the OOM strategy, a first target process to be terminated is selected according to the evaluation scores corresponding to each process and the preset input parameters; the first target process is terminated to release the corresponding memory; The input parameters are used to protect the specified process; When selecting the reserved memory strategy, the corresponding memory is released based on the minimum reserved memory; the minimum reserved memory is the minimum amount of free memory reserved before allocating memory; re-triggering the memory request based on the released memory; When selecting the OOM strategy, the first target process to be terminated is selected according to the evaluation scores corresponding to each process and the preset input parameters, including: When selecting the OOM strategy, based on the preset input parameters, the processes to be protected are eliminated from each process to obtain the processes to be evaluated; Calling a scoring function to determine an evaluation score of the process to be evaluated according to the resource usage of the process to be evaluated; The process to be evaluated with the highest evaluation score is used as the first target process.
2. The core dump method based on embedded device according to claim 1, characterized in that: When the reserved memory policy is selected, corresponding memory is released based on the minimum reserved memory, including: When the reserved memory policy is selected, a processing signal is sent to the target user state process; causing the target user state process to release minimum reserved memory in response to the processing signal; The kernel of the embedded device is caused to enter a reserved memory release process.
3. The core dump method based on embedded device according to claim 2, characterized in that: The kernel of the embedded device is caused to enter a reserved memory release process, including: When the interval time does not meet the preset time threshold, the memory application is re-triggered; the interval time is the time difference between two memory shortages; When the interval time meets a preset time threshold, a minimum reserved memory is obtained; the minimum reserved memory is adjusted, and memory is released according to the adjusted minimum reserved memory.
4. The core dump method based on embedded device according to claim 3, characterized in that: The method further comprises: When the memory application fails to be re-triggered, the OOM strategy is selected to terminate the second target process with the highest evaluation score among the processes and release the corresponding memory.
5. The core dump method based on embedded device according to claim 1, characterized in that: The method further comprises: After triggering the memory request, determining whether the memory of the embedded device is sufficient; When the memory is sufficient, allocating a first memory page based on the memory; generating a core dump file corresponding to the core process based on the first memory page; When the memory is insufficient, triggering page recycling, and determining whether the recycled memory is sufficient; When the reclaimed memory is sufficient, a second memory page is allocated based on the reclaimed memory; and a core dump file corresponding to the core process is generated based on the second memory page.
6. The core dump method based on embedded device according to claim 5, characterized in that: When the memory is insufficient, an OOM policy or a reserved memory policy is selected according to a preset configuration file, including: When the memory after recycling is insufficient, the OOM strategy or the reserved memory strategy is selected according to the preset configuration file.
7. A core dump device based on an embedded device, characterized in that: include: A trigger module, a selection module, a first execution module, a second execution module and a third execution module; The trigger module is used to respond to a core dump event of a core process of the embedded device and trigger a memory request; The selection module is used to select the OOM strategy or the reserved memory strategy according to a preset configuration file when the memory is insufficient; The first execution module is used to select the first target process to be terminated according to the evaluation score corresponding to each process and the preset input parameter when selecting the OOM strategy; terminate the first target process and release the corresponding memory; the input parameter is used to protect the specified process; The first execution module is further configured to, when selecting the OOM strategy, remove the processes to be protected from each process based on the preset input parameters to obtain the processes to be evaluated; Calling a scoring function to determine an evaluation score of the process to be evaluated according to the resource usage of the process to be evaluated; Taking the process to be evaluated with the highest evaluation score as the first target process; The second execution module is used to release the corresponding memory based on the minimum reserved memory when selecting the reserved memory strategy; the minimum reserved memory is the minimum amount of free memory reserved before allocating memory; The third execution module is used to re-trigger the memory application based on the released memory.
8. A computer device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps of the embedded device-based core dump method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the core dump method based on an embedded device according to any one of claims 1 to 6 are implemented.
