| 1 |
|
| 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 |
|
| 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 |
|
| 21 | void drain_all_stock(struct mem_cgroup *root_memcg);
|
| 22 |
|
| 23 | int memory_stat_show(struct seq_file *m, void *v);
|
| 24 |
|
| 25 | struct mem_cgroup *mem_cgroup_private_id_get_online(struct mem_cgroup *memcg,
|
| 26 | unsigned int n);
|
| 27 |
|
| 28 |
|
| 29 | #ifdef CONFIG_MEMCG_V1
|
| 30 |
|
| 31 |
|
| 32 | static inline bool do_memsw_account(void)
|
| 33 | {
|
| 34 | return !cgroup_subsys_on_dfl(memory_cgrp_subsys);
|
| 35 | }
|
| 36 |
|
| 37 | unsigned long memcg_events_local(struct mem_cgroup *memcg, int event);
|
| 38 | unsigned long memcg_page_state_local(struct mem_cgroup *memcg, int idx);
|
| 39 | unsigned long memcg_page_state_local_output(struct mem_cgroup *memcg, int item);
|
| 40 | bool memcg1_alloc_events(struct mem_cgroup *memcg);
|
| 41 | void memcg1_free_events(struct mem_cgroup *memcg);
|
| 42 |
|
| 43 | void memcg1_memcg_init(struct mem_cgroup *memcg);
|
| 44 | void memcg1_remove_from_trees(struct mem_cgroup *memcg);
|
| 45 |
|
| 46 | static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg)
|
| 47 | {
|
| 48 | WRITE_ONCE(memcg->soft_limit, PAGE_COUNTER_MAX);
|
| 49 | }
|
| 50 |
|
| 51 | struct cgroup_taskset;
|
| 52 | void memcg1_css_offline(struct mem_cgroup *memcg);
|
| 53 |
|
| 54 |
|
| 55 | enum res_type {
|
| 56 | _MEM,
|
| 57 | _MEMSWAP,
|
| 58 | _KMEM,
|
| 59 | _TCP,
|
| 60 | };
|
| 61 |
|
| 62 | bool memcg1_oom_prepare(struct mem_cgroup *memcg, bool *locked);
|
| 63 | void memcg1_oom_finish(struct mem_cgroup *memcg, bool locked);
|
| 64 | void memcg1_oom_recover(struct mem_cgroup *memcg);
|
| 65 |
|
| 66 | void memcg1_commit_charge(struct folio *folio, struct mem_cgroup *memcg);
|
| 67 | void memcg1_uncharge_batch(struct mem_cgroup *memcg, unsigned long pgpgout,
|
| 68 | unsigned long nr_memory, int nid);
|
| 69 |
|
| 70 | void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s);
|
| 71 | void reparent_memcg1_state_local(struct mem_cgroup *memcg, struct mem_cgroup *parent);
|
| 72 | void reparent_memcg1_lruvec_state_local(struct mem_cgroup *memcg, struct mem_cgroup *parent);
|
| 73 |
|
| 74 | void reparent_memcg_state_local(struct mem_cgroup *memcg,
|
| 75 | struct mem_cgroup *parent, int idx);
|
| 76 | void reparent_memcg_lruvec_state_local(struct mem_cgroup *memcg,
|
| 77 | struct mem_cgroup *parent, int idx);
|
| 78 |
|
| 79 | void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages);
|
| 80 | static inline bool memcg1_tcpmem_active(struct mem_cgroup *memcg)
|
| 81 | {
|
| 82 | return memcg->tcpmem_active;
|
| 83 | }
|
| 84 | bool memcg1_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages,
|
| 85 | gfp_t gfp_mask);
|
| 86 | static inline void memcg1_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
|
| 87 | {
|
| 88 | page_counter_uncharge(&memcg->tcpmem, nr_pages);
|
| 89 | }
|
| 90 |
|
| 91 | extern struct cftype memsw_files[];
|
| 92 | extern struct cftype mem_cgroup_legacy_files[];
|
| 93 |
|
| 94 | #else
|
| 95 |
|
| 96 | static inline bool do_memsw_account(void) { return false; }
|
| 97 | static inline bool memcg1_alloc_events(struct mem_cgroup *memcg) { return true; }
|
| 98 | static inline void memcg1_free_events(struct mem_cgroup *memcg) {}
|
| 99 |
|
| 100 | static inline void memcg1_memcg_init(struct mem_cgroup *memcg) {}
|
| 101 | static inline void memcg1_remove_from_trees(struct mem_cgroup *memcg) {}
|
| 102 | static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg) {}
|
| 103 | static inline void memcg1_css_offline(struct mem_cgroup *memcg) {}
|
| 104 |
|
| 105 | static inline bool memcg1_oom_prepare(struct mem_cgroup *memcg, bool *locked)
|
| 106 | {
|
| 107 | *locked = false;
|
| 108 | return true;
|
| 109 | }
|
| 110 | static inline void memcg1_oom_finish(struct mem_cgroup *memcg, bool locked) {}
|
| 111 | static inline void memcg1_oom_recover(struct mem_cgroup *memcg) {}
|
| 112 |
|
| 113 | static inline void memcg1_commit_charge(struct folio *folio,
|
| 114 | struct mem_cgroup *memcg) {}
|
| 115 |
|
| 116 | static inline void memcg1_uncharge_batch(struct mem_cgroup *memcg,
|
| 117 | unsigned long pgpgout,
|
| 118 | unsigned long nr_memory, int nid) {}
|
| 119 |
|
| 120 | static inline void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) {}
|
| 121 |
|
| 122 | static inline void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages) {}
|
| 123 | static inline bool memcg1_tcpmem_active(struct mem_cgroup *memcg) { return false; }
|
| 124 | static inline bool memcg1_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages,
|
| 125 | gfp_t gfp_mask) { return true; }
|
| 126 | static inline void memcg1_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages) {}
|
| 127 |
|
| 128 | #endif
|
| 129 |
|
| 130 | #endif
|