bloomberg/memray

Update the C++ FileSink to fall back to write() if memory mapping isn't supported

Open

#748 opened on Apr 11, 2025

View on GitHub
 (5 comments) (0 reactions) (1 assignee)Python (11,796 stars) (383 forks)batch import
enhancementgood first issue

Description

For the sake of performance, memray writes to capture files by mapping the capture file into memory and then writing to it as an in-memory array that is eventually synchronized to the filesystem. (See FileSink in sink.cpp / sink.h)

This is fast, but some (uncommon and non-standard) filesystems don't support it.

We should detect if the operations that we need (posix_fallocate and mmap) aren't supported by the filesystem that the capture file is being written to, and if so log a warning and fall back to a slower but more portable path that simply uses write() to append each new chunk of data to the capture file. In order to test this, we'll also need to add a way to force the slower path to be used even if posix_fallocate and mmap are supported. This should probably just be a MEMRAY_NO_MMAP=1 environment variable, or something like that.

Contributor guide

Update the C++ FileSink to fall back to write() if memory mapping isn't supported · bloomberg/memray#748 | Good First Issue