A method, device and medium for collecting an application process memory snapshot
By using a daemon process and control word to save a memory snapshot when the business process exits, the problem of limited memory snapshot mechanism is solved, and efficient memory snapshot and debugging are achieved in various scenarios.
Patent Information
- Application Number
- CN202211296496.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-21
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2042-10-21
AI Technical Summary
In existing technologies, memory snapshot mechanisms are only effective in specific scenarios, which limits the debugging process and results in incomplete memory snapshot files, affecting debugging efficiency.
By establishing a daemon process, a memory snapshot command is initiated after the business process exits. The control word is used to preserve the memory of the business process, and the VMA information is traversed and memory mapping is performed to save it to a file. This is suitable for various scenarios.
It improves the versatility of memory snapshots, making them applicable to various scenarios, thus enhancing debugging efficiency and avoiding limitations in specific scenarios and incomplete file information.
Smart Images

Figure CN115617521B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of process management technology, and in particular to a method, apparatus and medium for taking memory snapshots of application processes. Background Technology
[0002] When a program terminates abnormally or crashes during execution, the operating system records and saves the program's memory state at that time to a file, similar to a memory snapshot (core dump). Core dumps are important for programmers to diagnose and debug programs. For some program errors that are difficult to reproduce (such as pointer exceptions), core dump files can reveal the program's error scenarios online.
[0003] The core dump mechanism is only effective and reproducible in specific scenarios, such as when the core dump configuration conditions or signal trigger conditions (stopping the process, terminating the process, or terminating and causing a core dump) are met, a memory snapshot can be received. In scenarios where a memory snapshot is not received, the debugging process lacks a reference; or the received file may be incomplete, affecting the debugging process and directly impacting the debugging results.
[0004] Therefore, how to collect application process memory snapshots in various scenarios to improve versatility is a problem that those skilled in the art urgently need to solve. Summary of the Invention
[0005] The purpose of this invention is to provide a method, apparatus, and medium for obtaining memory snapshots of application processes, thereby improving the versatility of memory snapshot acquisition scenarios, making it applicable to various scenarios, and improving debugging efficiency.
[0006] To address the aforementioned technical problems, this invention provides a method for capturing memory snapshots of application processes, comprising:
[0007] A daemon process is established, and a memory snapshot instruction is initiated by the daemon process after the business process exits;
[0008] The business process invokes a control word to reserve the memory of the business process;
[0009] The daemon process iterates through the VMA information in the address space corresponding to the business process.
[0010] Memory mapping is performed based on the VMA information to obtain the address space of the business process and then transferred to a file.
[0011] Preferably, the control word is obtained by pre-setting a registered character device and calling the registered character device.
[0012] Preferably, the step of reserving the memory of the business process by calling the control word through the business process includes:
[0013] The control word is invoked in the registered character device;
[0014] Correspondingly, invoking the control word includes:
[0015] Call the get_task_mm command;
[0016] The control handle will be returned based on the get_task_mm instruction that was invoked.
[0017] Preferably, the step of traversing the VMA information within the address space corresponding to the business process through the daemon process includes:
[0018] The VMA information is obtained by traversing the head of the mmap linked list within the data structure to which the address space of the business process belongs.
[0019] Preferably, after traversing the VMA information within the address space corresponding to the business process through the daemon process, and before performing memory mapping based on the VMA information, the method further includes:
[0020] Save the VMA information;
[0021] After the business process exits, the daemon process calls the control word to request the vma list from the kernel;
[0022] Return the vma list to user space.
[0023] Preferably, the step of performing memory mapping based on the VMA information to obtain the address space of the service process includes:
[0024] The address space is obtained by performing mmap memory mapping based on the vma information and the vma list.
[0025] Preferably, after transferring the data to the file, the method further includes:
[0026] The registered character device initiates a de-enable resident instruction to release memory.
[0027] To address the aforementioned technical problems, the present invention also provides an apparatus for capturing memory snapshots of application processes, comprising:
[0028] A module is established to create a daemon process, which then initiates a memory snapshot command after the business process exits.
[0029] The calling module is used to call the control word through the business process to reserve the memory of the business process;
[0030] The traversal module is used to traverse the VMA information in the address space corresponding to the business process through the daemon process;
[0031] The mapping module is used to perform memory mapping based on the VMA information to obtain the address space of the business process and transfer it to a file.
[0032] To address the aforementioned technical problems, the present invention also provides an apparatus for capturing memory snapshots of application processes, comprising:
[0033] Memory, used to store computer programs;
[0034] A processor, used to implement the steps of the method for taking a snapshot of the application process memory as described above when executing the computer program.
[0035] To address the aforementioned technical problems, the present invention also provides a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of the method for capturing application process memory snapshots as described above.
[0036] This invention provides a method for capturing application process memory snapshots, comprising: establishing a daemon process, and having the daemon process initiate a memory snapshot instruction after the business process exits; using the business process to call a control word to preserve the memory of the business process; using the daemon process to traverse the VMA information within the address space corresponding to the business process; performing memory mapping based on the VMA information to obtain the address space of the business process and transferring it to a file. This method saves the memory of the business process when it exits by driving a control word, so that the system can reclaim the address space of the current business process and save it to a file to achieve a memory snapshot. It avoids the limitations of existing memory snapshots, which are only effective in specific scenarios (meeting certain triggering conditions), and the impact on the debugging process caused by incomplete memory snapshot files. It improves the versatility of memory snapshot acquisition, making it applicable to various scenarios and improving debugging efficiency.
[0037] In addition, the present invention also provides an apparatus and medium for taking snapshots of application process memory, which have the same beneficial effects as the method for taking snapshots of application process memory described above. Attached Figure Description
[0038] To more clearly illustrate the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0039] Figure 1 A flowchart illustrating a method for capturing memory snapshots of an application process, provided by an embodiment of the present invention;
[0040] Figure 2 This is a schematic diagram illustrating the creation of a process address space in an embodiment of the present invention;
[0041] Figure 3 This is a schematic diagram of the data structure within the process address space in an embodiment of the present invention;
[0042] Figure 4 A structural diagram of an apparatus for collecting memory snapshots of application processes provided in an embodiment of the present invention;
[0043] Figure 5 This is a structural diagram of another device for collecting application process memory snapshots provided in an embodiment of the present invention. Detailed Implementation
[0044] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of the present invention.
[0045] The core of this invention is to provide a method, apparatus, and medium for obtaining memory snapshots of application processes, which improves the versatility of memory snapshot acquisition scenarios, is applicable to various scenarios, and improves debugging efficiency.
[0046] To enable those skilled in the art to better understand the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0047] It should be noted that memory snapshots occur when existing applications terminate abnormally or crash during runtime, but not all applications will generate memory snapshots during runtime. For example, if a process is executed using the `kill -9` command, a memory snapshot will not occur because the process has not set the corresponding configuration conditions and trigger conditions. In Linux systems, signals are an asynchronous event handling mechanism. Each signal has its default operation, which mainly includes ignoring the signal, stopping the process, terminating the process, and terminating with a coredump. If all signals use the default operation, Table 1 shows the signal table with the default operation. As shown in Table 1, the signals in the table will generate memory snapshots when they occur. The method for collecting application process memory snapshots provided by this invention is applicable to Linux applications, and the debugging scenarios for Linux-based applications are diverse.
[0048] Table 1 shows the signal table for default operation.
[0049]
[0050]
[0051] Figure 1 A flowchart illustrating a method for capturing application process memory snapshots provided in an embodiment of the present invention is shown below. Figure 1 As shown, the method includes:
[0052] S11: Establish a daemon process, and initiate a memory snapshot command by the daemon process after the business process exits;
[0053] S12: Use the control word called by the business process to reserve the memory of the business process;
[0054] S13: Traverse the VMA information in the address space corresponding to the business process through the daemon process;
[0055] S14: Perform memory mapping based on the VMA information to obtain the address space of the business process and transfer it to a file.
[0056] Specifically, a daemon process is established so that it can initiate business processes. The daemon process is designed for business processes and its role is to monitor the current running status of the business processes. When a business process exits, it is responsible for initiating a memory snapshot instruction.
[0057] A memory snapshot records data in memory at a specific point in time and saves it to disk as a file. Even if the system crashes, the data remains. After the server restarts, the data can simply be restored. When a program crashes (core), it requires troubleshooting. This usually refers to a program that exits or terminates abnormally during runtime due to various exceptions or bugs, and under certain conditions, generates a file called a core file.
[0058] Typically, a core file contains the program's runtime memory, register states, stack pointer, memory management information, and various function call stack information. It can be understood as a file that stores the current state of the program. Many programs generate a core file when they encounter errors. By analyzing this file with tools, you can locate the stack call information corresponding to the abnormal program exit, find the problem, and resolve it in a timely manner.
[0059] By using control words to reserve memory for the business process, it's understandable that during communication between the application and the kernel, character devices need to be registered to implement the relevant control words. As one example, the control words are obtained by pre-setting and registering character devices, and then calling those registered devices.
[0060] Character devices process data as a byte stream, supporting both sequential and random access. Typical character devices include serial ports, keyboards, touchscreens, cameras, serial buses (Intel-Integrated Circuit bus, I2C), serial peripheral interfaces (SPI), sound cards, and frame buffers. Sequential access devices include serial ports, keyboards, and touchscreens; random access devices include frame buffers. Device numbers facilitate operating system management. Similarly, processes are managed by a process ID (Process Identifier, PID), which can be found using the `ps` command. Threads are managed by a thread ID (Thread Identifier, TID), which is returned when a thread is created. Just as everyone has a name, but names can be duplicated, identification numbers can be used to distinguish them.
[0061] Registering a character device involves the following steps:
[0062] 1. Request a device number for a character device, including a major device number and a minor device number:
[0063] 1. Use the kernel's automatic device number allocation function;
[0064] 2. Register a custom device number with the kernel;
[0065] 3. When uninstalling a module, deregister the device number;
[0066] 2. Request space for a cdev structure from the kernel to describe character devices;
[0067] 3. Initialize the cdev structure and initialize the set of operation functions;
[0068] 4. Register character devices with the kernel, where count represents the number of devices to register;
[0069] 5. When the driver is uninstalled, the cdev structure is unregistered to release system resources.
[0070] In this embodiment, the control word is invoked by calling the IO control (iocontrol, ioctl) function. ioctl is a function in the device driver that manages the device's input / output (I / O) channels. Managing I / O channels means controlling certain characteristics of the device, such as the serial port's baud rate or the motor's speed. In other words, during driver development, some I / O operations that logically cannot be categorized as either read or write can be considered part of the ioctl function. Read and write are for writing and reading data, and should be treated as simple data exchange. ioctl, however, controls some options for read and write operations.
[0071] The general parameter format for Ioctl is a command word (constant) plus command arguments. Usage: `int ioctl(int handle, int cmd, [int *argdx, int argcx])`;
[0072] Parameters: fd is the file identifier returned by the open function when the user program opens the device, cmd is the control command of the user program to the device, followed by some supplementary parameters, usually at most one, and the presence or absence of this parameter is related to the meaning of cmd.
[0073] While it's possible to control device I / O channels without using ioctl, for example, the driver could check for specially defined data streams during a write operation. If so, a control command would follow (a common practice in socket programming). However, this approach leads to unclear code division, a chaotic program structure, and confusion for programmers. Therefore, ioctl is used for control. The user program simply tells the driver what it wants to do via command codes (cmd); interpreting and implementing these commands is the driver's responsibility.
[0074] By invoking a control word through a business process to preserve the business process's memory and prevent the operating system from reclaiming it, this method, as one embodiment, includes:
[0075] Call the control word in the registered character device;
[0076] Correspondingly, the control words to be invoked include:
[0077] Call the get_task_mm command;
[0078] The control handle will be assigned based on the return value of the called get_task_mm instruction.
[0079] Specifically, a character device is registered and named / dev / plmm. This is implemented by the business process using an ioctl call: ioctl(" / dev / plmm", CMD_PIN). The CMD_PIN control word is driven in the character device, which calls the get_task_mm(current) instruction. The get_task_mm function retrieves the corresponding memory information based on the provided task descriptor information, storing this memory information in a variable of type mm_struct. The return value of this function is a variable of type struct task_struct, storing the task descriptor information that meets the conditions. The returned value is the memory information corresponding to the task descriptor, i.e., the memory information corresponding to a specific task. In this embodiment, it is assigned a control handle plmm_dump_pinnedmm.
[0080] Step S13, which involves traversing the VMA information within the address space corresponding to the business process via a daemon process and returning the obtained VMA information to the user space, includes, as one embodiment, the following:
[0081] The mmap linked list head within the data structure that contains the address space of the business process is traversed to obtain the vma information.
[0082] It is understandable that, through the character device control word CMD_GETMAP, the specific implementation traverses the head of the mmap linked list within the data structure belonging to the address space of the business process. The structure is: plmm_dump_pinnedmm->mmap. After traversing to the current VMA space, it continues traversing to the next VMA space and stores the results.
[0083] It's important to note that the process address space is the address space as seen from a process's perspective; it's the set of virtual addresses used by the process during runtime. The process address space consists of all linear addresses that the process is allowed to use. Each process sees a different set of linear addresses. The kernel dynamically modifies a process's address space by adding or removing certain linear address ranges. Because the kernel needs to distinguish between invalid linear addresses in user space (programming errors) and valid linear addresses (such as page faults caused by a user process accessing space allocated by malloc), it needs to determine the linear regions currently owned by a process.
[0084] Figure 2 This is a schematic diagram illustrating the creation of a process address space in an embodiment of the present invention, as shown below. Figure 2 As shown, for an ELF executable file, the exec system call invokes load_elf_binary to create the process's address space. The process address space is divided into multiple linear regions, including the stack, mmap mapping region, heap, bss, data segment, and text segment. Each linear region is managed by a vm_area_struct structure, which sets the access permissions and starting address of the linear region.
[0085] Figure 3 This is a schematic diagram of the data structure within the process address space in an embodiment of the present invention, such as... Figure 3As shown, a process's virtual memory space is divided into several regions, each with its own attributes and purpose. A valid address always falls within a certain region, and these regions do not overlap. In the Linux kernel, such regions are called virtual memory areas (VMAs). A VMA is an abstraction of a contiguous linear address space, possessing its own permissions (read, write, execute, etc.). Each virtual memory region is described by a related `struct vm_area_struct` structure. Several VMAs of a process must be organized in a certain way. These VMAs are contained in the process's memory descriptor, specifically in `struct mm_struct`. The VMAs are organized in two ways within `mm_struct`: a linked list (corresponding to the head of the `mmap` linked list) or a red-black tree (corresponding to the root node of the `mm_rb` linked list). Similar to other parts of the kernel, linked lists are used for traversal, and red-black trees are used for searching. In this embodiment, traversal is required, and a linked list is used to connect the VMAs.
[0086] In step S14, memory mapping is performed based on the VMA information to obtain the address space of the business process. Since the daemon process reads the business process's address space after it exits, mmap memory mapping is necessary. This mmap memory mapping is a shared memory mapping, which is arguably the most useful inter-process communication (IPC) method and the fastest form of IPC because processes can directly read and write memory without any data copying. For communication methods like pipes and message queues, four data copies are required between the kernel and user space, while shared memory only copies data twice: once from the input file to the shared memory area, and again from the shared memory area to the output file. In practice, when processes share memory, they don't always unmap after reading and writing a small amount of data and then re-establish the shared memory region for new communication. Instead, they maintain the shared region until communication is complete, thus keeping the data in shared memory and not writing it back to the file. The content in shared memory is usually written back to the file only when the mapping is unmapped. Therefore, communication using shared memory is highly efficient.
[0087] The `mmap()` system call enables processes to share memory by mapping the same regular file. Once the regular file is mapped into the process's address space, the process can access the file just like it accesses regular memory, without needing to call `read()`, `write()`, or other similar operations.
[0088] The address space of the business process is obtained based on the mapped memory, and then transferred to a file to complete a memory snapshot of the current business process. As one embodiment, step S14, which involves memory mapping based on VMA information to obtain the address space of the business process, includes:
[0089] Based on the vma information and the vma list, mmap memory mapping is performed to obtain the address space.
[0090] It is understandable that the address space is obtained by performing mmap memory mapping using the vma information in the vma list, such as... Figure 2 As shown, several VMAs must be organized in a certain way, and these VMAs are contained in the process's memory descriptor. Each VMA corresponds to the head of the mmap linked list, and based on the mmap memory mapping, the address space mapped after the business process exits can be obtained, thus enabling the business process to access its address space.
[0091] This invention provides a method for capturing application process memory snapshots, comprising: establishing a daemon process, and having the daemon process initiate a memory snapshot instruction after the business process exits; using a control word called by the business process to preserve the memory of the business process; traversing the VMA information within the address space corresponding to the business process through the daemon process; performing memory mapping based on the VMA information to obtain the address space of the business process and transferring it to a file. This method saves the memory of the business process when it exits by driving a control word, facilitating the system to reclaim the address space of the current business process and save it to a file to achieve a memory snapshot. It avoids the limitations of existing memory snapshots, which are only effective in specific scenarios (meeting certain triggering conditions), and the impact on debugging processes caused by incomplete memory snapshot files. This improves the versatility of memory snapshot acquisition, making it applicable to various scenarios and improving debugging efficiency.
[0092] Based on the above embodiments, after step S13, which involves traversing the VMA information within the address space corresponding to the business process through the daemon process, and before step S14, which involves memory mapping based on the VMA information, the method further includes:
[0093] Save VMA information;
[0094] After the business process exits, the daemon process requests the vma list from the kernel by calling the control word;
[0095] Return the vma list to user space.
[0096] Understandably, after the business process exits, the daemon process uses a character device to call the relevant control word to request the relevant VMA list from the kernel. It then uses ioctl(" / dev / plmm", CMD_GETMAP) to obtain the traversed VMA result information from the kernel character device and returns it to user space.
[0097] The embodiment of this invention provides a method to call the kernel via a character device control word to obtain the traversed vma list, which facilitates subsequent shared memory mapping to read the process address space.
[0098] Based on the above embodiments, after saving to a file, the method further includes:
[0099] The memory is freed by initiating a de-enable resident instruction through the registered character device.
[0100] After obtaining the address space of the business process, it is simultaneously transferred to the relevant file. A de-resident instruction is then initiated via the character device to allow the operating system to reclaim the current process's address space. The specific implementation is as follows:
[0101] Call mmput(plmm_dump_pinnedmm)
[0102] The kernel releases the page table space of the exited process by calling ioctl(" / dev / plmm", CMD_UNPIN).
[0103] The present invention provides that after the current business process is transferred to a file, a deactivation command is initiated through a character device to release memory, thereby saving memory resources.
[0104] The foregoing has described in detail various embodiments of the method for capturing application process memory snapshots. Based on this, the present invention also discloses an apparatus for capturing application process memory snapshots corresponding to the above-described method. Figure 4 This is a structural diagram of an apparatus for collecting memory snapshots of application processes, provided as an embodiment of the present invention. Figure 4 As shown, the device for taking a snapshot of an application process's memory includes:
[0105] Module 11 is established to create a daemon process, which then initiates a memory snapshot command after the business process exits.
[0106] Call module 12 to call control words through the business process in order to preserve the memory of the business process;
[0107] Traversal module 13 is used to traverse the VMA information in the address space corresponding to the business process through the daemon process;
[0108] The mapping module 14 is used to perform memory mapping based on the VMA information to obtain the address space of the business process and transfer it to a file.
[0109] Since the embodiments of the device part correspond to the embodiments described above, please refer to the embodiments described in the method part for the embodiments of the device part, and will not be repeated here.
[0110] This invention provides an apparatus for capturing application process memory snapshots, comprising: establishing a daemon process, which initiates a memory snapshot instruction after the business process exits; the business process calling a control word to preserve the memory of the business process; the daemon process traversing the VMA information in the address space corresponding to the business process; and performing memory mapping based on the VMA information to obtain the address space of the business process and transferring it to a file. This apparatus saves the memory of the business process when it exits by driving a control word, so that the system can reclaim the address space of the current business process and save it to a file to achieve a memory snapshot. This avoids the limitations of existing memory snapshots, which are only effective in specific scenarios (meeting certain triggering conditions), and the impact on the debugging process caused by incomplete memory snapshot files. It improves the versatility of memory snapshot acquisition, making it applicable to various scenarios and improving debugging efficiency.
[0111] Figure 5 A structural diagram of another apparatus for collecting application process memory snapshots provided in an embodiment of the present invention is shown below. Figure 5 As shown, the device includes:
[0112] Memory 21 is used to store computer programs;
[0113] Processor 22, for implementing steps of a method for taking a snapshot of the application process memory when executing a computer program.
[0114] The device for collecting application process memory snapshots provided in this embodiment may include, but is not limited to, smartphones, tablets, laptops, or desktop computers.
[0115] The processor 22 may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor 22 may be implemented using at least one of the following hardware forms: Digital Signal Processor (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 22 may also include a main processor and a coprocessor. The main processor, also known as the Central Processing Unit (CPU), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor 22 may integrate a Graphics Processing Unit (GPU), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, the processor 22 may also include an Artificial Intelligence (AI) processor, which handles computational operations related to machine learning.
[0116] The memory 21 may include one or more computer-readable storage media, which may be non-transitory. The memory 21 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In this embodiment, the memory 21 is used to store at least the following computer program 211, which, after being loaded and executed by the processor 22, is capable of implementing the relevant steps of the method for capturing application process memory snapshots disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory 21 may also include an operating system 212 and data 213, etc., and the storage method may be temporary storage or permanent storage. The operating system 212 may include Windows, Unix, Linux, etc. The data 213 may include, but is not limited to, the data involved in the method for capturing application process memory snapshots, etc.
[0117] In some embodiments, the apparatus for capturing application process memory snapshots may further include a display screen 23, an input / output interface 24, a communication interface 25, a power supply 26, and a communication bus 27.
[0118] Those skilled in the field can understand, Figure 5 The structure shown does not constitute a limitation on the means of taking snapshots of application process memory and may include more or fewer components than shown.
[0119] The processor 22 implements the method for taking a snapshot of the application process memory provided in any of the above embodiments by calling instructions stored in the memory 21.
[0120] This invention provides an apparatus for capturing application process memory snapshots, comprising: establishing a daemon process, which initiates a memory snapshot instruction after the business process exits; the business process calling a control word to preserve the memory of the business process; the daemon process traversing the VMA information in the address space corresponding to the business process; and performing memory mapping based on the VMA information to obtain the address space of the business process and transferring it to a file. This apparatus saves the memory of the business process when it exits by driving a control word, so that the system can reclaim the address space of the current business process and save it to a file to achieve a memory snapshot. This avoids the limitations of existing memory snapshots, which are only effective in specific scenarios (meeting certain triggering conditions), and the impact on the debugging process caused by incomplete memory snapshot files. It improves the versatility of memory snapshot acquisition, making it applicable to various scenarios and improving debugging efficiency.
[0121] Furthermore, the present invention also provides a computer-readable storage medium storing a computer program, which, when executed by processor 22, implements the steps of the method for taking a snapshot of the application process memory as described above.
[0122] It is understood that if the methods in the above embodiments are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and executes all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0123] For an introduction to the computer-readable storage medium provided by the present invention, please refer to the above method embodiments. The present invention will not be described in detail here, but it has the same beneficial effects as the above method for collecting application process memory snapshots.
[0124] The foregoing has provided a detailed description of a method, apparatus, and medium for capturing application process memory snapshots provided by the present invention. The various embodiments in the specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple, and relevant parts can be referred to in the method section. It should be noted that those skilled in the art can make several improvements and modifications to the present invention without departing from the principles of the invention, and these improvements and modifications also fall within the protection scope of the claims of the present invention.
[0125] It should also be noted that, in this specification, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
Claims
1. A method for capturing a memory snapshot of an application process, characterized in that, include: A daemon process is established, and a memory snapshot instruction is initiated by the daemon process after the business process exits; The business process invokes a control word to reserve the memory of the business process; The daemon process iterates through the VMA information in the address space corresponding to the business process. Memory mapping is performed based on the VMA information to obtain the address space of the business process and then transferred to a file; Correspondingly, after traversing the VMA information in the address space corresponding to the business process through the daemon process, and before performing memory mapping based on the VMA information, the method further includes: Save the VMA information; After the business process exits, the daemon process calls the control word to request the vma list from the kernel; Return the vma list to user space.
2. The method for capturing application process memory snapshots according to claim 1, characterized in that, The control word is obtained by pre-setting a registered character device and calling the registered character device.
3. The method for capturing application process memory snapshots according to claim 2, characterized in that, The step of reserving the memory of the business process by calling the control word through the business process includes: The control word is invoked in the registered character device; Correspondingly, invoking the control word includes: Call the get_task_mm command; The control handle will be returned based on the get_task_mm instruction that was invoked.
4. The method for capturing application process memory snapshots according to claim 3, characterized in that, The step of traversing the VMA information within the address space corresponding to the business process through the daemon process includes: The VMA information is obtained by traversing the head of the mmap linked list within the data structure to which the address space of the business process belongs.
5. The method for capturing application process memory snapshots according to claim 4, characterized in that, The step of performing memory mapping based on the VMA information to obtain the address space of the service process includes: The address space is obtained by performing mmap memory mapping based on the vma information and the vma list.
6. The method for capturing application process memory snapshots according to any one of claims 1 to 5, characterized in that, After transferring to the file, the following is also included: The registered character device initiates a de-enable resident instruction to release memory.
7. An apparatus for capturing memory snapshots of application processes, characterized in that, include: A module is established to create a daemon process, which then initiates a memory snapshot command after the business process exits. The calling module is used to call the control word through the business process to reserve the memory of the business process; The traversal module is used to traverse the VMA information in the address space corresponding to the business process through the daemon process; The mapping module is used to perform memory mapping based on the VMA information to obtain the address space of the business process and transfer it to a file; Correspondingly, after traversing the VMA information in the address space corresponding to the business process through the daemon process, and before performing memory mapping based on the VMA information, the method further includes: Save the VMA information; After the business process exits, the daemon process calls the control word to request the vma list from the kernel; Return the vma list to user space.
8. An apparatus for capturing memory snapshots of application processes, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the method for taking a snapshot of an application process memory as described in any one of claims 1 to 6 when executing the computer program.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method for taking a snapshot of an application process memory as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Crash information collection method and device, storage medium and electronic device
CN111611145A
Daemon process fault detection method and device, storage medium and electronic equipment
CN113901443A