How to write kernel space memory (physical address) to a file using O_DIRECT?
I want to write a physical memory to a file. The memory itself will not be touched again, thus I want to use O_DIRECT to gain the best write performance. My first idea was to open /dev/mem and mmap the memory and write everything to a file, which is opened with O_DIRECT . The write call fails ( EFAULT ) on the memory-address returned by mmap. If I do not use O_DIRECT , it results in a memcpy . #include <cstdint> #include <iostream> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <errno.h> #include <malloc.h> #include <sys/mman.h>