Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a large file that needs to be accessed (read-only) by several processes. I would like to load the file content into volatile memory at boot and then have the processes access it without communicating with each other.

I was thinking of setting aside physical memory for this purpose, and then hardcode the same physical address in each process. I would let each process make its own mapping to virtual memory, and have one of them write load the file content at boot. Is this possible on Linux (Android)? Is there a better way?

Some more perspective. The file is ~0.5 GB and it's important that read is as fast as possible. Yet the memory is restricted (embedded) so I don't want to have multiple copies of the same file in physical memory. Ideally, I would set aside a contiguous portion of physical memory.

From what I know about mmap, it doesn't load the file directly into memory, instead, it does so in a lazy manner, neither does it allow one to specify which physical memory to allocate to?

I'm thinking about using ION since I am on Android, but it seems to require IPC for sharing a memory handle.

question from:https://stackoverflow.com/questions/65935719/share-a-file-in-volatile-memory-between-processes-without-ipc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
182 views
Welcome To Ask or Share your Answers For Others

1 Answer

Why don't just use classic RAM disk approach? With Linux you can add something like mkdir /tmp/memdisk; mount -t tmpfs -o size=512m myramdisk /tmp/memdisk; cp your_file /tmp/memdisk to one of your system init scripts and just access the file from here. The only real downside of it is that you need root access but for custom embedded devices this should not be a problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...