Method and device for generating elf file based on virtual machine memory snapshot

By optimizing the ELF file generation process and processing the virtual machine memory snapshot content in segments, the problem of low virtual machine recovery efficiency is solved, accurate reconstruction and efficient recovery of memory status are achieved, storage overhead is reduced, and tool compatibility is ensured.

CN120704804APending Publication Date: 2025-09-26CHENGDU QUNXIN MICROELECTRONICS TECHNOLOGY CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510830704.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-20
Publication Date
2025-09-26

AI Technical Summary

Technical Problem

When generating virtual machine memory snapshots, the existing technology causes the generated flash memory snapshots to be too large, resulting in low efficiency in restoring the virtual machine operation, inability to effectively capture dynamic memory changes, and the risk of data inconsistency.

Method used

By optimizing the ELF file generation process, the memory snapshot content is segmented and selectively filled, the virtual machine memory is segmented using multiple memory block sizes, and valid data blocks are dynamically identified and merged to generate optimal memory segments, avoiding full memory dumps. A standardized ELF structure is used to ensure compatibility.

Benefits of technology

It achieves accurate reconstruction of the virtual machine's memory state, improves recovery efficiency, reduces storage and transmission overhead, ensures compatibility with existing tools, and is suitable for seamless recovery of long-running tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120704804A_ABST
    Figure CN120704804A_ABST
Patent Text Reader

Abstract

The invention relates to an elf file generation method and device based on a virtual machine memory snapshot. Comprising the following steps: respectively partitioning a memory of the virtual machine according to a plurality of set memory block sizes to obtain a plurality of continuous memory blocks corresponding to each memory block size; effective data memory blocks in the memory blocks are marked, and the continuous effective data memory blocks are combined into a memory segment; calculating a loading index corresponding to the size of each memory block according to the total size of the memory segments corresponding to the size of each memory block and the number of the memory segments; determining a target memory block size from the plurality of memory block sizes according to the loading index; and generating a section of each memory segment corresponding to the size of the target memory block, reading the content of each memory segment from the memory of the virtual machine, filling the content into the corresponding section, and writing the section into the elf file. According to the method, the problems that the newly generated elf file is too large and the loading efficiency is low are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of this specification relate to the field of computer technology, and in particular to a method and device for generating an ELF file based on a virtual machine memory snapshot. Background Art

[0002] When the Qemu emulator launches a virtual machine (VM) with a RISC-V CPU architecture, it uses the fw_payload.elf file as input. Qemu parses the section headers in the fw_payload.elf file and, based on the information in the section headers, loads the contents of each section into specific memory addresses to support the VM's normal operation. The fw_payload.elf file is still required when the VM resumes after an interruption. However, as the VM runs, the contents of the loaded sections change as the program runs. Therefore, the contents of the corresponding sections in the original fw_payload.elf file must be replaced with the contents of the sections in memory. Furthermore, the original fw_payload.elf file only contains the OpenSBI (Open Source Supervisor Binary Interface) firmware and the operating system image, which represent a subset of the VM's memory. The rest of the memory is not recorded. Since the VM's operation changes the memory state, all changes must be recorded. These changes are recorded as new sections in the fw_payload.elf file.

[0003] In order to record all changes in the virtual machine memory into the flash memory snapshot, the existing technology mostly records the contents of all memory pages of the virtual machine memory, resulting in the generated flash memory snapshot being too large, increasing the storage burden of the hard disk, and taking a long time to restore the flash memory snapshot, making the process of restoring the virtual machine operation inefficient.

[0004] How to improve the recovery efficiency of virtual machine running status is a technical problem that needs to be solved urgently. Summary of the Invention

[0005] To solve the problems existing in the prior art, the embodiments of this specification provide a method and device for generating an ELF file based on a virtual machine memory snapshot. By optimizing the ELF file generation process, the contents of the memory snapshot are segmented and selectively filled into the ELF file. While avoiding filling the entire memory snapshot content into the ELF file, the number of newly added segments of the ELF file is reduced, solving the problems of the newly generated ELF file being too large and having low loading efficiency.

[0006] The specific technical solutions of the embodiments of this specification are as follows:

[0007] On the one hand, an embodiment of this specification provides a method for generating an elf file based on a virtual machine memory snapshot, the method comprising:

[0008] Divide the memory of the virtual machine into blocks according to the set multiple memory block sizes, and obtain multiple continuous memory blocks corresponding to the respective memory block sizes;

