Kernel dump method and device, electronic equipment and readable storage medium

The dynamic memory allocation method for kernel dump mechanisms addresses the inefficiencies of static memory allocation by adjusting reserved space based on real-time usage, ensuring complete data capture and optimizing memory usage for kernel analysis and system performance.

CN120315872APending Publication Date: 2025-07-15GODSON ZHONGKE (BEIJING) INFORMATION TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510387726.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-28
Publication Date
2025-07-15

AI Technical Summary

Technical Problem

The problems of wasted memory resources and incomplete capture of data in the prior art have led to failure of kernel dumps and the inability to effectively analyze production kernel failures.

Method used

By dynamically adjusting the size of the memory area, the reserved memory area is divided according to the actual usage of the production kernel, ensuring that the complete data is captured when the kernel crashes.

Benefits of technology

Improves memory utilization, ensures that the capture kernel can generate complete dump files, improves troubleshooting efficiency and avoids waste of memory resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120315872A_ABST
    Figure CN120315872A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a kernel dump method, device and equipment and a readable storage medium. Relates to the technical field of computers. The method comprises the following steps: determining first parameters of a first memory slice area allocated for a production kernel, and obtaining a changed second parameter in the first parameters; the first memory area is used for storing production data of a production kernel; determining a third parameter according to the first parameter and the second parameter, and dividing a reserved memory area from the memory according to the third parameter; under the condition that the production kernel crashes, the capture kernel is controlled to capture the production data in the first memory area and store the production data in the reserved memory area, and meanwhile, a dump file is generated according to the production data. The stability and reliability of the target operating system can be enhanced, and meanwhile the utilization rate of memory resources is increased.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of computer technology, and particularly relates to a kernel dump method, device, electronic device and readable storage medium. Background Art

[0002] In a computer system, a kernel dump mechanism divides the kernel of the computer system into a production kernel and a capture kernel. During the normal operation of the system, a part of the memory space is reserved for temporarily storing the production data of the production kernel; when the production kernel crashes, the capture kernel is started, and the capture kernel is used in cooperation with the reserved memory space to obtain the production data and save the production data in a preset storage area, so that the production data during the operation of the production kernel can be retained.

[0003] However, in the related art, generally a static configuration method is used to determine the reserved memory space, resulting in a fixed size of the reserved memory space; if the reserved memory space is too large, it will cause waste of memory resources, and if the reserved memory space is insufficient, it may cause incomplete production data to be obtained, and the production kernel cannot be effectively analyzed and debugged. Summary of the Invention

[0004] The present invention aims to provide a kernel dump method, device, equipment and readable storage medium, and at least solve the problems in the related art.

[0005] In order to solve the above technical problems, the present invention is implemented as follows:

[0006] In a first aspect, an embodiment of the present invention provides a kernel dump method, and the method includes:

[0007] Determine a first parameter of a first memory area allocated for the production kernel, and obtain a second parameter that changes in the first parameter; the first memory area is used to store the production data of the production kernel;

[0008] Determine a third parameter according to the first parameter and the second parameter, and divide the reserved memory area from the memory according to the third parameter;

[0009] In the case where the production kernel crashes, control the capture kernel to capture the production data in the first memory area and store it in the reserved memory area, and generate a dump file according to the production data; for subsequent debugging and analysis of the production kernel.

[0010] In a second aspect, an embodiment of the present invention further provides a kernel dump device, and the device includes:

[0011] Parameter acquisition module: used to determine the first parameter of the first memory area allocated for the production kernel, and acquire the second parameter that has changed in the first parameter; the first memory area is used to store the production data of the production kernel;

[0012] Memory confirmation module: used to determine the third parameter according to the first parameter and the second parameter, and divide a reserved memory area from the memory according to the third parameter;

[0013] Dump execution module: used to, in the case of the production kernel crashing, control the capture kernel to capture the production data in the first memory area and store it in the reserved memory area, and at the same time generate a dump file according to the production data for subsequent debugging and analysis of the production kernel.

[0014] In a third aspect, an embodiment of the present invention further provides an electronic device, which includes a processor, a memory, and a program or instruction stored on the memory and executable on the processor. When the program or instruction is executed by the processor, the steps of the method described in the first aspect are implemented.

[0015] In a fourth aspect, an embodiment of the present invention further provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.

[0016] In the embodiment of the present invention, by acquiring the first parameter representing the usage situation of the first memory area allocated for the production kernel, and the second parameter that changes in real time in the first parameter, which represents the currently actually occupied memory area in the first memory area, the actual usage situation of the first memory area can be reflected in real time. Furthermore, the size of the reserved memory area in the first memory area can be flexibly adjusted dynamically, so that when the production kernel crashes, a reserved memory area of an appropriate size can be provided for the capture kernel to perform the kernel dump operation. On the one hand, the reserved memory area provides enough space to accommodate the complete production data in the production kernel acquired by the capture kernel, enabling the capture kernel to successfully generate a dump file for subsequent analysis and debugging, thereby providing more comprehensive information for troubleshooting the production kernel and improving the efficiency of troubleshooting; on the other hand, dividing the reserved memory area according to the actual occupancy of the first memory area also provides enough running space for other task programs of the production kernel, maximizing the utilization rate of the first memory area, avoiding waste of memory resources, and improving the performance of the production kernel. Description of the drawings

[0017] Figure 1 is a flowchart of the steps of a kernel dump method provided by an embodiment of the present invention;

[0018] Figure 2 It is a flowchart of steps of another kernel dump method provided by an embodiment of the present invention;

[0019] Figure 3 It is a schematic flowchart of a kernel dump method provided by an embodiment of the present invention;

[0020] Figure 4 It is a block diagram of a kernel dump device provided by an embodiment of the present invention;

[0021] Figure 5 It is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present invention. Detailed implementation manners

[0022] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention.

[0023] Figure 1 It is a flowchart of steps of a kernel dump method provided by an embodiment of the present invention. The method is applied to an electronic device installed with a target operating system. The kernel of the target operating system is divided into a production kernel and a capture kernel. As Figure 1 shown, the method may include:

[0024] Step 101: Determine a first parameter of a first memory area allocated to the production kernel, and obtain a second parameter that has changed in the first parameter; the first memory area is used to store production data of the production kernel.

[0025] The kernel is the core program of the operating system. It is the first layer of software expansion based on the hardware, provides basic functions for the operating system, and is responsible for managing the processes, memory, device drivers, files, and network systems of the operating system, etc.; the system management, resource allocation, process management, file system management, security protection, etc. functions that the kernel undertakes during normal operation are called the production tasks of the operating system. The data generated and used by the kernel to process these production tasks is called the production data of the kernel, such as the call stack of the kernel, the status information of the process, the module information of the kernel, etc.

[0026] Kernel dump is a tool that can be used to debug and analyze computer system failures. It can save the production data of the operating system kernel stored in memory when the operating system crashes or is abnormal, and is used to analyze the running state of the kernel afterwards in order to troubleshoot the cause of the failure.

[0027] To achieve the preservation of production data, the kernel dump divides the operating system kernel into a production kernel and a capture kernel. The production kernel interacts directly with the hardware and is responsible for handling daily business logic and system operations, that is, implementing the basic functions of the kernel. The capture kernel is a kernel specifically designed for the case of the production kernel crashing. During the normal operation of the production kernel, the capture kernel is in a closed state. When the production kernel crashes, the capture kernel is started to perform the work of saving production data.

[0028] In related technologies, such as the Kdump mechanism (a kernel dump mechanism based on the Linux operating system), while dividing the operating system kernel into a production kernel and a capture kernel, a part of the memory area is reserved to temporarily store the production data of the production kernel captured by the capture kernel. However, in related technologies, the reserved memory area is usually determined by a static configuration method, so that the size of the reserved memory area is fixed. For example, in the original Kdump mechanism, when the configuration command-line parameter crashkernel = 512M, during the operation of the operating system, a memory area with a fixed size of 512MB will be continuously reserved. When the production kernel crashes, the capture kernel uses this 512MB-sized memory area to capture production data. Thus, the following defects often exist:

