[PATCHSET 1/3 v3 block/for-4.1/core] writeback: cgroup writeback support

2015-04-06 Thread Tejun Heo
Subject: [PATCHSET 1/3 v3 block/for-4.1/core] writeback: cgroup writeback 
support

Hello,

This is v3 of cgroup writeback support patchset.  Changes from the
last take[L] are

* mapping_congested() is now inode_congested() and always operates on
  the inode regardless of the current task.  This was broken in the
  last take due to the logic carried over from multi-wb dirtying in
  the first take.  Noticed by Vivek.

* Fengguang noticed crash from the split congestion code when there's
  no blkcg policy active.  This is caused by blkcg pointlessly trying
  to micro optimize the allocation of root blkcg_gq and has caused
  similar bugs before.
  0004-blkcg-always-create-the-blkcg_gq-for-the-root-blkcg.patch
  added.

* Some minor bug fixes and cosmetic updates.  Nothing too interesting.

blkio cgroup (blkcg) is severely crippled in that it can only control
read and direct write IOs.  blkcg can't tell which cgroup should be
held responsible for a given writeback IO and charges all of them to
the root cgroup - all normal write traffic ends up in the root cgroup.
Although the problem has been identified years ago, mainly because it
interacts with so many subsystems, it hasn't been solved yet.

This patchset finally implements cgroup writeback support so that
writeback of a page is attributed to the corresponding blkcg of the
memcg that the page belongs to.

Overall design
--

* This requires cooperation between memcg and blkcg.  Each inode is
  assigned to the blkcg mapped to the memcg being dirtied.

* struct bdi_writeback (wb) was always embedded in struct
  backing_dev_info (bdi) and the distinction between the two wasn't
  clear.  This patchset makes wb operate as an independent writeback
  execution domain.  bdi->wb is still embedded and serves the root
  cgroup but there can be other wb's for other cgroups.

* Each wb is associated with memcg.  As memcg is implicitly enabled by
  blkcg on the unified hierarchy, this gives a unique wb for each
  memcg-blkcg combination.  When memcg-blkcg mapping changes, a new wb
  is created and the existing wb is unlinked and drained.

* An inode is associated with the matching wb when it gets dirtied for
  the first time and written back by that wb.  A later patchset will
  implement dynamic wb switching.

* All writeback operations are made per-wb instead of per-bdi.
  bdi-wide operations are split across all member wb's.  If some
  finite amount needs to be distributed, be it number of pages to
  writeback or bdi->min/max_ratio, it's distributed according to the
  bandwidth proportion a wb has in the bdi.

* cgroup writeback support adds one pointer to struct inode.


Missing pieces
--

* It requires some cooperation from the filesystem and currently only
  works with ext2.  The changes necessary on the filesystem side are
  almost trivial.  I'll write up a documentation on it.

* blk-throttle works but cfq-iosched isn't ready for writebacks coming
  down with different cgroups.  cfq-iosched should be updated to have
  a writeback ioc per cgroup and route writeback IOs through it.


How to test
---

* Boot with kernel option "cgroup__DEVEL__legacy_files_on_dfl".

* umount /sys/fs/cgroup/memory
  umount /sys/fs/cgroup/blkio
  mkdir /sys/fs/cgroup/unified
  mount -t cgroup -o __DEVEL__sane_behavior cgroup /sys/fs/cgroup/unified
  echo +blkio > /sys/fs/cgroup/unified/cgroup.subtree_control

* Build the cgroup hierarchy (don't forget to enable blkio using
  subtree_control) and put processes in cgroups and run tests on ext2
  filesystems and blkio.throttle.* knobs.

This patchset contains the following 48 patches.

 0001-memcg-add-per-cgroup-dirty-page-accounting.patch
 0002-blkcg-move-block-blk-cgroup.h-to-include-linux-blk-c.patch
 0003-update-CONFIG_BLK_CGROUP-dummies-in-include-linux-bl.patch
 0004-blkcg-always-create-the-blkcg_gq-for-the-root-blkcg.patch
 0005-memcg-add-mem_cgroup_root_css.patch
 0006-blkcg-add-blkcg_root_css.patch
 0007-cgroup-block-implement-task_get_css-and-use-it-in-bi.patch
 0008-blkcg-implement-task_get_blkcg_css.patch
 0009-blkcg-implement-bio_associate_blkcg.patch
 0010-memcg-implement-mem_cgroup_css_from_page.patch
 0011-writeback-move-backing_dev_info-state-into-bdi_write.patch
 0012-writeback-move-backing_dev_info-bdi_stat-into-bdi_wr.patch
 0013-writeback-move-bandwidth-related-fields-from-backing.patch
 0014-writeback-s-bdi-wb-in-mm-page-writeback.c.patch
 0015-writeback-move-backing_dev_info-wb_lock-and-worklist.patch
 0016-writeback-reorganize-mm-backing-dev.c.patch
 0017-writeback-separate-out-include-linux-backing-dev-def.patch
 0018-bdi-make-inode_to_bdi-inline.patch
 0019-writeback-add-gfp-to-wb_init.patch
 0020-bdi-separate-out-congested-state-into-a-separate-str.patch
 0021-writeback-add-CONFIG-BDI_CAP-FS-_CGROUP_WRITEBACK.patch
 0022-writeback-make-backing_dev_info-host-cgroup-specific.patch
 0023-writeback-blkcg-associate-each-blkcg_gq-with-the-cor.patch
 0024-writeb

