3

I am trying to restrict I/O write usage on my server using cgroups.

Here is my partition table info:

major minor  #blocks  name    
   8        0   10485760 sda
   8        1    9437184 sda1
   8        2    1047552 sda2

Here is my Filesystem structure:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       8.9G  8.4G   37M 100% /
none           1004M     0 1004M   0% /dev/shm

Here is my cgroups configuration:

mount { 
    blkio = /cgroup/blkio;      
}

group test2 {
    blkio {
        blkio.throttle.write_iops_device="";
        blkio.throttle.read_iops_device="8:0 10485760";
        blkio.throttle.write_bps_device="";
        blkio.throttle.read_bps_device="8:0 10485760";
        blkio.weight="";
        blkio.weight_device="";
    }
}

When I execute the following read command, it restrict the read operation to use only 10 B/s

dd if=file_1 of=/dev/zero

When I execute the following Write command, it is not restricting as per the configuration

dd of=file_1 if=/dev/zero

What am I missing?

  • 2
    It looks like you're out of space... – ewwhite Mar 10 '15 at 11:34
  • Write operation is working fine, but it should not use more than 10 B/s but it uses around 70 to 80 B/s – Divij Satra Mar 10 '15 at 11:59
  • 1
    But... You are out of disk space. – ewwhite Mar 10 '15 at 12:05
  • I have remove the some log files after that here is my new Filesystem structure: `Filesystem Size Used Avail Use% Mounted on /dev/sda1 8.9G 1.1G 7.5G 12% / none 1004M 0 1004M 0% /dev/shm` But still i cant restrict to Write I/O operation – Divij Satra Mar 10 '15 at 13:31
  • @DivijSatra You are actually restricting the read stage to 10 **MB/s** not 10 *B/s*. Writing to `/dev/zero` is probably what leads to confusion about the transfer rate since dd compute this based on read and write rates and is not aware that the target file descriptor will discard the data behind the scenes, making the write operation to return very fast to the caller without actually writing any block. – Xavier Lucas Mar 10 '15 at 18:34
  • Hi, Yes its 10 MB/s not 10 B/s. i have change the command .Now my dd command to `dd of=file_2 if=file_1 bs=24M count=100` so now reading and writing are from same account but write usage is not under the 10 MB/s here is the output of iotop command `Total DISK READ: 43.45 M/s | Total DISK WRITE: 113.88 M/s TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND 1497 be/4 test2 43.45 M/s 47.53 M/s 0.00 % 84.64 % dd of=fil~ count=100 1434 be/4 test2 0.00 B/s 0.00 B/s 0.00 % 0.00 % -bash` – Divij Satra Mar 11 '15 at 07:06
  • @DivijSatra Do you actually add the command PID to group2 tasklist before the read/write operations take place ? – Xavier Lucas Mar 23 '15 at 00:27
  • NO. Firstly there is no tasklist file there is only tasks file in that i cant write any thing. simply i just run the following command:`echo PID > /cgroup/blkio/test2/tasks` i got the error like: `-bash: echo: write error: Invalid argument` – Divij Satra Mar 24 '15 at 10:44

1 Answers1

1

You probably sorted it out by now, but according to this blog post you need to tell dd to open the output file with O_DIRECT flag, otherwise caching kicks in and your cgroup config becomes useless:

dd of=file_1 if=/dev/zero oflag=direct
Lucio Crusca
  • 420
  • 3
  • 12
  • 33