[0029] Waste of memory resources: The reserved memory area is continuously reserved during the operation of the operating system. Even if there is no kernel dump, if the reserved memory space is too large, other task programs corresponding to the production kernel cannot use this part of the memory area, resulting in waste of memory resources. Especially for embedded systems with relatively limited hardware resources, waste of memory resources needs to be emphasized and avoided.

[0030] Incomplete capture of data: If the reserved memory space is insufficient, it will cause the capture kernel to be unable to capture all necessary production data, that is, the capture kernel cannot completely copy the production data to the reserved memory space, making it impossible to successfully generate a dump file and resulting in a dump failure, which leads to the inability to effectively analyze the cause of the operating system failure based on the dump file.

[0031] To solve the above problems, an embodiment of the present invention provides a kernel dump method. First, this solution determines a first parameter of a first memory area allocated to the production kernel in the target operating system. The first memory area is a memory area allocated to the production kernel for the production kernel to store production data, and the first parameter is used to characterize the information of the first memory area. Subsequently, a reserved memory area for kernel dump can be further divided from the first memory area; in this embodiment, the first parameter is a parameter set, which may include the maximum physical page frame number in the memory, the total number of physical page frames in the memory, the number of physical page frames corresponding to the first memory area, the capacity size of the first memory area, the number of physical page frames corresponding to each occupied memory area in the first memory area, and the size of each occupied memory area in the first memory area; among them, the first parameter used to characterize the memory and the first memory area can be determined during the startup process of the target operating system, and the first parameter (i.e., the second parameter) used to characterize the occupied memory area in the first memory area can be determined during the running process of the target operating system.

[0032] Exemplarily, the first parameter of the first memory area may include the overall capacity size of the first memory area when the target operating system starts. Specifically, through the memory management interface function provided by the production kernel, the first parameter of the first memory area is confirmed; since the overall capacity size of the memory may change due to human operations during the running of the target operating system, and the overall capacity size of the first memory area depends on the overall capacity size of the memory, it is necessary to determine the overall capacity size of the memory when the target operating system starts, and accordingly determine the overall capacity size of the first memory area. For example, in a target operating system that manages memory based on physical page frames, there is a global variable named max_pfn in the production kernel to represent the number of the largest physical page frame. This global variable is set as the first parameter during the initialization of the production kernel. By accessing this variable, for example, through the following C language code: extern unsigned long max_pfn, the number of the largest physical page frame can be obtained to confirm the total number of physical page frames. These physical page frames can all be allocated to the first memory area, so that the overall capacity size of the first memory area can be calculated by combining the fixed size of the physical page frame and the total number of physical page frames.

[0033] Subsequently, during the operation of the target operating system, obtain the second parameter that has changed in the first parameter; during the operation of the target operating system, there are memory areas in the first memory area that change dynamically according to the actual usage. These dynamically changing memory areas cannot be allocated again because they have been occupied by various applications during the operation of the operating system. The second parameter can be used to represent the relevant information of these currently occupied memory areas, including the number of physical page frames corresponding to each of these currently occupied memory areas, their respective capacity sizes, as well as the sum of the number of physical page frames corresponding to each of these currently occupied memory areas and the sum of their respective capacity sizes.

[0034] Exemplarily, the occupied memory areas represented by the second parameter may include: memory areas filled with zeros, memory buffer areas that can be quickly allocated, memory buffer areas specific to the Central Processing Unit (CPU), memory areas accessible by the user space, memory areas to be allocated for new tasks, damaged memory areas caused by hardware failures, and temporarily unavailable memory areas.

[0035] Exemplarily, the above-mentioned occupied memory areas can be marked and distinguished by a bitmap. The bitmap can represent the usage status of the memory area through data bits, and different data bits correspond to different usage status flags. For example, for a memory area with a continuous address segment from 0xFFFFFFFFFFFFFFDF to 0xFFFFFFFFFFFFFFFF, the data bits of the bitmap of this address segment are all 01001, and the usage status flag corresponding to the data bit 01001 is "poisoned", then this segment of the memory area is a damaged memory area caused by a hardware failure.

[0036] Exemplarily, normal operations of the target operating system for memory, such as allocating and releasing memory areas, performing memory mapping and file I / O, reclaiming memory areas, handling memory area errors, and performing memory hot plugging, may all cause the memory areas represented by the second parameter to change dynamically during the normal operation of the target operating system.

[0037] The second parameter can characterize information related to memory areas that undergo dynamic changes during the operation of the operating system and cannot be allocated for use by the kernel dump mechanism. For example, in a target operating system that manages memory based on physical page frames, the number of physical page frames with the status flag set to offline (hereinafter referred to as n(offline)) can be used as one of the second parameters. By multiplying n(offline) by the fixed size of each physical page frame, the capacity of the temporarily unavailable memory area can be determined. Memory diagnosis is started at the first moment, and it is measured that n(offline) = 6000, that is, the second parameter is 6000, indicating that the memory areas corresponding to 6000 physical page frames are in a temporarily unavailable state (assuming that this memory area is used for memory diagnosis). After the first moment, the memory diagnosis ends, and this part of the memory area is put back online. It is measured again that n(offline) = 0, that is, the second parameter becomes 0, indicating that there is currently no memory area in a temporarily unavailable state. Throughout this process, the production kernel of the target operating system runs normally, but the second parameter undergoes a dynamic change in which the number of physical page frames decreases from 6000 to 0.

[0038] Through the second parameter, the current actual usage of at least part of the first memory area can be reflected. Thus, based on the initial overall usage of the first memory area reflected by the first parameter and the dynamic change in the usage of the occupied memory area reflected by the second parameter, the first memory area can be adaptively divided to determine the reserved memory area in the subsequent process.

[0039] Step 102: Determine a third parameter according to the first parameter and the second parameter, and divide a reserved memory area from the memory according to the third parameter.

[0040] After obtaining the first parameter and the second parameter, a third parameter for the reserved memory area used by the kernel dump mechanism can be determined; the third parameter may include the number of physical page frames corresponding to the reserved memory area, the capacity size of the reserved memory area, the starting number of the physical page frames corresponding to the reserved memory area, the starting physical address of the reserved memory area, etc.; for example, if the first parameter is used to represent the overall capacity size of the first memory area, and the second parameter is used to represent the capacity size of the occupied memory area in the first memory area, then based on the first parameter and the second parameter, the capacity size of the reserved memory area that can be allocated to the kernel dump mechanism in the first memory area can be confirmed. It can be understood that since the value of the second parameter can change dynamically with the running status of the system, the value of the third parameter obtained through the first parameter and the second parameter also changes dynamically. For example, during the startup process of the operating system, the first parameter obtained represents that the total capacity size of the first memory area is 2GB, and the capacity size of the currently occupied memory area represented by the second parameter is 1.5GB. Before the production kernel crashes during the operation of the operating system, the capacity size of the currently occupied memory area represented by the second parameter obtained again becomes 0.6GB. Then the finally determined size of the reserved memory area can be 2 - 0.6 = 1.4GB.

[0041] Exemplarily, the division of the reserved memory area can be performed through the cma_alloc() function provided by the Contiguous Memory Allocator (CMA). cma_alloc() can take the memory size value as the input parameter (such as 512MB) and return a physical address (such as 0x0000000000FFFFDF). This physical address represents the starting physical address of the memory area with this memory size value in the continuous memory area reserved by the CMA. Through the starting physical address and the memory size value, the division of the reserved memory area can be confirmed in the continuous memory area reserved by the CMA.

