Commit 644547a9 authored by Lu Jialin's avatar Lu Jialin Committed by Ma Wupeng
Browse files

cgroup: support cgroup writeback on cgroupv1

hulkl inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5ZG61



-------------------------------

In cgroupv1, cgroup writeback is not supproted for two problems:
1) Blkcg_css and memcg_css are mounted on different cgroup trees.
   Therefore, blkcg_css cannot be found according to a certain memcg_css.
2) Buffer I/O is worked by kthread, which is in the root_blkcg.
   Therefore, blkcg cannot limit wbps and wiops of buffer I/O.

We solve the two problems to support cgroup writeback on cgroupv1.
1) A memcg is attached to the blkcg_root css when the memcg was created.
2) We add a member "wb_blkio_ino" in mem_cgroup_legacy_files.
   User can attach a memcg to a cerntain blkcg through echo the file
   inode of the blkcg into the wb_blkio of the memcg.
3) inode_cgwb_enabled() return true when memcg and io are both mounted
   on cgroupv2 or both on cgroupv1.
4) Buffer I/O can find a blkcg according to its memcg.

Thus, a memcg can find a certain blkcg, and cgroup writeback can be
supported on cgroupv1.

Signed-off-by: default avatarLu Jialin <lujialin4@huawei.com>
parent 5a8638d6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -136,6 +136,7 @@ CONFIG_MEMCG_KMEM=y
CONFIG_MEMCG_MEMFS_INFO=y
CONFIG_BLK_CGROUP=y
CONFIG_CGROUP_WRITEBACK=y
CONFIG_CGROUP_V1_WRITEBACK=y
CONFIG_CGROUP_SCHED=y
CONFIG_FAIR_GROUP_SCHED=y
CONFIG_QOS_SCHED_SMT_EXPELLER=y
+1 −0
Original line number Diff line number Diff line
@@ -155,6 +155,7 @@ CONFIG_MEMCG_KMEM=y
CONFIG_MEMCG_MEMFS_INFO=y
CONFIG_BLK_CGROUP=y
CONFIG_CGROUP_WRITEBACK=y
CONFIG_CGROUP_V1_WRITEBACK=y
CONFIG_CGROUP_SCHED=y
CONFIG_QOS_SCHED=y
CONFIG_FAIR_GROUP_SCHED=y
+3 −0
Original line number Diff line number Diff line
@@ -1146,6 +1146,9 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
	INIT_HLIST_HEAD(&blkcg->blkg_list);
#ifdef CONFIG_CGROUP_WRITEBACK
	INIT_LIST_HEAD(&blkcg->cgwb_list);
#endif
#ifdef CONFIG_CGROUP_V1_WRITEBACK
	INIT_LIST_HEAD(&blkcg->memcg_list);
#endif
	list_add_tail(&blkcg->all_blkcgs_node, &all_blkcgs);

+25 −4
Original line number Diff line number Diff line
@@ -167,6 +167,26 @@ static inline int bdi_sched_wait(void *word)
	return 0;
}

#ifdef CONFIG_CGROUP_V1_WRITEBACK
void wb_kill_memcg_blkcg(struct cgroup_subsys_state *css);
void wb_attach_memcg_to_blkcg(struct cgroup_subsys_state *memcg_css,
			      struct cgroup_subsys_state *blkcg_css);
bool cgroup1_writeback_enabled(void);
#else
static inline void wb_kill_memcg_blkcg(struct cgroup_subsys_state *css)
{
}
static inline void
wb_attach_memcg_to_blkcg(struct cgroup_subsys_state *memcg_css,
			 struct cgroup_subsys_state *blkcg_css)
{
}
static inline bool cgroup1_writeback_enabled(void)
{
	return false;
}
#endif	/* CONFIG_CGROUP_V1_WRITEBACK */

#ifdef CONFIG_CGROUP_WRITEBACK

struct bdi_writeback *wb_get_lookup(struct backing_dev_info *bdi,
@@ -193,8 +213,9 @@ static inline bool inode_cgwb_enabled(struct inode *inode)
{
	struct backing_dev_info *bdi = inode_to_bdi(inode);

	return cgroup_subsys_on_dfl(memory_cgrp_subsys) &&
		cgroup_subsys_on_dfl(io_cgrp_subsys) &&
	return ((cgroup_subsys_on_dfl(memory_cgrp_subsys) &&
	       cgroup_subsys_on_dfl(io_cgrp_subsys)) ||
	       cgroup1_writeback_enabled()) &&
	       (bdi->capabilities & BDI_CAP_WRITEBACK) &&
	       (inode->i_sb->s_iflags & SB_I_CGROUPWB);
}
+4 −1
Original line number Diff line number Diff line
@@ -59,9 +59,12 @@ struct blkcg {
#ifdef CONFIG_CGROUP_WRITEBACK
	struct list_head		cgwb_list;
#endif

#if defined(CONFIG_CGROUP_V1_WRITEBACK) && !defined(__GENKSYMS__)
	struct list_head		memcg_list;
#else
	KABI_RESERVE(1)
	KABI_RESERVE(2)
#endif
	KABI_RESERVE(3)
	KABI_RESERVE(4)
};
Loading