-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_huge.sh
More file actions
executable file
·102 lines (89 loc) · 3.72 KB
/
Copy pathrun_huge.sh
File metadata and controls
executable file
·102 lines (89 loc) · 3.72 KB
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
#!/bin/bash
# Function to check THP settings
check_thp_settings() {
local enabled=$(cat /sys/kernel/mm/transparent_hugepage/enabled 2>/dev/null)
local defrag=$(cat /sys/kernel/mm/transparent_hugepage/defrag 2>/dev/null)
local errors=0
local advice=""
# Check if THP is supported
if [ ! -f "/sys/kernel/mm/transparent_hugepage/enabled" ]; then
echo "ERROR: Transparent HugePages not supported on this system!"
echo " Your kernel might not support THP or it might be disabled in BIOS."
return 1
fi # Changed this line - removed extra }
# Check enabled status
if [[ ! "$enabled" =~ "always"|"madvise" ]]; then
errors=$((errors + 1))
advice="${advice}- Transparent HugePages is not properly enabled.\n"
advice="${advice} Current setting: $enabled\n"
advice="${advice} Run as root: echo madvise > /sys/kernel/mm/transparent_hugepage/enabled\n\n"
fi
# Check defrag status
if [[ ! "$defrag" =~ "always"|"madvise" ]]; then
errors=$((errors + 1))
advice="${advice}- THP defragmentation is not properly configured.\n"
advice="${advice} Current setting: $defrag\n"
advice="${advice} Run as root: echo madvise > /sys/kernel/mm/transparent_hugepage/defrag\n\n"
fi
# If there are errors, display advice
if [ $errors -gt 0 ]; then
echo "WARNING: System is not optimally configured for huge pages!"
echo -e "$advice"
echo "To make these changes permanent, create a systemd service:"
echo "1. Create /etc/systemd/system/hugepage-settings.service with:"
echo "[Unit]"
echo "Description=Set Transparent Hugepage Settings"
echo "After=network.target"
echo ""
echo "[Service]"
echo "Type=oneshot"
echo "ExecStart=/bin/bash -c 'echo madvise > /sys/kernel/mm/transparent_hugepage/enabled && echo madvise > /sys/kernel/mm/transparent_hugepage/defrag'"
echo "RemainAfterExit=yes"
echo ""
echo "[Install]"
echo "WantedBy=multi-user.target"
echo ""
echo "2. Then run:"
echo " sudo systemctl enable hugepage-settings"
echo " sudo systemctl start hugepage-settings"
echo ""
fi
return $errors
}
# Usage check
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <path_to_executable> [args...]"
exit 1
fi
# Check THP settings
check_thp_settings
# Get the executable and its arguments
EXECUTABLE=$1
shift
# Set LD_AUDIT and LD_LIBRARY_PATH_DIR
CURRENT_DIR=$(pwd)
LD_AUDIT_PATH="./bin/tpromote.so"
LD_LIBRARY_PATH_DIR="$CURRENT_DIR/output"
# Check if required files exist
if [ ! -f "$LD_AUDIT_PATH" ]; then
echo "ERROR: tpromote.so not found in ./bin/ directory!"
echo "Please run 'make' first to build tpromote.so"
exit 1
fi
if [ ! -d "$LD_LIBRARY_PATH_DIR" ]; then
echo "WARNING: output directory not found. Creating it..."
mkdir -p "$LD_LIBRARY_PATH_DIR"
fi
# Check if we should use tdispatch for better coverage
TDISPATCH_PATH="./bin/tdispatch"
if [ -f "$TDISPATCH_PATH" ] && [ -x "$TDISPATCH_PATH" ]; then
# Run with tdispatch which will analyze dependencies and ensure all get huge pages
echo "Running with tdispatch and huge page support..."
echo "Command: HUGIFIER_VERBOSE=1 LD_AUDIT=$LD_AUDIT_PATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH_DIR $TDISPATCH_PATH $EXECUTABLE $@"
HUGIFIER_VERBOSE=1 LD_AUDIT=$LD_AUDIT_PATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH_DIR "$TDISPATCH_PATH" "$EXECUTABLE" "$@"
else
# Fallback to direct execution
echo "Running with huge page support..."
echo "Command: LD_AUDIT=$LD_AUDIT_PATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH_DIR $EXECUTABLE $@"
LD_AUDIT=$LD_AUDIT_PATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH_DIR "$EXECUTABLE" "$@"
fi