On Wed, Feb 28, 2024 at 01:01:55PM +0100, David Hildenbrand wrote:
On 28.02.24 12:47, Stefano Garzarella wrote:
Add a new `shm` bool option for `-object memory-backend-file`.

When this option is set to true, the POSIX shm_open(3) is used instead
of open(2).

So a file will not be created in the filesystem, but a "POSIX shared
memory object" will be instantiated. In Linux this turns into a file
in /dev/shm, but in other OSes this may not happen (for example in
macOS or FreeBSD nothing is shown in any filesystem).

This new feature is useful when we need to share guest memory with
another process (e.g. vhost-user backend), but we don't have
memfd_create() or any special filesystems (e.g. /dev/shm) available
as in macOS.

Signed-off-by: Stefano Garzarella <sgarz...@redhat.com>
I am not sure this is the best way to support shm_open() in QEMU.

Other solutions I had in mind were:

- create a new memory-backend-shm

- extend memory-backend-memfd to use shm_open() on systems where memfd is
not available (problem: shm_open wants a name to assign to the object, but
we can do a workaround by using a random name and do the unlink right away)

Any preference/suggestion?

Both sound like reasonable options, and IMHO better than hostmem-file with things that are not necessarily "real" files.

Yeah, I see.

Regarding memory-backend-memfd, we similarly have to pass a name to memfd_create(), although for different purpose: "The name supplied in name is used as a filename and will be displayed as the target of the corresponding symbolic link in the directory /proc/self/fd/".


Okay, so I guess it must be unique only in the process, while for shm_open() it is global.

Likely, memory-backend-shm that directly maps to shm_open() and only provides properties reasonable for shm_open() is the cleanest approach. So that would currently be my preference :)

Thank you for your thoughts, I think I will go toward this direction (memory-backend-shm).

It was also my first choice, but in order to have a working RFC right away, I modified memory-backend-file.


Reply via email to