at for-next 5.4 kB view raw
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 8/* Cgroup v1 and v2 common declarations */ 9 10int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask, 11 unsigned int nr_pages); 12 13static inline int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask, 14 unsigned int nr_pages) 15{ 16 if (mem_cgroup_is_root(memcg)) 17 return 0; 18 19 return try_charge_memcg(memcg, gfp_mask, nr_pages); 20} 21 22void mem_cgroup_id_get_many(struct mem_cgroup *memcg, unsigned int n); 23void mem_cgroup_id_put_many(struct mem_cgroup *memcg, unsigned int n); 24 25/* 26 * Iteration constructs for visiting all cgroups (under a tree). If 27 * loops are exited prematurely (break), mem_cgroup_iter_break() must 28 * be used for reference counting. 29 */ 30#define for_each_mem_cgroup_tree(iter, root) \ 31 for (iter = mem_cgroup_iter(root, NULL, NULL); \ 32 iter != NULL; \ 33 iter = mem_cgroup_iter(root, iter, NULL)) 34 35#define for_each_mem_cgroup(iter) \ 36 for (iter = mem_cgroup_iter(NULL, NULL, NULL); \ 37 iter != NULL; \ 38 iter = mem_cgroup_iter(NULL, iter, NULL)) 39 40/* Whether legacy memory+swap accounting is active */ 41static inline bool do_memsw_account(void) 42{ 43 return !cgroup_subsys_on_dfl(memory_cgrp_subsys); 44} 45 46/* 47 * Per memcg event counter is incremented at every pagein/pageout. With THP, 48 * it will be incremented by the number of pages. This counter is used 49 * to trigger some periodic events. This is straightforward and better 50 * than using jiffies etc. to handle periodic memcg event. 51 */ 52enum mem_cgroup_events_target { 53 MEM_CGROUP_TARGET_THRESH, 54 MEM_CGROUP_TARGET_SOFTLIMIT, 55 MEM_CGROUP_NTARGETS, 56}; 57 58unsigned long mem_cgroup_usage(struct mem_cgroup *memcg, bool swap); 59 60void drain_all_stock(struct mem_cgroup *root_memcg); 61 62unsigned long memcg_events(struct mem_cgroup *memcg, int event); 63unsigned long memcg_events_local(struct mem_cgroup *memcg, int event); 64unsigned long memcg_page_state_local(struct mem_cgroup *memcg, int idx); 65unsigned long memcg_page_state_output(struct mem_cgroup *memcg, int item); 66unsigned long memcg_page_state_local_output(struct mem_cgroup *memcg, int item); 67int memory_stat_show(struct seq_file *m, void *v); 68 69/* Cgroup v1-specific declarations */ 70#ifdef CONFIG_MEMCG_V1 71 72bool memcg1_alloc_events(struct mem_cgroup *memcg); 73void memcg1_free_events(struct mem_cgroup *memcg); 74 75void memcg1_memcg_init(struct mem_cgroup *memcg); 76void memcg1_remove_from_trees(struct mem_cgroup *memcg); 77 78static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg) 79{ 80 WRITE_ONCE(memcg->soft_limit, PAGE_COUNTER_MAX); 81} 82 83struct cgroup_taskset; 84void memcg1_css_offline(struct mem_cgroup *memcg); 85 86/* for encoding cft->private value on file */ 87enum res_type { 88 _MEM, 89 _MEMSWAP, 90 _KMEM, 91 _TCP, 92}; 93 94bool memcg1_oom_prepare(struct mem_cgroup *memcg, bool *locked); 95void memcg1_oom_finish(struct mem_cgroup *memcg, bool locked); 96void memcg1_oom_recover(struct mem_cgroup *memcg); 97 98void memcg1_commit_charge(struct folio *folio, struct mem_cgroup *memcg); 99void memcg1_swapout(struct folio *folio, struct mem_cgroup *memcg); 100void memcg1_uncharge_batch(struct mem_cgroup *memcg, unsigned long pgpgout, 101 unsigned long nr_memory, int nid); 102 103void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s); 104 105void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages); 106static inline bool memcg1_tcpmem_active(struct mem_cgroup *memcg) 107{ 108 return memcg->tcpmem_active; 109} 110bool memcg1_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages, 111 gfp_t gfp_mask); 112static inline void memcg1_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages) 113{ 114 page_counter_uncharge(&memcg->tcpmem, nr_pages); 115} 116 117extern struct cftype memsw_files[]; 118extern struct cftype mem_cgroup_legacy_files[]; 119 120#else /* CONFIG_MEMCG_V1 */ 121 122static inline bool memcg1_alloc_events(struct mem_cgroup *memcg) { return true; } 123static inline void memcg1_free_events(struct mem_cgroup *memcg) {} 124 125static inline void memcg1_memcg_init(struct mem_cgroup *memcg) {} 126static inline void memcg1_remove_from_trees(struct mem_cgroup *memcg) {} 127static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg) {} 128static inline void memcg1_css_offline(struct mem_cgroup *memcg) {} 129 130static inline bool memcg1_oom_prepare(struct mem_cgroup *memcg, bool *locked) { return true; } 131static inline void memcg1_oom_finish(struct mem_cgroup *memcg, bool locked) {} 132static inline void memcg1_oom_recover(struct mem_cgroup *memcg) {} 133 134static inline void memcg1_commit_charge(struct folio *folio, 135 struct mem_cgroup *memcg) {} 136 137static inline void memcg1_swapout(struct folio *folio, struct mem_cgroup *memcg) {} 138 139static inline void memcg1_uncharge_batch(struct mem_cgroup *memcg, 140 unsigned long pgpgout, 141 unsigned long nr_memory, int nid) {} 142 143static inline void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) {} 144 145static inline void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages) {} 146static inline bool memcg1_tcpmem_active(struct mem_cgroup *memcg) { return false; } 147static inline bool memcg1_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages, 148 gfp_t gfp_mask) { return true; } 149static inline void memcg1_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages) {} 150 151#endif /* CONFIG_MEMCG_V1 */ 152 153#endif /* __MM_MEMCONTROL_V1_H */