Questions tagged [mmap]
All about using memory mapped files. Questions on programming should be asked on Stack Overflow SE.
60
questions
0
votes
1
answer
29
views
In what segment does mmap allocate memory
I thought first that it was the heap, but it seems to allocate memory in a different place. radare2 tags it as folowing:
0x00007fb07dacd000 - 0x00007fb07dace000 - usr 4K s rw- unk2 unk2
Since it ...
0
votes
1
answer
48
views
Is the memory usage of typical software exaggerated?
Suppose multiple processes are using the same shared library (such as Gtk). Presumably, they mmap the library file, and physically, the RAM is shared?
However, the size of the library gets added to ...
1
vote
0
answers
67
views
Howto enable Nginx memory caching with mmap()
I am a newbie nginx admin. I used nginx-quic to get features like HTTP/3 over QUIC. However, HTTP/3 perfoms 2x to 3x slower than HTTP/2, so I am trying to optimize the experimental server. (The test ...
1
vote
2
answers
161
views
Write in /dev/mem without using mmap
It is possible to write on /dev/mem without using mmap?
I'm enabling pull-up resistors on a Raspberry Pi inside an LKM and the function void *mmap (caddr_t addr, size_t len, int prot, int flags, int ...
1
vote
1
answer
387
views
Do docker containers share RAM for files memory mapped from the same layer but a different image?
I'm not 100% certain about whether this is a U&L question or a SO question. On balance I'm posting it on U&L as it's OS related.
Background
As far as I know, Linux will load shared libraries (...
0
votes
1
answer
214
views
mmap(): Is it possible to prevent writing back to file with MAP_SHARED flag?
As I understand, 'MAP_SHARED' flag in mmap() shares any changes made by a process to the memory map immediately with other processes and eventually writes the changes back to the file. Is it possible ...
1
vote
0
answers
62
views
linux enable large page management
I am doing some experiments. Some huge pages (2MB) are used in the experiment, so that the 21-bit page offset can remain unchanged when performing virtual address translation.
I found some methods on ...
1
vote
0
answers
33
views
Is there a way to tell how much memory is file-backed on Linux process?
I'm looking to see how much of my memory is file-backed on a process. Unfortunately proc/pid/smap_rollup shows stats for how much memory is being used, but it doesn't seem to differentiate between ...
-1
votes
1
answer
244
views
What is the path of data transfer when using memory mapped file?
Is there any difference between the data transfer paths using read()/write() and using mmap() on a file?
What does "kernel" mean in https://stackoverflow.com/a/41419353?
mmap doesn't ...
0
votes
1
answer
515
views
Do anonymous memory mapping and shared memory allocate space from physical memory only?
In Linux,
when using mmap() for anonymous memory mapping, or using malloc(), do they allocate "space" from only physical memory, or either physical memory or swap or their combination? (I ...
2
votes
1
answer
513
views
mmap a file vs mmap in malloc
I'm kind of confused by mmap.
Well, I know that when we malloc a big size of memory, we will invoke the function mmap, which will allocate an area in memory. In this case, mmap just allocate some ...
1
vote
2
answers
1k
views
What is the behaviour of a file-backed memory map when reading from or writing to an address larger than the length of the file?
I'm trying to figure out whether it would be undefined behaviour to open a memory map to a file with a very large length. My use-case is that I want to be able to see new data when the file is ...
2
votes
0
answers
443
views
Mapping guest RAM to file in qemu
We're emulating a Cortex M3 cpu and would like to pass some parameters to the guest during run-time. The simplest idea seems to be to write directly to some memory area. I tried simply adding -mem-...
0
votes
0
answers
117
views
SIGBUS immediately after successful mremap for shared memory
I am using POSIX shared memory. Initially I map four shared memory buffers. One of them exceeds its allocated size so I call mremap:
void * remap_shm(void *old_address, size_t old_size, size_t ...
5
votes
1
answer
508
views
Is it possible to disable unnecessary disk writes to mmap files on linux?
I would like to know if there is a way to prevent Linux from periodically syncing mmap'd files to disk, while still allowing the OS to write back when physical memory gets tight.
I am writing ...
2
votes
1
answer
658
views
How to revoke write permissions on a shared memory object s.t. subsequent writes to aleady mapped pages by other processes will fail?
Is there any way to revoke write permissions to shared memory by the process who created that shared object, s.t. any other process who has mapped the shared memory to its virtual space with write ...
1
vote
1
answer
236
views
Memory map to process for a large code segment
I know that pmap of a process shows how the memory mapping is done. For example, the first lines of pmap output shows the memory mapping to the text segment of the process' executable. Assume I have a ...
1
vote
0
answers
185
views
php 7.3 mmap munmap too much calls\time on Ubuntu 18+
Good day everyone. Here i have problem with after migrating highload backend php server to new one. ( Dedicated ) . For this point i started comparing ubuntu 16 and 20 ( 18 the same ) .
I bought 2 ...
1
vote
2
answers
508
views
What is lazy swap reservation?
I am reading the Linux Progamming Interface.
49.9 MAP_NORESERVE and Swap Space Overcommitting
Some applications create large (usually private anonymous) mappings,
but use only a small part ...
1
vote
0
answers
2k
views
Mmap failed with operation not permitted
I've compiled application on Linux, but I got this error
wiringPiSetup: mmap (GPIO) failed: Operation not permitted
After that:
I've added iomem=relaxed to grub
cat /proc/cmdline
BOOT_IMAGE=/...
1
vote
1
answer
88
views
Mapping several files into one [closed]
I need to make two files appear as one :
+----------------+ +------------------+
| | | |
|...
1
vote
1
answer
389
views
User-space swap on mmap()-ped files
Imagine a system with very small ram (nearly embedded). It is enough - for nearly all tasks, but with an exception. There is a task X, which requires a huge amount of RAM what the machine has not.
...
2
votes
1
answer
679
views
Mmaping tremendously large files
I have a very large disk drive (2TB), but not very much RAM (8GB). I'd like to be able to run some big data experiments on a large file (~200GB) that exists on my disk's filesystem. I understand that ...
0
votes
0
answers
46
views
Discrepancy between linux man page and implementation of mmap
I am trying to compile a program that requires the mmap(2) to support the flag MAP_SYNC, but my compiler reports that no such thing exists. Now, I manually verified the header file for mmap and found ...
1
vote
1
answer
1k
views
How do I create a temporary file in memory?
I need to create some (small) temporary files in my zsh scripts, and I want them to live on RAM so as to avoid disk IO.
What are the idiomatic ways of doing this? I want it to work on Linux and macOS, ...
1
vote
1
answer
585
views
Weird major page fault number when reading sequentially / randomly in mmap region
I'm following this answer, trying to generate some major page faults with mmap:
#include <fcntl.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/stat.h>
int main(...
5
votes
1
answer
2k
views
mmap: effect of other processes writing to a file previously mapped read-only
I am trying to understand what happens when a file, which has been mapped into memory by the mmap system call, is subsequently written to by other processes.
I have mmaped memory with PROT_READ ...
0
votes
1
answer
205
views
mmap - map to address above 2^48
I understand that the used address space of 64-bit PCs is [0,2^48), but can I use mmap to map a file to an address above 248?
I wrote the following code but found out the mapped address was still ...
1
vote
1
answer
243
views
unlink/rm target of an open symlink
I've come across an issue where processes that load symlinked .so files crash if I update the .so while the processes are still running.
I have long-running processes that load shared libraries (.so)...
0
votes
0
answers
86
views
Is a mmaped file considered an open file in linux/unix?
Hi I feel confused about open file and mmapped file. I know that if a file is accessed using system call such as read/write will return a file descriptor, and be considered as an open file? How about ...
7
votes
1
answer
681
views
ld.so.cache and libc.so.6 memory-mapped for every call?
Playing with strace, it appears to me that ld.so.cache and libc.so.6 are opened and mapped to memory for almost every process. At least those processes that I experimented with. Doesn't this mean ...
2
votes
0
answers
556
views
Is there a standard for the Linux user-space memory map?
I'm contemplating a project where I would use a memory mapped file that is shared between multiple processes, and in order to be able to use pointer values in the mapped region in all those processes*,...
5
votes
2
answers
10k
views
How to use dd if=/dev/mem in place of devmem ?
It seems like
root@testbox:~# dd if=/dev/mem bs=1 count=4 skip=2149646336 | hd
should be nearly equivalent to
root@testbox:~# devmem 2149646336 32
But, while devmem works great, that dd invocation ...
0
votes
2
answers
998
views
Does a forked process copy all mapped memory when writing?
I understand that a forked process maps the parent's memory and copies it when writing to it. Does it copy just what it needs written or does it copy the entire mapped memory ?
1
vote
1
answer
1k
views
Monitoring page cache / memory mapped files access
I have an app that uses multiple memory mapped files. If I check the major page faults numbers (with /proc/<pid>/stat), they skyrocket.
I was wondering if it's possible to monitor somehow what ...
18
votes
5
answers
7k
views
what is the purpose of memory overcommitment on Linux?
I know about memory overcommitment and I profoundly dislike it and usually disable it. I am not thinking of setuid-based system processes (like those running sudo or postfix) but of an ordinary Linux ...
1
vote
0
answers
279
views
journalctl's mmap() calls make it incredibly slow
Whenever I run journalctl, it runs astonishingly slowly. It often takes minutes or even hours to return results. I've experienced some other performance problems on the affected machine that seemed to ...
4
votes
1
answer
6k
views
program stack size
I learned default stack size for each process is limited to 8MB and mmap_base is calculated based on stack size in rlimit and random value. Code below is mmap_base function which calculates mmap_base ...
14
votes
1
answer
16k
views
Understanding mmap
I was going through documentation regarding mmap here and tried to implement it using this video.
I have a few questions regarding its implementation.
Does mmap provide a mapping of a file and return ...
3
votes
0
answers
399
views
How to find part of the code which creates Anonymous private memory mapped region
I'm analyzing /proc/pid/smaps output for C++ process and I find large number of private memory mapped regions. Number of memory mapped regions keep growing based on the traffic.
Is there a way I can ...
6
votes
1
answer
3k
views
If I mmap a file from tmpfs, will it double the memory usage?
I am working on a system where we lock files in memory using mmap and MAP_LOCKED and MAP_POPULATE for performance. If we do this with a file that is in tmpfs, will it use the existing tmpfs memory ...
0
votes
1
answer
463
views
Do regular reads benefit from mmap?
If I use mmap on some file descriptor fd, will regular calls to read() be "aware" that there is a memory mapping of the file and read from memory directly?
What if mlock() is used after mmap(). Is it ...
7
votes
1
answer
332
views
How is the page cache mapped in the kernel on 64-bit x86 architectures?
On a modern 64-bit x86 Linux, how is the mapping between virtual and physical pages set up, kernel side? On the user side, you can mmap in pages from the page cache, and this will map 4K pages in ...
7
votes
1
answer
955
views
OOM from iterating over very large memory map
I'm writing a simulator that relies on generating a (potentially) very large problem domain. As the data can't fit in RAM, I use 4 four memory mapped files to hold it. This is a 64-bit application ...
1
vote
0
answers
101
views
The same program which uses 'mmap' behaves differently on the different machines
I am running an application which uses a huge memory mapped file on two different machines (CentOS 7).
I found that the same program's performance is significantly different when it's running on two ...
2
votes
1
answer
100
views
Doubt about mmap
I'm trying to build a cache package for golang that relies on mmap to store large amounts of content in memory, even more than the system has.
The cache doesn't need to be persistant; every time the ...
1
vote
1
answer
523
views
Pagemap on memory mapped devices not working
I am trying to find the physical addresses of heap variables, stack variables and memory mapped peripheral addresses using the /proc/{pid}/pagemap file using the steps detailed in the file: http://lxr....
3
votes
2
answers
674
views
Can I add to /proc/self?
I want to create a number of named memory regions in my program, and mmap them somewhere so that other processes can read them. I can't guarantee that only one instance of my program will run at a ...
1
vote
3
answers
2k
views
mmap and slow DMA transfers
I have a process that reads data from a hardware device using DMA transfers at a speed of ~4 * 50MB/s and at the same time the data is processed, compressed and written to a 4TB memory mapped file.
...
0
votes
1
answer
191
views
Linux Swap Space
I have 32GB memory. SSD and NonSSD drives.
I installed Linux to NonSSD drive but I prefer SSD for /var directory and I didn't create swap space because there is high memory.
I know physical memory +...