[PATCH 0/1] MR10251: server: Create temp files for anonymous mappings with memfd_create() if available.
From: Paul Gofman <pgofman@codeweavers.com> --- configure.ac | 1 + server/mapping.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/configure.ac b/configure.ac index 77b80ecb395..35f21a7b486 100644 --- a/configure.ac +++ b/configure.ac @@ -2116,6 +2116,7 @@ AC_CHECK_FUNCS(\ getifaddrs \ getrandom \ kqueue \ + memfd_create \ pipe2 \ port_create \ posix_fadvise \ diff --git a/server/mapping.c b/server/mapping.c index 905d528b04f..d3fcc708022 100644 --- a/server/mapping.c +++ b/server/mapping.c @@ -365,6 +365,13 @@ static int create_temp_file( file_pos_t size ) char tmpfn[16]; int fd; +#ifdef HAVE_MEMFD_CREATE + if ((fd = memfd_create( "wine-mapping", 0 )) != -1) + { + if (grow_file( fd, size )) return fd; + close( fd ); + } +#endif if (temp_dir_fd == -1) { temp_dir_fd = server_dir_fd; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10251
Anonymous sections are used by Java VM for nearly all of the JVM managed memory (and JVM is used, in particular, by Killer Inn game). If the temporary file ends up being created on a real persistent filesystem and not in-memory FS any write access to mapped section views triggers write of the memory to disk, which is a huge performance issue (and there is seemingly no way around that on Unix, if the mmap'ed memory is mapped to a file it is going to be updated after memory changes, even if lazily). Now by default those mapped files end up in /tmp which is most of the time backed by in-memory FS and this problem is not there (yet for various reasons those files may end up in persistent FS). There is another issue with /tmp FS however. Typically these days when it is backed by tmpfs it is not very big (rule of thumb default is one half of system RAM). In case of Killer Inn / JVM, if there is less than 8GB of free space in /tmp, the game outright crashes as there is not enough space to b ack all the JVM allocated memory. That, in particular, prevents the game from working on Steam Deck. memfd doesn't have such limits and is guaranteed to allocate a file not backed by persistent storage (while that memory can still be swapped to swap space). -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10251#note_131418
participants (2)
-
Paul Gofman -
Paul Gofman (@gofman)