cgroups blkio subsystem is not counting the block write byte count properly for conatiner applications

坚强是说给别人听的谎言 提交于 2021-01-29 14:33:04

问题


I am working on the linux kernel base 3.14 version and i have enabled the cgroup and blkio subsystem on it for checking the write byte count of the block device from the container and host applications.

But, I have problems in getting the written bytes from the cgroup blkio throttling function for the container application.

It works for the main hierarchy (e.g. /sys/fs/cgroup/blkio/blkio.throttle.io_service_bytes) , but not for the deeper ones (e.g. /sys/fs/cgroup/blkio/lxc/web (container name is web))

I created a small test script (checkWrite), which will simply enter ther cgroup it is started in (pwd) and will create 1M.

  #!/bin/bash

SIZE=1M
DST="/home/root"
#check if we are in the /sys/fs/cgroup/ dir
if [ ! -e ./tasks ]; then
    echo "Error, this script must be started in a cgroup blkio directory"
    echo "Start in or below /sys/fs/cgroup/blkio !"
    exit -1
fi

echo "Using the cgroup: ${PWD##*/cgroup}"

# add myself to cgroup
echo $$ > tasks

mygroup=`cat /proc/$$/cgroup | grep blkio`
echo "we're now in bklio cgroup: ${mygroup}"

# call sync to let kernel store data
sync
sleep 1

# fetch current writen bytes count for eMMC 
before=$(cat blkio.throttle.io_service_bytes | grep "179:24 Write")
echo "before writing: ${before}"

echo "writing ${SIZE} random data to ${DST}/DELME ..."
dd if=/dev/urandom of=${DST}/DELME bs=${SIZE} count=1

sync
sleep 2

# fetch current writen bytes count for eMMC 
after=$(cat blkio.throttle.io_service_bytes | grep "179:24 Write")
echo "after writing: ${after}"
written=$((${after##* }-${before##* }))
written=$((written/1024))
echo "written = ${after##* }B - ${before##* }B = ${written}kB"

rm -rf ${DST}/DELME

The output is;

/sys/fs/cgroup/blkio# ~/checkWrite 
Using the cgroup: /blkio
we're now in bklio cgroup: 3:blkio:/                                                         <- this task is in this blkio chgroup now
before writing: 179:24 Write 200701952                                                   <- from blkio.throttle.io_service_bytes
writing 1M random data to /var/opt/bosch/dynweb/DELME ...
1+0 records in
1+0 records out
after writing: 179:24 Write 201906176
written = 201906176B - 200701952B = **1176kB**                                  **<- fairly ok**

/sys/fs/cgroup/blkio/lxc/web# ~/checkWrite 
Using the cgroup: /blkio/system.slice
we're now in bklio cgroup: 3:blkio:/system.slice
before writing: 179:24 Write 26064896
writing 1M random data to /var/opt/bosch/dynweb/DELME ...
1+0 records in
1+0 records out
after writing: 179:24 Write 26130432
written = 26130432B - 26064896B = **64kB**                                              **<- much too less**

Do I misunderstand the handling?

If it is not working, then how to monitor/watch/read the block device write from the container applications.

来源:https://stackoverflow.com/questions/52760057/cgroups-blkio-subsystem-is-not-counting-the-block-write-byte-count-properly-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!