Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 2429  / 2 Years ago, sun, november 6, 2022, 9:08:25

I have the current scenario:




  • 16GB or RAM. For the most part, around 10~12GB unused


  • Almost never install/remove software, this is a mature system


  • Only reboot like once a week, so (re-)boot time is irrelevant


  • /usr is around 8GB


  • HDD is slow, and no budget to change that in the near future


  • Mounting /tmp as tmpfs in fstab did wonders for performance




And I just had this crazy idea:



Is it possible to, somehow, use my RAM to "store" /usr?



In that that, when starting up, it reads current /usr content from HDD and copy it to a tmpfs and mount that as /usr?



If possible, also flushing the (perhaps updated) contents back to HDD when shutting down? Or maybe allowing me to easily "temporarily switch back to HDD" when eventually needed to install/remove new software or updates?



Any approach is welcome, ready-to-use commands will be highly regarded.



Thanks!


More From » mount

 Answers
4

This is possible, but pointless. The kernel keeps a cache of data from the disk in RAM. The data that you used most recently is kept in RAM. You will naturally end up with the parts of /usr that you use often in RAM, and the parts you don't use won't be taking up any RAM.



If you want better reaction time when you start an application, you can seed the cache. A file is loaded into memory the first time you use it, and remains there until the memory is reused for something else. You can force a file to be loaded:



cat /path/to/file >/dev/null


For example, to preload all executables and libraries into RAM:



cat /bin/* /lib/* /usr/bin/* /usr/lib/* >/dev/null


This can take a while to complete, so you should do it in the background. You can put the following command in /etc/rc.local:



ionice -c 3 cat /bin/* /lib/* /usr/bin/* /usr/lib/* >/dev/null &


To also load all libraries in subdirectories of /usr/lib* it could be useful to run find:



ionice -c 3 find /bin /usr/bin /usr/lib* -type f -exec ionice -c 3 cat '{}' ';' > /dev/null &

[#38508] Monday, November 7, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
horicgly

Total Points: 36
Total Questions: 126
Total Answers: 104

Location: Iceland
Member since Thu, Dec 1, 2022
1 Year ago
horicgly questions
Thu, Jun 23, 22, 15:02, 2 Years ago
Wed, Nov 10, 21, 00:19, 3 Years ago
Thu, May 5, 22, 14:58, 2 Years ago
;