projects/linux·blob master · refs

130 lines · 4.5 KiB

1/* SPDX-License-Identifier: GPL-2.0-or-later */
2
3#ifndef __MM_MEMCONTROL_V1_H
4#define __MM_MEMCONTROL_V1_H
5
6#include <linux/cgroup-defs.h>
7#include <linux/memcontrol.h>
8
9/* Cgroup v1 and v2 common declarations */
10
11/*
12 * Iteration constructs for visiting all cgroups (under a tree). If
13 * loops are exited prematurely (break), mem_cgroup_iter_break() must
14 * be used for reference counting.
15 */
16#define for_each_mem_cgroup_tree(iter, root) \
17 for (iter = mem_cgroup_iter(root, NULL, NULL); \
18 iter != NULL; \
19 iter = mem_cgroup_iter(root, iter, NULL))
20
21void drain_all_stock(struct mem_cgroup *root_memcg);
22
23int memory_stat_show(struct seq_file *m, void *v);
24
25struct mem_cgroup *mem_cgroup_private_id_get_online(struct mem_cgroup *memcg,
26 unsigned int n);
27
28/* Cgroup v1-specific declarations */
29#ifdef CONFIG_MEMCG_V1
30
31/* Whether legacy memory+swap accounting is active */
32static inline bool do_memsw_account(void)
33{
34 return !cgroup_subsys_on_dfl(memory_cgrp_subsys);
35}
36
37unsigned long memcg_events_local(struct mem_cgroup *memcg, int event);
38unsigned long memcg_page_state_local(struct mem_cgroup *memcg, int idx);
39unsigned long memcg_page_state_local_output(struct mem_cgroup *memcg, int item);
40bool memcg1_alloc_events(struct mem_cgroup *memcg);
41void memcg1_free_events(struct mem_cgroup *memcg);
42
43void memcg1_memcg_init(struct mem_cgroup *memcg);
44void memcg1_remove_from_trees(struct mem_cgroup *memcg);
45
46static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg)
47{
48 WRITE_ONCE(memcg->soft_limit, PAGE_COUNTER_MAX);
49}
50
51struct cgroup_taskset;
52void memcg1_css_offline(struct mem_cgroup *memcg);
53
54/* for encoding cft->private value on file */
55enum res_type {
56 _MEM,
57 _MEMSWAP,
58 _KMEM,
59 _TCP,
60};
61
62bool memcg1_oom_prepare(struct mem_cgroup *memcg, bool *locked);
63void memcg1_oom_finish(struct mem_cgroup *memcg, bool locked);
64void memcg1_oom_recover(struct mem_cgroup *memcg);
65
66void memcg1_commit_charge(struct folio *folio, struct mem_cgroup *memcg);
67void memcg1_uncharge_batch(struct mem_cgroup *memcg, unsigned long pgpgout,
68 unsigned long nr_memory, int nid);
69
70void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s);
71void reparent_memcg1_state_local(struct mem_cgroup *memcg, struct mem_cgroup *parent);
72void reparent_memcg1_lruvec_state_local(struct mem_cgroup *memcg, struct mem_cgroup *parent);
73
74void reparent_memcg_state_local(struct mem_cgroup *memcg,
75 struct mem_cgroup *parent, int idx);
76void reparent_memcg_lruvec_state_local(struct mem_cgroup *memcg,
77 struct mem_cgroup *parent, int idx);
78
79void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages);
80static inline bool memcg1_tcpmem_active(struct mem_cgroup *memcg)
81{
82 return memcg->tcpmem_active;
83}
84bool memcg1_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages,
85 gfp_t gfp_mask);
86static inline void memcg1_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
87{
88 page_counter_uncharge(&memcg->tcpmem, nr_pages);
89}
90
91extern struct cftype memsw_files[];
92extern struct cftype mem_cgroup_legacy_files[];
93
94#else /* CONFIG_MEMCG_V1 */
95
96static inline bool do_memsw_account(void) { return false; }
97static inline bool memcg1_alloc_events(struct mem_cgroup *memcg) { return true; }
98static inline void memcg1_free_events(struct mem_cgroup *memcg) {}
99
100static inline void memcg1_memcg_init(struct mem_cgroup *memcg) {}
101static inline void memcg1_remove_from_trees(struct mem_cgroup *memcg) {}
102static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg) {}
103static inline void memcg1_css_offline(struct mem_cgroup *memcg) {}
104
105static inline bool memcg1_oom_prepare(struct mem_cgroup *memcg, bool *locked)
106{
107 *locked = false;
108 return true;
109}
110static inline void memcg1_oom_finish(struct mem_cgroup *memcg, bool locked) {}
111static inline void memcg1_oom_recover(struct mem_cgroup *memcg) {}
112
113static inline void memcg1_commit_charge(struct folio *folio,
114 struct mem_cgroup *memcg) {}
115
116static inline void memcg1_uncharge_batch(struct mem_cgroup *memcg,
117 unsigned long pgpgout,
118 unsigned long nr_memory, int nid) {}
119
120static inline void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) {}
121
122static inline void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages) {}
123static inline bool memcg1_tcpmem_active(struct mem_cgroup *memcg) { return false; }
124static inline bool memcg1_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages,
125 gfp_t gfp_mask) { return true; }
126static inline void memcg1_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages) {}
127
128#endif /* CONFIG_MEMCG_V1 */
129
130#endif /* __MM_MEMCONTROL_V1_H */