mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-27 06:04:23 +08:00
mm: memcg: put cgroup v1-specific code under a config option
Put legacy cgroup v1 memory controller code under a new CONFIG_MEMCG_V1 config option. The option is turned off by default. Nobody except those who are still using cgroup v1 should turn it on. If the option is not set, memory controller can still be mounted under cgroup v1, but none of memcg-specific control files are present. Please note, that not all cgroup v1's memory controller code is guarded yet (but most of it), it's a subject for some follow-up work. Thanks to Michal Hocko for providing a better Kconfig option description. [roman.gushchin@linux.dev: better config option description provided by Michal] Link: https://lkml.kernel.org/r/ZnxXNtvqllc9CDoo@google.com Link: https://lkml.kernel.org/r/20240625005906.106920-14-roman.gushchin@linux.dev Signed-off-by: Roman Gushchin <roman.gushchin@linux.dev> Acked-by: Michal Hocko <mhocko@suse.com> Acked-by: Shakeel Butt <shakeel.butt@linux.dev> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Muchun Song <muchun.song@linux.dev> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
6f1173d684
commit
e93d4166b4
@ -1851,7 +1851,7 @@ static inline bool mem_cgroup_zswap_writeback_enabled(struct mem_cgroup *memcg)
|
|||||||
|
|
||||||
/* Cgroup v1-related declarations */
|
/* Cgroup v1-related declarations */
|
||||||
|
|
||||||
#ifdef CONFIG_MEMCG
|
#ifdef CONFIG_MEMCG_V1
|
||||||
unsigned long memcg1_soft_limit_reclaim(pg_data_t *pgdat, int order,
|
unsigned long memcg1_soft_limit_reclaim(pg_data_t *pgdat, int order,
|
||||||
gfp_t gfp_mask,
|
gfp_t gfp_mask,
|
||||||
unsigned long *total_scanned);
|
unsigned long *total_scanned);
|
||||||
@ -1883,7 +1883,7 @@ static inline void mem_cgroup_unlock_pages(void)
|
|||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* CONFIG_MEMCG */
|
#else /* CONFIG_MEMCG_V1 */
|
||||||
static inline
|
static inline
|
||||||
unsigned long memcg1_soft_limit_reclaim(pg_data_t *pgdat, int order,
|
unsigned long memcg1_soft_limit_reclaim(pg_data_t *pgdat, int order,
|
||||||
gfp_t gfp_mask,
|
gfp_t gfp_mask,
|
||||||
@ -1922,6 +1922,6 @@ static inline bool mem_cgroup_oom_synchronize(bool wait)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_MEMCG */
|
#endif /* CONFIG_MEMCG_V1 */
|
||||||
|
|
||||||
#endif /* _LINUX_MEMCONTROL_H */
|
#endif /* _LINUX_MEMCONTROL_H */
|
||||||
|
17
init/Kconfig
17
init/Kconfig
@ -969,6 +969,23 @@ config MEMCG
|
|||||||
help
|
help
|
||||||
Provides control over the memory footprint of tasks in a cgroup.
|
Provides control over the memory footprint of tasks in a cgroup.
|
||||||
|
|
||||||
|
config MEMCG_V1
|
||||||
|
bool "Legacy cgroup v1 memory controller"
|
||||||
|
depends on MEMCG
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
Legacy cgroup v1 memory controller which has been deprecated by
|
||||||
|
cgroup v2 implementation. The v1 is there for legacy applications
|
||||||
|
which haven't migrated to the new cgroup v2 interface yet. If you
|
||||||
|
do not have any such application then you are completely fine leaving
|
||||||
|
this option disabled.
|
||||||
|
|
||||||
|
Please note that feature set of the legacy memory controller is likely
|
||||||
|
going to shrink due to deprecation process. New deployments with v1
|
||||||
|
controller are highly discouraged.
|
||||||
|
|
||||||
|
San N is unsure.
|
||||||
|
|
||||||
config MEMCG_KMEM
|
config MEMCG_KMEM
|
||||||
bool
|
bool
|
||||||
depends on MEMCG
|
depends on MEMCG
|
||||||
|
@ -96,7 +96,8 @@ obj-$(CONFIG_NUMA) += memory-tiers.o
|
|||||||
obj-$(CONFIG_DEVICE_MIGRATION) += migrate_device.o
|
obj-$(CONFIG_DEVICE_MIGRATION) += migrate_device.o
|
||||||
obj-$(CONFIG_TRANSPARENT_HUGEPAGE) += huge_memory.o khugepaged.o
|
obj-$(CONFIG_TRANSPARENT_HUGEPAGE) += huge_memory.o khugepaged.o
|
||||||
obj-$(CONFIG_PAGE_COUNTER) += page_counter.o
|
obj-$(CONFIG_PAGE_COUNTER) += page_counter.o
|
||||||
obj-$(CONFIG_MEMCG) += memcontrol.o memcontrol-v1.o vmpressure.o
|
obj-$(CONFIG_MEMCG_V1) += memcontrol-v1.o
|
||||||
|
obj-$(CONFIG_MEMCG) += memcontrol.o vmpressure.o
|
||||||
ifdef CONFIG_SWAP
|
ifdef CONFIG_SWAP
|
||||||
obj-$(CONFIG_MEMCG) += swap_cgroup.o
|
obj-$(CONFIG_MEMCG) += swap_cgroup.o
|
||||||
endif
|
endif
|
||||||
|
@ -70,7 +70,7 @@ unsigned long memcg_page_state_local_output(struct mem_cgroup *memcg, int item);
|
|||||||
int memory_stat_show(struct seq_file *m, void *v);
|
int memory_stat_show(struct seq_file *m, void *v);
|
||||||
|
|
||||||
/* Cgroup v1-specific declarations */
|
/* Cgroup v1-specific declarations */
|
||||||
|
#ifdef CONFIG_MEMCG_V1
|
||||||
void memcg1_remove_from_trees(struct mem_cgroup *memcg);
|
void memcg1_remove_from_trees(struct mem_cgroup *memcg);
|
||||||
|
|
||||||
static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg)
|
static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg)
|
||||||
@ -105,4 +105,23 @@ void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s);
|
|||||||
extern struct cftype memsw_files[];
|
extern struct cftype memsw_files[];
|
||||||
extern struct cftype mem_cgroup_legacy_files[];
|
extern struct cftype mem_cgroup_legacy_files[];
|
||||||
|
|
||||||
|
#else /* CONFIG_MEMCG_V1 */
|
||||||
|
|
||||||
|
static inline void memcg1_remove_from_trees(struct mem_cgroup *memcg) {}
|
||||||
|
static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg) {}
|
||||||
|
static inline bool memcg1_wait_acct_move(struct mem_cgroup *memcg) { return false; }
|
||||||
|
static inline void memcg1_css_offline(struct mem_cgroup *memcg) {}
|
||||||
|
|
||||||
|
static inline bool memcg1_oom_prepare(struct mem_cgroup *memcg, bool *locked) { return true; }
|
||||||
|
static inline void memcg1_oom_finish(struct mem_cgroup *memcg, bool locked) {}
|
||||||
|
static inline void memcg1_oom_recover(struct mem_cgroup *memcg) {}
|
||||||
|
|
||||||
|
static inline void memcg1_check_events(struct mem_cgroup *memcg, int nid) {}
|
||||||
|
|
||||||
|
static inline void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) {}
|
||||||
|
|
||||||
|
extern struct cftype memsw_files[];
|
||||||
|
extern struct cftype mem_cgroup_legacy_files[];
|
||||||
|
#endif /* CONFIG_MEMCG_V1 */
|
||||||
|
|
||||||
#endif /* __MM_MEMCONTROL_V1_H */
|
#endif /* __MM_MEMCONTROL_V1_H */
|
||||||
|
@ -4398,18 +4398,20 @@ struct cgroup_subsys memory_cgrp_subsys = {
|
|||||||
.css_free = mem_cgroup_css_free,
|
.css_free = mem_cgroup_css_free,
|
||||||
.css_reset = mem_cgroup_css_reset,
|
.css_reset = mem_cgroup_css_reset,
|
||||||
.css_rstat_flush = mem_cgroup_css_rstat_flush,
|
.css_rstat_flush = mem_cgroup_css_rstat_flush,
|
||||||
.can_attach = memcg1_can_attach,
|
|
||||||
#if defined(CONFIG_LRU_GEN) || defined(CONFIG_MEMCG_KMEM)
|
#if defined(CONFIG_LRU_GEN) || defined(CONFIG_MEMCG_KMEM)
|
||||||
.attach = mem_cgroup_attach,
|
.attach = mem_cgroup_attach,
|
||||||
#endif
|
#endif
|
||||||
.cancel_attach = memcg1_cancel_attach,
|
|
||||||
.post_attach = memcg1_move_task,
|
|
||||||
#ifdef CONFIG_MEMCG_KMEM
|
#ifdef CONFIG_MEMCG_KMEM
|
||||||
.fork = mem_cgroup_fork,
|
.fork = mem_cgroup_fork,
|
||||||
.exit = mem_cgroup_exit,
|
.exit = mem_cgroup_exit,
|
||||||
#endif
|
#endif
|
||||||
.dfl_cftypes = memory_files,
|
.dfl_cftypes = memory_files,
|
||||||
|
#ifdef CONFIG_MEMCG_V1
|
||||||
|
.can_attach = memcg1_can_attach,
|
||||||
|
.cancel_attach = memcg1_cancel_attach,
|
||||||
|
.post_attach = memcg1_move_task,
|
||||||
.legacy_cftypes = mem_cgroup_legacy_files,
|
.legacy_cftypes = mem_cgroup_legacy_files,
|
||||||
|
#endif
|
||||||
.early_init = 0,
|
.early_init = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -5581,7 +5583,9 @@ static int __init mem_cgroup_swap_init(void)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
WARN_ON(cgroup_add_dfl_cftypes(&memory_cgrp_subsys, swap_files));
|
WARN_ON(cgroup_add_dfl_cftypes(&memory_cgrp_subsys, swap_files));
|
||||||
|
#ifdef CONFIG_MEMCG_V1
|
||||||
WARN_ON(cgroup_add_legacy_cftypes(&memory_cgrp_subsys, memsw_files));
|
WARN_ON(cgroup_add_legacy_cftypes(&memory_cgrp_subsys, memsw_files));
|
||||||
|
#endif
|
||||||
#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP)
|
#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP)
|
||||||
WARN_ON(cgroup_add_dfl_cftypes(&memory_cgrp_subsys, zswap_files));
|
WARN_ON(cgroup_add_dfl_cftypes(&memory_cgrp_subsys, zswap_files));
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user