Memory sharing

Guests in a hypervisor system can share memory regions through which they can pass data to each other or the hypervisor host.

In a QNX hypervisor system, client applications running in guests create and manage shared memory, and can use shared memory regions to share data. If data needs to be shared between a guest or guests and the hypervisor host domain, applications running in the hypervisor host domain can also create shared memory regions, or attach to regions created by guests.

Assuming that all sharing is between guests, and not with the hypervisor host, to set up memory sharing in your hypervisor system:

  1. Edit the qvm configuration files (*.qvmconf) for the VMs hosting the guests that will share memory to enable shared memory services (see Configuring the VMs below).
  2. Create a client application that runs in the guests and uses shared memory services, and run it on multiple guests.

The hypervisor-shmem-examples-*.tgz archive available with QNX hypervisors includes source code for example memory sharing programs: ghstest.c for a QNX guest, and for the hypervisor host.

How shared memory works

To use shared memory, a client (an application running in a guest or in the hypervisor host) needs:

The hypervisor provides the shmem vdev, which implements setting up the shared memory mapping and the interrupts you need to use shared memory. This vdev provides additional functionality to simplify using shared memory. These include:

Figure 1. A 128 MB memory allocation (“moo”) shared by Guest 0 and Guest 1

The figure above illustrates memory sharing between two guests. Guest 0 attempts to attach to a 128 MB shared memory area (“moo”) first. Since no such area exists at the specified location, the attempt to attach creates the area and allows the guest to attach to it. Guest 1 can simply attach to the same name to share data memory with Guest 0.

For more information about shared memory regions, see Factory and control pages below.

Note:

All the connections to a shared memory region are peers. That is, there is no distinction between the guest that creates a shared memory region and the guest that attaches to it. Simply, the first attempt to attach to a shared memory region creates the region. As far as the guest is concerned, it simply attaches to the region.

This design avoids ordering problems where the system designer would have to make sure that one guest always comes up and creates the shared memory region before another guest tries to attach to it.