[0042] Through the first parameter representing the first memory area and the second parameter reflecting the occupied and dynamically changing memory area in the first memory area, the third parameter of the reserved memory area can be obtained. The third parameter can be used to determine the capacity size of the reserved memory area; it can be understood that the first parameter and the second parameter reflect the actual usage of the first memory area. By obtaining the third parameter through the first parameter and the second parameter and determining the capacity size of the reserved memory area through the third parameter, dynamic allocation of the reserved memory area can be achieved according to the actual usage of the first memory area, thereby enabling the size of the reserved memory area to be flexibly adjusted. Thus, waste of memory resources can be avoided, and at the same time, enough space can be provided for the kernel dump mechanism to obtain production data as completely as possible when the production kernel crashes.

[0043] Step 103: In the case where the production kernel crashes, control the capture kernel to capture the production data in the first memory area and store it in the reserved memory area, and simultaneously generate a dump file based on the production data for subsequent debugging and analysis of the production kernel.

[0044] When the production kernel crashes, start the capture kernel and control the capture kernel to obtain the production data stored in the first memory area and temporarily store it in the reserved memory area, where the reserved memory area is determined by the third parameter updated most recently. The crash of the production kernel may be caused by a fatal error in the mathematical operation of the production task in the production kernel. For example, a mathematical operation with a divisor of 0 occurs. After the crash, the production kernel will become stuck and can no longer read and write production data from the first memory area. At this time, the capture kernel will be started for dumping the production data: the capture kernel copies the production data from the memory area storing the production data in the first memory area to the reserved memory area, and writes the production data in the reserved memory area to a storage device such as a hard disk in the form of a dump file, so as to store the production data for a long time. When the dump file is generated, the kernel dump process ends, and the target operating system restarts to enable the production kernel to resume normal operation. After the target operation restarts, relevant technical personnel can read the dump file to analyze and debug the production data when the production kernel crashes, locate and solve the cause that causes the production kernel to crash. Exemplarily, the dump file includes various data structures, and professional analysis tools such as crash or gdb (GNU Debugger) can be used to view and analyze the production data stored in the dump file.

[0045] In summary, in the embodiment of the present invention, by obtaining the first parameter representing the usage of the first memory area allocated to the production kernel, and the second parameter that changes in real time in the first parameter and represents the currently actually occupied memory area in the first memory area, the actual usage of the first memory area can be reflected in real time. Furthermore, the size of the reserved memory area in the first memory area can be flexibly adjusted dynamically, so that when the production kernel crashes, a reserved memory area of an appropriate size can be provided for the capture kernel to perform the kernel dump operation. On the one hand, the reserved memory area provides enough space to accommodate the complete production data in the production kernel obtained by the capture kernel, enabling the capture kernel to successfully generate a dump file for subsequent analysis and debugging, thereby providing more comprehensive information for troubleshooting the production kernel and improving the efficiency of troubleshooting. On the other hand, dividing the reserved memory area according to the actual occupancy of the first memory area also provides enough running space for other task programs of the production kernel, maximizing the utilization rate of the first memory area, avoiding waste of memory resources, and improving the performance of the production kernel.

[0046] Figure 2 It is a flowchart of steps of another kernel dump method provided by an embodiment of the present invention. The method is applied to an electronic device installed with a target operating system, and the kernel of the target operating system is divided into a production kernel and a capture kernel; the memory of the electronic device is divided into multiple physical page frames of the same size and continuously numbered. The first parameter includes the size of the first memory area, as Figure 2 shown, the method includes:

[0047] Step 201, obtain the maximum value of the numbers of the physical page frames.

[0048] In memory management, memory is generally divided into multiple physical page frames of the same size and continuously numbered for management. Thus, in the embodiments of the present application, the first parameter, the second parameter, the third parameter, etc. can be obtained based on the physical page frames, and then memory areas such as the first memory area and the reserved memory area can be determined; by obtaining the maximum value of the numbers of the physical page frames, the total number of physical page frames can be determined, and further the size of the first memory area can be determined; the number of a physical page frame (PageFrame Number, PFN) is used to index the physical page frame in the page table data structure, that is, the physical page frame with a number is addressable, and each physical page frame has a unique PFN. The PFN can not only reflect the number of physical page frames, but also reflect the position of the physical page frame.

[0049] Exemplarily, for a memory with a capacity of 8 GB and the size of each physical page frame being 4 KB, then the size of each physical page frame is converted to bytes (Byte) as 4 × 1024 = 4096 Bytes. The capacity of the 8G memory is converted to bytes for representation as 8 × 1024 × 1024 × 1024 = 8589934592 Bytes. Then the number of physical page frames is 8589934592 ÷ 4096 = 2097152. The numbers of the physical page frames start from 0, so the maximum value maxpfn of the numbers of the physical page frames is 2097152 - 1 = 2097151; since maxpfn can be directly obtained, obtaining the maximum value maxpfn of the numbers is equivalent to obtaining the total number of physical page frames.

[0050] Step 202, traverse all memory segments of the memory, and obtain the usage information corresponding to each memory segment.

[0051] Before determining the first memory section, it is necessary to traverse the memory to exclude memory areas that cannot be allocated to the first memory section. For a target operating system based on the Sparse Memory Model, the memory is divided into multiple memory sections for management. A memory section can include multiple physically contiguous physical page frames, and the sizes of multiple memory sections can be different. Traversing all physical page frames according to their numbers has relatively large time and space overheads. Therefore, the usage information of the memory can be obtained by traversing the memory sections to improve the efficiency of traversing the memory. The usage information of the memory characterizes the usage of the physical page frames in the memory section and is used to determine whether there are memory holes in the memory that cannot be used by the production kernel.

[0052] Step 203: Confirm the size of the first memory section according to the maximum value of the numbers and the usage information.

[0053] After obtaining the maximum value of the numbers and the usage information, excluding the part characterized in the usage information that cannot be used by the production kernel, the size of the first memory section allocated to the production kernel for storing production data can be obtained.

[0054] Optionally, the usage information includes the number of physical page frames of memory holes in the memory section; the physical page frames of memory holes are used to characterize the physical page frames that cannot be used by the production kernel; Step 203 may include:

[0055] Sub-step 2031: Determine the total number of physical page frames according to the maximum value of the numbers, calculate the first difference between the total number and the total number of physical page frames of memory holes, and determine the size of the first memory section according to the first difference.

[0056] The size of the first memory section can be deduced from the number of physical page frames corresponding to the first memory section; the usage information may include the memory capacity size occupied by memory holes. By traversing the memory sections, the memory holes existing in each section can be obtained. The total number of physical page frames of memory holes can characterize the total size of memory holes in the memory. By calculating the maximum value of the numbers of physical page frames to obtain the total number of physical page frames, and then calculating the first difference between the total number of physical page frames and the total number of physical page frames of memory holes, the capacity size of the first memory section in the memory can be determined.

[0057] Exemplarily, the maximum value maxpfn of the physical page frame numbers is 2097151, so there are a total of maxpfn + 1 = 2097152 physical page frames. The capacity of each physical page frame is 4KB. By traversing the memory segment, it is determined that there are a total of 50 physical page frames that are memory hole physical page frames. Then the first memory area includes ram_pfn = 2097152 - 50 = 2097102 physical page frames, that is, the capacity of the first memory area is 2097102 × 4 = 8388408KB. That is, there is the following formula: ram_pfn = maxpfn + 1 - a, where ram_pfn represents the number of physical page frames corresponding to the first memory area, maxpfn represents the maximum value of the physical page frame numbers, and a represents the number of memory hole physical page frames; in this example, maxpfn, ram_pfn, and the calculated capacity of 8388408KB based on ram_pfn are all the first parameters obtained during the startup process of the target operating system.

[0058] Step 204, during the running of the target operating system, obtain the first parameter at every preset period;

