# US 10,503,405 B2 · Zero copy memory reclaim using copy-on-write

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

- Number: US 10,503,405 B2
- Document ID: US10503405B2
- Status: Granted
- Kind: B2
- Application number: 14/619,006
- Filed: 2015-02-10
- Published: 2016-08-11
- Granted: 2019-12-10
- Earliest claimed: 2015-02-10
- Assignees: Red Hat Israel, Ltd.
- Applicants: Red Hat Israel, Ltd.
- Inventors: Michael Tsirkin
- Web page: https://patentgrep.com/patent/US10503405B2

## CPC

- G06F 3/061: {Improving I/O performance}
- G06F 13/00: Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units (interface circuits for specific input/output devices G06F3/00 {; multiprogram control therefor G06F9/46}; multiprocessor systems G06F15/16 )
- G06F 3/0634: {by changing the state or mode of one or more devices}
- G06F 3/0659: {Command handling arrangements, e.g. command buffers, queues, command scheduling}
- G06F 3/0664: {at device level, e.g. emulation of a storage device or system}
- G06F 3/0673: {Single storage device}
- G06F 12/08: in hierarchically structured memory systems, e.g. virtual memory systems
- G06F 12/10: Address translation
- G06F 2212/151: Emulated environment, e.g. virtual machine
- G06F 2212/656: Address space sharing
- G06F 2212/657: Virtual address space management
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A processing device receives a request to provide a hardware device with direct memory access to a contents of a virtual memory location in application memory of an application. Responsive to the request, the processing device locks the virtual memory location. The processing device makes a determination to reclaim a physical memory location mapped to the virtual memory location. The processing device then determines whether the hardware device has completed the access to a physical memory location mapped to the virtual memory location. Responsive to determining that the hardware device has not completed the access to the physical memory location, the processing device implements a copy-on-write policy for the virtual memory location.

## Claims

### Claim 1

A method comprising:
detecting, by a processing device, a request to provide a hardware device with direct memory access to memory of an application, wherein the memory comprises a virtual memory page mapped to a physical memory location that is accessible to the hardware device;
pinning the memory of the application, wherein the pinning causes content of the virtual memory page to remain at the physical memory location;
making, by the processing device, a determination to reclaim memory of the application in view of a timer associated with the direct memory access;
responsive to the determination to reclaim memory, implementing, by the processing device, a copy-on-write policy for the memory of the application prior to the direct memory access completing, wherein the copy-on-write policy enables the application to update the virtual memory page and have the content remain at the physical memory location accessible to the hardware device.

### Claim 2 (depends on 1)

The method of claim 1, wherein the request to provide the direct memory access to the contents of the virtual memory page comprises a request for zero copy transmission of the contents of the virtual memory page from a network interface controller (NIC).

### Claim 3 (depends on 1)

The method of claim 1, wherein making the determination to reclaim memory of the application comprises:
setting the timer responsive to the request; and
making the determination to reclaim the memory of the application at an expiration of the timer.

### Claim 4 (depends on 1)

The method of claim 1, wherein making the determination to reclaim memory of the application is further in view of an indication that the application is to reclaim a portion of the memory.

### Claim 5 (depends on 1)

The method of claim 1, further comprising:
detecting a page fault responsive to an operation of the application on the virtual memory page;
determining whether the hardware device has completed the direct memory access at the physical memory location mapped to the virtual memory page; and
responsive to determining that the hardware device has completed the direct memory access to the physical memory location mapped to the virtual memory page, removing the copy-on-write policy and performing the operation of the application on the virtual memory page.

### Claim 6 (depends on 1)

The method of claim 1, further comprising:
prior to pinning the memory, determining whether the physical memory location is shared with at least one of an additional application or an additional hardware device;
responsive to determining that the physical memory location is shared with at least one of the additional application or the additional hardware device, copying the contents of the virtual memory page to a socket buffer; and
responsive to determining that the physical memory location is not shared with at least one of the additional application or the additional hardware device, proceeding with pinning the content of the virtual memory page at the physical memory location.

### Claim 7 (depends on 1)

The method of claim 1, further comprising responsive to the request, granting the direct memory access for the hardware device to the physical memory location mapped to the virtual memory page.

### Claim 8

