I’m trying to create a memory mapping of length greater than the underlying file. When I access pages of the mapping (which are not correspondingly mapped to a file), a SIGBUS is caused. However when I try to access the memory outside the memory mapping length, it should cause SIGSEGV (but isn’t), why is that? Answer Stopping your program and
Tag: mmap
How to increase the size of memory region allocated with mmap()
I’m allocating memory using mmap Linux syscall. Is it possible to increase the size of allocated memory region preserving its start address and contents? How to do it properly? Answer On Linux, use the mremap(2) Linux-specific system call without MREMAP_MAYMOVE to extend the existing mapping, without considering the option of remapping those physical pages to a different virtual address where
Is it possible to add a customized name for the (non file-backed) mmap region?
Just curious whether it is possible to specify a name for the non file-backed mmap region? Some thing like the [New VMA area] in the following example: Answer The content of maps comes from the show_map_vma function in fs/proc/task_mmu.c. Looking at it, if you want a custom name for a non-file-backed mapping, it’d need to come from either vma->vm_ops->name or
Accessing physical address space using mmap in Linux: passing the correct arguments to mmap
I need to access and write to some physical addresses in my RAM. I was looking at this answer and the definition of mmap. If addr is NULL, then the kernel chooses the (page-aligned) address at which to create the mapping; this is the most portable method of creating a new mapping. If addr is not NULL, then the kernel
how to use mmap and shm_open to shared memory among multiple independent processes
I want to share memory among processes, which run independently instead of fork. I’ve read the man page for mmap and shm_open, and still confused about the usage. shared memory, in my mind, should be the mechanism of mapping virtual memory space among different processes, but Why mmap has the fd argument? Does it mean the memory is actually shared
Why is MAP_GROWSDOWN mapping does not grow?
I tried to create MAP_GROWSDOWN mapping with the expectation it would grow automatically. As specified in the manual page: MAP_GROWSDOWN This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory. The return address is one page lower than the memory area that is actually created in the process’s
mmap: performance when using multithreading
I have a program which performs some operations on a lot of files (> 10 000). It spawns N worker threads and each thread mmaps some file, does some work and munmaps it. The problem I am facing right now is that whenever I use just 1 process with N worker threads, it has worse performance than spawning 2 processes
c++ close a open() file read with mmap
I am working with mmap() to fastly read big files, basing my script on this question answer (Fast textfile reading in c++). I am using the second version from sehe answer : and it works just great. But if I implement it over a loop of several files (I just change the main() function name to: and then get the
Segmentation fault when maping /dev/mem
I’m trying to mmap a memory from my FPGA on a linux running on my Zedboard SoC. I can read the contents correctly using devmem on the command line, but when trying to read it through C I get a segmentation fault. The barebones code shown below throws the segmentation fault when trying to print the contents of the memory.
Passing Variable Length C String Through Mmap-ed Shared Memory
Let’s say I have a process A and a process B, and process A would like to pass a C string to process B through a shm_open() + mmap() shared memory. What’s the most latency efficient way? The answer of this post suggested that after C++11, std::atomic is the right way to share data over shared memory. However, I fail