[0059] Steps 204 - 206 describe a method for capturing changes in the second parameter: during the running of the target operating system, a timer is configured for the first memory area to actively obtain the first parameter at every preset period; the part in the first parameter that represents the initial overall capacity of the first memory area can be determined and saved during the startup process of the target operating system for subsequent use, while the part of the first memory area related to the second parameter will change due to the running of the target operating system; through the timer, the first parameter can be obtained at every preset period to determine the change situation of the second parameter in the first parameter.

[0060] The second parameter can represent the following multiple memory areas:

[0061] Memory areas filled with zeros. The production kernel often needs to allocate memory areas initialized to zero, such as pages for new processes or clearing disk caches. To avoid the zeroing operation for each allocation, the production kernel reserves some memory areas filled with zeros.

[0062] Memory buffer areas that can be quickly allocated. The production kernel needs to frequently allocate and release physical areas during operation. To improve efficiency, the production kernel caches the recently released memory areas to form memory buffer areas. The production kernel will first obtain new memory areas from the memory buffer areas for allocation. When the memory buffer areas are empty, the production kernel will perform other memory area allocation operations. This part of the memory buffer areas is generally not used for other tasks.

[0063] The CPU-specific memory buffer area functions similarly to the quickly allocatable memory buffer area. However, to improve cache efficiency and avoid multiple CPU cores competing for the same memory area, this part of the memory buffer area is private to the CPU core and thus cannot be used for kernel dumps.

[0064] The memory area accessible to user space. The production kernel maps a part of the memory area to user space for users to use. This part of the memory area is also not suitable as the reserved memory area for kernel dumps.

[0065] The memory area to be allocated for new tasks. The production kernel reserves a part of the unused memory area for future allocation to new production tasks. When the production kernel needs to allocate a new memory area, it will first obtain it from this part of the memory area. Therefore, although this part of the memory area is free, it is still not suitable as the reserved memory area allocated for kernel dumps.

[0066] The damaged memory area caused by hardware failures. When the hardware detects a memory error, it will mark the affected memory area to prevent the production kernel from using these memory areas and avoid the spread of data errors. Correspondingly, this part of the memory area is not suitable as the reserved memory area allocated for kernel dumps.

[0067] The temporarily unavailable memory area. The production kernel can mark a part of the memory area as offline for operations such as memory hotplugging or memory diagnosis; the production kernel will not allocate any processes to this part of the memory area until these memory areas are marked as online again by the production kernel; it can be understood that this part of the memory area marked as offline cannot be used as the reserved memory area for kernel dumps.

[0068] In a target operating system that manages memory based on physical page frames, each physical page frame is configured with a page data structure, and the flags field in the page data structure indicates the usage status corresponding to each physical page frame. For example, pfn_zero is used to represent a physical page frame filled with all zeros. All the physical page frames filled with all zeros together constitute the memory area filled with zeros as described above. Adaptively, pfn_cache can be used to represent a physical page frame cache that can be quickly allocated (corresponding to the memory buffer area that can be quickly allocated in the above text), pfn_cache_private can be used to represent a CPU-specific physical page frame cache (corresponding to the memory buffer area specific to the central processing unit in the above text), pfn_user can be used to represent a physical page frame that can be accessed by the user space (corresponding to the memory area that can be accessed by the user space in the above text), pfn_free can be used to represent a physical page frame to be allocated for a new task (corresponding to the memory area to be allocated for a new task in the above text), pfn_hwpoison can be used to represent a damaged physical page frame caused by a hardware failure (corresponding to the damaged memory area caused by a hardware failure in the above text), and pfn_offline can be used to represent a temporarily unavailable physical page frame (corresponding to the temporarily unavailable memory area in the above text). By obtaining the total number of physical page frames corresponding to the above flags field, the number of physical page frames corresponding to the memory area corresponding to the second parameter can be determined.

[0069] Step 205: For the current cycle, when the target parameter included in the obtained first parameter changes compared to the previous cycle, use the target parameter as the second parameter that has changed.

[0070] In the first parameter obtained in the current cycle, if the target parameter changes compared to the target parameter in the previous cycle, then the target parameter can be used as the second parameter that has changed. The range of the target parameter is the same as that of the second parameter. In a target operating system that manages memory based on physical page frames, the target parameter can be the number of physical page frames corresponding to the memory area represented by the second parameter. Exemplarily, the size of each physical page frame is 4KB. In the first cycle, if among the obtained target parameters, only pfn_zero = 40, it indicates that the number of physical page frames corresponding to the memory area filled with all zeros is 40, that is, the capacity of the memory area filled with all zeros is 40 × 4 = 160KB. In the adjacent second cycle, if the obtained target parameter pfn_zero becomes 50, it indicates that the capacity of the memory area filled with all zeros becomes 50 × 4 = 200KB. Since pfn_zero has changed, the physical page frame pfn_zero = 50 filled with all zeros will be retained as the second parameter that has changed.

[0071] Step 206: For the current cycle, if the target parameter included in the obtained first parameter remains unchanged compared to the previous cycle, then it is ignored.

[0072] The intervals at which some memory areas corresponding to the second parameter change are longer than the preset cycle, or these memory areas do not change until the production kernel crashes. In this case, the target parameter obtained in the current cycle can be ignored, and the target parameter can be re-obtained in the next cycle. Exemplarily, the size of each physical page frame is 4KB. In the first cycle, among the obtained target parameters, there is only and exactly pfn_hwpoison = 0, indicating that the number of physical page frames corresponding to the damaged memory area caused by a hardware fault is 0, that is, the capacity of the damaged memory area caused by the hardware fault is 0 × 4 = 0KB. In the adjacent second cycle, the obtained target parameter pfn_hwpoison is still 0, which indicates that the capacity of the damaged memory area caused by the hardware fault has not changed. The value of pfn_hwpoison in the second cycle has not changed compared to the first cycle. In this case, the value of pfn_hwpoison obtained in the second cycle can be ignored, and the target parameter is waited to be continuously obtained in the next cycle adjacent to the second cycle; if the third parameter is calculated in the second cycle, then the value of the second parameter at this time is 0, that is, there is no occupied memory area.

[0073] By setting a timer, the value of the second parameter can be updated periodically to ensure that the third parameter of the reserved memory area can be determined based on the latest second parameter. Exemplarily, in the target operating system that manages memory based on physical page frames, the only obtained target parameter is the number of pfn_offline; the total value of the target parameters obtained in the first cycle is 1024, that is, there are a total of 1024 physical page frames corresponding to memory areas that are temporarily unavailable in the first cycle, and these memory areas cannot be allocated to the reserved memory area. The total value of the target parameters obtained in the adjacent second cycle is 1280, that is, there are a total of 1280 physical page frames corresponding to memory areas that cannot be allocated to the reserved memory area in the second cycle. If the third parameter is calculated in the second cycle, then the value of the number of physical page frames with the status flag of offline in the second parameter at this time is 1280, that is, pfn_offline = 1280.

[0074] Step 207: During the operation of the target operating system, when the status monitoring function detects a change in the second parameter, the changed second parameter is obtained in real time; the status monitoring function is configured in the first memory area.

[0075] Step 207 describes another method for capturing changes in the second parameter, which is to set a status monitoring function for the first memory area, and monitor the changes in the second parameter through the status monitoring function; in the target operating system that manages memory based on physical page frames, the status monitoring function can monitor the page data structures of each physical page frame respectively, so as to judge in real time whether the target parameter has changed according to the changes in the flags field in the page; for example, the flags field in the page data structure can change when actions such as mapping between physical page frames and virtual memory, unbuffered I / O, memory errors, and memory hotplug occur. The frequencies of these operations are relatively low, and the corresponding change frequency of the flags field is not high either. Therefore, setting the status monitoring function will not introduce excessive time and space overhead. For example, the status hook function pfn_offline_hook can be configured as the status monitoring function. It takes a global variable that records the total number of pfn_offline as the input parameter and updates this global variable in the function body. Assume that the initial number of pfn_offline is 0, that is, there are no offline physical page frames initially. When performing a memory hotplug operation, pfn_offline_hook detects that the flags fields of 1280 physical page frames become pfn_offline, that is, the target parameter has changed from 0 to 1280. At this time, 1280 can be used as the number of physical page frames with the status flag of offline in the second parameter, that is, pfn_offline = 1280; by setting the status monitoring function for all occupied memory areas (refer to the various memory areas enumerated in step 204) in the first memory area, the number of physical page frames of each currently occupied memory area in the first memory area can be obtained.

