File Index
Files and directories
Sign in
FILE

memcontrol-v1.h

File preview with syntax highlighting.

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