Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions cgroup-limit/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ if [[ "$(stat -f -c "%T" /sys/fs/cgroup)" == "cgroup2fs" ]] ; then
CGROUPV2=true
fi

if [[ $CGROUPV2 == true ]] && [[ $(dotnet --version) == "3."* ]]; then
echo "cgroup v2 is not fully supported on .NET Core 3.x. Skipping."
exit 0
fi

# For mono-based runtimes (ppc64le, s390x), cgroup support is only functional
# on .NET 7.0 and later.
if [[ "$(uname -m)" == "s390x" ]] || [[ "$(uname -m)" == "ppc64le" ]] ; then
IFS='.-' read -ra VERSION <<< "${1:-$(dotnet --version)}"
if [[ "${VERSION[0]}" -lt "7" ]]; then
echo "cgroup support is not available on Mono-based runtimes before .NET 7. Skipping."
exit 0
fi
fi

if [ -z "$(command -v systemctl)" ]; then
echo "Environment does not use systemd"
exit 0
Expand All @@ -41,18 +26,17 @@ if [ "$UID" != "0" ]; then
if ! grep -q "cpu" "/sys/fs/cgroup/user.slice/user-$UID.slice/user@$UID.service/cgroup.controllers" ; then
# user can't set cpu limits, use sudo.
SYSTEMD_RUN="sudo -n $SYSTEMD_RUN"

# Pass DOTNET_ROOT to support testing against a dotnet tarball.
# On RHEL 7 we don't pass the envvar because systemd-run doesn't support '-E' yet and the envvar is passed by default.
if [[ "$runtime_id" != "rhel.7"* ]]; then
SYSTEMD_RUN="$SYSTEMD_RUN -E DOTNET_ROOT=$DOTNET_ROOT"
fi
else
# run on behalf of user.
SYSTEMD_RUN="$SYSTEMD_RUN --user"
fi
fi

# Pass DOTNET_ROOT to support testing against a dotnet tarball.
SYSTEMD_RUN="$SYSTEMD_RUN -E DOTNET_ROOT=$DOTNET_ROOT"
# Unset DOTNET_PROCESSOR_COUNT so .NET won't return its value instead of the cgroup CPU limit.
SYSTEMD_RUN="$SYSTEMD_RUN -E DOTNET_PROCESSOR_COUNT="

memory_args="-p MemoryLimit=100M"
if [[ $CGROUPV2 == true ]]; then
memory_args="-p MemoryMax=100M"
Expand Down
Loading