0000-readahead 1.03 KB
Newer Older
1 2 3 4 5 6 7 8 9
#!/bin/sh

READAHEAD_LIST="/usr/share/amnesia/readahead-list"
BACKGROUND_AT="^usr/bin/Xorg$"

Readahead ()
{

	# Do not readahead when "profile" appears on kernel command line
10 11 12 13
	if grep -qw "profile" /proc/cmdline
	then
		return 0
	fi
14

15 16 17 18 19
	if ! test -e "$READAHEAD_LIST"
	then
		echo "the readahead list (${READAHEAD}) does not exist."
		return
	fi
20 21 22 23 24 25 26

	echo " readahead"
	Start_readahead
}

Start_readahead ()
{
27 28
	FG_FILES="sed -n -e \\:$BACKGROUND_AT:q;p $READAHEAD_LIST"
	BG_FILES="sed -n -e \\:$BACKGROUND_AT:,\$p $READAHEAD_LIST"
29 30
	FG_SIZE=$(
	 cd /
31
	 $FG_FILES |
32
	 xargs du -bc 2>/dev/null |
33 34
	 awk '$2 ~ /^total$/ { t = t + $1 } END { print t }')
	(cd /
35
	 $BG_FILES |
36
	 xargs stat >/dev/null 2>/dev/null || :)
37
	(cd /
38
	 $FG_FILES |
39
	 xargs cat 2>/dev/null |
40
	 pv -f -s ${FG_SIZE} >/dev/null || :)
41
	(cd /
42
	 start-stop-daemon \
43 44
		--start --background --make-pidfile --startas /bin/sh \
		--pidfile /var/run/background-readahead.pid -- \
45
		-c "$BG_FILES | xargs cat >/dev/null 2>&1")
46 47 48 49 50 51

	# Creating state file
	touch /var/lib/live/config/readahead
}

Readahead