Skip to main content
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 (...
Austin Hemmelgarn's user avatar
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 ...
Stephen Kitt's user avatar
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 ...
Anmol's user avatar
  • 51
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: ...
Geoffrey Anderson's user avatar
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 ...
cg909's user avatar
  • 7,480
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 ...
Jasen's user avatar
  • 3,915
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 ...
glasstea's user avatar
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 ...
Marcus Müller's user avatar
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....
Luis Felipe Dominguez Vega's user avatar
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 ...
Marcus Müller's user avatar
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 ...
AlexP's user avatar
  • 10.8k
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 ...
schily's user avatar
  • 19.8k
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 ...
aviro's user avatar
  • 6,955
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, ...
jsbillings's user avatar
  • 24.9k
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 ...
pythoninthegrass's user avatar
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.
Marcus Müller's user avatar
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 --...
Stephen Kitt's user avatar
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 ...
user10489's user avatar
  • 10.9k
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 ...
Simon Richter's user avatar
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.
Tobias Reich's user avatar
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 ...
Artem S. Tashkinov's user avatar
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 ...
Stephen Kitt's user avatar
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 ...
Edwin Buck's user avatar
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 ...
Stephen Kitt's user avatar
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 ...
Philip Couling's user avatar
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 ...
sourcejedi's user avatar
  • 53.5k
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) { ...
V13's user avatar
  • 5,135
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 ...
Yurij Goncharuk's user avatar
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, ...
IljaBek's user avatar
  • 123

Only top scored, non community-wiki answers of a minimum length are eligible