Last active
December 17, 2015 00:19
-
-
Save kakra/5520200 to your computer and use it in GitHub Desktop.
A very basic ruby script for defragmenting files on btrfs loaded by preload daemon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env ruby | |
# | |
# basic concept script for defragmenting files on btrfs loaded by preload daemon | |
# | |
# Actually, this idea is working in the spirit of systemd's readahead function which | |
# can defrag (and relocate?) files on btrfs during boot. Preload takes on where | |
# readahead stops working, so it should be a great place to continue integrating that | |
# idea there. This script is actually here, to test the impact of such an idea and | |
# find first caveats and show-stoppers. | |
# | |
# Author: Kai Krakow <[email protected]> | |
# License: GPL3 | |
file_already_queued = {} | |
IO.popen('xargs --no-run-if-empty --max-args=20 --max-procs=3 --null btrfs filesystem defragment -v -clzo', 'w') do |xargs| | |
File.foreach('/var/lib/preload/preload.state') do |line| | |
next unless %r{^(EXE|MAP)\s.*?file://(.*)} =~ line | |
next if file_already_queued[name = $2] | |
if File.exists?(name) | |
xargs.print "#{name}\0" | |
file_already_queued[name] = true | |
end | |
end | |
xargs.flush | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment