bloomberg/memray

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

Open

#748 aberto em 11 de abr. de 2025

Ver no GitHub
 (10 comments) (0 reactions) (1 assignee)Python (383 forks)batch import
enhancementgood first issue

Métricas do repositório

Stars
 (11.796 stars)
Métricas de merge de PR
 (Mesclagem média 2d) (2 fundiu PRs em 30d)

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.

Guia do colaborador