[PATCHSET 1/3 v3 block/for-4.1/core] writeback: cgroup writeback support

2015-04-06 Thread Tejun Heo
Subject: [PATCHSET 1/3 v3 block/for-4.1/core] writeback: cgroup writeback 
support

Hello,

This is v3 of cgroup writeback support patchset.  Changes from the
last take[L] are

* mapping_congested() is now inode_congested() and always operates on
  the inode regardless of the current task.  This was broken in the
  last take due to the logic carried over from multi-wb dirtying in
  the first take.  Noticed by Vivek.

* Fengguang noticed crash from the split congestion code when there's
  no blkcg policy active.  This is caused by blkcg pointlessly trying
  to micro optimize the allocation of root blkcg_gq and has caused
  similar bugs before.
  0004-blkcg-always-create-the-blkcg_gq-for-the-root-blkcg.patch
  added.

* Some minor bug fixes and cosmetic updates.  Nothing too interesting.

blkio cgroup (blkcg) is severely crippled in that it can only control
read and direct write IOs.  blkcg can't tell which cgroup should be
held responsible for a given writeback IO and charges all of them to
the root cgroup - all normal write traffic ends up in the root cgroup.
Although the problem has been identified years ago, mainly because it
interacts with so many subsystems, it hasn't been solved yet.

This patchset finally implements cgroup writeback support so that
writeback of a page is attributed to the corresponding blkcg of the
memcg that the page belongs to.

Overall design
--

* This requires cooperation between memcg and blkcg.  Each inode is
  assigned to the blkcg mapped to the memcg being dirtied.

* struct bdi_writeback (wb) was always embedded in struct
  backing_dev_info (bdi) and the distinction between the two wasn't
  clear.  This patchset makes wb operate as an independent writeback
  execution domain.  bdi-wb is still embedded and serves the root
  cgroup but there can be other wb's for other cgroups.

* Each wb is associated with memcg.  As memcg is implicitly enabled by
  blkcg on the unified hierarchy, this gives a unique wb for each
  memcg-blkcg combination.  When memcg-blkcg mapping changes, a new wb
  is created and the existing wb is unlinked and drained.

* An inode is associated with the matching wb when it gets dirtied for
  the first time and written back by that wb.  A later patchset will
  implement dynamic wb switching.

* All writeback operations are made per-wb instead of per-bdi.
  bdi-wide operations are split across all member wb's.  If some
  finite amount needs to be distributed, be it number of pages to
  writeback or bdi-min/max_ratio, it's distributed according to the
  bandwidth proportion a wb has in the bdi.

* cgroup writeback support adds one pointer to struct inode.


Missing pieces
--

* It requires some cooperation from the filesystem and currently only
  works with ext2.  The changes necessary on the filesystem side are
  almost trivial.  I'll write up a documentation on it.

* blk-throttle works but cfq-iosched isn't ready for writebacks coming
  down with different cgroups.  cfq-iosched should be updated to have
  a writeback ioc per cgroup and route writeback IOs through it.


How to test
---

* Boot with kernel option cgroup__DEVEL__legacy_files_on_dfl.

* umount /sys/fs/cgroup/memory
  umount /sys/fs/cgroup/blkio
  mkdir /sys/fs/cgroup/unified
  mount -t cgroup -o __DEVEL__sane_behavior cgroup /sys/fs/cgroup/unified
  echo +blkio  /sys/fs/cgroup/unified/cgroup.subtree_control

* Build the cgroup hierarchy (don't forget to enable blkio using
  subtree_control) and put processes in cgroups and run tests on ext2
  filesystems and blkio.throttle.* knobs.

This patchset contains the following 48 patches.

 0001-memcg-add-per-cgroup-dirty-page-accounting.patch
 0002-blkcg-move-block-blk-cgroup.h-to-include-linux-blk-c.patch
 0003-update-CONFIG_BLK_CGROUP-dummies-in-include-linux-bl.patch
 0004-blkcg-always-create-the-blkcg_gq-for-the-root-blkcg.patch
 0005-memcg-add-mem_cgroup_root_css.patch
 0006-blkcg-add-blkcg_root_css.patch
 0007-cgroup-block-implement-task_get_css-and-use-it-in-bi.patch
 0008-blkcg-implement-task_get_blkcg_css.patch
 0009-blkcg-implement-bio_associate_blkcg.patch
 0010-memcg-implement-mem_cgroup_css_from_page.patch
 0011-writeback-move-backing_dev_info-state-into-bdi_write.patch
 0012-writeback-move-backing_dev_info-bdi_stat-into-bdi_wr.patch
 0013-writeback-move-bandwidth-related-fields-from-backing.patch
 0014-writeback-s-bdi-wb-in-mm-page-writeback.c.patch
 0015-writeback-move-backing_dev_info-wb_lock-and-worklist.patch
 0016-writeback-reorganize-mm-backing-dev.c.patch
 0017-writeback-separate-out-include-linux-backing-dev-def.patch
 0018-bdi-make-inode_to_bdi-inline.patch
 0019-writeback-add-gfp-to-wb_init.patch
 0020-bdi-separate-out-congested-state-into-a-separate-str.patch
 0021-writeback-add-CONFIG-BDI_CAP-FS-_CGROUP_WRITEBACK.patch
 0022-writeback-make-backing_dev_info-host-cgroup-specific.patch
 0023-writeback-blkcg-associate-each-blkcg_gq-with-the-cor.patch
 0024-writeback-attribute-stats