A non-transitory computer readable medium comprising instructions that, when executed by a processing device, cause the processing device to:
detect a request to provide a hardware device with direct memory access to memory of an application, wherein the memory comprises a virtual memory page mapped to a physical memory location that is accessible to the hardware device;
pin the memory of the application, wherein to pin the memory causes content of the virtual memory page to remain at the physical memory location;
make a determination to reclaim memory of the application in view of a timer associated with the direct memory access;
responsive to the determination to reclaim memory, implement a copy-on-write policy for the memory of the application prior to the direct memory access completing, wherein the copy-on-write policy enables the application to update the virtual memory page and have the content remain at the physical memory location accessible to the hardware device.

### Claim 9 (depends on 8)

The non-transitory computer readable medium of claim 8, wherein the request to provide the direct memory access to the contents of the virtual memory page comprises a request for zero copy transmission of the contents of the virtual memory page from a network interface controller (NIC).

### Claim 10 (depends on 8)

The non-transitory computer readable medium of claim 8, wherein the determination to reclaim memory comprises the processing device to:
start the timer responsive to the request; and
make the determination to reclaim the memory of the application at an expiration of the timer.

### Claim 11 (depends on 8)

The non-transitory computer readable medium of claim 8, wherein to make the determination to reclaim memory of the application the processing device is further to receive an indication the application is to reclaim a portion of the memory.

### Claim 12 (depends on 8)

The non-transitory computer readable medium of claim 8, wherein the processing device is further to:
detect a page fault responsive to an operation of the application on the virtual memory page;
determine whether the hardware device has completed the direct memory access at the physical memory location mapped to the virtual memory page; and
responsive to determining that the hardware device has completed the direct memory access to the physical memory location, remove the copy-on-write policy and perform the operation of the application on the virtual memory page.

### Claim 13 (depends on 8)

The non-transitory computer readable medium of claim 8, wherein to detect the request, the processing device is to execute an operating system that receives the request from the application.

### Claim 14 (depends on 8)

The non-transitory computer readable medium of claim 8, wherein to detect the request, the processing device is to execute a hypervisor that receives the request from a guest operating system.

### Claim 15 (depends on 8)

The non-transitory computer readable medium of claim 8, wherein the processing device is further to:
prior to pinning the memory, determine whether the physical memory location is shared with at least one of an additional application or an additional hardware device;
responsive to determining that the physical memory location is shared with at least one of the additional application or the additional hardware device, copy contents of the virtual memory page to a socket buffer; and
responsive to determining that the physical memory location is not shared with at least one of the additional application or the additional hardware device, proceed with pinning the virtual memory page.

### Claim 16 (depends on 8)

The non-transitory computer readable medium of claim 8, wherein the processing device is further to grant the direct memory access for the hardware device to the physical memory location mapped to the virtual memory page responsive to the request.

### Claim 17

A computing device comprising:
a data storage comprising a physical memory location;
a network interface controller (NIC) coupled to the data storage; and
a processing device operatively coupled to the data storage and to the NIC, the processing device to:
detect a request to provide the NIC with a zero copy transmission of contents of a memory of an application, wherein the memory comprises a virtual memory page mapped to the physical memory location;
pin the memory of the application, wherein to pin the memory causes content of the virtual memory page to remain at the physical memory location;
make a determination to reclaim memory of the application in view of a timer associated with the direct memory access;
responsive to the determination to reclaim memory, implement a copy-on-write policy for the memory of the application prior to the direct memory access completing, wherein the copy-on-write policy enables the application to update the virtual memory page and have the content remain at the physical memory location accessible to the hardware device.

### Claim 18 (depends on 17)

The computing device of claim 17, wherein to make the determination to reclaim memory the processing device is to:
start the timer responsive to the request, and
make the determination to reclaim the memory of the application at an expiration of the timer.

### Claim 19 (depends on 17)

The computing device of claim 17, wherein to make the determination to reclaim memory the processing device is to receive an indication that the application is to reclaim a portion of the memory.

### Claim 20 (depends on 17)

The computing device of claim 17, wherein the processing device is further to:
detect a page fault responsive to an operation of the application on the virtual memory page;
determine whether the NIC has completed the transmission; and
responsive to determining that the NIC has completed the transmission, remove the copy-on-write policy and perform the operation of the application on the virtual memory page.
