/rampin

Try to make Windows preload files into RAM by memory mapping and touching them.

Primary LanguageCThe UnlicenseUnlicense

rampin

A small C program to try keep a file or few in Windows RAM cache. For a Unix (not only Linux) alternative see vmtouch.

Takes one or more filenames as arguments, opens them as read only and memory maps them whole, then accesses each 4 KiB page of it to bring them into memory and then sleeps for 30 seconds and accesses them again to keep them in memory.

By default it never quits so you'll have to somehow kill it once you are done.

A sole -h will print full help to stdout. Options -0, -1, etc. up to -9 will make it quit after that many sleep + touch loops, not counting the initial one so -0 will map the file, touch all pages once, and quit right after, -1 will map, touch once, and sleep once and touch again and then quit, etc.

This program only makes sense if you have RAM to spare and/or are on 64-bit. I wrote it to speed up level loading in an old game that has a total of 5 GiB of assets and a 32-bit exe, so the game, OS and all the assets fit into my PC's RAM.

This program might easily backfire if used too greedily and your OS might start paging to disk!

To make it easier to rampin entire dir tree I use this help script named rampintree, but mapping and touching many files one after another has been added recently to the rampin program itself so just rampin * or rampin + list of files works too. You can write a similar script in Powershell, Batch, pure sh and Busybox, etc.

In the future rampin will likely offer an option to recurse directories on its own (if you need that option now you can open an issue here to let me know).

#!/bin/bash

if [ "$#" -eq 1 ]
then
    find "$1" -type f | xargs -P 99000 -I @ rampin @
fi

The above might work poorly and cause lower reading speeds on an HDD. For an HDD a script that reads files one by one (and uses only one process) could be:

#!/bin/bash
if [ "$#" -eq 1 ]
then
    rampin `find "$1" -type f`
fi

Go to releases to download a Windows exe compiled with Pelles C with no -O2 to avoid running into any -O2 optimizer bug similar to this one that affected stb_image: Pelles C forum bug report