# US 2024/0394092 A1 · Memory snapshot management method and apparatus, and device and medium

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2024/0394092 A1
- Document ID: US20240394092A1
- Status: Published application
- Kind: A1
- Application number: 18/697,242
- Filed: 2022-11-30
- Published: 2024-11-28
- Earliest claimed: 2022-02-09
- Assignees: Suzhou Metabrain Intelligent Technology Co., Ltd.
- Applicants: Inspur Suzhou Intelligent Technology Co., Ltd.
- Inventors: Liang WANG; Shengli ZHOU; Zhen FENG
- Web page: https://patentgrep.com/patent/US20240394092A1

## CPC

- G06F 9/45558: {Hypervisor-specific management and integration aspects}
- G06F 11/1451: {by selection of backup contents}
- G06F 2009/45575: {Starting, stopping, suspending or resuming virtual machine instances}
- G06F 2009/45583: {Memory management, e.g. access or allocation}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Provided in the present disclosure are a memory and apparatus for managing a memory snapshot, a device, and a medium. The method includes: when a memory snapshot generation command is acquired, a virtual machine is suspended; a two-level page table of the virtual machine is copied to obtain a first snapshot page table, and a read-only identifier is set for each of page table entries of the two-level page table; and memory pages corresponding to page table entries of the first snapshot page table are acquired by means of the page table entries of the first snapshot page table, a reference count of each of the memory pages is increased, and the virtual machine is restored from a suspended state to a running state.

## Claims

### Claim 1

A method for managing a memory snapshot, comprising:
in response to acquiring a memory snapshot generation command, suspending a virtual machine;
copying a two-level page table of the virtual machine to obtain a first snapshot page table, and setting a read-only identifier for each of page table entries of the two-level page table; and
acquiring memory pages corresponding to page table entries of the first snapshot page table by means of the page table entries of the first snapshot page table, increasing a reference count of each of the memory pages, and restoring the virtual machine from a suspended state to a running state.

### Claim 2 (depends on 1)

The method for managing the memory snapshot as claimed in claim 1, wherein copying the two-level page table of the virtual machine to obtain the first snapshot page table comprises:
copying the two-level page table of the virtual machine at a level of a Kernel-based Virtual Machine (KVM) to obtain the first snapshot page table, wherein the KVM is a virtualization technology.

### Claim 3 (depends on 1)

The method for managing the memory snapshot as claimed in claim 1, the method further comprises:
after setting all of the page table entries of the two-level page table to a snapshot read-only mode, recording the two-level page table as an initial page table.

### Claim 4 (depends on 1)

The method for managing the memory snapshot as claimed in claim 1, wherein the two-level page table, the first snapshot page table, and the memory pages are all stored in a memory.

### Claim 5 (depends on 1)

The method for managing the memory snapshot as claimed in claim 1, wherein the method further comprises:
in response to the reference count of one memory page being decreased to zero, deleting a heap memory pointed to by an object.

### Claim 6 (depends on 1)

The method for managing the memory snapshot as claimed in claim 1, wherein the method further comprises:
in response to increasing a reference to one memory page, increasing the reference count of the memory page by one, or in response to decreasing the reference to the memory page, decreasing the reference count of the memory page by one.

### Claim 7 (depends on 1)

The method for managing the memory snapshot as claimed in claim 1, wherein after restoring the virtual machine from the suspended state to the running state, the method further comprises:
in a running process of the virtual machine, in response to detecting that memory data in one memory page of the virtual machine is changed, performing a memory write operation.

### Claim 8 (depends on 7)

The method for managing the memory snapshot as claimed in claim 7, wherein in the process of performing the memory write operation, the method further comprises:
exiting the virtual machine from a virtual state, and querying, by means of a virtual machine monitor program, the page table entries of the two-level page table to obtain a query result;
in response to the query result indicating that one page table entry carries the read-only identifier, copying a current memory page to obtain a copied memory page, and decreasing the reference count of the memory page before the memory data is changed; and
pointing a pointer of the page table entry in the two-level page table to the copied memory page, clearing the read-only identifier of the page table entry in the two-level page table, and re-entering the virtual machine into the virtual state.

### Claim 9 (depends on 8)

The method for managing the memory snapshot as claimed in claim 8, wherein the method further comprises:
setting the read-only identifier for the virtual machine; and
distinguishing a memory snapshot from a virtual machine memory according to the read-only identifier.

