mapex: use more RAM, get rid of program startup lag
Posted: 11. Sep 2014, 16:29
You know the story: you have a hulking workstation with a dozen GB of RAM, but you still have to wait for the hard disk to do its thing when you start a new program. This vexes me a bit, so I wrote a Python script to solve it:
It would be invoked on a bunch of top level directories, like 'mapex.py /var /usr /opt'; maybe from a xinitrc or xprofile script. On the workstation I'm on now (Fedora 20, 4 GB RAM) it
- runs in 3-5 seconds
- causes the page cache to inflate by several hundred MB
- makes applications subsequently load in less than half the normal time
Needless to say it won't be very helpful on machines with < 1 GB of RAM.
(Also it's probably not idiomatic Python, but it gets the job done so whatever...)
Edit: slightly less stupid version below...
Edit: yeah, let's *not* try for write access to files in /usr!
Code: Select all
#!/usr/bin/env python2
import mmap, os, sys
import os.path
for paths in sys.argv:
for root, dirs, files in os.walk(paths):
for f in files:
if (os.path.isfile(f) > 0) and (os.path.getsize(f) > 0):
with open(f, "rb") as fd:
mmap.mmap(fd.fileno(), 0)
- runs in 3-5 seconds
- causes the page cache to inflate by several hundred MB
- makes applications subsequently load in less than half the normal time
Needless to say it won't be very helpful on machines with < 1 GB of RAM.
(Also it's probably not idiomatic Python, but it gets the job done so whatever...)
Edit: slightly less stupid version below...
Code: Select all
#!/usr/bin/env python2
import mmap, os, os.path, sys
f_list = []
for arg in sys.argv:
for root, dirs, files in os.walk(arg, followlinks=True):
f_list.extend(files)
for f in f_list:
if (os.path.exists(f) > 0) and (os.path.getsize(f) > 0) and (os.path.isfile(f) > 0):
with open(f, "rb") as fd:
mmap.mmap(fd.fileno(), 0)