Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
switch from cgroups v1 to v2
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3934
Location: Hamburg

PostPosted: Sun Jan 24, 2021 11:40 am    Post subject: switch from cgroups v1 to v2 Reply with quote

I do wonder if it has an advantage and if - how can I convert my current logic:
Code:
#!/bin/sh
# set -x

# set cgroup v1 limits

set -euf
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
export LANG=C.utf8


# use cgroup v1 if available
if ! hash -r cgcreate || ! hash -r cgset || ! -d /sys/fs/cgroup; then
  exit 0
fi

# make this script available for non-tinderbox consumers too
cp /opt/tb/bin/cgroup-release-agent.sh /usr/local/bin/
chmod 755 /usr/local/bin/cgroup-release-agent.sh

echo 1 > /sys/fs/cgroup/memory/memory.use_hierarchy
for i in cpu memory
do
  echo "/usr/local/bin/cgroup-release-agent.sh" > /sys/fs/cgroup/$i/release_agent
done

# prefer a generic name b/c "tinderbox" is just one consumer of CGroups
name=/local
cgcreate -g cpu,memory:$name

# reserve 8 vCPU for members of $name, period=0.1 sec
cgset -r cpu.cfs_quota_us=800000  $name

# reserve 120 GB RAM (8GB left) and 140 GB RAM+swap
cgset -r memory.limit_in_bytes=120G       $name
cgset -r memory.memsw.limit_in_bytes=140G $name
to have asubgroup called local which is used later as
Code:
function CgroupCreate() {
  local name=$1
  local pid=$2

  # use cgroup v1 if available
  if ! hash -r cgcreate || ! hash -r cgset || ! -d /sys/fs/cgroup; then
    return 0
  fi

  cgcreate -g cpu,memory:$name

  cgset -r cpu.cfs_quota_us=150000          $name
  cgset -r memory.limit_in_bytes=20G        $name
  cgset -r memory.memsw.limit_in_bytes=30G  $name

  for i in cpu memory
  do
    echo      1 > /sys/fs/cgroup/$i/$name/notify_on_release
    echo "$pid" > /sys/fs/cgroup/$i/$name/tasks
  done
}
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum