# US 2013/0159635 A1 · System and method for maintaining memory page sharing in a virtual environment

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

- Number: US 2013/0159635 A1
- Document ID: US20130159635A1
- Status: Published application
- Kind: A1
- Application number: 13/768,637
- Filed: 2013-02-15
- Published: 2013-06-20
- Earliest claimed: 2008-10-06
- Assignees: VMware, Inc.
- Inventors: Ole AGESEN
- Web page: https://patentgrep.com/patent/US20130159635A1

## CPC

- G06F 12/08: in hierarchically structured memory systems, e.g. virtual memory systems
- G06F 9/45537: {Provision of facilities of other operating environments, e.g. WINE (I/O emulation G06F13/105)}
- G06F 9/544: {Buffers; Shared memory; Pipes}
- G06F 2209/542: Intercept
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

In a virtualized system using memory page sharing, a method is provided for maintaining sharing when Guest code attempts to write to the shared memory. In one embodiment, virtualization logic uses a pattern matcher to recognize and intercept page zeroing code in the Guest OS. When the page zeroing code is about to run against a page that is already zeroed, i.e., contains all zeros, and is being shared, the memory writes in the page zeroing code have no effect. The virtualization logic skips over the writes, providing an appearance that the Guest OS page zeroing code has run to completion but without performing any of the writes that would have caused a loss of page sharing. The pattern matcher can be part of a binary translator that inspects code before it executes.

## Claims

### Claim 1

In a system comprising virtualization logic and a virtual machine (VM) running Guest code, a method of sharing memory pages in the virtualized system comprising:
monitoring the Guest code;
determining whether a portion of Guest code is to be executed identically or not, wherein the portion of Guest code contains one or more instructions for writing first data to a target memory page; and
if it is determined that the portion of Guest code is not to be executed identically, then:
executing alternate code in place of the portion of Guest code; and
continuing execution of the Guest code from a point within the Guest code subsequent to a location of the portion of Guest code,
wherein determining whether the portion of Guest code is to be executed identically or not is a function of at least one of:
a match between contents of the target memory page and the first data; and
a sharing state of the target memory page.

### Claim 2 (depends on 1)

The method of claim 1, wherein determining whether the portion of Guest code is to be executed identically or not is also a function of whether or not the portion of Guest code matches a predetermined code pattern.

### Claim 3 (depends on 2)

The method of claim 2, wherein the predetermined code pattern identifies Guest code that writes at least a portion of a content of interest to a page of memory.

### Claim 4 (depends on 1)

The method of claim 1, wherein the first data comprises at least a portion of a content of interest.

### Claim 5 (depends on 1)

The method of claim 1, wherein the first data includes all zeroes.

### Claim 6

A method of maintaining memory page sharing in a system running a virtual machine (VM) and having virtualization logic, the method comprising:
intercepting a portion of Guest code running in the VM that writes at least a portion of a content of interest to a target memory page;
determining contents of the target memory page; and
determining whether or not to identically execute the intercepted portion of Guest code as a function of the contents of the target memory page.

### Claim 7 (depends on 6)

The method of claim 6, wherein determining whether or not to identically execute the intercepted portion of Guest code is also a function of whether the target memory page is being shared.

### Claim 8 (depends on 7)

The method of claim 7, wherein if it is determined that the target memory page is being shared, and if it is determined that the content of the target memory page matches the content of interest, the method further comprising:
advancing a state of the Guest code in the VM past the intercepted portion of Guest code,
whereby a resultant state of the Guest code appears to have run the intercepted portion of Guest code.

### Claim 9 (depends on 8)

The method of claim 8, wherein advancing the state of the Guest code in the VM comprises:
updating corresponding registers and flags in the VM.

### Claim 10 (depends on 7)

The method of claim 7, wherein if it is determined that the target memory page is being shared, and if it is determined that the content of the target memory page does not match the content of interest, the method further comprising:
discontinuing sharing of the target memory page.

### Claim 11 (depends on 7)

The method of claim 7, wherein if it is determined that the target memory page is not being shared, and if it is determined that the content of the target memory page does not match the content of interest, the method further comprising:
writing to establish the content of interest in the target memory page; and
updating a state of the Guest code in the VM to represent execution of the portion of Guest code.

### Claim 12 (depends on 11)

The method of claim 11, wherein updating the state of the Guest code in the VM comprises:
updating corresponding registers and flags in the VM.

### Claim 13 (depends on 11)

The method of claim 11, further comprising:
identifying the target memory page as a candidate for subsequent memory page sharing.

### Claim 14 (depends on 6)

The method of claim 6, wherein intercepting the portion of Guest code comprises:
the virtualization logic receiving a page fault representing an attempt by the Guest code to write to a protected memory page.

### Claim 15 (depends on 14)

The method of claim 14, wherein the page fault is generated by a CPU running in a hardware virtualization mode.

### Claim 16 (depends on 14)

The method of claim 14, wherein if the target memory page comprises a primary page table having a corresponding shadow page table, the method further comprising:
removing a trace operation synchronizing the shadow page table with the primary page table; and
freeing memory allocated to the shadow page table.