[0009] For a plurality of consecutive memory blocks corresponding to each memory block size, mark valid data memory blocks in each memory block, and merge the consecutive valid data memory blocks into a memory segment;

[0010] Calculate the loading index corresponding to each memory block size based on the total size of all memory segments and the number of memory segments corresponding to each memory block size;

[0011] determining a target memory block size from a plurality of memory block sizes according to the loading indicator;

[0012] Generate a section for each memory segment corresponding to the target memory block size, read the contents of each memory segment from the memory of the virtual machine and fill them into the corresponding section, and write the section into the ELF file.

[0013] Furthermore, the memory block size is an integer multiple of the memory page size of the virtual machine.

[0014] Furthermore, marking the valid data memory blocks in each memory block further includes:

[0015] Determine whether the contents of the memory block are all zero bytes;

[0016] If not, the memory block is marked as a valid data memory block.

[0017] Furthermore, when merging consecutive valid data memory blocks into a memory segment, the method further includes:

[0018] Record the starting memory address and memory segment size of each memory segment in the memory;

[0019] Generating a section for each memory segment corresponding to the target memory block size further includes:

[0020] Writing the starting memory address and memory segment size of the memory segment into the section header of the section corresponding to the memory segment;

[0021] Reading the contents of each memory segment from the memory of the virtual machine and filling the contents into the corresponding section further includes:

[0022] According to the starting memory address of the memory segment, the bytes of the memory segment size are read from the memory and filled into the section corresponding to the memory segment.

[0023] Furthermore, the step of calculating the loading index corresponding to the memory block size includes:

[0024] The total loading time is calculated using the formula T = total_size * load_mem_time + n * parse_sec_time, where T represents the total loading time, total_size represents the total size of all memory segments, load_mem_time represents the time required for the simulator where the virtual machine resides to load a unit of memory, n represents the number of memory segments, and parse_sec_time represents the time required for the simulator to parse a section header.

[0025] The total loading time is used as the loading index.

[0026] Furthermore, determining the target memory block size from a plurality of memory block sizes according to the loading indicator further includes:

[0027] The memory block size with the shortest total loading time is used as the target memory block size.

[0028] Furthermore, dividing the memory of the virtual machine into blocks according to the set multiple memory block sizes further includes:

[0029] The memory of the virtual machine is divided into blocks starting from the designated memory addresses of the memory according to the set multiple memory block sizes.

[0030] Furthermore, the method further comprises:

[0031] For the content before the specified memory address in the memory, determine the original section corresponding to the content before the specified memory address from the original elf file according to the specified memory address;

[0032] Update the content before the specified memory address in the memory into the original section.

[0033] On the other hand, an embodiment of this specification further provides an elf file generation device based on a virtual machine memory snapshot, the device comprising:

[0034] A memory block division unit is used to divide the memory of the virtual machine into blocks according to a plurality of set memory block sizes, thereby obtaining a plurality of memory blocks corresponding to the respective memory block sizes;

[0035] A memory block merging unit is used to mark valid data memory blocks in each memory block for a plurality of memory blocks corresponding to each memory block size, and merge consecutive valid data memory blocks into a memory segment;

[0036] a loading index calculation unit, configured to calculate a loading index corresponding to each memory block size according to the total size of all memory segments corresponding to each memory block size and the number of memory segments;

[0037] a target memory block size determining unit, configured to determine a target memory block size from a plurality of memory block sizes according to the loading indicator;

[0038] The section generation unit is used to generate a section for each memory segment corresponding to the target memory block, read the content of each memory segment from the memory of the virtual machine and fill it into the corresponding section, and write the section into the ELF file.

[0039] On the other hand, an embodiment of this specification further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program implements the above method when executed by a processor.

[0040] The innovative memory snapshot generation mechanism of the embodiments of this specification significantly improves the reliability and efficiency of virtual machine recovery scenarios. Its technical effects include but are not limited to the following three aspects:

[0041] 1. Accurately reconstruct memory states to resolve recovery dependency and integrity issues:

[0042] The traditional virtual machine snapshot mechanism relies on the static content of the original firmware image file (fw_payload.elf), which cannot capture dynamic changes in memory during runtime, resulting in the risk of data inconsistency during recovery. The embodiment of this specification dynamically rewrites the elf file content, and embeds all memory change data (including the updated content of the original section and the newly added memory area) at the moment of virtual machine interruption into a new elf file in a segmented manner. This method completely records the full state of the virtual machine's memory, eliminates dependence on the original file during recovery, avoids startup failures or data errors caused by incomplete memory content, and is particularly suitable for seamless recovery scenarios of long-running tasks.

