diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index a8b32e09937a302a239b4373c05a166090c3ecf2..28642f0c3311f162888bf2051267c653fb3f3402 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -496,6 +496,9 @@ nosocket -- Disable socket memory accounting. nokmem -- Disable kernel memory accounting. + cgwb_v1 Enable writeback control for cgroup for cgroup v1 + interface. + checkreqprot [SELINUX] Set initial checkreqprot flag value. Format: { "0" | "1" } See security/selinux/Kconfig help text. diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h index d4088485acabbd69a8c838a800898c96c34cefc5..09ab0679ab338a657ce4c120de0052b3c6c37973 100644 --- a/include/linux/backing-dev.h +++ b/include/linux/backing-dev.h @@ -233,6 +233,21 @@ void wb_memcg_offline(struct mem_cgroup *memcg); void wb_blkcg_offline(struct blkcg *blkcg); int inode_congested(struct inode *inode, int cong_bits); +extern bool cgwb_v1; + +static inline bool memcg_blkcg_on_dfl(void) +{ + return cgroup_subsys_on_dfl(memory_cgrp_subsys) && + cgroup_subsys_on_dfl(io_cgrp_subsys); +} + +static inline bool cgroup_writeback_support_v1(void) +{ + return cgwb_v1 && + !cgroup_subsys_on_dfl(memory_cgrp_subsys) && + !cgroup_subsys_on_dfl(io_cgrp_subsys); +} + /** * inode_cgwb_enabled - test whether cgroup writeback is enabled on an inode * @inode: inode of interest @@ -248,7 +263,9 @@ static inline bool inode_cgwb_enabled(struct inode *inode) { struct backing_dev_info *bdi = inode_to_bdi(inode); - return bdi_cap_account_dirty(bdi) && + return (memcg_blkcg_on_dfl() || + cgroup_writeback_support_v1()) && + bdi_cap_account_dirty(bdi) && (bdi->capabilities & BDI_CAP_CGROUP_WRITEBACK) && (inode->i_sb->s_iflags & SB_I_CGROUPWB); } diff --git a/mm/backing-dev.c b/mm/backing-dev.c index de01892e13a534dcd1212ab24e39dfd80a307ecd..7f30da5822d92bba37534a1f0fe0a681e5226bad 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -49,6 +49,9 @@ static void bdi_debug_init(void) if (!bdi_debug_root) return; + if (!cgwb_v1) + return; + memcg_blkcg_file = debugfs_create_file("bdi_wb_link", 0444, bdi_debug_root, NULL, &memcg_blkcg_debug_fops); #endif @@ -455,6 +458,9 @@ int allocate_memcg_blkcg_links(int count, struct list_head *tmp_links) struct memcg_blkcg_link *link; int i; + if (!cgwb_v1) + return 0; + for (i = 0; i < count; i++) { link = kzalloc(sizeof(*link), GFP_KERNEL); if (!link) { @@ -482,6 +488,9 @@ void insert_memcg_blkcg_link(struct cgroup_subsys *ss, struct cgroup_subsys_state *memcg_css; int err; + if (!cgwb_v1) + return; + if (ss->id != io_cgrp_id && ss->id != memory_cgrp_id) return; @@ -567,6 +576,9 @@ static void delete_blkcg_link(struct cgroup_subsys_state *blkcg_css) void delete_memcg_blkcg_link(struct cgroup_subsys *ss, struct cgroup_subsys_state *css) { + if (!cgwb_v1) + return; + if (ss->id != io_cgrp_id && ss->id != memory_cgrp_id) return; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b1cdb2657161f791fbdadf069a8ecc38f739677d..66e731779b2a6ea6c10025d3508994cbc85367fa 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -468,7 +468,8 @@ struct cgroup_subsys_state *mem_cgroup_css_from_page(struct page *page) memcg = page->mem_cgroup; - if (!memcg) + if (!memcg || + (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgwb_v1)) memcg = root_mem_cgroup; return &memcg->css; @@ -6369,6 +6370,16 @@ static int __init cgroup_memory(char *s) } __setup("cgroup.memory=", cgroup_memory); +bool cgwb_v1 = false; + +static int __init enable_cgroup_writeback_v1(char *s) +{ + cgwb_v1 = true; + + return 0; +} +__setup("cgwb_v1", enable_cgroup_writeback_v1); + /* * subsys_initcall() for memory controller. *