### Claim 17 (depends on 6)

The method of claim 6, further comprising:
the Guest code notifying the virtualization logic that the portion of Guest code is about to execute.

### Claim 18 (depends on 6)

The method of claim 6, further comprising:
the virtualization logic defining an instruction break point on an instruction of the portion of Guest code.

### Claim 19 (depends on 6)

The method of claim 6, further comprising:
predetermining a memory page location for the portion of Guest code; and
defining the predetermined memory page location as a memory page from which no code is to be executed.

### Claim 20 (depends on 6)

The method of claim 6, further comprising:
translating Guest code into translated code prior to execution in the VM; and
intercepting the portion of Guest code comprises comparing the Guest code to one or more predetermined code patterns during the translation.

### Claim 21 (depends on 20)

The method of claim 20, wherein translating Guest code into translated code comprises a binary translation.

### Claim 22

A computer program product comprising a non-transitory computer readable medium having computer readable program code embodied thereon for performing a method of sharing memory pages in a system comprising virtualization logic and a virtual machine (VM) running Guest code, the method comprising:
monitoring the Guest code;
determining whether a portion of Guest code is to be executed identically or not, wherein the portion of Guest code contains one or more instructions for writing first data to a target memory page; and
if it is determined that the portion of Guest code is not to be executed identically, then:
executing alternate code in place of the portion of Guest code; and
continuing execution of the Guest code from a point within the Guest code subsequent to a location of the portion of Guest code,
wherein determining whether the portion of Guest code is to be executed identically or not is a function of at least one of:
a match between contents of the target memory page and the first data; and
a sharing state of the target memory page.

### Claim 23 (depends on 22)

The computer program product of claim 22, wherein determining whether the portion of Guest code is to be executed identically or not is also a function of whether or not the portion of Guest code matches a predetermined code pattern.

### Claim 24 (depends on 23)

The computer program product of claim 23, wherein the predetermined code pattern identifies Guest code that writes at least a portion of a content of interest to a page of memory.

### Claim 25 (depends on 22)

The computer program product of claim 22, wherein the first data comprises at least a portion of a content of interest.

### Claim 26

A computer program product comprising a non-transitory computer readable medium having computer readable program code embodied thereon for performing a method of maintaining memory page sharing in a system running a virtual machine (VM) and having virtualization logic, the method comprising:
intercepting a portion of Guest code running in the VM that writes at least a portion of a content of interest to a target memory page;
determining contents of the target memory page; and
determining whether or not to identically execute the intercepted portion of Guest code as a function of the contents of the target memory page.

### Claim 27 (depends on 26)

The computer program product of claim 26, wherein determining whether or not to identically execute the intercepted portion of Guest code is also a function of whether the target memory page is being shared.

### Claim 28 (depends on 27)

The computer program product of claim 27, wherein if it is determined that the target memory page is being shared, and if it is determined that the content of the target memory page matches the content of interest, the method further comprising:
advancing a state of the Guest code in the VM past the intercepted portion of Guest code,
whereby a resultant state of the Guest code appears to have run the intercepted portion of Guest code.

### Claim 29 (depends on 27)

The computer program product of claim 27, wherein if it is determined that the target memory page is being shared, and if it is determined that the content of the target memory page does not match the content of interest, the method further comprising:
discontinuing sharing of the target memory page.

### Claim 30 (depends on 27)

The computer program product of claim 27, wherein if it is determined that the target memory page is not being shared, and if it is determined that the content of the target memory page does not match the content of interest, the method further comprising:
writing to establish the content of interest in the target memory page; and
updating a state of the Guest code in the VM to represent execution of the intercepted portion of Guest code.

### Claim 31 (depends on 30)

The computer program product of claim 30, the method further comprising:
identifying the target memory page as a candidate for subsequent memory page sharing.

### Claim 32 (depends on 26)

The computer program product of claim 26, wherein intercepting the portion of Guest code comprises:
the virtualization logic receiving a page fault representing an attempt by the Guest code to write to a protected memory page.

### Claim 33 (depends on 32)

The computer program product of claim 32, wherein if the target memory page comprises a primary page table having a corresponding shadow page table, the method further comprising:
removing a trace operation synchronizing the shadow page table with the primary page table; and
freeing memory allocated to the shadow page table.

### Claim 34 (depends on 26)

The computer program product of claim 26, the method further comprising:
the Guest code notifying the virtualization logic that the intercepted portion of Guest code is about to execute.

### Claim 35 (depends on 26)

The computer program product of claim 26, the method further comprising:
the virtualization logic defining an instruction break point on an instruction of the intercepted portion of Guest code.

### Claim 36 (depends on 26)

The computer program product of claim 26, the method further comprising:
predetermining a memory page location for the intercepted portion of Guest code; and
defining the predetermined memory page location as a memory page from which no code is to be executed.

### Claim 37 (depends on 26)

The computer program product of claim 26, the method further comprising:
translating Guest code into translated code prior to execution in the VM; and
intercepting the portion of Guest code comprises comparing the Guest code to one or more predetermined code patterns during the translation.
