blk-cgroup.c (bb9d97b6dffa10cec5e1ce9adbce60f3c2b5eabc) | blk-cgroup.c (6e736be7f282fff705db7c34a15313281b372a76) |
---|---|
1/* 2 * Common Block IO controller cgroup interface 3 * 4 * Based on ideas and code from CFQ, CFS and BFQ: 5 * Copyright (C) 2003 Jens Axboe <axboe@kernel.dk> 6 * 7 * Copyright (C) 2008 Fabio Checconi <fabio@gandalf.sssup.it> 8 * Paolo Valente <paolo.valente@unimore.it> --- 16 unchanged lines hidden (view full) --- 25static DEFINE_SPINLOCK(blkio_list_lock); 26static LIST_HEAD(blkio_list); 27 28struct blkio_cgroup blkio_root_cgroup = { .weight = 2*BLKIO_WEIGHT_DEFAULT }; 29EXPORT_SYMBOL_GPL(blkio_root_cgroup); 30 31static struct cgroup_subsys_state *blkiocg_create(struct cgroup_subsys *, 32 struct cgroup *); | 1/* 2 * Common Block IO controller cgroup interface 3 * 4 * Based on ideas and code from CFQ, CFS and BFQ: 5 * Copyright (C) 2003 Jens Axboe <axboe@kernel.dk> 6 * 7 * Copyright (C) 2008 Fabio Checconi <fabio@gandalf.sssup.it> 8 * Paolo Valente <paolo.valente@unimore.it> --- 16 unchanged lines hidden (view full) --- 25static DEFINE_SPINLOCK(blkio_list_lock); 26static LIST_HEAD(blkio_list); 27 28struct blkio_cgroup blkio_root_cgroup = { .weight = 2*BLKIO_WEIGHT_DEFAULT }; 29EXPORT_SYMBOL_GPL(blkio_root_cgroup); 30 31static struct cgroup_subsys_state *blkiocg_create(struct cgroup_subsys *, 32 struct cgroup *); |
33static int blkiocg_can_attach(struct cgroup_subsys *, struct cgroup *, 34 struct cgroup_taskset *); 35static void blkiocg_attach(struct cgroup_subsys *, struct cgroup *, 36 struct cgroup_taskset *); | 33static int blkiocg_can_attach_task(struct cgroup *, struct task_struct *); 34static void blkiocg_attach_task(struct cgroup *, struct task_struct *); |
37static void blkiocg_destroy(struct cgroup_subsys *, struct cgroup *); 38static int blkiocg_populate(struct cgroup_subsys *, struct cgroup *); 39 40/* for encoding cft->private value on file */ 41#define BLKIOFILE_PRIVATE(x, val) (((x) << 16) | (val)) 42/* What policy owns the file, proportional or throttle */ 43#define BLKIOFILE_POLICY(val) (((val) >> 16) & 0xffff) 44#define BLKIOFILE_ATTR(val) ((val) & 0xffff) 45 46struct cgroup_subsys blkio_subsys = { 47 .name = "blkio", 48 .create = blkiocg_create, | 35static void blkiocg_destroy(struct cgroup_subsys *, struct cgroup *); 36static int blkiocg_populate(struct cgroup_subsys *, struct cgroup *); 37 38/* for encoding cft->private value on file */ 39#define BLKIOFILE_PRIVATE(x, val) (((x) << 16) | (val)) 40/* What policy owns the file, proportional or throttle */ 41#define BLKIOFILE_POLICY(val) (((val) >> 16) & 0xffff) 42#define BLKIOFILE_ATTR(val) ((val) & 0xffff) 43 44struct cgroup_subsys blkio_subsys = { 45 .name = "blkio", 46 .create = blkiocg_create, |
49 .can_attach = blkiocg_can_attach, 50 .attach = blkiocg_attach, | 47 .can_attach_task = blkiocg_can_attach_task, 48 .attach_task = blkiocg_attach_task, |
51 .destroy = blkiocg_destroy, 52 .populate = blkiocg_populate, 53#ifdef CONFIG_BLK_CGROUP 54 /* note: blkio_subsys_id is otherwise defined in blk-cgroup.h */ 55 .subsys_id = blkio_subsys_id, 56#endif 57 .use_id = 1, 58 .module = THIS_MODULE, --- 1564 unchanged lines hidden (view full) --- 1623} 1624 1625/* 1626 * We cannot support shared io contexts, as we have no mean to support 1627 * two tasks with the same ioc in two different groups without major rework 1628 * of the main cic data structures. For now we allow a task to change 1629 * its cgroup only if it's the only owner of its ioc. 1630 */ | 49 .destroy = blkiocg_destroy, 50 .populate = blkiocg_populate, 51#ifdef CONFIG_BLK_CGROUP 52 /* note: blkio_subsys_id is otherwise defined in blk-cgroup.h */ 53 .subsys_id = blkio_subsys_id, 54#endif 55 .use_id = 1, 56 .module = THIS_MODULE, --- 1564 unchanged lines hidden (view full) --- 1621} 1622 1623/* 1624 * We cannot support shared io contexts, as we have no mean to support 1625 * two tasks with the same ioc in two different groups without major rework 1626 * of the main cic data structures. For now we allow a task to change 1627 * its cgroup only if it's the only owner of its ioc. 1628 */ |
1631static int blkiocg_can_attach(struct cgroup_subsys *ss, struct cgroup *cgrp, 1632 struct cgroup_taskset *tset) | 1629static int blkiocg_can_attach_task(struct cgroup *cgrp, struct task_struct *tsk) |
1633{ | 1630{ |
1634 struct task_struct *task; | |
1635 struct io_context *ioc; 1636 int ret = 0; 1637 1638 /* task_lock() is needed to avoid races with exit_io_context() */ | 1631 struct io_context *ioc; 1632 int ret = 0; 1633 1634 /* task_lock() is needed to avoid races with exit_io_context() */ |
1639 cgroup_taskset_for_each(task, cgrp, tset) { 1640 task_lock(task); 1641 ioc = task->io_context; 1642 if (ioc && atomic_read(&ioc->nr_tasks) > 1) 1643 ret = -EINVAL; 1644 task_unlock(task); 1645 if (ret) 1646 break; 1647 } | 1635 task_lock(tsk); 1636 ioc = tsk->io_context; 1637 if (ioc && atomic_read(&ioc->nr_tasks) > 1) 1638 ret = -EINVAL; 1639 task_unlock(tsk); 1640 |
1648 return ret; 1649} 1650 | 1641 return ret; 1642} 1643 |
1651static void blkiocg_attach(struct cgroup_subsys *ss, struct cgroup *cgrp, 1652 struct cgroup_taskset *tset) | 1644static void blkiocg_attach_task(struct cgroup *cgrp, struct task_struct *tsk) |
1653{ | 1645{ |
1654 struct task_struct *task; | |
1655 struct io_context *ioc; 1656 | 1646 struct io_context *ioc; 1647 |
1657 cgroup_taskset_for_each(task, cgrp, tset) { 1658 task_lock(task); 1659 ioc = task->io_context; 1660 if (ioc) 1661 ioc->cgroup_changed = 1; 1662 task_unlock(task); | 1648 /* we don't lose anything even if ioc allocation fails */ 1649 ioc = get_task_io_context(tsk, GFP_ATOMIC, NUMA_NO_NODE); 1650 if (ioc) { 1651 ioc->cgroup_changed = 1; 1652 put_io_context(ioc); |
1663 } 1664} 1665 1666void blkio_policy_register(struct blkio_policy_type *blkiop) 1667{ 1668 spin_lock(&blkio_list_lock); 1669 list_add_tail(&blkiop->list, &blkio_list); 1670 spin_unlock(&blkio_list_lock); --- 24 unchanged lines hidden --- | 1653 } 1654} 1655 1656void blkio_policy_register(struct blkio_policy_type *blkiop) 1657{ 1658 spin_lock(&blkio_list_lock); 1659 list_add_tail(&blkiop->list, &blkio_list); 1660 spin_unlock(&blkio_list_lock); --- 24 unchanged lines hidden --- |