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
13
votes
1 answer

How would I design and implement a non-blocking memory mapping module for node.js

There exists the mmap module for node.js: https://github.com/bnoordhuis/node-mmap/ As the author Ben Noordhuis notes, accesing mapped memory can block, which is why he does not recommend it anymore and discontinued it. So I wonder how would I…
citykid
  • 9,916
  • 10
  • 55
  • 91
13
votes
2 answers

Does mmap or malloc allocate RAM?

I know this is probably a stupid question but i've been looking for awhile and can't find a definitive answer. If I use mmap or malloc (in C, on a linux machine) does either one allocate space in RAM? For example, if I have 2GB of RAM and wanted to…
cHam
  • 2,624
  • 7
  • 26
  • 28
13
votes
2 answers

mmap slower than ioremap

I am developing for an ARM device running Linux 2.6.37. I am trying to toggle an IO pin as fast as possible. I made a little kernel module and a user space application. I tried two things : Manipulate the GPIO control registers directly from the…
Julien
  • 1,181
  • 10
  • 31
13
votes
7 answers

How to mmap the stack for the clone() system call on linux?

The clone() system call on Linux takes a parameter pointing to the stack for the new created thread to use. The obvious way to do this is to simply malloc some space and pass that, but then you have to be sure you've malloc'd as much stack space as…
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
12
votes
1 answer

Resize POSIX shared memory. A working example

I have a shared dynamic array within POSIX model between two different applications. I would like to have an ability to change its size without copying. Unfortunately I couldn't find right solution to increase and decrease POSIX shared memory in C…
Dennis V
  • 574
  • 7
  • 19
12
votes
3 answers

How do I write to a memory-mapped address in Rust?

I'm trying to make "Blinky" for STM32F1xx in Rust. I know that there are libs for it, but I want to make my own "lib" for learning purposes. I can access STM32's "registers" by their addresses like this in C: *(uint32_t*)(0x40021000 + 0x018) |=…
fevgenym
  • 568
  • 7
  • 20
12
votes
4 answers

Efficiently reading a very large text file in C++

I have a very large text file(45GB). Each line of the text file contains two space separated 64bit unsigned integers as shown below. 4624996948753406865 10214715013130414417 4305027007407867230 4569406367070518418 10817905656952544704…
Pattu
  • 3,481
  • 8
  • 32
  • 41
12
votes
2 answers

Is it possible to "punch holes" through mmap'ed anonymous memory?

Consider a program which uses a large number of roughly page-sized memory regions (say 64 kB or so), each of which is rather short-lived. (In my particular case, these are alternate stacks for green threads.) How would one best do to allocate these…
Dolda2000
  • 25,216
  • 4
  • 51
  • 92
12
votes
2 answers

mmap allocates memory in heap ?

I was reading about mmap in wikipedia and trying out this example http://en.wikipedia.org/wiki/Mmap#Example_of_usage. I have compiled this program with gcc and ran valgrind overit. Here is valgrind output: # valgrind a.out ==7018== Memcheck, a…
Sethu
  • 323
  • 1
  • 3
  • 7
12
votes
13 answers

What is the fastest way to read 10 GB file from the disk?

We need to read and count different types of messages/run some statistics on a 10 GB text file, e.g a FIX engine log. We use Linux, 32-bit, 4 CPUs, Intel, coding in Perl but the language doesn't really matter. I have found some interesting tips in…
alex
  • 1,757
  • 4
  • 21
  • 32
12
votes
2 answers

Why does munmap needs a length as parameter?

I was wondering, why should the size of mapped memory being one parameter passed in, since there couldn't more more than one mapping starting from same address (could they ?), why won't linux kernel record both start address, length together, but…
daisy
  • 22,498
  • 29
  • 129
  • 265
11
votes
4 answers

Why does fopen/fgets use both mmap and read system calls to access the data?

I have a small example program which simply fopens a file and uses fgets to read it. Using strace, I notice that the first call to fgets runs a mmap system call, and then read system calls are used to actually read the contents of the file. on…
bdk
  • 4,769
  • 29
  • 33
11
votes
1 answer

mmap: mapping in user space a kernel buffer allocated with kmalloc

Which is the correct way to map in an user space process a buffer allocated with kmalloc? Maybe i didn't understand memory mapping yet...I write a kernel module that allocs this buffer (for example 120 bytes) and i would read and write it in a…
MirkoBanchi
  • 2,173
  • 5
  • 35
  • 52
11
votes
1 answer

Are multiple MAP_PRIVATE mappings of the same file, in the same process, still private?

Linux mmap(2) says: MAP_PRIVATE Create a private copy-on-write mapping. Updates to the mapping are not visible to other processes mapping the same file, and are not carried through to the underlying file. It is unspecified whether changes made to…
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
11
votes
4 answers

Limit buffer cache used for mmap

I have a data structure that I'd like to rework to page out on-demand. mmap seems like an easy way to run some initial experiments. However, I want to limit the amount of buffer cache that the mmap uses. The machine has enough memory to page the…
JaredC
  • 5,150
  • 1
  • 20
  • 45