HACKER Q&A
📣 dogol

Keep binaries in system memory never removed till manually done so


How do we have Linux OS to keep some small executable binaries in a system memory location never getting removed till manually instructed so, with purpose to prevent inefficiency repetitive read then load - close then unload the binary from storage and memory?


  👤 h2odragon Accepted Answer ✓
https://en.wikipedia.org/wiki/Sticky_bit

> superuser could tag these files to be retained in main memory, even when their need ends, to minimize swapping that would occur when another need arises, and the file now has to be reloaded from relatively slow secondary memory. This function has become obsolete due to swapping optimization.

.... "the Linux kernel ignores the sticky bit on files."


👤 JoeAltmaier
Yeah this has been a thing since computers.

I had a lock feature in a distributed-client cache back in the day. You could lock in some tool file etc that you used frequently, so performance would be stable over some long operation e.g. a build.

I always wondered if people were really any better at choosing, than my cache algorithm. Hard to say. Can't really take statistics, because you can't measure the pattern they didn't use!


👤 nycpig
VMTouch may be helpful. https://hoytech.com/vmtouch/

Just lock the file into memory using:

```vmtouch -l /path/to/binary```


👤 dezgeg
I think you could make a program to mmap() all the files you want and then call mlockall() and never exit.

👤 malux85
A bit clunky, but can you mount a RAM disk and then put your executables in there? This would at least stop the Disk I/O

👤 bigbillheck
Do you know that you actually need this? Have you measured how much time you're losing to this process?

👤 peter-m80
The filesystem already has a cache

👤 goldenkey
Best to write a launcher that simply forks an existing process that is in the right initial state. Other folks mention caching the ELF file but that will be slower than the loaded executable being cloned for a new process.

👤 sharts
If the binaries are small then to what extent are inefficiencies of read/load affecting the workload?

Modern kernels are probably smart enough to already handle this for repetitive behavior.

Of course you could always profile things to determine what’s happening and whether any of the suggestions actually improve anything.


👤 cpach
tmpfs?