[0076] Step 208: Calculate the second difference between the size of the first memory area and the size of the occupied memory areas in the first memory area, and use the second difference as the size of the reserved memory area; the second parameter includes the size of the occupied memory areas in the first memory area, and the third parameter includes the size of the reserved memory area.

[0077] In step 208, the occupied memory area in the first memory area characterized by the second parameter can be called the second memory area. By calculating the size difference between the first memory area and the second memory area, the size of the reserved memory area can be determined. It should be noted that in step 208, the size of the second memory area refers to the total size of all occupied memory areas in the first memory area. Exemplarily, in a target operating system that manages memory based on physical page frames, the size of a memory area can be characterized by the number of physical page frames. The size of the first memory area characterized by the first parameter is ram_pfn = 2097152, that is, the first memory area includes 2097152 physical page frames. The latest second parameter obtained in real time characterizes the size of the second memory area as 1900544, that is, the second memory area includes a total of 1900544 physical page frames. At this time, the size of the reserved memory area is 2097152 - 1900544 = 196608, that is, the reserved memory area includes 196608 physical page frames, and its capacity size is 196608×4÷1024 = 768MB. The size of the second memory area characterized by the above second parameter can be obtained through the formula of the sum of each field representing the usage status of physical page frames. Specifically, it is obtained through (pfn_zero + pfn_cache + pfn_cache_private + pfn_user + pfn_free + pfn_hwpoison + pfn_offline), where each item represents the number of physical page frames corresponding to a memory area, and the reference relationship of each item can be referred to step 204 above and will not be elaborated here, that is, (pfn_zero + pfn_cache + pfn_cache_private + pfn_user + pfn_free + pfn_hwpoison + pfn_offline) = 1900544.

[0078] Step 209, control the continuous memory allocator to allocate a continuous physical memory area from the memory to the reserved memory area, and use the starting address of the continuous physical memory area as the starting address of the reserved memory area.

[0079] After determining the size of the reserved memory area, an area of memory with a sufficient size can be allocated from the first memory area to the reserved memory area according to the size of the reserved memory area; to reduce the complexity of memory management, a physically contiguous memory area is generally selected as the reserved memory area, and this step can be performed by a contiguous memory allocator. The contiguous memory allocator allocates a part of the contiguous physical memory area reserved by CMA as the reserved memory area according to the size of the reserved memory area. During the allocation process, the starting address of the reserved memory area will be determined by CMA. Based on the starting address and the size of the reserved memory area, the reserved memory area can be determined in the contiguous physical memory area.

[0080] Optionally, in step 209, controlling the contiguous memory allocator to allocate a contiguous physical memory area to the reserved memory area according to the size of the reserved memory area may include:

[0081] Sub-step 2091: In the case where the size of the contiguous physical memory area is less than the size of the reserved memory area, the contiguous physical memory area is spliced with other free memory areas in the first memory area to obtain the reserved memory area.

[0082] Since the size of the contiguous physical memory area reserved by CMA is fixed, there may be a situation where the size of the contiguous physical memory area does not meet the size of the reserved memory area for kernel dump. Therefore, all the contiguous physical memory areas can be spliced with other free memory areas in the first memory area to obtain a contiguous reserved memory area; for example, in a target operating system that manages memory based on physical page frames, the size of each physical page frame is 4KB, and the contiguous physical memory area reserved by CMA is 512MB, corresponding to 512×1024÷4 = 131072 physical page frames. These physical page frames are all used for the allocation of the reserved memory area. The size of the reserved memory area is 196608, that is, the reserved memory area includes 196608 physical page frames, and its capacity is 196608×4÷1024 = 768MB. Obviously, 512 < 768, that is, the size of the contiguous physical memory area is less than the size of the reserved memory area. It is necessary to select 196608 - 131072 = 65536 physical page frames from other free memory areas and splice them with the physical page frames corresponding to the contiguous physical memory area reserved by CMA to obtain a total of 196608 physical page frames that meet the capacity size of the reserved memory area. It should be noted that the memory area allocated by CMA, that is, the memory area corresponding to 131072 physical page frames, has contiguous physical addresses, and the memory area corresponding to the 65536 physical page frames selected from other free memory areas also has contiguous physical addresses, but the result after their splicing is only contiguous in logical addresses and not in physical addresses.

[0083] Sub-step 2092: When the size of the continuous physical memory area is greater than or equal to the size of the reserved memory area, directly select a continuous memory area in the continuous physical memory area as the reserved memory area.

[0084] If the capacity of the reserved memory area is smaller than the capacity of the continuous physical memory area reserved by CMA, then CMA can select a continuous memory area with a capacity equal to that of the reserved memory area from the reserved continuous physical memory area as the reserved memory area; for example, in a target operating system based on physical page frames in other embodiments, the size of each physical page frame is 4KB, the continuous physical memory area reserved by CMA is 1024MB, corresponding to 1024×1024÷4 = 262144 physical page frames, and all these physical page frames are used for the allocation of the reserved memory area. The size of the reserved memory area is 196608, that is, the reserved memory area includes 196608 physical page frames, and its capacity is 196608×4÷1024 = 768MB. Obviously, 1024>768, that is, the size of the continuous physical memory area is sufficient to meet the allocation of the reserved memory area. At this time, CMA can select 196608 physical page frames from the reserved continuous physical memory area and allocate them to the reserved memory area.

[0085] The allocation of the reserved memory area can be carried out through the CMA allocation function, such as the function cma_alloc(). When the size of the continuous physical memory area reserved by CMA does not meet the requirements of the reserved memory area, cma_alloc() will fail in allocation and return NULL. At this time, the function alloc_pages() can be used to splice other free memory areas; the input parameters of alloc_pages() include a zone modifier, which is used to indicate from which memory zone alloc_pages allocates memory. The memory zone is a region obtained by dividing the first memory area according to the physical address. For example, the zone modifier __GFP_HIGHMEM indicates that free memory areas are allocated from the high memory zone (HighMemory, high address range. In a 32-bit system, it is usually located in the address segment above 0x80000000). Here, the free memory area refers to the unallocated memory area in the first memory area that is neither the memory area represented by the second parameter nor stores production data; it should be noted that although alloc_pages() can allocate multiple physically contiguous memory areas at one time, during the operation of the target operating system, if memory fragmentation is serious, the function alloc_pages() often cannot locate a single physically contiguous memory area large enough to meet the capacity of the reserved memory area. The physical addresses of the reserved memory areas obtained by splicing through alloc_pages() are not contiguous, which will cause more memory fragmentation in the first memory area and affect the performance of the first memory area and the reserved memory areas therein. However, the continuous physical memory areas reserved by CMA can avoid the problem of memory fragmentation, improve the allocation efficiency and data continuity when performing a kernel dump. Therefore, generally, the CMA allocation function is first used to allocate the reserved memory area, that is, continuous memory areas are first selected from the continuous physical memory areas reserved by CMA for the reserved memory area. If the size of the reserved continuous physical memory area is not enough, it is processed as in sub-step 2091.

[0086] Step 210: Generate a memory description parameter according to the third parameter, and pass the memory description parameter to the capture kernel; the memory description parameter is used to indicate the location of the reserved memory area.