[0043] 2. Optimize memory storage efficiency and reduce storage and transmission overhead:

[0044] Traditional full memory dumps (such as qemu snapshots) generate a large amount of redundant data (such as all-zero pages), which takes up a lot of storage space. The embodiments of this specification use an intelligent memory block analysis and merging algorithm to partition the virtual machine's memory using multiple memory block sizes, dynamically identify non-zero data blocks, and merge adjacent areas. The optimal memory block size is selected through iterative optimization, balancing the number of large memory segments generated according to the optimal memory block size with the continuity within the segments. This achieves both efficient compression and expression of memory data while taking into account the loading efficiency of qemu.

[0045] 3. Enhance cross-platform compatibility and toolchain integration capabilities:

[0046] As a standard file format, elf naturally supports multiple debuggers and loaders. This specification embodiment is generated by standardizing the elf structure, fully reusing the section header structure of the original elf, only modifying the content field and the newly added dynamic section, avoiding the compatibility problem of the private snapshot format, ensuring seamless compatibility with existing tools (such as readelf, objdump). Developers can directly use GDB to load the newly generated elf file and carry out memory state debugging, without the need to customize parsing tools, reducing secondary development costs. For example, the distribution and size of the memory segment can be visually viewed by the readelf-S command, which is convenient for problem diagnosis. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the embodiments of this specification or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0048] Figure 1FIG2 is a flow chart of a method for generating an elf file based on a virtual machine memory snapshot in an embodiment of this specification;

[0049] Figure 2 FIG2 is a flow chart of determining whether a memory block is a valid data memory block in an embodiment of this specification;

[0050] Figure 3 The figure shows a flow chart of generating a section corresponding to a memory segment in an embodiment of this specification;

[0051] Figure 4 FIG2 is a schematic diagram showing the relationship between the fw_payload.elf file finally generated in the embodiment of this specification and the newly added section and the virtual machine memory;

[0052] Figure 5 The figure shows a flow chart of updating the content before the specified memory address to the original section in the embodiment of this specification;

[0053] Figure 6 The figure shows a schematic diagram of the structure of an elf file generation device based on a virtual machine memory snapshot in an embodiment of this specification;

[0054] Figure 7 The figure shows a schematic diagram of the structure of a computer device in an embodiment of this specification.

[0055]

Description of the accompanying drawings

[0056] 601, memory block unit;

[0057] 602, memory block merging unit;

[0058] 603. Loading index calculation unit;

[0059] 604. Target memory block size determination unit;

[0060] 605, section generation unit;

[0061] 702. Computer equipment;

[0062] 704. Processing equipment;

[0063] 706. Storage resources;

[0064] 708, drive system;

[0065] 710, input / output module;

[0066] 712. Input devices;

[0067] 714. Output device;

[0068] 716. Presentation equipment;

[0069] 718. Graphical User Interface;

[0070] 720, network interface;

[0071] 722, communication link;

[0072] 724. Communication bus. DETAILED DESCRIPTION

[0073] The following will be combined with the drawings in the embodiments of this specification to clearly and completely describe the technical solutions in the embodiments of this specification. Obviously, the embodiments described are only part of the embodiments of this specification, not all of them. Based on the embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the embodiments of this specification.

[0074] It should be noted that the terms "first", "second", etc. in the description and claims of the embodiments of this specification and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the embodiments of this specification described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, apparatus, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0075] It should be noted that the acquisition, storage, use, and processing of data in the technical solutions of the embodiments of this specification comply with the relevant provisions of national laws and regulations.

[0076] It should be noted that in the embodiments of this specification, certain software, components, models and other existing solutions in the industry may be mentioned. They should be regarded as exemplary and their purpose is only to illustrate the feasibility of implementing the technical solution of this application, but it does not mean that the applicant has or will necessarily use the solution.

[0077] In response to the problems existing in the prior art, an embodiment of this specification provides an ELF file generation method based on a virtual machine memory snapshot. By optimizing the ELF file generation process, the content of the memory snapshot is segmented and selectively filled into the ELF file. While avoiding filling the entire memory snapshot content into the ELF file, the number of newly added segments of the ELF file is reduced, solving the problems of the newly generated ELF file being too large and having low loading efficiency. Figure 1 The figure shows a flow chart of a method for generating an elf file based on a virtual machine memory snapshot according to an embodiment of this specification. The process of generating an elf file is described in this figure. The order of steps listed in the embodiment is only one way of executing the steps among many, and does not represent the only execution order. When the actual system or device product is executed, it can be executed in sequence or in parallel according to the method shown in the embodiment or the accompanying drawings. Specifically, Figure 1 As shown, the method can be executed by a computer and may include:

