# US 2024/0176640 A1 · Method and apparatus for managing memory

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

- Number: US 2024/0176640 A1
- Document ID: US20240176640A1
- Status: Published application
- Kind: A1
- Application number: 18/219,106
- Filed: 2023-07-07
- Published: 2024-05-30
- Earliest claimed: 2022-07-08
- Assignees: Montage Technology Co., Ltd.
- Applicants: Montage Technology Co., Ltd.
- Inventors: Weibin DAI; Shuangshuang LI; Jiang CHENG
- Web page: https://patentgrep.com/patent/US20240176640A1

## CPC

- G06F 9/45558: {Hypervisor-specific management and integration aspects}
- G06F 2009/45583: {Memory management, e.g. access or allocation}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A method and apparatus for managing memory are provided. The method for managing memory includes: while a virtual machine is running, receiving, by a virtual machine memory management module, a memory allocation request sent by a user process in the virtual machine; sending, by the virtual machine memory management module according to the memory allocation request sent by the user process, the memory allocation request to a virtual PCIe device in a virtual machine manager to enable the virtual PCIe device to request memory from a host memory management module; and acquiring, by the virtual machine memory management module via the virtual PCIe device, a memory space allocated by the host memory management module and configuring the memory space to the user process. The method for managing memory can improve the efficiency of memory utilization.

## Claims

### Claim 1

A method for managing memory, comprising:
while a virtual machine is running, receiving, by a virtual machine memory management module, a memory allocation request sent by a user process in the virtual machine;
sending, by the virtual machine memory management module according to the memory allocation request sent by the user process, the memory allocation request to a virtual PCIe device in a virtual machine manager to enable the virtual PCIe device to request memory from a host memory management module; and
acquiring, by the virtual machine memory management module via the virtual PCIe device, a memory space allocated by the host memory management module and configuring the memory space to the user process.

### Claim 2 (depends on 1)

The method for managing memory as in claim 1, wherein the virtual PCIe device comprises a first base address register and a second base address register, wherein the first base address register is used for communication between the virtual machine memory management module and the virtual machine manager, and the second base address register is used for mapping host memory spaces to memory spaces of the virtual machine.

### Claim 3 (depends on 2)

The method for managing memory as in claim 2, wherein when the virtual machine is created, a size of the second base address register is specified and no physical memory space is allocated for the second base address register, thereby reserving a section of address space within the virtual machine so that the host memory spaces can be mapped to the section of address space in batches.

### Claim 4 (depends on 2)

The method for managing memory as in claim 2, wherein acquiring, by the virtual machine memory management module via the virtual PCIe device, the memory space allocated by the host memory management module and configuring the memory space to the user process comprises:
mapping, by the virtual machine memory management module via the virtual PCIe device, the memory space allocated by the host memory management module to the second base address register; and
configuring, by the virtual machine memory management module via the second base address register, the memory space allocated by the host memory management module to the user process.

### Claim 5 (depends on 4)

The method for managing memory as in claim 4, wherein the virtual machine manager is further used for sending notifications to the virtual machine memory management module after mapping the memory space allocated by the host memory management module to the second base address register.

### Claim 6 (depends on 2)

The method for managing memory as in claim 2, wherein sending, by the virtual machine memory management module, the memory allocation request to the virtual PCIe device in the virtual machine manager, comprises:
writing, by the virtual machine memory management module, the memory allocation request to the first base address register to enable the virtual PCIe device to acquire, by reading the first base address register, the memory allocation request written by the virtual machine memory management module.

### Claim 7 (depends on 1)

The method for managing memory as in claim 1, wherein before sending the memory allocation request to the virtual PCIe device in the virtual machine manager, the method for managing memory further comprises:
determining, by the virtual machine memory management module according to the memory allocation request sent by the user process, whether a local memory pool of the virtual machine has enough local memory spaces to accommodate the user process; and
if the local memory pool of the virtual machine has enough local memory spaces to accommodate the user process, configuring, by the virtual machine memory management module, a local memory space in the local memory pool of the virtual machine to the user process, otherwise, sending the memory allocation request to the virtual PCIe device in the virtual machine manager.

### Claim 8 (depends on 7)

The method for managing memory as in claim 7, further comprising:
receiving, by the virtual machine memory management module, a memory release request sent by the user process; and
releasing, by the virtual machine memory management module according to the memory release request, the local memory space configured to the user process to the local memory pool of the virtual machine.

### Claim 9 (depends on 7)

The method for managing memory as in claim 7, further comprising:
releasing the local memory spaces of the local memory pool of the virtual machine to the host memory management module when the virtual machine memory management module is unloaded or when the virtual machine exits.

### Claim 10 (depends on 1)

The method for managing memory as in claim 1, wherein the memory space allocated by the host memory management module comprises at least part of a heterogeneous memory.

### Claim 11

An apparatus for managing memory, comprising: at least one virtual machine memory management module, at least one virtual machine manager, a virtual PCIe device integrated in the virtual machine manager, and a host memory management module, wherein the virtual machine memory management module and the virtual machine manager both correspond to a virtual machine, wherein when the virtual machine is running, the virtual machine memory management module:
receives a memory allocation request sent by a user process in the virtual machine;
sends, according to the memory allocation request sent by the user process, the memory allocation request to the virtual PCIe device in the virtual machine manager to enable the virtual PCIe device to request memory from the host memory management module; and
configures the memory space to the user process after acquiring, via the virtual PCIe device, the memory space allocated by the host memory management module.
