Commit cf4973d8 authored by chenridong's avatar chenridong Committed by yanhaitao
Browse files

cgroup: support cgroup writeback on cgroupv1

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I8LY4S



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

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>
Signed-off-by: default avatarchenridong <chenridong@huawei.com>
parent b4f5f93b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1363,6 +1363,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);

+3 −0
Original line number Diff line number Diff line
@@ -114,6 +114,9 @@ struct blkcg {
#ifdef CONFIG_CGROUP_WRITEBACK
	struct list_head		cgwb_list;
#endif
#ifdef CONFIG_CGROUP_V1_WRITEBACK
	struct list_head		memcg_list;
#endif
};

static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)
+25 −4
Original line number Diff line number Diff line
@@ -149,6 +149,26 @@ static inline bool mapping_can_writeback(struct address_space *mapping)
	return inode_to_bdi(mapping->host)->capabilities & BDI_CAP_WRITEBACK;
}

#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,
@@ -174,8 +194,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);
}
+5 −0
Original line number Diff line number Diff line
@@ -320,6 +320,11 @@ struct mem_cgroup {
	struct memcg_cgwb_frn cgwb_frn[MEMCG_CGWB_FRN_CNT];
#endif

#ifdef CONFIG_CGROUP_V1_WRITEBACK
	struct cgroup_subsys_state	*wb_blk_css;
	struct list_head		memcg_node;
#endif

	/* List of events which userspace want to receive */
	struct list_head event_list;
	spinlock_t event_list_lock;
+5 −0
Original line number Diff line number Diff line
@@ -981,6 +981,11 @@ config CGROUP_WRITEBACK
	depends on MEMCG && BLK_CGROUP
	default y

config CGROUP_V1_WRITEBACK
	bool "Support Cgroup Writeback On Cgroupv1"
	depends on CGROUP_WRITEBACK
	default n

menuconfig CGROUP_SCHED
	bool "CPU controller"
	default n
Loading