[0078] Step 101: Divide the memory of the virtual machine into blocks according to a plurality of set memory block sizes, and obtain a plurality of continuous memory blocks corresponding to the respective memory block sizes;

[0079] Step 102: for a plurality of consecutive memory blocks corresponding to each memory block size, mark the valid data memory blocks in each memory block, and merge the consecutive valid data memory blocks into a memory segment;

[0080] Step 103: Calculate the loading index corresponding to each memory block size according to the total size of all memory segments and the number of memory segments corresponding to each memory block size;

[0081] Step 104: determining a target memory block size from a plurality of memory block sizes according to the loading indicator;

[0082] Step 105: Generate a section for each memory segment corresponding to the target memory block size, read the content of each memory segment from the memory of the virtual machine and fill it into the corresponding section, and write the section into the ELF file.

[0083] In the embodiments of this specification, you can first obtain the data of the entire virtual machine memory when the virtual machine is interrupted. Specifically, you can read the data of each memory page through the interface provided by qemu, and then write these memory page data into an empty file in sequence. Finally, the data of this file is equivalent to the data of the entire virtual machine memory. If you want to obtain the data at a certain address in the memory later, you only need to read the data at the offset position equal to the address in the file.

[0084] In this embodiment of the present specification, the memory block size is an integer multiple of the virtual machine's memory page size. The entire virtual machine's memory is typically divided into pages, each of which is a continuous 4096 (PAGE_SIZE) bytes of memory. In this embodiment of the present specification, multiple consecutive pages of memory during a virtual machine interruption are grouped into a memory block. The size of each memory block is n*PAGE_SIZE (where n is the number of consecutive pages, and n>=1).

[0085] It can be understood that the sizes of the multiple memory blocks in the embodiments of this specification can be in the form of the number n of consecutive pages. According to each value of n, multiple consecutive pages are grouped into a memory block.

[0086] For example, the entire memory data at the time of the virtual machine interruption is divided into blocks. Specifically, the obtained file representing the memory data at the time of the virtual machine interruption is used to divide the contents of the file into multiple 1MB (1024KB) memory blocks, each of which is composed of 256 consecutive memory pages (each memory page is 4KB in size). Furthermore, the memory blocks can be numbered according to the order in which they are located in the file, starting from 0 and continuously increasing to the last memory block, so that the address of the memory block in the memory can be subsequently located by the block number.

[0087] Then the embodiment of this specification filters out invalid data memory blocks. In the embodiment of this specification, the steps of determining whether a memory block is a valid data memory block are as follows: Figure 2 As shown, specifically including:

[0088] Step 201: Determine whether the contents of the memory block are all zero bytes;

[0089] Step 202: If not, mark the memory block as a valid data memory block;

[0090] Step 203: If yes, mark the memory block as an invalid data memory block.

[0091] In the embodiment of the present specification, all memory blocks corresponding to each memory block size obtained in step 101 are scanned to determine whether the contents of the memory blocks are all zero bytes. If not, the block is marked as a "non-zero data block", i.e., a valid memory data block. If all zeros are, the block is marked as a "zero data block", i.e., an invalid memory data block.

[0092] In an embodiment of the present specification, the memory blocks are continuous, that is, the end address of the previous memory block and the starting address of the next memory block are continuous. If the end address of the previous valid data memory block and the starting address of the next valid data memory block are continuous (that is, there is no invalid data memory block between the two valid data memory blocks), then the two valid data memory blocks are merged into a memory segment (if multiple valid data memory blocks meet the above conditions, then the multiple valid data memory blocks are merged into a memory segment). If a valid data memory block is preceded and followed by invalid data memory blocks, then the valid data memory block is also used as a memory segment.

[0093] Exemplarily, the contents of all memory blocks that make up the virtual machine's memory are scanned, and the attributes of each memory block are marked. Specifically, the contents of the memory data file representing the interruption of the virtual machine operation are read byte by byte. After reading 1024KB (block size) bytes, the reading is paused to determine whether all bytes of the memory block read this time are non-zero. If all bytes are zero, the memory block is considered to be a "zero data block". If there is any non-zero byte, the memory block is considered to be a "non-zero data block". Then, the content of the next memory block is read from the file, and it is determined whether it belongs to a "zero data block" or a "non-zero data block" until the contents of all memory blocks are scanned and the numbers of all "non-zero data blocks" are recorded.

