User Tools

Site Tools


Sidebar

software:cgroups

cgroups livedemo on Fedora 15

Showing something live is especially nice, prepared this on my Fedora 15 laptop. Processes are started, cpu usage plotted realtime using gnuplot. Looks like this: https://fluxcoil.net/files/screenshow_cgroups.png

Steps to reproduce:

# start in 2 terminals cpu hog processes. use taskset to ensure they use the same core, makes handling easier.
taskset -c 0 cat /dev/zero >/dev/null

# in a third terminal find out the pids and start gnuplot:
ps ax|grep zero
echo $pin0 >c0/tasks
echo $pin1 >c1/tasks
# get my hackish script that outputs cpu usage of processes:
wget https://fluxcoil.net/files/scripts/watchprocs2.pl
chmod +x watchprocs2.pl
# from http://www.lysium.de/blog/index.php?/archives/234-Plotting-data-with-gnuplot-in-real-time.html get the plotscript:
wget http://www.lysium.de/sw/driveGnuPlotStreams.pl
chmod +x driveGnuPlotStreams.pl
# and start the plotting:
./watchprocs2.pl 22617 22639 | ./driveGnuPlotStreams.pl 2 1 50 -10 110  500x300+0+0 'process0' 'process1' 0 0

# now in a fourth terminal as root change the weight of the processes
cd /sys/fs/cgroup/cpu
mkdir c0 c1
echo $pin0 >c0/tasks
echo $pin1 >c1/tasks
cat c*/cpu.shares
echo 300 >c0/cpu.shares

Using live rendering & displaying also works, but limited - changing the cpu.shares has no big influence. I suspect this is due to the graphics part not beeing weighted and eating many resources then.

exploring the cpu group scheduler subsystem

### mount cgroup
$ mkdir /cgroup
$ mount -t cgroup none /cgroup/

### create 2 groups
$ mkdir admins users

### give the groups resources
$ echo 0 >admins/cpuset.cpus
$ echo 0 >users/cpuset.cpus
$ echo 0 >admins/cpuset.mems
$ echo 0 >users/cpuset.mems

### create 3 processes, watch in a terminal top. The get equal parts of cpu-time
$ taskset -c 0 yes admins >/dev/null &
[1] 3562
$ taskset -c 0 yes users >/dev/null &
[2] 3563
$ taskset -c 0 yes users >/dev/null &
[3] 3564
$ ps -C yes -o pid,args
  PID COMMAND
 3562 yes admins
 3563 yes users
 3564 yes users

### stuff processes into appropriate groups
$ echo 3562 >admins/tasks 
$ echo 3563 >users/tasks
$ echo 3564 >users/tasks
### notice in top how the groups now get equal shares of cpu-resources

### adjust priorities
$ cat admins/cpu.shares 
1024
$ echo 3072 >admins/cpu.shares 

### check how misbehaving processes fall into parent cgroup
$ for i in $(seq 1 30); do $(taskset -c 0 yes misbehaving >/dev/null &); done
$ ps -C yes -o pid,%cpu,args|head    
  PID %CPU COMMAND
 3562 57.7 yes admins
 3563 20.0 yes users
 3564 19.7 yes users
 3600  0.8 yes misbehave
 3602  0.7 yes misbehave
 3604  0.7 yes misbehave
 3606  0.8 yes misbehave
 3608  0.7 yes misbehave
 3610  0.7 yes misbehave

limiting i/o

yum -y install libcgroup
service cgconfig start
mkdir /cgroup/blkio/restrict
echo $$ >/cgroup/blkio/restrict/tasks
modprobe scsi_debug sector_size=1024    # lets screate a device sda working with 1024bytes/block
echo "8:0 104857" >/cgroup/blkio/restrict/blkio.throttle.write_bps_device       # restrict access to 8:0 to 104857b/sec
mkdir /mnt/tmp
mkfs.ext2 -F -b 1024 /dev/sda           # create filesystem w/ 1024b blocksize
mount /dev/sda /mnt/tmp
sync
time for i in {0..99}; do touch /mnt/tmp/file_$i; sync; done    # lets create 100 files there and sync.
                                                                # 1 ext2-block = 1 sd-block touched each time.
umount /mnt/tmp

mkfs.ext2 -F -b 4096 /dev/sda           # create filesystem w/ 1024b blocksize
mount /dev/sda /mnt/tmp
sync
time for i in {0..99}; do touch /mnt/tmp/file_$i; sync; done    # lets create 100 files there and sync.
                                                                # 1 ext2-block = 4 sd-blocks touched each time.
umount /mnt/tmp


mkfs.ext2 -F -b 1024 /dev/sda           # create filesystem w/ 1024b blocksize
mount /dev/sda /mnt/tmp
sync
time for i in {0..99}; do dd if=/dev/zero of=/mnt/tmp/file_$i bs=3500 count=1; sync; done       # lets create 100 files there and sync.
                                                                                                # 4 ext2-blocks = 4 sd-blocks touched each time.
                                                                                                # sda sector_size 1024: real    0m6.591s
                                                                                                # sda sector_size 4096: real    0m11.723s 21s 20s
umount /mnt/tmp
mkfs.ext2 -F -b 4096 /dev/sda           # create filesystem w/ 1024b blocksize
mount /dev/sda /mnt/tmp
sync
time for i in {0..99}; do dd if=/dev/zero of=/mnt/tmp/file_$i bs=3500 count=1; sync; done       # lets create 100 files there and sync.
                                                                                                # 1 ext2-blocks = 4 sd-blocks touched each time.
                                                                                                # sda sector_size 1024: real    0m29.813s
                                                                                                # sda sector_size 4096: real    0m26.088s 30s 29s
umount /mnt/tmp
software/cgroups.txt ยท Last modified: 2019/12/08 12:29 by chris