22
votes
Accepted
Understanding mmap
Answering things in order:
It returns a pointer to the location in virtual memory, and virtual memory address space is allocated, but the file is not locked in any way unless you explicitly lock it (...
8
votes
Accepted
Sharing file descriptors
When you share a file descriptor over a socket, the kernel mediates. You need to prepare data using the cmsg(3) macros, send it using sendmsg(2) and receive it using recvmsg(2). The kernel is involved ...
5
votes
Share memory between a virtual machine and the host
Actually you can do it, but you need some experience in embedded software development, you can use the concept of inter-VM communication, which is acheived by making a virtual-PCI device available to ...
5
votes
Will swap file engage automatically when I write too much to /dev/shm
I just went ahead and see what happens, when you write too many files to /dev/shm.
OSError: [Errno 28] No space left on device
During handling of the above exception, another exception occurred:
...
4
votes
Accepted
How does a process and its children use memory in case of mmap()?
On fork() the memory space of the parent process is cloned into the child process. As an optimization, modern operating systems use COW (copy on write), so all private memory is shared with the child ...
4
votes
Are sharing a memory-mapped file and sharing a memory region implemented based on each other?
Are sharing a memory-mapped file and sharing a memory region implemented based on each other?
Pretty much, at the end of the day /dev/shm is just a ramdisk.
Does a "memory-mapped file" reside on ...
4
votes
Accepted
Issues Using GPSD as Source for Chronyd
Turns out that gpsd needed the -n flag. I added that in /etc/default/gpsd
-n
Don't wait for a client to connect before polling whatever GPS is associated with it.
Some ...
4
votes
Accepted
Is it possible for two processes to use the same shared-memory without resorting to a file to obtain it, be it a memory-mapped file or /dev/shm file?
Apologies in advance if that is a silly question, but is there such a thing as a pure shared memory between processes, not backed by a file.
Not a silly question!
There is, it's the default way of ...
4
votes
AMDGPU driver vramlimit
I have the same problem and my BIOS Setup dont allow to me change the ammount of shared Video RAM, but i found the documentation of these parameters. I need to check if that works.
https://www.kernel....
3
votes
Accepted
shmget() and shmat()
Yes, that is correct. It's the idea of shared memory that different processes can map the same actual memory; and because of virtual addressing, these addresses don't have to be the same.
You can even ...
2
votes
Accepted
Processor not seeing changes to POSIX shared memory?
As far as I can see, four processes get spawned in quick succession, and each of them tries to do * sum += some_value; it is perfectly possible that they all see * sum as being zero before the ...
2
votes
Is the shared library object loaded as shared memory for the program?
Since all modern OS follow the basic concepts from SunOS-4.0 (1988) and since they are even based on the code from SunOS (Sun offered the sources in the early 1990 to FreeBSD from where is has been ...
2
votes
When should I alter overcommit_memory and what should I take into consideration when doing so?
First of all, I would check the logs if there's any reference for OOM. You might not see the memory consumption increase until it's too late, if a certain program suddenly tries to consume large ...
2
votes
Accepted
FFmpeg cannot write file to /dev/shm: Permission Denied
If you are using snaps, this forum post indicates there are specific patterns that are allowed for files in /dev/shm:
/dev/shm/snap.<snapname>.*
Another forum member suggested this hack, ...
2
votes
Values from sysctl -A don't match /etc/sysctl.conf even after restart
Kudos to alexander-dankin for setting me on the right path.
Per OP, I had a similar issue with fio benchmarking and solved it with a modified version of what Alexander posted.
Below are the steps that ...
2
votes
Accepted
Using IPC_CREAT with an already created shared memory segment
Yes, that's the idea. You use IPC_CREAT to allow the creation, not to force it. To force creation (and failure if the key already exists), IPC_CREAT | IPC_EXCL.
1
vote
Accepted
Can mmap be used to create a file which references memory subset of another file?
You can’t do this with mmap, but you can go directly to the end of your plan and use loopback devices: losetup has an --offset option to specify where a loopback starts in the containing file, and a --...
1
vote
Accepted
Why does ftruncate with a shared memory object not use memory?
The ftruncate system call changes the length of a file, not its size. If you use ls -s on the file before and after ftruncate, you will see the actual size has not changed.
What you have done is to ...
1
vote
Shared Memory using shmget() and shmat()
From an implementation perspective, it's not much different from a file system inside a ramdisk, and this is how Linux implements it.
If you do not delete a file you created before exiting your ...
1
vote
Accepted
Browser (Opera, Chromium...) start causing Permission denied (13) error for shared memory
Looks like a reboot solved the issue.
However I have no idea what happened - and why it only seems to happen to browsers.
1
vote
Accepted
Can a process share unused memory with others?
You're seemingly reading it wrong.
The first column is VIRT, it's inconsequential and in absolute most cases should be ignored completely.
What you're interested in is RSS and each of your processes ...
1
vote
Shared memory using shmget()
The address you get back from shmat() is a virtual address, as is any address which can be used directly as a pointer. Virtual addresses are indirect: they effectively point into address translation ...
1
vote
Accepted
Delete POSIX shared memory owned by different user
Root can delete shared memory (or other IPC items) owned by any user. If you need a pragmatic way to do this, do this as root.
Otherwise, you will need to possibly alter the permissions on the ...
1
vote
Do anonymous memory mapping and shared memory allocate space from physical memory only?
If they allocate memory at all, they only reserve it as space in swap.
mmap, malloc, and shmget allocate space in the calling process’ address space; on Linux, mmap and shmget also reserve space in ...
1
vote
How to revoke write permissions on a shared memory object s.t. subsequent writes to aleady mapped pages by other processes will fail?
This simply isn't possible with Linux permissions model. There's unlikely to be any direct mechanism in the form you are asking.
Why?
Once a process has mmap'd a file, it's access to the file is ...
1
vote
Accepted
calling fsync() on in-memory files
No effect. It is not associated with permanent storage.
Historically, mixing mmap() and read()/write() could give inconsistent results.
Modern Linux is very carefully structured to make it work ...
1
vote
Is it wrong to think of "memfd"s as accounted "to the process that owns the file"?
Building on @danblack's answer:
The decision is based on oom_kill_process() (cleaned up a bit):
for_each_thread(p, t) {
list_for_each_entry(child, &t->children, sibling) {
...
1
vote
Accepted
Change ownership of shared memory
There is no tool do this. Only ipcrm (for deleting presented shared memory objects), ipcmk (for creating shared memory objects) and ipcs (for showing existing shared memory objects) are present (I ...
1
vote
2GB of shared memory used as shown in free
The reason was me making a typo in dd command, writing to a physical file /dev/mmcblk1:
> ll /dev/mmcblk*
-rw-r--r-- 1 root root 1.9G 2017-11-03 18:09 /dev/mmcblk1
brw-rw---- 1 root disk 179, ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
shared-memory × 82linux × 30
memory × 21
mmap × 10
linux-kernel × 7
ipc × 7
c × 6
virtual-memory × 6
posix × 5
ubuntu × 4
process × 4
permissions × 3
fstab × 3
limit × 3
tmpfs × 3
debian × 2
centos × 2
rhel × 2
filesystems × 2
kernel × 2
mount × 2
virtual-machine × 2
kernel-modules × 2
java × 2
ffmpeg × 2