[0094] Integrate multiple consecutive "non-zero data blocks" into a larger memory segment. Specifically, in the second step, the numbers of all "non-zero data blocks" are recorded, starting from the first "non-zero data block", and recorded as the starting position and end position of a memory segment. Then scan the number of the next "non-zero data block" to determine whether the number is numerically continuous with the previous number. If it is continuous, update the end position of the current memory segment to the number of the current "non-zero data block". If it is not continuous, add a new memory segment record, and set the starting position and end position of this new memory segment to the number of the current "non-zero data block". Continuously scan the number of "non-zero data blocks", and generate new memory segments and continuously update the end position of the memory segments according to the above steps until all "non-zero data blocks" have been scanned.

[0095] In the embodiments of this specification, the number of memory block sizes and the size of each memory block can be empirical or experimental values. For example, the memory block sizes include 2MB, 4MB, and 8MB. For each memory block size, steps 102-103 are performed. Finally, for each memory block size, the corresponding total memory segment size and number of memory segments can be obtained.

[0096] After obtaining the multiple memory segments corresponding to each memory block size, the loading index corresponding to each memory block size is calculated based on the total size of the memory segments corresponding to each memory block size and the number of memory segments. Specifically, the step of calculating the loading index corresponding to the memory block size includes:

[0097] The total loading time is calculated by the formula T = total_size * load_mem_time + n * parse_sec_time, where T represents the total loading time, total_size represents the total size of all memory segments, load_mem_time represents the time required for the simulator where the virtual machine is located to load the unit memory, and the unit of the unit memory needs to be consistent with the unit of the memory segment size. For example, if the unit of the memory segment size is megabytes (M), the unit memory size is 1M, n represents the number of memory segments, and parse_sec_time represents the time required for the simulator to parse a section header;

[0098] The total loading time is used as the loading index.

[0099] It can be understood that the total loading time is calculated by the above formula. If the total loading time is shorter, the loading efficiency of the memory segment generated according to the corresponding memory block size is higher. Therefore, the memory block size with the shortest total loading time is used as the target memory block size.

[0100] Finally, a section of each memory segment corresponding to the target memory block size is generated, the contents of each memory segment are read from the memory of the virtual machine and filled into the corresponding section, and the section is written into the ELF file.

[0101] In the embodiments of this specification, Figure 3 As shown, when continuous valid data memory blocks are merged into a memory segment, the method further includes:

[0102] Step 301: Record the starting memory address and memory segment size of each memory segment in the memory;

[0103] Generating a section for each memory segment corresponding to the target memory block size further includes:

[0104] Step 302: Write the starting memory address and memory segment size of the memory segment into the section header of the section corresponding to the memory segment;

[0105] Reading the contents of each memory segment from the memory of the virtual machine and filling the contents into the corresponding section further includes:

[0106] Step 303: Read the bytes of the memory segment size from the memory according to the starting memory address of the memory segment and fill them into the section corresponding to the memory segment.

[0107] In the embodiment of this specification, an optimal memory block size (ie, target memory block size) is selected by analyzing memory data when the virtual machine is interrupted, and information of each memory segment corresponding to the optimal memory block size is also recorded.

[0108] First, the starting memory address of each memory segment is calculated based on the starting position of each memory segment corresponding to the optimal memory block size. Specifically, the starting position of the memory segment records the number of the first memory block in the memory segment. Since the size of the memory block has been determined, the address of the memory block in the memory can be further calculated. This address is also the starting memory address of the memory segment.

[0109] Then, each memory segment is added to the elf file as a new section. Specifically, a new section is first generated for fw_payload.elf using the elfio tool. Based on the starting memory address of the memory segment, the number of bytes represented by the memory segment size is read from the file representing the memory data when the virtual machine is interrupted, using this memory address as the file offset. The newly generated section is filled with the read content, and the memory load address of the section is set to the starting memory address of the memory segment.

[0110] According to one embodiment of the present specification, since the frontmost part of the memory data already has a corresponding section in the original elf file, for example, the original fw_payload.elf file records the opensbi firmware part, therefore, in the embodiment of the present specification, the memory of the virtual machine is divided into blocks starting from the specified memory address of the memory according to the set multiple memory block sizes.

[0111] Optionally, the designated memory address may be the end address corresponding to the first 2MB of memory. In this embodiment, the memory data is segmented starting from the 2MB of memory. When generating the first section, the first 2MB of memory content is ignored. Specifically, the starting address of the memory segment corresponding to the first section is set to 2MB, and the size is set to the original size minus 2MB. The section generation step is then performed.