[0087] After generating the third parameter, that is, determining the size and starting address of the reserved memory area, the third parameter needs to be passed to the capture kernel so that the capture kernel can use the reserved memory area when performing a kernel dump. For this purpose, a memory description parameter needs to be generated according to the third parameter, and the third parameter is passed to the capture kernel through the memory description parameter.

[0088] Exemplarily, in a target operating system that manages memory based on physical page frames, memory description parameters can be described in the C language as the following data structure:

[0089] struct capture_memory{......} The name of this data structure is capture_memory. In struct capture_memory{......}, the unsigned long start_pfn field is used to define the number of the starting physical page frame of the reserved memory area, the size_t num_pages field is used to define the number of physical page frames allocated to the reserved memory area, and the bool is_cma field is used to define whether the memory area is allocated by CMA; by writing the third parameter (the size and starting address of the reserved memory area) into the capture_memory data structure, the memory description parameters that the capture kernel can parse and recognize can be obtained.

[0090] For the above data structure, there is the following example:

[0091] struct capture_memory capture_mem[2] indicates that there are at most two memory areas in the reserved memory area of this example. One is the memory area formed by CMA from the reserved continuous physical memory area, and the other is the memory area formed by the alloc_pages function by splicing other free memory areas. In this example, the starting address of the reserved memory area in the continuous physical memory area reserved by CMA is determined by the capture_mem[0].start_pfn field, the capacity size of the continuous memory area allocated by CMA to the reserved memory area, that is, 131072 physical page frames, is determined by the capture_mem[0].num_pages = 131072 field, and the capture_mem[0].is_cma = true field indicates that the memory area numbered [0] is allocated by CMA; the starting address of the free memory area spliced after the continuous physical memory area reserved by CMA is determined by the capture_mem[1].start_pfn field, the capacity size of this free memory area, that is, 65536 physical page frames, is determined by the capture_mem[1].num_pages = 65536 field, and the capture_mem[1].is_cma = false field indicates that the memory area numbered [1] is allocated by the alloc_pages function.

[0092] Step 211: In the case where the production kernel crashes, start the capture kernel and control the capture kernel to parse the memory description parameters, so that the capture kernel determines the location of the reserved memory area according to the parsing result.

[0093] In the case where the production kernel crashes, the hardware of the electronic device where the target operating system is located triggers a system reset and starts the capture kernel. After the capture kernel is started, it parses the memory description parameters generated by the latest third parameter, so that the capture kernel locates the specific location and other relevant parameters of the reserved memory area according to the parsing result. Thereafter, the capture kernel can cooperate with the reserved memory area to generate a dump file.

[0094] When the production kernel crashes, the production kernel cannot continue to execute production tasks, such as mathematical operations on data, etc., but the production kernel can still perform some basic operations, such as printing logs, controlling the CPU to jump to a specified memory address, etc.;

[0095] Exemplarily, after the production kernel crashes, the production kernel uses a jump instruction to drive the CPU to jump to the starting physical address of the reserved memory area (for example, the physical address corresponding to the physical page frame number 185102) and starts the capture kernel (it can start the capture kernel when the CPU jumps to a preset location in the memory according to a preset instruction).

[0096] After the capture kernel boots up, by parsing the code segment struct capture_memory capture_mem[2], the capture kernel learns that the reserved memory area consists of two memory areas; through the code segment capture_mem[0].is_cma = true, it is determined that the memory area labeled [0] is allocated by CMA from the reserved continuous physical memory area. Through the code segment capture_mem[0].start_pfn = 185102, it is determined that the number of the starting physical page frame of the memory area allocated by CMA is 185102. The starting physical address of this memory area corresponds to the 185102 + 1 = 185103rd physical page frame in the entire memory. Through the code segment capture_mem[0].num_pages = 131072, the capacity of the memory area allocated by CMA is determined, that is, 131072 physical page frames. If the size of each physical page frame is 4KB, then CMA allocates a memory area of 131072 × 4 ÷ 1024 = 512MB to the reserved memory area; through the code segment capture_mem[1].is_cma = false, it is determined that the memory area labeled [1] is allocated by alloc_pages(). Through the code segment capture_mem[1].start_pfn = 326174, it is determined that the number of the starting physical page frame of the memory area allocated by CMA is 326174. The starting physical address of this memory area corresponds to the 326174 + 1 = 326175th physical page frame in the entire memory. Through the code segment capture_mem[1].num_pages = 65536, the capacity of the memory area allocated by CMA is determined, that is, 65536 physical page frames. If the size of each physical page frame is 4KB, then CMA allocates a memory area of 65536 × 4 ÷ 1024 = 256MB to the reserved memory area.

[0097] Step 212: Control the capture kernel to capture the production data in the first memory area and store it in the reserved memory area according to the position of the reserved memory area, and at the same time generate a dump file based on the production data for subsequent debugging and analysis of the production kernel.

[0098] This step can be combined with reference to Step 103 above. After the capture kernel boots up, the capture kernel will copy the production data in the first memory area to the reserved memory area, and in the reserved memory area, add file header and other information to the production data to generate a dump file that can be recognized by relevant analysis tools.

[0099] Exemplarily, in the Linux system, the dump file may include the following parts:

[0100] File header: Contains metadata information about the dump file itself, such as file type, file size, generation time, etc.;

[0101] Production data: Includes memory image, stack information, register status, etc.;

[0102] Among them, the memory image records the memory layout of the process when the production kernel crashes, such as the starting address, size, and permissions of the memory area; the stack information is used to record the stack content of the process when the production kernel crashes, such as the pointers, parameters, and local variables of each stack frame; the register status is used to record the register values of the process when the production kernel crashes, such as the instruction pointer, stack pointer, and flag register of the CPU.

[0103] After the dump file is generated, the capture kernel will write the dump file to a preset storage location, so that the dump file and the production data in it can be saved for a long time; after the dump file is stored, relevant analysis tools, such as crash or gdb, can be used to view and analyze the production data in the dump file.

[0104] Exemplarily, by typing crash / lib / debug / lib / modules / …… / vmcore in the Linux command line, the crash tool can be used to print the dump file (in Linux, the dump file is called vmcore, and it can be understood that lib / debug / lib / modules / …… / is the storage location of the dump file on the hard disk). In the vmcore information printed by the crash tool, the [PANIC: "BUG: unable to handle kernel NULL pointer dereference at 000000000000000c"] field indicates the direct cause of the production kernel crash, and the [PID: 27005] field indicates the relevant process number. By using the crash>bt pid command, the memory stack information of the process with PID 27005 can be printed. In the memory stack information, there are fields such as [exception RIP: my_openat+36] and [RIP:ffffffffc07c5024]. From this, it can be known that the instruction data at the 36th byte offset in my_openat caused the production kernel to crash. Relevant technical personnel can modify the file corresponding to this instruction according to the positioning of the crash tool to debug the production kernel.

[0105] Figure 3 It is a flowchart showing the process of a kernel dump method provided by an embodiment of the present invention. Figure 3 Schematically describes the entire process of the kernel dump method from the perspectives of the production kernel and the capture kernel; asFigure 3 As shown, the method may include:

[0106] Step S1: Start the target operating system.

[0107] Step S2: Configure the command line parameter crashkernel = dynamic.

[0108] In the embodiment of the present invention, the kernel dump method can be enabled by setting the value of crashkernel to dynamic.

[0109] Step S3: Start the production kernel.

[0110] Step S4: Calculate the size of the reserved memory area according to the first parameter and the second parameter.

[0111] It can be understood that Step S4 encompasses the process of calculating the size of the reserved memory slice in Steps 201 - 208 above.

[0112] Step S5: Divide the reserved memory area according to the calculated size.

[0113] It can be understood that Steps S5, S9, S10, S11, S12, and S13 describe the relevant content in Step 209 above, where Step S13 is equivalent to sub - step 2091.

[0114] Step S6: The target operating system starts successfully and runs normally.

