-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrdma_startup.sh
More file actions
executable file
·139 lines (117 loc) · 3.67 KB
/
Copy pathrdma_startup.sh
File metadata and controls
executable file
·139 lines (117 loc) · 3.67 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
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
#! /bin/bash
# copied and modified from https://github.com/uclasystem/hermit/blob/master/remoteswap/client/manage_rswap_client.sh
### CONFIGURATION ###
server_ip="192.168.233.23"
server_port="50000"
user_home=$(eval echo ~$(logname))
swap_file="${user_home}/swapfile"
SWAP_PARTITION_SIZE_GB="64"
### some constants ###
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
client_path="${script_dir}/mirai_client"
client_module="${client_path}/mirai_client.ko"
server_path="${script_dir}/mirai_server"
server_binary="${server_path}/mirai_server"
### Warning ###
echo "!! Warning, check the parameters below : "
echo "Assigned memory server IP ${server_ip} Port ${server_port}"
echo "swapfile ${swap_file}, size ${SWAP_PARTITION_SIZE_GB} GB"
echo " "
### Action ###
action=$1
if [[ -z "${action}" ]]; then
echo "!! No action specified. Please specify one of the following actions:"
echo "[ client_build | client_start | client_restart | client_stop | server_build | erver_start | swap_create | swap_stop ]"
echo ""
read action
fi
function close_swapfiles() {
all_swaps=$(swapon --noheadings --raw | awk '{print $1}')
if [ -z ${all_swaps} ]; then
echo "No active swap files found."
else
echo "Disabling the following swap files:"
echo ${all_swaps}
for swap in ${all_swaps}; do
swapoff "$swap"
done
fi
echo ""
}
function create_swapfile() {
if [[ -e ${swap_file} ]]; then
echo "Checking if existing ${swap_file} has size ${SWAP_PARTITION_SIZE_GB}G..."
cur_size_in_bytes=$(stat -c%s "${swap_file}")
request_size_in_bytes=$((SWAP_PARTITION_SIZE_GB * 1024 * 1024 * 1024))
if [[ "${cur_size_in_bytes}" -ne "${request_size_in_bytes}" ]]; then
echo "Size mismatch: ${swap_file} is not ${SWAP_PARTITION_SIZE_GB}G. Deleting it..."
rm -f "${swap_file}"
else
echo "Existing ${swap_file} matches expected size. Reusing it."
fi
fi
echo ""
if [[ ! -e ${swap_file} ]]; then
echo "Creating ${swap_file} with size ${SWAP_PARTITION_SIZE_GB}G..."
fallocate -l "${SWAP_PARTITION_SIZE_GB}G" "${swap_file}"
chmod 600 "${swap_file}"
mkswap "${swap_file}"
fi
swapon "${swap_file}"
if swapon --show=NAME --noheadings | grep -q "${swap_file}"; then
echo "Successfully mounted ${swap_file} as swap."
else
echo "!! Failed to mount ${swap_file} as swap device."
exit 1
fi
}
function check_permissions() {
if [ "$(id -u)" -ne 0 ]; then
echo "This script with \`${action}\` action must be running as root"
exit
fi
}
if [[ "${action}" = "client_build" ]]; then
make -C ${client_path} clean
make -C ${client_path}
elif [[ "${action}" = "client_start" ]]; then
check_permissions
close_swapfiles
create_swapfile
echo ""
echo "${action}..."
echo "load depdendencies..."
modprobe ib_core
modprobe rdma_cm
insmod ${client_module} ip=${server_ip} port=${server_port} size=${SWAP_PARTITION_SIZE_GB}
elif [[ "${action}" = "client_restart" ]]; then
check_permissions
rmmod ${client_module}
echo "Please restart rdma memory server. Press <Enter> to continue..."
read
echo "${action}..."
insmod ${client_module} ip=${server_ip} port=${server_port} size=${SWAP_PARTITION_SIZE_GB}
elif [[ "${action}" = "client_stop" ]]; then
check_permissions
echo "${action}..."
close_swapfiles
rmmod ${client_module}
elif [[ "${action}" = "server_build" ]]; then
make -C ${server_path} clean
make -C ${server_path}
elif [[ "${action}" = "server_start" ]]; then
echo "${action}..."
echo "Press <Ctrl-C> to stop the server."
bash -c "$server_binary ${server_port}"
exit
elif [[ "${action}" = "swap_create" ]]; then
check_permissions
close_swapfiles
create_swapfile
elif [[ "${action}" = "swap_stop" ]]; then
check_permissions
close_swapfiles
else
echo "!! Wrong choice : ${action}"
exit
fi