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

Docker memory limit causes SLUB unable to allocate with large page cache

Given a process that creates a large linux kernel page cache via mmap'd files, running in a docker container (cgroup) with a memory limit causes kernel slab allocation errors: Jul 18 21:29:01 ip-10-10-17-135 kernel: [186998.252395] SLUB: Unable to…
David
  • 1,391
  • 11
  • 22
20
votes
2 answers

How to use mmap to allocate a memory in heap?

Just the question stated, how can I use mmap() to allocate a memory in heap? This is my only option because malloc() is not a reentrant function.
domlao
  • 15,663
  • 34
  • 95
  • 134
20
votes
1 answer

Why does mmap() use MAP_FAILED instead of NULL?

Does anybody know why mmap() returns MAP_FAILED instead of NULL? It seems that MAP_FAILED is (void*)-1 on most systems. Why doesn't mmap() just use NULL instead? I know that address 0x0 is technically a valid memory page, whereas (void*)-1 will…
fieldtensor
  • 3,972
  • 4
  • 27
  • 43
20
votes
2 answers

Is there a difference between mmap MAP_SHARED and MAP_PRIVATE when PROT_READ is also used?

If I create an mmap(2) of a file with a prot parameter of PROT_READ only and the file backing it is also read-only and does not change, is there any performance difference (or any difference at all) between MAP_SHARED and MAP_PRIVATE ? Will the…
Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319
19
votes
2 answers

Why can we allocate a 1 PB (10^15) array and get access to the last element, but can't free it?

As known: http://linux.die.net/man/3/malloc By default, Linux follows an optimistic memory allocation strategy. This means that when malloc() returns non-NULL there is no guarantee that the memory really is available. In case it turns out that…
Alex
  • 12,578
  • 15
  • 99
  • 195
19
votes
1 answer

Why file starting offset in mmap() must be multiple of the page size

In mmap() manpage: Its prototype is: void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); and description: The mmap() function asks to map 'length' bytes starting at offset 'offset' from the file (or other object)…
password636
  • 981
  • 1
  • 7
  • 18
19
votes
4 answers

mmap: will the mapped file be loaded into memory immediately?

From the manual, I just know that mmap() maps a file to a virtual address space, so the file can be randomly accessed. But, it is unclear to me that whether the mapped file is loaded into memory immediately? I guess that kernel manages the mapped…
Dagang
  • 24,586
  • 26
  • 88
  • 133
19
votes
3 answers

mmap and memory usage

I am writing a program that receives huge amounts of data (in pieces of different sizes) from the network, processes them and writes them to memory. Since some pieces of data can be very large, my current approach is limiting the buffer size used.…
Elektito
  • 3,863
  • 8
  • 42
  • 72
18
votes
7 answers

Examining mmaped addresses using GDB

I'm using the driver I posted at Direct Memory Access in Linux to mmap some physical ram into a userspace address. However, I can't use GDB to look at any of the address; i.e., x 0x12345678 (where 0x12345678 is the return value of mmap) fails with…
Mikeage
  • 6,424
  • 4
  • 36
  • 54
18
votes
1 answer

How to mmap() a large file without risking the OOM killer?

I've got an embedded ARM Linux box with a limited amount of RAM (512MB) and no swap space, on which I need to create and then manipulate a fairly large file (~200MB). Loading the entire file into RAM, modifying the contents in-RAM, and then writing…
Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234
18
votes
1 answer

Path to in-memory-file without dumping in tmp

Is there a way in python to get the path to the in-memory file, so it'll behave as a normal file for methods which needs file path? My objective is to protect the file, so avoiding dumping into /tmp. Trying to read an encrypted file -> decrypt a…
Shubham Jain
  • 876
  • 1
  • 9
  • 17
18
votes
4 answers

Shared Memory or mmap - Linux C/C++ IPC

The context is Inter-Process-Communication where one process("Server") has to send fixed-size structs to many listening processes("Clients") running on the same machine. I am very comfortable doing this in Socket Programming. To make the…
Humble Debugger
  • 4,439
  • 11
  • 39
  • 56
18
votes
8 answers

mmap problem, allocates huge amounts of memory

I got some huge files I need to parse, and people have been recommending mmap because this should avoid having to allocate the entire file in-memory. But looking at 'top' it does look like I'm opening the entire file into the memory, so I think I…
monkeyking
  • 6,670
  • 24
  • 61
  • 81
18
votes
4 answers

Overlapping pages with mmap (MAP_FIXED)

Due to some obscure reasons which are not relevant for this question, I need to resort to use MAP_FIXED in order to obtain a page close to where the text section of libc lives in memory. Before reading mmap(2) (which I should had done in the first…
fons
  • 4,905
  • 4
  • 29
  • 49
17
votes
2 answers

mmap with /dev/zero

Say I allocate a big memory (40MB) with mmap using /dev/zero as follows. fd = open("/dev/zero", O_RDWR); a = mmap (0, 4096e4, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FILE, fd, 0); What I understand is that the kernel will initialize memories to…
MetallicPriest
  • 29,191
  • 52
  • 200
  • 356