[0115] Step S7: When the second memory area changes, obtain the corresponding second parameter that has changed.

[0116] It can be understood that after obtaining the changed second parameter, it is necessary to recalculate the size of the reserved memory area according to the latest second parameter, that is, Step S4 needs to be re - executed after Step S7.

[0117] Step S8: The production kernel crashes.

[0118] Step S9: Apply for CMA memory according to the size.

[0119] It can be understood that the size here refers to the size of the reserved memory area, and CMA memory refers to the continuous physical memory area reserved by CMA.

[0120] Step S10: Determine whether the application is successful.

[0121] Step S11: If the application fails, reduce the continuous physical memory area of CMA and re - apply.

[0122] Since there may be continuous memory areas in the CMA region that have already been allocated to other tasks, there may be cases where the application fails. Reducing the continuous physical memory area of CMA means excluding the continuous memory areas in the CMA region that have been allocated to other tasks to ensure that the application for CMA memory can succeed.

[0123] Step S12: Calculate whether the applied CMA memory meets the size of the reserved memory area.

[0124] That is, judge the relationship between the size of the continuous physical memory area allocated by CMA and the size of the reserved memory area.

[0125] Step S13: Concatenate the CMA region with other free memory areas to obtain the reserved memory area.

[0126] That is, when the size of the continuous physical memory area is less than the size of the reserved memory area, use alloc_pages to apply for the remaining memory. This step is equivalent to sub-step 2091 above.

[0127] Step S14: Construct the parameter elfcorehdr for capturing the kernel.

[0128] The parameter elfcorehdr represents the physical address of the ELF (Executable and Linkable Format) file header; ELF is a standard file format used for executable files, object files, shared link libraries, and kernel dumps, etc.; constructing elfcorehdr ensures that the captured kernel can successfully parse the memory description parameters.

[0129] Step S15: Generate memory description parameters.

[0130] It can be understood that this step is equivalent to step 210 above.

[0131] Step S16: Start the captured kernel

[0132] Step S17: Parse the memory description parameters.

[0133] Step S18: Determine the location of the reserved memory area according to the parsing result.

[0134] It can be understood that steps S16 - S17 are equivalent to step 211 above.

[0135] Step S19: The captured kernel starts successfully.

[0136] Step S20: Generate a dump file.

[0137] Step S21: Store the dump file.

[0138] It can be understood that storing the dump file and writing the dump file into a component device such as a hard disk that can store data for a long time, steps S19 - S21 are equivalent to step 212 above.

[0139] Step S22, end the restart.

[0140] The end restart here is equivalent to ending the kernel dump process and restarting the target operating system.

[0141] In summary, by obtaining the first parameter representing the usage of the first memory area allocated to the production kernel, and the second parameter that changes in real time in the first parameter, which represents the memory area actually occupied in the first memory area, the actual usage of the first memory area can be reflected in real time. Furthermore, the size of the reserved memory area in the first memory area can be flexibly adjusted dynamically, so that when the production kernel crashes, a reserved memory area of an appropriate size can be provided for the capture kernel to perform the kernel dump operation. On the one hand, the reserved memory area provides enough space to accommodate the complete production data in the production kernel obtained by the capture kernel, enabling the capture kernel to successfully generate a dump file for subsequent analysis and debugging, thus providing more comprehensive information for troubleshooting the production kernel and improving the efficiency of troubleshooting; on the other hand, dividing the reserved memory area according to the actual occupancy of the first memory area also provides enough running space for other task programs of the production kernel, maximizing the utilization rate of the first memory area, avoiding waste of memory resources, and improving the performance of the production kernel.

[0142] Figure 4 It is a block diagram of a kernel dump device 30 provided by an embodiment of the present invention. As Figure 4 shown, the device 30 includes:

[0143] A parameter acquisition module 301: used to determine the first parameter of the first memory area allocated to the production kernel, and acquire the second parameter that changes in the first parameter; the first memory area is used to store the production data of the production kernel;

[0144] A memory confirmation module 302: used to determine the third parameter according to the first parameter and the second parameter, and divide a reserved memory area from the memory according to the third parameter;

[0145] A dump execution module 303: used to control the capture kernel to capture the production data in the first memory area and store it in the reserved memory area in the case of a crash of the production kernel, and generate a dump file according to the production data for subsequent debugging and analysis of the production kernel.

[0146] Optionally, the memory of the electronic device is divided into multiple physical page frames of the same size and consecutively numbered; the first parameter includes the size of the first memory area; the parameter acquisition module 302 may include:

[0147] Physical page frame number acquisition sub-module: for acquiring the maximum value of the numbers of the physical page frames;

[0148] Memory statistics sub-module: for traversing all memory segments of the memory to acquire the usage information corresponding to each memory segment;

[0149] First capacity confirmation sub-module: for confirming the size of the first memory area according to the maximum value of the numbers and the usage information.

[0150] Optionally, the usage information includes the number of physical page frames of memory holes in the memory segment; the first capacity confirmation sub-module may include:

[0151] Capacity calculation unit: for determining the total number of the physical page frames according to the maximum value of the numbers, calculating a first difference between the total number and the sum of the numbers of the physical page frames of the memory holes, and determining the size of the first memory area according to the first difference.

[0152] Optionally, the first parameter includes the size of the first memory area, the second parameter includes the size of the occupied memory area in the first memory area, and the third parameter includes the size of the reserved memory area; the parameter acquisition module 301 may include:

[0153] Second capacity confirmation sub-module: for calculating a second difference between the size of the first memory area and the size of the occupied memory area in the first memory area, and using the second difference as the size of the reserved memory area.

[0154] Optionally, the apparatus 30 may further include:

[0155] Address confirmation module: for controlling the continuous memory allocator to allocate a continuous physical memory area from the memory to the reserved memory area, and using the starting address of the continuous physical memory area as the starting address of the reserved memory area.

[0156] Optionally, the address confirmation module may include:

[0157] First address confirmation sub-module: for splicing the continuous physical memory area and other free memory areas in the first memory area to obtain the reserved memory area when the size of the continuous physical memory area is less than the size of the reserved memory area;

[0158] The second address confirmation sub-module: used to directly select a continuous memory area in the continuous physical memory area as the reserved memory area.

[0159] Optionally, the device 30 may further include:

[0160] The memory description parameter transmission module: used to generate memory description parameters according to the third parameter and transmit the memory description parameters to the capture kernel; the memory description parameters are used to indicate the position of the reserved memory area;

[0161] The memory description parameter parsing module: used to control the capture kernel to parse the memory description parameters to obtain a parsing result to determine the position of the reserved memory area.

[0162] Optionally, the first memory area is configured with a status monitoring function; the parameter acquisition module 301 may include:

[0163] The status monitoring sub-module: used to obtain the changed second parameter in real time when the status monitoring function monitors that the second parameter has changed during the operation of the target operating system.

[0164] In summary, in the embodiment of the present invention, by obtaining the first parameter of the first memory area allocated to the production kernel and the second parameter that changes during the operation of the target operating system, the actual usage of the first memory area can be reflected, and then the size of the reserved memory area in the first memory area can be flexibly adjusted dynamically. Thus, when the production kernel crashes, a reserved memory area of an appropriate size can be provided for the capture kernel to perform the kernel dump operation. On the one hand, the reserved memory area provides enough space to ensure that the capture kernel can obtain the complete production data in the production kernel, facilitating the capture kernel to generate a dump file faster for subsequent analysis and debugging, thereby providing more comprehensive information for troubleshooting the production kernel and improving the efficiency of troubleshooting the production kernel; on the other hand, dividing the reserved memory area according to the actual usage of the first memory area can provide sufficient running space for other task programs of the production kernel, maximizing the utilization rate of the first memory area, avoiding waste of memory resources, and improving the performance of the production kernel.

