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
17
votes
3 answers

how can I detect whether a specific page is mapped in memory?

I would like to detect whether or not a specific page has already been mapped in memory. The goal here is to be able to perform this check before calling mmap with a fixed memory address. The following code illustrates what happens in this case by…
mathieu
  • 2,954
  • 2
  • 20
  • 31
17
votes
1 answer

Unmap of NumPy memmap

I can't find any documentation on how numpy handles unmapping of previously memory mapped regions: munmap for numpy.memmap() and numpy.load(mmap_mode). My guess is it's done only at garbage collection time, is that correct?
Radim
  • 4,208
  • 3
  • 27
  • 38
17
votes
3 answers

Mapping non-contiguous blocks from a file into contiguous memory addresses

I am interested in the prospect of using memory mapped IO, preferably exploiting the facilities in boost::interprocess for cross-platform support, to map non-contiguous system-page-size blocks in a file into a contiguous address space in memory. A…
aSteve
  • 1,956
  • 1
  • 20
  • 35
16
votes
2 answers

How would one prevent MMAP from caching values?

I've written a linux driver that ioremaps exports PCI BAR0 for a particular device to a sysfs binary attribute allowing userspace to directly control it. The problem rears when I attempt to MMAP on top of the attribute to directly access that bit of…
Sean Madden
  • 1,069
  • 2
  • 10
  • 22
16
votes
2 answers

What is the difference between MAP_SHARED and MAP_PRIVATE in the mmap function?

Playing around with mmap for the fun of it, I have the following code: (.. snip ..) fd = open("/home/me/straight_a.txt", O_RDONLY); if (fd == -1) { perror("open"); exit(1); } m = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_FILE|MAP_PRIVATE,…
ntl0ve
  • 1,896
  • 3
  • 19
  • 25
16
votes
3 answers

Platform independent memory mapped [file] IO

I've spent some time investigating memory mapped IO for an application I'm working on. I have some very large (TB scale) files, and I want to map segments from them into memory, for both reading and writing, making maximum use of OS-level caching. …
aSteve
  • 1,956
  • 1
  • 20
  • 35
16
votes
1 answer

mmap on /proc/pid/mem

Has anybody succeeded in mmap'ing a /proc/pid/mem file with Linux kernel 2.6? I am getting an ENODEV (No such device) error. My call looks like this: char * map = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, mem_fd, offset); And I have verified…
Amittai Aviram
  • 2,270
  • 3
  • 25
  • 32
16
votes
2 answers

Random mmaped memory access up to 16% slower than heap data access

Our software builds a data structure in memory that is about 80 gigabytes large. It can then either use this data structure directly to do its computation, or dump it to disk so it can be reused several times afterwards. A lot of random memory…
Brutos
  • 701
  • 4
  • 15
16
votes
2 answers

What does mmap do?

What does this line of code do? mmap(NULL, n, PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
user439459
16
votes
2 answers

Reduce memory fragmentation with MALLOC_MMAP_THRESHOLD_ and MALLOC_MMAP_MAX_

I've been experimenting with MALLOC_MMAP_THRESHOLD_ and MALLOC_MMAP_MAX_ env variables to affect memory management in a long-running Python 2 process. See http://man7.org/linux/man-pages/man3/mallopt.3.html I got the idea from this bug report:…
lbolla
  • 5,387
  • 1
  • 22
  • 35
16
votes
5 answers

Can the dirtiness of pages of a mmap be found from userspace?

Can dirtiness of pages of a (non-shared) mmap be accessed from userspace under linux 2.6.30+? Platform-specific hacks and kludges welcome. Ideally, I'm looking for an array of bits, one per page (4kB?) of the mmap'ed region, which are set if that…
fadedbee
  • 42,671
  • 44
  • 178
  • 308
16
votes
2 answers

Anonymous mmap zero-filled?

In Linux, the mmap(2) man page explains that an anonymous mapping . . . is not backed by any file; its contents are initialized to zero. The FreeBSD mmap(2) man page does not make a similar guarantee about zero-filling, though it does promise that…
jbapple
  • 3,297
  • 1
  • 24
  • 38
16
votes
2 answers

In linux , how to create a file descriptor for a memory region

I have some program handling some data either in a file or in some memory buffer. I want to provide uniform way to handle these cases. I can either 1) mmap the file so we can handle them uniformly as a memory buffer; 2) create FILE* using fopen and…
Kan Li
  • 8,557
  • 8
  • 53
  • 93
16
votes
2 answers

How to access mmaped /dev/mem without crashing the Linux kernel?

I have a simple program that tries to access the physical memory in user space, where the kernel stores the 1st struct page. On a 64 bit machine this address is: kernel virtual address: ffffea0000000000 physical address: 0000620000000000 I am…
Vinay
  • 433
  • 1
  • 5
  • 11
15
votes
4 answers

Shmem vs tmpfs vs mmap

Does someone know how well the following 3 compare in terms of speed: shared memory tmpfs (/dev/shm) mmap (/dev/shm) Thanks!
SyRenity
  • 841
  • 5
  • 11
  • 18