github.com/eth-easl/loader@v0.0.0-20230908084258-8a37e1d94279/scripts/isolation/define_cgroup.sh (about) 1 #!/usr/bin/env bash 2 3 # 4 # MIT License 5 # 6 # Copyright (c) 2023 EASL and the vHive community 7 # 8 # Permission is hereby granted, free of charge, to any person obtaining a copy 9 # of this software and associated documentation files (the "Software"), to deal 10 # in the Software without restriction, including without limitation the rights 11 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 # copies of the Software, and to permit persons to whom the Software is 13 # furnished to do so, subject to the following conditions: 14 # 15 # The above copyright notice and this permission notice shall be included in all 16 # copies or substantial portions of the Software. 17 # 18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 # SOFTWARE. 25 # 26 27 CURRENT_USER=$SUDO_USER 28 29 sudo apt-get install cgroup-tools cgroupfs-mount libcgroup1 -y 30 31 # If it's not already mounted, mount the cpuset 32 if [[ ! $(mount | grep cpuset) ]] ; then 33 mount -t cgroup -ocpuset cpuset /sys/fs/cgroup/cpuset 34 fi 35 36 # Create a group with the $CURRENT_USER who is able to write the task file. 37 cgcreate -a $CURRENT_USER -t $CURRENT_USER -g cpuset,memory:loader-cg 38 39 # Assign a full socket (8 cores) to it. 40 echo "8-15" > /sys/fs/cgroup/cpuset/loader-cg/cpuset.cpus 41 echo "0" > /sys/fs/cgroup/cpuset/loader-cg/cpuset.mems 42 43 # Specify memory limit (20GiB). 44 echo "21470000000" > /sys/fs/cgroup/memory/loader-cg/memory.limit_in_bytes 45 46 echo 'CGroup loader-cg created'