[0165] The kernel dump device in the embodiments of the present invention may be a device, or a component, an integrated circuit, or a chip in a terminal. The device may be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device may be a mobile phone, a tablet computer, a laptop computer, a palmtop computer, a vehicle-mounted electronic device, a wearable device, an ultra-mobile personal computer (UMPC), a netbook, or a personal digital assistant (PDA), etc., and the non-mobile electronic device may be a server, a Network Attached Storage (NAS), a personal computer (PC), a television (TV), a teller machine, or a self-service machine, etc. The embodiments of the present invention do not make specific limitations.

[0166] The kernel dump device provided in the embodiments of the present invention can implement each process implemented by the kernel dump device in the method embodiments. To avoid repetition, it will not be elaborated here.

[0167] Optionally, the embodiments of the present invention further provide an electronic device, including a processor, a memory, a program or instruction stored on the memory and executable on the processor. When the program or instruction is executed by the processor, it implements each process of the above firmware update method embodiment and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.

[0168] It should be noted that the electronic device in the embodiments of the present invention includes the above-mentioned mobile electronic devices and non-mobile electronic devices.

[0169] Figure 5 FIG. 1300 is a schematic hardware structure diagram of an electronic device according to an embodiment of the present invention.

[0170] The electronic device 1300 includes, but is not limited to: a radio frequency unit 1301, a network module 1302, an audio output unit 1303, an input unit 1304, a sensor 1305, a display unit 1306, a user input unit 1307, an interface unit 1308, a memory 1309, and a processor 1310, etc.

[0171] Those skilled in the art can understand that the electronic device 1300 may further include a power supply (such as a battery) for supplying power to each component. The power supply may be logically connected to the processor 1310 through a power management system, so as to implement functions such as management of charging, discharging, and power consumption management through the power management system. Figure 5The structure of the electronic device shown does not limit the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have a different component arrangement, which will not be elaborated here.

[0172] It should be understood that in the embodiments of the present invention, the input unit 1304 may include a Graphics Processing Unit (GPU) 13041 and a microphone 13042. The GPU 13041 processes the image data of static pictures or videos obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The display unit 1306 may include a display panel 13061, and the display panel 13061 may be configured in the form of a liquid crystal display, an organic light-emitting diode, etc. The user input unit 1307 includes at least one of a touch panel 13071 and other input devices 13072. The touch panel 13071 is also referred to as a touch screen. The touch panel 13071 may include two parts: a touch detection device and a touch controller. The other input devices 13072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which will not be elaborated here.

[0173] The memory 1309 can be used to store software programs and various data. The memory 1309 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data. Among them, the first storage area may store an operating system, application programs or instructions required for at least one function (such as a sound playback function, an image playback function, etc.). In addition, the memory 1309 may include volatile memory or non-volatile memory, or the memory 1309 may include both volatile and non-volatile memory. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDR SDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synch link dynamic random access memory (SLDRAM), and a direct rambus random access memory (DRRAM). The memory 1309 in the embodiments of the present invention includes but is not limited to these and any other suitable types of memory.

[0174] The processor 1310 may include one or more processing units; optionally, the processor 1310 integrates an application processor and a modem processor. Among them, the application processor mainly processes operations related to the operating system, user interface, and application programs, etc., and the modem processor mainly processes wireless communication signals, such as a baseband processor. It can be understood that the above modem processor may not be integrated into the processor 1310 either.

[0175] The embodiments of the present invention also provide a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, it implements each process of the above embodiment of the kernel dump method and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.

[0176] The embodiments of the present invention have been described above in conjunction with the accompanying drawings. However, the present invention is not limited to the above specific embodiments. The above specific embodiments are merely illustrative rather than restrictive. Under the inspiration of the present invention, those of ordinary skill in the art can also make many forms without departing from the spirit of the present invention and the scope protected by the claims, and all of them fall within the protection scope of the present invention.

Claims

1. A kernel dump method, characterized in that, The method includes: Determining a first parameter of a first memory area allocated for a production kernel, and obtaining a second parameter that has changed in the first parameter; the first memory area is used to store production data of the production kernel; Determining a third parameter according to the first parameter and the second parameter, and partitioning a reserved memory area from the memory according to the third parameter; In the case where the production kernel crashes, controlling a capture kernel to capture the production data in the first memory area and store it in the reserved memory area, and simultaneously generating a dump file according to the production data for subsequent debugging and analysis of the production kernel.

2. The method according to claim 1, wherein The memory is divided into multiple physical page frames of the same size and continuously numbered; The first parameter includes the size of the first memory area; the determining of the first parameter of the first memory area allocated for the production kernel includes: Obtaining the maximum value of the numbers of the physical page frames; Traversing all memory segments of the memory to obtain usage information corresponding to each memory segment; Confirming the size of the first memory area according to the maximum value of the numbers and the usage information.

3. The method according to claim 2, wherein The usage information includes the number of physical page frames of memory holes in the memory segment; Then, the confirming of the size of the first memory area includes: Determining the total number of physical page frames according to the maximum value of the numbers, calculating a first difference between the total number and the sum of the numbers of the physical page frames of the memory holes, and determining the size of the first memory area according to the first difference.

4. The method according to claim 1, characterized in that, The second parameter includes the size of the memory area already occupied in the first memory area, and the third parameter includes the size of the reserved memory area; Then, the determining of the third parameter according to the first parameter and the second parameter includes: Calculating a second difference between the size of the first memory area and the size of the memory area already occupied in the first memory area, and using the second difference as the size of the reserved memory area.

5. The method according to claim 4, wherein The third parameter further includes the starting address of the reserved memory area; then, the method further includes: Controlling a continuous memory allocator to allocate a continuous physical memory area from the memory to the reserved memory area, and using the starting address of the continuous physical memory area as the starting address of the reserved memory area.

6. The method according to claim 5, wherein The allocating of the continuous physical memory area from the memory to the reserved memory area includes: In the case where the continuous physical memory area is smaller than the reserved memory area, splicing the continuous physical memory area with other free memory areas in the first memory area to obtain the reserved memory area; Otherwise, directly selecting a continuous memory area in the continuous physical memory area as the reserved memory area.

7. The method according to claim 1, characterized in that The method further includes: Generating a memory description parameter according to the third parameter, and passing the memory description parameter to the capture kernel; the memory description parameter is used to indicate the location of the reserved memory area; Then, before the controlling the capture kernel to capture the production data in the first memory area and store it in the reserved memory area, it further includes: Control the capture kernel to parse the memory description parameter to obtain a parsing result, so as to determine the location of the reserved memory area.

8. The method according to claim 1, characterized in that, The first memory area is configured with a status monitoring function; Then, obtaining the second parameter that changes in the first parameter includes: During the operation of the target operating system, when the status monitoring function detects that the second parameter changes, the second parameter is obtained in real time.

9. A kernel dump device, characterized in that, The device includes: A parameter acquisition module: used to determine the first parameter of the first memory area allocated for the production kernel, and obtain the second parameter that changes in the first parameter; the first memory area is used to store the production data of the production kernel; A memory confirmation module: used to determine a third parameter according to the first parameter and the second parameter, and divide a reserved memory area from the memory according to the third parameter; A dump execution module: used to control the capture kernel to capture the production data in the first memory area and store it in the reserved memory area when the production kernel crashes, and generate a dump file according to the production data for subsequent debugging and analysis of the production kernel.

10. An electronic device, characterized in that, It includes a processor, a memory, and a program or instruction stored on the memory and executable on the processor. When the program or instruction is executed by the processor, the steps of the kernel dump method according to any one of claims 1 to 8 are implemented.

11. A readable storage medium, characterized in that, A program or instruction is stored on the readable storage medium. When the program or instruction is executed by a processor, the steps of the kernel dump method according to any one of claims 1 to 8 are implemented.

Citation Information

Cited By

  • Memory management method, program product, equipment and medium

    CN120743564A