Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I temporally write a file to the filesystem but actually hold it on RAM?

Tags:

file

linux

ram

I have a server that receives a file in a HTTP request, I'd like to make that file available to another process but I don't want the I/O overhead of writing that file to disk.

Are there any directories in linux that are actually mapped to RAM, so the process I start can access a path as is were a normal file?

I know that if I do this in a normal file, then there is a good chance that the file wont actually be flushed to disk because of cache, but that's not what I'm looking for.

like image 445
Martin Volpe Avatar asked Nov 27 '25 13:11

Martin Volpe


2 Answers

There are no guaranteed locations that are backed by RAM, but it's not particularly hard to convert /tmp to be backed by RAM if you have enough of RAM to spare. Given that /tmp is cleaned out on boot anyway, it's an ideal choice for a RAM disk, since data loss due to power loss doesn't matter; the data would have been cleaned on boot anyway.

like image 68
ShadowRanger Avatar answered Nov 30 '25 01:11

ShadowRanger


You can use the following to create a RAM disk (as per these instructions):

mkdir /mnt/ramdisk
mount -t ramfs -o size=512m ramfs /mnt/ramdisk
like image 25
Smeeheey Avatar answered Nov 30 '25 01:11

Smeeheey