使用cgroup 限制進程的磁碟io,cgroup進程磁碟io

來源:互聯網
上載者:User

使用cgroup 限制進程的磁碟io,cgroup進程磁碟io

cat /etc/cgconfig.conf 

#

#  Copyright IBM Corporation. 2007

#

#  Authors:     Balbir Singh <balbir@linux.vnet.ibm.com>

#  This program is free software; you can redistribute it and/or modify it

#  under the terms of version 2.1 of the GNU Lesser General Public License

#  as published by the Free Software Foundation.

#

#  This program is distributed in the hope that it would be useful, but

#  WITHOUT ANY WARRANTY; without even the implied warranty of

#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

#

# See man cgconfig.conf for further details.

#

# By default, mount all controllers to /cgroup/<controller>


mount {

        cpuset  = /cgroup/cpuset;

        cpu     = /cgroup/cpu;

        cpuacct = /cgroup/cpuacct;

        memory  = /cgroup/memory;

        devices = /cgroup/devices;

        freezer = /cgroup/freezer;

        net_cls = /cgroup/net_cls;

        blkio   = /cgroup/blkio;

}

group shard_0{

        blkio{

                blkio.throttle.read_iops_device="253:3 16000";

                blkio.throttle.write_iops_device="253:3 16000";

                blkio.weight="500";

        }

}

group shard_1{

        blkio{

                blkio.throttle.read_iops_device="253:3 16000";

                blkio.throttle.write_iops_device="253:3 16000";

                blkio.weight="500";

        }

}


blkio.throttle.read_iops_device 讀iops

blkio.throttle.write_iops_device 寫iops


253:3是裝置的編號

比如我們要限制進程在flashcache上的iops


[root@test ~]# ls -l /dev/mapper/cachedev

lrwxrwxrwx 1 root root 7 Jan 25 21:16 /dev/mapper/cachedev -> ../dm-3


這裡看到只是一個軟串連,我們接著找

[root@test~]# ls -l /dev/dm-3 

brw-rw---- 1 root disk 253, 3 Jan 25 21:16 /dev/dm-3


因此我們限制某個進程在 flashcache上的iops最高16000就 寫成 253:3 16000


啟動cgroup

[root@c3-b2c-dba-backend-mysql09 /]# service cgconfig restart

Stopping cgconfig service:                                 [  OK  ]

Starting cgconfig service:                                 [  OK  ]


然後就可以將進程id寫進cgroup 對應的task了


[root@test shard_0]# pwd

/cgroup/blkio/shard_0

[root@test shard_0]# cat tasks 

48554

339938

340404

340414

340487

340498

340547

340560

340568

340581

340587

340602

340608

340609

340624

340633

340650

340657

340659

340660

340669

340672

340675

340685

340687

340689

340690

340701

340708

340709

340710

340711

340712

340719

341151

341157

341158

341159

341160

341162

341171

341172

341178

341180

341186

341187

341192

341204

341212

341229

341231

341237

341245

341248

341249

341250

341251

341252

341253

341254

341255

341256

341257

341258

341259

341260

341261

341262

341263

341264

341265

341270

341273

341279

341284

341285

341286

341288

341294

341295

341296

341297

341298

341299

341300

341301

341307

341308

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.