blob: 341bce0e1928c0541f4d01979967a868beeba747 (
plain) (
blame)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
#!/bin/sh
# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
# BEGIN environment bootstrap section
# Do not edit between here and END as this section should stay identical in all scripts
findpath () {
myname=${0}
mypath=${myname%/*}
myname=${myname##*/}
if [ "$mypath" ] && [ -d "$mypath" ]; then
return
fi
mypath=$(pwd)
if [ -f "${mypath}/${myname}" ]; then
return
fi
echo "FATAL: Could not figure out the path where $myname lives from $0"
exit 1
}
COMMON_ENV=libexec/vespa/common-env.sh
source_common_env () {
if [ "$VESPA_HOME" ] && [ -d "$VESPA_HOME" ]; then
export VESPA_HOME
common_env=$VESPA_HOME/$COMMON_ENV
if [ -f "$common_env" ]; then
. $common_env
return
fi
fi
return 1
}
findroot () {
source_common_env && return
if [ "$VESPA_HOME" ]; then
echo "FATAL: bad VESPA_HOME value '$VESPA_HOME'"
exit 1
fi
if [ "$ROOT" ] && [ -d "$ROOT" ]; then
VESPA_HOME="$ROOT"
source_common_env && return
fi
findpath
while [ "$mypath" ]; do
VESPA_HOME=${mypath}
source_common_env && return
mypath=${mypath%/*}
done
echo "FATAL: missing VESPA_HOME environment variable"
echo "Could not locate $COMMON_ENV anywhere"
exit 1
}
findroot
# END environment bootstrap section
bname=`basename $0`
no_valgrind=true
use_callgrind=false
export STD_THREAD_PREVENT_TRY_CATCH=true
export GLIBCXX_FORCE_NEW=1
unset LD_PRELOAD
check_bname_in_value () {
if [ "$1" = "all" ]; then
return 0
fi
for f in $1; do
if [ "$f" = "$bname" ]; then
return 0
fi
done
return 1
}
configure_valgrind () {
no_valgrind=true
if which valgrind >/dev/null; then
if check_bname_in_value $VESPA_USE_VALGRIND; then
no_valgrind=false
valgrind_log=$VESPA_HOME/tmp/valgrind.$bname.log.$$
case $VESPA_VALGRIND_OPT in
*callgrind*) use_callgrind=true;;
esac
fi
fi
}
configure_huge_pages () {
if check_bname_in_value $VESPA_USE_HUGEPAGES_LIST; then
log_debug_message "Want huge pages for '$bname' since VESPA_USE_HUGEPAGES_LIST=${VESPA_USE_HUGEPAGES_LIST}"
export VESPA_USE_HUGEPAGES="yes"
fi
}
configure_use_madvise () {
for f in $VESPA_USE_MADVISE_LIST
do
# log_debug_message "Testing '$f'"
app=`echo $f | cut -d '=' -f1`
limit=`echo $f | cut -d '=' -f2`
if [ "$app" = "$bname" ]; then
log_debug_message "I ($bname) shall use madvise with limit $limit, as set in VESPA_USE_MADVISE_LIST"
export VESPA_MALLOC_MADVISE_LIMIT="$limit"
break
fi
if [ "$app" = "all" ]; then
log_debug_message "I shall use madvise with limit $limit, as VESPA_USE_MADVISE_LIST is 'all'"
export VESPA_MALLOC_MADVISE_LIMIT="$limit"
fi
done
}
configure_vespa_malloc () {
if check_bname_in_value $VESPA_USE_NO_VESPAMALLOC; then
# log_debug_message "Not using vespamalloc for '$bname' since VESPA_USE_NO_VESPAMALLOC=${VESPA_USE_NO_VESPAMALLOC}"
return
fi
suf=vespa/malloc/libvespamalloc.so
if check_bname_in_value $VESPA_USE_VESPAMALLOC_D; then
suf=vespa/malloc/libvespamallocd.so
fi
if check_bname_in_value $VESPA_USE_VESPAMALLOC_DST; then
suf=vespa/malloc/libvespamallocdst16.so
fi
if $no_valgrind || $use_callgrind; then
# should really check that format is same as binary below
for pre in lib64 lib; do
tryfile="${VESPA_HOME}/${pre}/${suf}"
if [ -f "$tryfile" ]; then
LD_PRELOAD="$tryfile"
log_debug_message "Using LD_PRELOAD='$tryfile'"
if [ "$VESPA_USE_HUGEPAGES" ]; then
export VESPA_MALLOC_HUGEPAGES="$VESPA_USE_HUGEPAGES"
log_debug_message "enabling hugepages for '$0-bin'."
fi
break
fi
done
fi
}
configure_numa_ctl () {
numactl=""
if numactl --interleave all true &> /dev/null; then
# We are allowed to use numactl
numactl="numactl --interleave all"
if [ "$VESPA_AFFINITY_CPU_SOCKET" ]; then
numcpu=`numactl --hardware 2>/dev/null | grep available | cut -d' ' -f2`
if [ "$numcpu" ] && [ "$numcpu" -gt 1 ]; then
log_debug_message "Starting $0 with affinity $VESPA_AFFINITY_CPU_SOCKET out of $numcpu"
node=$(($VESPA_AFFINITY_CPU_SOCKET % $numcpu))
numactl="numactl --cpunodebind=$node --membind=$node"
fi
fi
fi
}
configure_valgrind
configure_huge_pages
configure_use_madvise
configure_vespa_malloc
if $no_valgrind ; then
configure_numa_ctl
ulimit -c unlimited
log_debug_message "Starting $0 with : " \
$numactl env LD_PRELOAD=$LD_PRELOAD $0-bin "$@"
exec $numactl env LD_PRELOAD=$LD_PRELOAD $0-bin "$@"
else
if $use_callgrind ; then
export LD_PRELOAD
else
export LD_PRELOAD=""
fi
# ignore signal until shared libraries have loaded, etc:
trap "" SIGTERM
log_debug_message "Starting $0 with : " \
valgrind $VESPA_VALGRIND_OPT --log-file="$valgrind_log" $0-bin "$@"
exec valgrind $VESPA_VALGRIND_OPT --log-file="$valgrind_log" $0-bin "$@"
fi
|