[0112] When all memory segments are added as sections to the fw_payload.elf file, a new fw_payload.elf file is generated that contains all the necessary memory information for the virtual machine to resume running from the interruption point. The relationship between the final generated fw_payload.elf file and the newly added sections and the virtual machine memory is as follows Figure 4 shown.

[0113] According to one embodiment of this specification, Figure 5 As shown, the method further includes:

[0114] Step 501: for the content before the specified memory address in the memory, determine the original section corresponding to the content before the specified memory address from the original ELF file according to the specified memory address;

[0115] Step 502: Update the content before the designated memory address in the memory into the original section.

[0116] In the embodiment of this specification, detailed information of each section in the original fw_payload.elf file is obtained. Specifically, all section header information of the fw_payload.elf file can be parsed by the elfio tool. Each section header records the information of its corresponding section, including the name of the section, file offset position, load attribute, memory load address, size and other information. The name of each section is a unique string used to identify the section; the file offset position of the section represents the offset of the starting position of the section in the fw_payload.elf file relative to the first byte of the file; the load attribute of the section indicates whether the content of the section needs to be loaded into the memory when the loader loads the elf file. If it needs to be loaded into the memory, the attribute is "load"; the memory load address of the section represents the address in the memory where the section needs to be loaded. This information only exists when the section load attribute is "load"; the size of the section represents the number of bytes occupied by the content of the section.

[0117] Record the information of each section, and use the section name as an identifier. Bind the file offset position, loading attributes, memory loading address, size and other information corresponding to the section to the name. Later, you can use this name as an index to obtain the specific information of the section.

[0118] Traverse all recorded sections. For each section, determine whether the section attribute is "load". If not, skip the section and do not need to do any processing. If it is, it means that this section needs to be loaded into the memory by the loader, and its content needs to be updated according to the real-time data of the memory operation. Specifically, based on the memory loading address of the section, in the file representing the memory data when the virtual machine is interrupted, use this memory loading address as the file offset, and read the number of bytes represented by the size of the section from the file; then, based on the file offset position of the section, write the read content to the corresponding position in the original fw_payload.elf file.

[0119] In this way, the contents of each original section in the fw_payload.elf file are replaced with the memory contents corresponding to each section when the virtual machine is interrupted, completing the modification of the original section content.

[0120] It should be noted that the contents of this part are all contained in the range before the specified memory address in the memory, that is, within the range of 0-2M.

[0121] It should be noted that after obtaining the fw_payload.elf file using the methods of the embodiments of this specification, restoring the virtual machine's operating state using the fw_payload.elf file also involves obtaining detailed information about each section in the original fw_payload.elf file, determining the section's load attributes, and restoring the section's contents to the virtual machine's memory based on the section's memory load address, thereby restoring the virtual machine's operating state. Because the memory segments that generate the sections are obtained after filtering through the load index, restoring the virtual machine's operating state based on these sections is the most efficient.

[0122] The innovative memory snapshot generation mechanism of the embodiments of this specification significantly improves the reliability and efficiency of virtual machine recovery scenarios. Its technical effects include but are not limited to the following three aspects:

[0123] 1. Accurately reconstruct memory states to resolve recovery dependency and integrity issues:

[0124] The traditional virtual machine snapshot mechanism relies on the static content of the original firmware image file (fw_payload.elf), which cannot capture dynamic changes in memory during runtime, resulting in the risk of data inconsistency during recovery. The embodiment of this specification dynamically rewrites the elf file content, and embeds all memory change data (including the updated content of the original section and the newly added memory area) at the moment of virtual machine interruption into a new elf file in a segmented manner. This method completely records the full state of the virtual machine's memory, eliminates dependence on the original file during recovery, avoids startup failures or data errors caused by incomplete memory content, and is particularly suitable for seamless recovery scenarios of long-running tasks.

[0125] 2. Optimize memory storage efficiency and reduce storage and transmission overhead:

[0126] Traditional full memory dumps (such as qemu snapshots) generate a large amount of redundant data (such as all-zero pages), which takes up a lot of storage space. The embodiments of this specification use an intelligent memory block analysis and merging algorithm to partition the virtual machine's memory using multiple memory block sizes, dynamically identify non-zero data blocks, and merge adjacent areas. The optimal memory block size is selected through iterative optimization, balancing the number of large memory segments generated according to the optimal memory block size with the continuity within the segments. This achieves both efficient compression and expression of memory data while taking into account the loading efficiency of qemu.

