0

I have an application which opens a large file (about 1-2GB) every time it runs.

For development/testing reasons, I need to keep restarting the application, and the 30s-1m wait time to load the file from HDD becomes a bit inconvenient.

Is there a way to put the file in the RAM (and keep it there), so loading would be faster?

1
  • Would a ramdisk be an option? Commented Mar 13, 2020 at 13:03

2 Answers 2

7

If your system has enough RAM, the file should be cached in memory, so it shouldn’t be re-read from the drive every time.

You can try to force the issue by copying the file to a tmpfs file system, and load it from there. tmpfs file systems are RAM-based. Most distributions now use a tmpfs for /tmp, so copying the file there will work; if you need to, you can mount a tmpfs yourself somewhere else and copy the file there. However, if memory is short, the contents of a tmpfs can be swapped out, so you may end up reading from swap.

2

The file system should already cache the file if you have enough RAM.

However, to create a dedicated 2GiB RAM-disk at /tmp/ramdisk for the purpose you can do the following:

sudo mkdir /tmp/ramdisk sudo mount -t tmpfs -o size=2G myramdisk /tmp/ramdisk 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.