|
From: | Stefano Garzarella |
Subject: | Re: [PATCH 9/9] hostmem-file: support POSIX shm_open() |
Date: | Thu, 29 Feb 2024 09:57:22 +0100 |
On Wed, Feb 28, 2024 at 01:32:17PM +0100, Markus Armbruster wrote:
Stefano Garzarella <sgarzare@redhat.com> writes: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 <sgarzare@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-shmHow would that look like? Would it involve duplicating code?
I was looking at it just now, and apart from some boilerplate code to create the object, the rest in the end is pretty specific and a lot of things in memory-backend-file wouldn't be supported by memory-backend-shm anyway, so I'll give it a try for v2 by adding it.
- 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)Hmm. Too much magic? I don't know...
Yeah, I agree.
Any preference/suggestion?[...]diff --git a/qapi/qom.json b/qapi/qom.json index 2a6e49365a..bfb01b909f 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -682,6 +682,9 @@# @mem-path: the path to either a shared memory or huge page # filesystem mount Does this need adjustment?
Good point. For now I think I will drop this patch and add memory-backend-shm in v2, but if I go back I will fix it!
[...]# writable RAM instead of ROM, and want to set this property to 'off'. # (default: auto, since 8.2) # +# @shm: if true, shm_open(3) is used to create/open POSIX shared memory +# object; if false, an open(2) is used. (default: false) (since 9.0) +#Please format like this for consistency:
Sure.
# @shm: if true, shm_open(3) is used to create/open POSIX shared memory # object; if false, an open(2) is used (default: false) (since 9.0)
I just noticed that I followed the property just above (@rom). Should we fix that one?
Thanks, Stefano
[Prev in Thread] | Current Thread | [Next in Thread] |