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)