-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.sh
executable file
·61 lines (48 loc) · 1.17 KB
/
preload.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
set -euo pipefail
cd "$(dirname "$0")"
# Don't slow down the boot process, start preloading after
if [ "${1:-}" == "boot" ]; then
sleep 30
fi
source "config"
if uname -r | grep -qE '-server$'; then
printf >&2 -- "Not preloading as we're running the server kernel\n"
exit
fi
function get_payload {
cat -- "${list_dir}"/*.list | grep -vE '^#|^$' | xargs -I{} readlink -m {} | sort -u
}
function calc_size {
local -i total_size=0
local -i count=0
while read path; do
if [ -e "${path}" ]; then
local -i size="$(stat -c%s "${path}")"
total_size+=size
count+=1
fi
done < "${full_list}"
printf -- "%d files, %dMB\n" "${count}" "$((total_size / 1048576))"
}
declare -r mode="${1:-}"
function rm_full_list {
rm -f -- "${full_list}"
}
declare -r full_list="$(mktemp)"
trap rm_full_list EXIT
get_payload > "${full_list}"
if [ "${mode}" == "debug" ] || [ "${mode}" == "dry" ]; then
calc_size
fi
if [ "${mode}" != "dry" ]; then
printf -- "Preloading\n"
declare -r arch="$(uname -m)"
killall -q do_preload || true
ionice -c 3 \
nice -n 20 \
./do_preload < "${full_list}" &
declare -ri pid="$!"
echo '1000' > "/proc/${pid}/oom_score_adj"
wait "${pid}"
fi