if [[ "$1" == "-cgroup-v2" ]]; then
cgroup2=1
usage_file=current fi
if [[ $cgroup2 ]]; then
CGROUP_ROOT=$(mount -t cgroup2 | head -1 | awk '{print $3}') if [[ -z "$CGROUP_ROOT" ]]; then
CGROUP_ROOT=$(mktemp -d)
mount -t cgroup2 none $CGROUP_ROOT
do_umount=1 fi echo"+hugetlb +memory" >$CGROUP_ROOT/cgroup.subtree_control else
CGROUP_ROOT=$(mount -t cgroup | grep ",hugetlb" | awk '{print $3}') if [[ -z "$CGROUP_ROOT" ]]; then
CGROUP_ROOT=/dev/cgroup/memory
mount -t cgroup memory,hugetlb $CGROUP_ROOT
do_umount=1 fi fi
MNT='/mnt/huge'
function assert_with_retry() {
local actual_path="$1"
local expected="$2"
local tolerance=$((7 * 1024 * 1024))
local timeout=20
local interval=1
local start_time
local now
local elapsed
local actual
start_time=$(date +%s)
while true; do
actual="$(cat "$actual_path")"
if [[ $actual -ge $(($expected - $tolerance)) ]] &&
[[ $actual -le $(($expected + $tolerance)) ]]; then
return 0 fi
now=$(date +%s)
elapsed=$((now - start_time))
if [[ $elapsed -ge $timeout ]]; then echo"actual = $((${actual%% *} / 1024 / 1024)) MB" echo"expected = $((${expected%% *} / 1024 / 1024)) MB"
cleanup
exit 1 fi
sleep $interval done
}
function assert_state() {
local expected_a="$1"
local expected_a_hugetlb="$2"
local expected_b=""
local expected_b_hugetlb=""
if [ ! -z ${3:-} ] && [ ! -z ${4:-} ]; then
expected_b="$3"
expected_b_hugetlb="$4" fi
if [[ -n "$expected_b" && -n "$expected_b_hugetlb" ]]; then
assert_with_retry "$CGROUP_ROOT/a/b/memory.$usage_file""$expected_b"
assert_with_retry "$CGROUP_ROOT/a/b/hugetlb.${MB}MB.$usage_file""$expected_b_hugetlb" fi
}
function setup() { echo 100 >/proc/sys/vm/nr_hugepages
mkdir "$CGROUP_ROOT"/a
sleep 1 if [[ $cgroup2 ]]; then echo"+hugetlb +memory" >$CGROUP_ROOT/a/cgroup.subtree_control else echo 0 >$CGROUP_ROOT/a/cpuset.mems echo 0 >$CGROUP_ROOT/a/cpuset.cpus fi
mkdir "$CGROUP_ROOT"/a/b
if [[ ! $cgroup2 ]]; then echo 0 >$CGROUP_ROOT/a/b/cpuset.mems echo 0 >$CGROUP_ROOT/a/b/cpuset.cpus fi
mkdir -p "$MNT"
mount -t hugetlbfs none "$MNT"
}
write_hugetlbfs() {
local cgroup="$1"
local path="$2"
local size="$3"
if [[ $cgroup2 ]]; then echo $$ >$CGROUP_ROOT/$cgroup/cgroup.procs else echo 0 >$CGROUP_ROOT/$cgroup/cpuset.mems echo 0 >$CGROUP_ROOT/$cgroup/cpuset.cpus echo $$ >"$CGROUP_ROOT/$cgroup/tasks" fi
./write_to_hugetlbfs -p "$path" -s "$size" -m 0 -o if [[ $cgroup2 ]]; then echo $$ >$CGROUP_ROOT/cgroup.procs else echo $$ >"$CGROUP_ROOT/tasks" fi echo
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.