[0127] 3. Enhance cross-platform compatibility and toolchain integration capabilities:

[0128] As a standard file format, elf naturally supports multiple debuggers and loaders. This specification embodiment is generated by standardizing the elf structure, fully reusing the section header structure of the original elf, only modifying the content field and the newly added dynamic section, avoiding the compatibility problem of the private snapshot format, ensuring seamless compatibility with existing tools (such as readelf, objdump). Developers can directly use GDB to load the newly generated elf file and carry out memory state debugging, without the need to customize parsing tools, reducing secondary development costs. For example, the distribution and size of the memory segment can be visually viewed by the readelf-S command, which is convenient for problem diagnosis.

[0129] Based on the same inventive concept, the embodiment of this specification also provides an elf file generation device based on a virtual machine memory snapshot, such as Figure 6 Shown, including:

[0130] The memory block division unit 601 is used to divide the memory of the virtual machine into blocks according to the set multiple memory block sizes, and obtain multiple memory blocks corresponding to the respective memory block sizes;

[0131] A memory block merging unit 602 is configured to mark valid data memory blocks in each memory block for a plurality of memory blocks corresponding to each memory block size, and merge consecutive valid data memory blocks into a memory segment;

[0132] A loading index calculation unit 603 is configured to calculate a loading index corresponding to each memory block size according to the total size of all memory segments corresponding to each memory block size and the number of memory segments;

[0133] a target memory block size determining unit 604, configured to determine a target memory block size from a plurality of memory block sizes according to the loading indicator;

[0134] The section generation unit 605 is configured to generate a section for each memory segment corresponding to the target memory block, read the contents of each memory segment from the memory of the virtual machine and fill the contents into the corresponding section, and write the section into an ELF file.

[0135] The beneficial effects achieved by the above-mentioned device are consistent with the beneficial effects achieved by the above-mentioned method, and will not be described in detail in the embodiments of this specification.

[0136] like Figure 7 Schematic diagram of the structure of a computer device according to an embodiment of the present specification. The computer device according to this embodiment is capable of executing the methods of the embodiments of the present specification described above. Computer device 702 may include one or more processing devices 704, such as one or more central processing units (CPUs), each of which may implement one or more hardware threads. Computer device 702 may also include any storage resources 706 for storing any type of information, such as code, settings, data, etc. For example, and without limitation, storage resources 706 may include any one or more combinations of the following: any type of RAM, any type of ROM, flash memory devices, hard disks, optical disks, etc. More generally, any storage resource may use any technology to store information. Furthermore, any storage resource may provide volatile or non-volatile retention of information. Furthermore, any storage resource may represent a fixed or removable component of computer device 702. In one embodiment, when processing device 704 executes associated instructions stored in any storage resource or combination of storage resources, computer device 702 may perform any operation of the associated instructions. The computer device 702 also includes one or more drive systems 708 for interacting with any storage resources, such as a hard disk drive system, an optical disk drive system, and the like.

[0137] The computer device 702 may also include an input / output module 710 (I / O) for receiving various inputs (via input devices 712) and for providing various outputs (via output devices 714). A specific output mechanism may include a presentation device 716 and an associated graphical user interface (GUI) 718. In other embodiments, the input / output module 710 (I / O), input devices 712, and output devices 714 may not be included, and the computer device 702 may simply be a computer device in a network. The computer device 702 may also include one or more network interfaces 720 for exchanging data with other devices via one or more communication links 722. One or more communication buses 724 couple the components described above together.

[0138] The communication link 722 may be implemented in any manner, for example, via a local area network, a wide area network (e.g., the Internet), a point-to-point connection, etc., or any combination thereof. The communication link 722 may include any combination of hardwired links, wireless links, routers, gateway functions, name servers, etc., governed by any protocol or combination of protocols.

[0139] The embodiments of this specification also provide a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program implements the above method when executed by a processor.

[0140] The embodiments of this specification also provide a computer-readable instruction, wherein when a processor executes the instruction, the program therein causes the processor to execute the above method.

[0141] It should be understood that in the various embodiments of the present specification, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present specification.

[0142] It should also be understood that in the embodiments of this specification, the term "and / or" is merely a description of the relationship between associated objects, indicating that three possible relationships exist. For example, "A and / or B" can represent three situations: A exists alone, A and B exist simultaneously, or B exists alone. Furthermore, in the embodiments of this specification, the character " / " generally indicates that the associated objects are in an "or" relationship.

[0143] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in the embodiments of this specification can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the embodiments of this specification.

[0144] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0145] In the several embodiments provided in the embodiments of this specification, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, or can be electrical, mechanical or other forms of connection.

[0146] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of this specification.

[0147] In addition, the functional units in each embodiment of the present specification may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0148] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of this specification is essentially 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, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the embodiment of this specification. The aforementioned storage medium includes: various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0149] The embodiments of this specification use specific embodiments to illustrate the principles and implementation methods of the embodiments of this specification. The description of the above embodiments is only used to help understand the methods and core ideas of the embodiments of this specification. At the same time, for those skilled in the art, based on the ideas of the embodiments of this specification, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as a limitation on the embodiments of this specification.

Claims

1. A method for generating an elf file based on a virtual machine memory snapshot, characterized in that: The method comprises: Divide the memory of the virtual machine into blocks according to the set multiple memory block sizes, and obtain multiple continuous memory blocks corresponding to the respective memory block sizes; For a plurality of consecutive memory blocks corresponding to each memory block size, mark valid data memory blocks in each memory block, and merge the consecutive valid data memory blocks into a memory segment; Calculate the loading index corresponding to each memory block size based on the total size of all memory segments and the number of memory segments corresponding to each memory block size; determining a target memory block size from a plurality of memory block sizes according to the loading indicator; Generate a section for each memory segment corresponding to the target memory block size, read the contents of each memory segment from the memory of the virtual machine and fill them into the corresponding section, and write the section into the ELF file.

2. The method according to claim 1, characterized in that The memory block size is an integer multiple of the memory page size of the virtual machine.

3. The method according to claim 1, characterized in that Marking valid data memory blocks in each memory block further includes: Determine whether the contents of the memory block are all zero bytes; If not, the memory block is marked as a valid data memory block.

4. The method according to claim 3, characterized in that When merging consecutive valid data memory blocks into a memory segment, the method further includes: Record the starting memory address and memory segment size of each memory segment in the memory; Generating a section for each memory segment corresponding to the target memory block size further includes: Writing the starting memory address and memory segment size of the memory segment into the section header of the section corresponding to the memory segment; Reading the contents of each memory segment from the memory of the virtual machine and filling the contents into the corresponding section further includes: According to the starting memory address of the memory segment, the bytes of the memory segment size are read from the memory and filled into the section corresponding to the memory segment.

5. The method according to claim 1, wherein The step of calculating the loading index corresponding to the memory block size includes: The total loading time is calculated using the formula T = total_size * load_mem_time + n * parse_sec_time, where T represents the total loading time, total_size represents the total size of all memory segments, load_mem_time represents the time required for the simulator where the virtual machine resides to load a unit of memory, n represents the number of memory segments, and parse_sec_time represents the time required for the simulator to parse a section header. The total loading time is used as the loading index.

6. The method according to claim 5, characterized in that Determining a target memory block size from a plurality of memory block sizes according to the loading indicator further comprises: The memory block size with the shortest total loading time is used as the target memory block size.

7. The method according to claim 1, characterized in that Dividing the memory of the virtual machine into blocks according to the set multiple memory block sizes further includes: The memory of the virtual machine is divided into blocks starting from the designated memory addresses of the memory according to the set multiple memory block sizes.

8. The method according to claim 7, characterized in that The method further comprises: For the content before the specified memory address in the memory, determine the original section corresponding to the content before the specified memory address from the original elf file according to the specified memory address; Update the content before the specified memory address in the memory into the original section.

9. A device for generating elf files based on virtual machine memory snapshots, characterized in that: The device comprises: A memory block division unit is used to divide the memory of the virtual machine into blocks according to a plurality of set memory block sizes, thereby obtaining a plurality of memory blocks corresponding to the respective memory block sizes; A memory block merging unit is used to mark valid data memory blocks in each memory block for a plurality of memory blocks corresponding to each memory block size, and merge consecutive valid data memory blocks into a memory segment; a loading index calculation unit, configured to calculate a loading index corresponding to each memory block size according to the total size of all memory segments corresponding to each memory block size and the number of memory segments; a target memory block size determining unit, configured to determine a target memory block size from a plurality of memory block sizes according to the loading indicator; The section generation unit is used to generate a section for each memory segment corresponding to the target memory block, read the content of each memory segment from the memory of the virtual machine and fill it into the corresponding section, and write the section into the ELF file.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.

Citation Information

Cited By

  • Full-system simulation snapshot generation and recovery method

    CN121807622A