### Claim 10 (depends on 1)

The method for managing the memory snapshot as claimed in claim 1, wherein the method further comprises:
in response to acquiring a memory snapshot restoration command, copying the first snapshot page table to obtain a second snapshot page table;
deleting a current two-level page table of the virtual machine, taking the second snapshot page table as a new current two-level page table of the virtual machine, and clearing page cache corresponding to the first snapshot page table.

### Claim 11 (depends on 10)

The method for managing the memory snapshot as claimed in claim 10, wherein in response to acquiring the memory snapshot restoration command, copying the first snapshot page table to obtain the second snapshot page table comprises:
in response to acquiring the memory snapshot restoration command, acquiring an operation instruction transmitted from a level of a KVM; and
copying the first snapshot page table according to the operation instruction to obtain the second snapshot page table, wherein the KVM is a virtualization technology.

### Claim 12 (depends on 11)

The method for managing the memory snapshot as claimed in claim 11, wherein before deleting the current two-level page table of the virtual machine, the method further comprises:
acquiring the memory pages corresponding to the page table entries of the first snapshot page table by means of the page table entries of the first snapshot page table, and increasing the reference count of each of the memory pages of the first snapshot page table;
acquiring memory pages corresponding to page table entries of the current two-level page table by means of the page table entries of the current two-level page table, and decreasing a reference count of each of the memory pages of the current two-level page table, wherein the memory pages corresponding to the page table entries of the first snapshot page table is the same as the memory pages corresponding to the page table entries of the current two-level page table.

### Claim 13

(canceled)

### Claim 14 (depends on 12)

The method for managing the memory snapshot as claimed in claim 12, wherein before acquiring the memory pages corresponding to the page table entries of the first snapshot page table by means of the page table entries of the first snapshot page table, the method further comprises.

### Claim 15 (depends on 1)

The method for managing the memory snapshot as claimed in claim 1, wherein the method further comprises:
in response to acquiring a memory snapshot deletion command, acquiring the memory pages corresponding to the page table entries of the first snapshot page table by means of the page table entries of the first snapshot page table, and decreasing the reference count of each of the memory pages; and
deleting the first snapshot page table.

### Claim 16 (depends on 12)

The method for managing the memory snapshot as claimed in claim 12, wherein after increasing the reference count of each of the memory pages and before restoring the virtual machine from the suspended state to the running state, the method further comprises:
clearing cache of the current two-level page table.

### Claim 17

(canceled)

### Claim 18

(canceled)

### Claim 19

An electronic device, comprising:
one or more memories, configured to store computer readable instructions; and
one or more processors, configured to execute the computer readable instructions to cause the one or more processors to:
in response to acquiring a memory snapshot generation command, suspend a virtual machine;
copy a two-level page table of the virtual machine to obtain a first snapshot page table, and set a read-only identifier for each of page table entries of the two-level page table; and
acquire memory pages corresponding to page table entries of the first snapshot page table by means of the page table entries of the first snapshot page table, increase a reference count of each of the memory pages, and restore the virtual machine from a suspended state to a running state.

### Claim 20

A non-volatile computer readable storage medium, configured to store computer readable instructions, wherein the computer readable instructions, when being executed by one or more processors, are configured to cause the one or more processors to:
in response to acquiring a memory snapshot generation command, suspend a virtual machine;
copy a two-level page table of the virtual machine to obtain a first snapshot page table, and set a read-only identifier for each of page table entries of the two-level page table; and
acquire memory pages corresponding to page table entries of the first snapshot page table by means of the page table entries of the first snapshot page table, increase a reference count of each of the memory pages, and restore the virtual machine from a suspended state to a running state.

### Claim 21 (depends on 1)

The method for managing the memory snapshot as claimed in claim 1, wherein after restoring the virtual machine from the suspended state to the running state, the method further comprises:
in a running process of the virtual machine, in response to detecting that memory data in one memory page of the virtual machine is unchanged, not performing a memory write operation.

### Claim 22 (depends on 1)

The method for managing the memory snapshot as claimed in claim 1, wherein the method further comprises:
after suspending a virtual machine, not copying all memory data.

### Claim 23 (depends on 1)

The method for managing the memory snapshot as claimed in claim 1, wherein copying a two-level page table of the virtual machine to obtain a first snapshot page table comprises:
copying the two-level page table of the virtual machine to obtain the first snapshot page table, and using the first snapshot page table as a snapshot index.
