Questions tagged [mmap]

mmap is a POSIX-compliant Unix system call that maps files or devices into memory.

mmap() creates a new mapping in the virtual address space of the calling process.

https://en.wikipedia.org/wiki/Mmap

1936 questions
9
votes
3 answers

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…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
9
votes
3 answers

memory mapped files and pointers to volatile objects

My understanding of the semantics of volatile in C and C++ is that it turns memory access into (observable) side effects. Whenever reading or writing to a memory mapped file (or shared memory) I would expect the the pointer to be volatile qualified,…
Arvid
  • 10,915
  • 1
  • 32
  • 40
9
votes
2 answers

GDB can't access mmap()'d kernel allocated memory?

I'm running into an issue with GDB and some buffers allocated in kernel space. The buffers are allocated by a kernel module that is supposed to allocate contiguous blocks of memory, and then memory mapped into userspace via a mmap() call. GDB,…
Ryan Talbot
  • 115
  • 1
  • 6
9
votes
2 answers

Write-only mapping a O_WRONLY opened file supposed to work?

Is mmap() supposed to be able to create a write-only mapping of a O_WRONLY opened file? I am asking because following fails on a Linux 4.0.4 x86-64 system (strace log): mkdir("test", 0700) = 0 open("test/foo", O_WRONLY|O_CREAT, 0666) =…
maxschlepzig
  • 35,645
  • 14
  • 145
  • 182
9
votes
1 answer

Java map / nio / NFS issue causing a VM fault: "a fault occurred in a recent unsafe memory access operation in compiled Java code"

I have written a parser class for a particular binary format (nfdump if anyone is interested) which uses java.nio's MappedByteBuffer to read through files of a few GB each. The binary format is just a series of headers and mostly fixed-size binary…
Matthew Bloch
  • 357
  • 2
  • 10
9
votes
3 answers

Why does mmap() fail with ENOMEM on a 1TB sparse file?

I've been working with large sparse files on openSUSE 11.2 x86_64. When I try to mmap() a 1TB sparse file, it fails with ENOMEM. I would have thought that the 64 bit address space would be adequate to map in a terabyte, but it seems not.…
metadaddy
  • 4,234
  • 1
  • 22
  • 46
9
votes
2 answers

When would one use mmap MAP_FIXED?

I've been looking at the different flags for the mmap function, namely MAP_FIXED, MAP_SHARED, MAP_PRIVATE. Can someone explain to me the purpose of MAP_FIXED? There's no guarantee that the address space will be used in the first place.
Abundance
  • 1,963
  • 3
  • 24
  • 46
9
votes
1 answer

alignment and granularity of mmap

I am confused by the specification of mmap. Let pa be the return address of mmap (the same as the specification) pa = mmap(addr, len, prot, flags, fildes, off); In my opinion after the function call succeed the following range is valid [ pa,…
OwnWaterloo
  • 1,963
  • 14
  • 11
9
votes
0 answers

madvise system call with MADV_SEQUENTIAL call takes too long to finish

In my code I am using an external C library and the library calls madvise with MADV_SEQUENTIAL option which takes too long to finish. In my opinion only calling madvise with MADV_SEQUENTIAL is enough for our job. My first question is, why multiple…
denizeren
  • 934
  • 8
  • 20
9
votes
2 answers

Print the symbol table of an ELF file

I have a program which uses the mmap system call: map_start = mmap(0, fd_stat.st_size, PROT_READ | PROT_WRITE , MAP_SHARED, fd, 0) and a header variable: header = (Elf32_Ehdr *) map_start; How can I access the symbol table and print its whole…
kitsuneFox
  • 1,243
  • 3
  • 18
  • 31
9
votes
1 answer

Trap all accesses to an address range (Linux)

Background I'm writing a framework to enable co-simulation of RTL running in a simulator and un-modified host software. The host software is written to control actual hardware and typically works in one of two ways: Read/Write calls through a…
Chiggs
  • 2,824
  • 21
  • 31
9
votes
4 answers

Does madvise(___, ___, MADV_DONTNEED) instruct the OS to lazily write to disk?

Hypothetically, suppose I want to perform sequential writing to a potentially very large file. If I mmap() a gigantic region and madvise(MADV_SEQUENTIAL) on that entire region, then I can write to the memory in a relatively efficient manner. This I…
Badmanchild
  • 990
  • 9
  • 18
9
votes
1 answer

how to do mmap for cacheable PCIe BAR

I am trying to write a driver with custom mmap() function for PCIe BAR, with the goal to make this BAR cacheable in the processor cache. I am aware this is not the best way to achieve highest bandwidth and that the order of writes is unpredictable…
sols
  • 91
  • 1
  • 4
9
votes
2 answers

Poor memcpy performance in user space for mmap'ed physical memory in Linux

Of 192GB RAM installed on my computer, I have 188GB RAM above 4GB (at hardware address 0x100000000) reserved by the Linux kernel at boot time (mem=4G memmap=188G$4G). A data acquisition kernel modules accumulates data into this large area used as a…
PeterW
  • 111
  • 1
  • 4
8
votes
4 answers

mmap slower than getline?

I face the challenge of reading/writing files (in Gigs) line by line. Reading many forum entries and sites (including a bunch of SO's), mmap was suggested as the fastest option to read/write files. However, when I implement my code with both…
Ian
  • 3,500
  • 1
  • 24
  • 25