Skip to content

Instantly share code, notes, and snippets.

@jhrcz
Last active December 4, 2017 12:00
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jhrcz/5874840 to your computer and use it in GitHub Desktop.
Save jhrcz/5874840 to your computer and use it in GitHub Desktop.
force cpu and blkio thottle of kvm guests
#!/bin/bash
cat /cgroup/blkio/libvirt/qemu/blkio.throttle.read_bps_device
cat /cgroup/blkio/libvirt/qemu/blkio.throttle.write_bps_device
cat /cgroup/blkio/libvirt/qemu/*/blkio.throttle.read_bps_device
cat /cgroup/blkio/libvirt/qemu/*/blkio.throttle.write_bps_device
# 10MBps
#BPSLIMIT=10485760
# 200MBps
#BPSLIMIT=209715200
# 50MBps
#BPSLIMIT=52428800
# 30MBps
BPSLIMIT=31457280
# unlimited / default
#BPSLIMIT=0
DEV_MAJOR=253
DEV_MINOR_LIST="0 1 2"
if [ -n "$1" ]
then
BPSLIMIT="$1"
fi
virsh list --name | while read n
do
[ -n "$n" ] || continue
echo $n
for DEV_MINOR in $DEV_MINOR_LIST
do
echo "$DEV_MAJOR:$DEV_MINOR $BPSLIMIT" > /cgroup/blkio/libvirt/qemu/$n/blkio.throttle.read_bps_device
echo "$DEV_MAJOR:$DEV_MINOR $BPSLIMIT" > /cgroup/blkio/libvirt/qemu/$n/blkio.throttle.write_bps_device
done
cat "/cgroup/blkio/libvirt/qemu/$n/blkio.throttle.read_bps_device"
cat "/cgroup/blkio/libvirt/qemu/$n/blkio.throttle.write_bps_device"
done
cat /cgroup/blkio/libvirt/qemu/blkio.throttle.read_bps_device
cat /cgroup/blkio/libvirt/qemu/blkio.throttle.write_bps_device
cat /cgroup/blkio/libvirt/qemu/*/blkio.throttle.read_bps_device
cat /cgroup/blkio/libvirt/qemu/*/blkio.throttle.write_bps_device
virsh list --name | while read n
do
[ -n "$n" ] || continue
echo $n
echo "/cgroup/cpu/libvirt/qemu/$n/cpu.shares"
cat "/cgroup/cpu/libvirt/qemu/$n/cpu.shares"
vcpu=$(virsh vcpucount --current --maximum $n | head -n 1)
shares=$((1024*$vcpu))
echo "$shares" > "/cgroup/cpu/libvirt/qemu/$n/cpu.shares"
cat "/cgroup/cpu/libvirt/qemu/$n/cpu.shares"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment