Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 2 | /* memcontrol.h - Memory Controller |
| 3 | * |
| 4 | * Copyright IBM Corporation, 2007 |
| 5 | * Author Balbir Singh <balbir@linux.vnet.ibm.com> |
| 6 | * |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 7 | * Copyright 2007 OpenVZ SWsoft Inc |
| 8 | * Author: Pavel Emelianov <xemul@openvz.org> |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #ifndef _LINUX_MEMCONTROL_H |
| 12 | #define _LINUX_MEMCONTROL_H |
Hirokazu Takahashi | f8d66542 | 2009-01-07 18:08:02 -0800 | [diff] [blame] | 13 | #include <linux/cgroup.h> |
Ying Han | 456f998 | 2011-05-26 16:25:38 -0700 | [diff] [blame] | 14 | #include <linux/vm_event_item.h> |
Glauber Costa | 7ae1e1d | 2012-12-18 14:21:56 -0800 | [diff] [blame] | 15 | #include <linux/hardirq.h> |
Glauber Costa | a8964b9 | 2012-12-18 14:22:09 -0800 | [diff] [blame] | 16 | #include <linux/jump_label.h> |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 17 | #include <linux/page_counter.h> |
| 18 | #include <linux/vmpressure.h> |
| 19 | #include <linux/eventfd.h> |
Johannes Weiner | 00f3ca2 | 2017-07-06 15:40:52 -0700 | [diff] [blame] | 20 | #include <linux/mm.h> |
| 21 | #include <linux/vmstat.h> |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 22 | #include <linux/writeback.h> |
Johannes Weiner | fdf1cdb | 2016-03-15 14:57:25 -0700 | [diff] [blame] | 23 | #include <linux/page-flags.h> |
Ying Han | 456f998 | 2011-05-26 16:25:38 -0700 | [diff] [blame] | 24 | |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 25 | struct mem_cgroup; |
Roman Gushchin | bf4f059 | 2020-08-06 23:20:49 -0700 | [diff] [blame] | 26 | struct obj_cgroup; |
Balbir Singh | 8697d33 | 2008-02-07 00:13:59 -0800 | [diff] [blame] | 27 | struct page; |
| 28 | struct mm_struct; |
Glauber Costa | 2633d7a | 2012-12-18 14:22:34 -0800 | [diff] [blame] | 29 | struct kmem_cache; |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 30 | |
Johannes Weiner | 71cd311 | 2017-05-03 14:55:13 -0700 | [diff] [blame] | 31 | /* Cgroup-specific page state, on top of universal node page state */ |
| 32 | enum memcg_stat_item { |
Johannes Weiner | 468c398 | 2020-06-03 16:02:01 -0700 | [diff] [blame] | 33 | MEMCG_SWAP = NR_VM_NODE_STAT_ITEMS, |
Johannes Weiner | 71cd311 | 2017-05-03 14:55:13 -0700 | [diff] [blame] | 34 | MEMCG_SOCK, |
Roman Gushchin | 772616b | 2020-08-11 18:30:21 -0700 | [diff] [blame] | 35 | MEMCG_PERCPU_B, |
Shakeel Butt | 4e5aa1f | 2022-01-14 14:05:45 -0800 | [diff] [blame] | 36 | MEMCG_VMALLOC, |
Johannes Weiner | b2807f0 | 2016-01-20 15:03:22 -0800 | [diff] [blame] | 37 | MEMCG_NR_STAT, |
Greg Thelen | 2a7106f | 2011-01-13 15:47:37 -0800 | [diff] [blame] | 38 | }; |
| 39 | |
Johannes Weiner | e27be24 | 2018-04-10 16:29:45 -0700 | [diff] [blame] | 40 | enum memcg_memory_event { |
| 41 | MEMCG_LOW, |
Johannes Weiner | 71cd311 | 2017-05-03 14:55:13 -0700 | [diff] [blame] | 42 | MEMCG_HIGH, |
| 43 | MEMCG_MAX, |
| 44 | MEMCG_OOM, |
Roman Gushchin | fe6bdfc | 2018-06-14 15:28:05 -0700 | [diff] [blame] | 45 | MEMCG_OOM_KILL, |
Dan Schatzberg | b6bf9ab | 2022-01-14 14:05:35 -0800 | [diff] [blame] | 46 | MEMCG_OOM_GROUP_KILL, |
Jakub Kicinski | 4b82ab4 | 2020-06-01 21:49:52 -0700 | [diff] [blame] | 47 | MEMCG_SWAP_HIGH, |
Tejun Heo | f3a53a3 | 2018-06-07 17:05:35 -0700 | [diff] [blame] | 48 | MEMCG_SWAP_MAX, |
| 49 | MEMCG_SWAP_FAIL, |
Johannes Weiner | e27be24 | 2018-04-10 16:29:45 -0700 | [diff] [blame] | 50 | MEMCG_NR_MEMORY_EVENTS, |
Johannes Weiner | 71cd311 | 2017-05-03 14:55:13 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
Johannes Weiner | 5660048 | 2012-01-12 17:17:59 -0800 | [diff] [blame] | 53 | struct mem_cgroup_reclaim_cookie { |
Mel Gorman | ef8f232 | 2016-07-28 15:46:05 -0700 | [diff] [blame] | 54 | pg_data_t *pgdat; |
Johannes Weiner | 5660048 | 2012-01-12 17:17:59 -0800 | [diff] [blame] | 55 | unsigned int generation; |
| 56 | }; |
| 57 | |
Johannes Weiner | 71cd311 | 2017-05-03 14:55:13 -0700 | [diff] [blame] | 58 | #ifdef CONFIG_MEMCG |
| 59 | |
| 60 | #define MEM_CGROUP_ID_SHIFT 16 |
| 61 | #define MEM_CGROUP_ID_MAX USHRT_MAX |
| 62 | |
| 63 | struct mem_cgroup_id { |
| 64 | int id; |
Kirill Tkhai | 1c2d479 | 2018-10-26 15:09:28 -0700 | [diff] [blame] | 65 | refcount_t ref; |
Johannes Weiner | 71cd311 | 2017-05-03 14:55:13 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 68 | /* |
| 69 | * Per memcg event counter is incremented at every pagein/pageout. With THP, |
Randy Dunlap | 0845f83 | 2020-08-11 18:32:40 -0700 | [diff] [blame] | 70 | * it will be incremented by the number of pages. This counter is used |
| 71 | * to trigger some periodic events. This is straightforward and better |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 72 | * than using jiffies etc. to handle periodic memcg event. |
| 73 | */ |
| 74 | enum mem_cgroup_events_target { |
| 75 | MEM_CGROUP_TARGET_THRESH, |
| 76 | MEM_CGROUP_TARGET_SOFTLIMIT, |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 77 | MEM_CGROUP_NTARGETS, |
| 78 | }; |
| 79 | |
Chris Down | 871789d | 2019-05-14 15:46:57 -0700 | [diff] [blame] | 80 | struct memcg_vmstats_percpu { |
Johannes Weiner | 2d146aa | 2021-04-29 22:56:26 -0700 | [diff] [blame] | 81 | /* Local (CPU and cgroup) page state & events */ |
| 82 | long state[MEMCG_NR_STAT]; |
| 83 | unsigned long events[NR_VM_EVENT_ITEMS]; |
| 84 | |
| 85 | /* Delta calculation for lockless upward propagation */ |
| 86 | long state_prev[MEMCG_NR_STAT]; |
| 87 | unsigned long events_prev[NR_VM_EVENT_ITEMS]; |
| 88 | |
| 89 | /* Cgroup1: threshold notifications & softlimit tree updates */ |
| 90 | unsigned long nr_page_events; |
| 91 | unsigned long targets[MEM_CGROUP_NTARGETS]; |
| 92 | }; |
| 93 | |
| 94 | struct memcg_vmstats { |
| 95 | /* Aggregated (CPU and subtree) page state & events */ |
| 96 | long state[MEMCG_NR_STAT]; |
| 97 | unsigned long events[NR_VM_EVENT_ITEMS]; |
| 98 | |
| 99 | /* Pending child counts during tree propagation */ |
| 100 | long state_pending[MEMCG_NR_STAT]; |
| 101 | unsigned long events_pending[NR_VM_EVENT_ITEMS]; |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | struct mem_cgroup_reclaim_iter { |
| 105 | struct mem_cgroup *position; |
| 106 | /* scan generation, increased every round-trip */ |
| 107 | unsigned int generation; |
| 108 | }; |
| 109 | |
| 110 | /* |
Yang Shi | 3c6f17e | 2021-05-04 18:36:33 -0700 | [diff] [blame] | 111 | * Bitmap and deferred work of shrinker::id corresponding to memcg-aware |
| 112 | * shrinkers, which have elements charged to this memcg. |
Kirill Tkhai | 0a4465d | 2018-08-17 15:47:37 -0700 | [diff] [blame] | 113 | */ |
Yang Shi | e4262c4 | 2021-05-04 18:36:23 -0700 | [diff] [blame] | 114 | struct shrinker_info { |
Kirill Tkhai | 0a4465d | 2018-08-17 15:47:37 -0700 | [diff] [blame] | 115 | struct rcu_head rcu; |
Yang Shi | 3c6f17e | 2021-05-04 18:36:33 -0700 | [diff] [blame] | 116 | atomic_long_t *nr_deferred; |
| 117 | unsigned long *map; |
Kirill Tkhai | 0a4465d | 2018-08-17 15:47:37 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Shakeel Butt | 7e1c0d6 | 2021-09-02 14:55:00 -0700 | [diff] [blame] | 120 | struct lruvec_stats_percpu { |
| 121 | /* Local (CPU and cgroup) state */ |
| 122 | long state[NR_VM_NODE_STAT_ITEMS]; |
| 123 | |
| 124 | /* Delta calculation for lockless upward propagation */ |
| 125 | long state_prev[NR_VM_NODE_STAT_ITEMS]; |
| 126 | }; |
| 127 | |
| 128 | struct lruvec_stats { |
| 129 | /* Aggregated (CPU and subtree) state */ |
| 130 | long state[NR_VM_NODE_STAT_ITEMS]; |
| 131 | |
| 132 | /* Pending child counts during tree propagation */ |
| 133 | long state_pending[NR_VM_NODE_STAT_ITEMS]; |
| 134 | }; |
| 135 | |
Kirill Tkhai | 0a4465d | 2018-08-17 15:47:37 -0700 | [diff] [blame] | 136 | /* |
Hao Lee | 242c37b | 2019-11-30 17:50:12 -0800 | [diff] [blame] | 137 | * per-node information in memory controller. |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 138 | */ |
Mel Gorman | ef8f232 | 2016-07-28 15:46:05 -0700 | [diff] [blame] | 139 | struct mem_cgroup_per_node { |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 140 | struct lruvec lruvec; |
Johannes Weiner | a983b5e | 2018-01-31 16:16:45 -0800 | [diff] [blame] | 141 | |
Shakeel Butt | 7e1c0d6 | 2021-09-02 14:55:00 -0700 | [diff] [blame] | 142 | struct lruvec_stats_percpu __percpu *lruvec_stats_percpu; |
| 143 | struct lruvec_stats lruvec_stats; |
Johannes Weiner | a983b5e | 2018-01-31 16:16:45 -0800 | [diff] [blame] | 144 | |
Michal Hocko | b4536f0c8 | 2017-01-10 16:58:04 -0800 | [diff] [blame] | 145 | unsigned long lru_zone_size[MAX_NR_ZONES][NR_LRU_LISTS]; |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 146 | |
Yafang Shao | 9da83f3 | 2019-11-30 17:50:03 -0800 | [diff] [blame] | 147 | struct mem_cgroup_reclaim_iter iter; |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 148 | |
Yang Shi | e4262c4 | 2021-05-04 18:36:23 -0700 | [diff] [blame] | 149 | struct shrinker_info __rcu *shrinker_info; |
Yang Shi | 0a432dc | 2019-09-23 15:38:12 -0700 | [diff] [blame] | 150 | |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 151 | struct rb_node tree_node; /* RB tree node */ |
| 152 | unsigned long usage_in_excess;/* Set to the value by which */ |
| 153 | /* the soft limit is exceeded*/ |
| 154 | bool on_tree; |
| 155 | struct mem_cgroup *memcg; /* Back pointer, we cannot */ |
| 156 | /* use container_of */ |
| 157 | }; |
| 158 | |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 159 | struct mem_cgroup_threshold { |
| 160 | struct eventfd_ctx *eventfd; |
| 161 | unsigned long threshold; |
| 162 | }; |
| 163 | |
| 164 | /* For threshold */ |
| 165 | struct mem_cgroup_threshold_ary { |
| 166 | /* An array index points to threshold just below or equal to usage. */ |
| 167 | int current_threshold; |
| 168 | /* Size of entries[] */ |
| 169 | unsigned int size; |
| 170 | /* Array of thresholds */ |
Gustavo A. R. Silva | 307ed94 | 2020-03-23 18:36:10 -0500 | [diff] [blame] | 171 | struct mem_cgroup_threshold entries[]; |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | struct mem_cgroup_thresholds { |
| 175 | /* Primary thresholds array */ |
| 176 | struct mem_cgroup_threshold_ary *primary; |
| 177 | /* |
| 178 | * Spare threshold array. |
| 179 | * This is needed to make mem_cgroup_unregister_event() "never fail". |
| 180 | * It must be able to store at least primary->size - 1 entries. |
| 181 | */ |
| 182 | struct mem_cgroup_threshold_ary *spare; |
| 183 | }; |
| 184 | |
Aaron Lu | e81bf97 | 2018-06-07 17:09:44 -0700 | [diff] [blame] | 185 | #if defined(CONFIG_SMP) |
| 186 | struct memcg_padding { |
| 187 | char x[0]; |
| 188 | } ____cacheline_internodealigned_in_smp; |
Huilong Deng | 6a1803b | 2021-06-28 19:38:24 -0700 | [diff] [blame] | 189 | #define MEMCG_PADDING(name) struct memcg_padding name |
Aaron Lu | e81bf97 | 2018-06-07 17:09:44 -0700 | [diff] [blame] | 190 | #else |
| 191 | #define MEMCG_PADDING(name) |
| 192 | #endif |
| 193 | |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 194 | /* |
Tejun Heo | 97b2782 | 2019-08-26 09:06:56 -0700 | [diff] [blame] | 195 | * Remember four most recent foreign writebacks with dirty pages in this |
| 196 | * cgroup. Inode sharing is expected to be uncommon and, even if we miss |
| 197 | * one in a given round, we're likely to catch it later if it keeps |
| 198 | * foreign-dirtying, so a fairly low count should be enough. |
| 199 | * |
| 200 | * See mem_cgroup_track_foreign_dirty_slowpath() for details. |
| 201 | */ |
| 202 | #define MEMCG_CGWB_FRN_CNT 4 |
| 203 | |
| 204 | struct memcg_cgwb_frn { |
| 205 | u64 bdi_id; /* bdi->id of the foreign inode */ |
| 206 | int memcg_id; /* memcg->css.id of foreign inode */ |
| 207 | u64 at; /* jiffies_64 at the time of dirtying */ |
| 208 | struct wb_completion done; /* tracks in-flight foreign writebacks */ |
| 209 | }; |
| 210 | |
| 211 | /* |
Roman Gushchin | bf4f059 | 2020-08-06 23:20:49 -0700 | [diff] [blame] | 212 | * Bucket for arbitrarily byte-sized objects charged to a memory |
| 213 | * cgroup. The bucket can be reparented in one piece when the cgroup |
| 214 | * is destroyed, without having to round up the individual references |
| 215 | * of all live memory objects in the wild. |
| 216 | */ |
| 217 | struct obj_cgroup { |
| 218 | struct percpu_ref refcnt; |
| 219 | struct mem_cgroup *memcg; |
| 220 | atomic_t nr_charged_bytes; |
| 221 | union { |
| 222 | struct list_head list; |
| 223 | struct rcu_head rcu; |
| 224 | }; |
| 225 | }; |
| 226 | |
| 227 | /* |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 228 | * The memory controller data structure. The memory controller controls both |
| 229 | * page cache and RSS per cgroup. We would eventually like to provide |
| 230 | * statistics based on the statistics developed by Rik Van Riel for clock-pro, |
| 231 | * to help the administrator determine what knobs to tune. |
| 232 | */ |
| 233 | struct mem_cgroup { |
| 234 | struct cgroup_subsys_state css; |
| 235 | |
Johannes Weiner | 73f576c | 2016-07-20 15:44:57 -0700 | [diff] [blame] | 236 | /* Private memcg ID. Used to ID objects that outlive the cgroup */ |
| 237 | struct mem_cgroup_id id; |
| 238 | |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 239 | /* Accounted resources */ |
Waiman Long | bd0b230 | 2020-10-13 16:52:56 -0700 | [diff] [blame] | 240 | struct page_counter memory; /* Both v1 & v2 */ |
| 241 | |
| 242 | union { |
| 243 | struct page_counter swap; /* v2 only */ |
| 244 | struct page_counter memsw; /* v1 only */ |
| 245 | }; |
Johannes Weiner | 0db1529 | 2016-01-20 15:02:50 -0800 | [diff] [blame] | 246 | |
| 247 | /* Legacy consumer-oriented counters */ |
Waiman Long | bd0b230 | 2020-10-13 16:52:56 -0700 | [diff] [blame] | 248 | struct page_counter kmem; /* v1 only */ |
| 249 | struct page_counter tcpmem; /* v1 only */ |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 250 | |
Johannes Weiner | f7e1cb6 | 2016-01-14 15:21:29 -0800 | [diff] [blame] | 251 | /* Range enforcement for interrupt charges */ |
| 252 | struct work_struct high_work; |
| 253 | |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 254 | unsigned long soft_limit; |
| 255 | |
| 256 | /* vmpressure notifications */ |
| 257 | struct vmpressure vmpressure; |
| 258 | |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 259 | /* |
Roman Gushchin | 3d8b38e | 2018-08-21 21:53:54 -0700 | [diff] [blame] | 260 | * Should the OOM killer kill all belonging tasks, had it kill one? |
| 261 | */ |
| 262 | bool oom_group; |
| 263 | |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 264 | /* protected by memcg_oom_lock */ |
| 265 | bool oom_lock; |
| 266 | int under_oom; |
| 267 | |
| 268 | int swappiness; |
| 269 | /* OOM-Killer disable */ |
| 270 | int oom_kill_disable; |
| 271 | |
Shakeel Butt | 1e577f9 | 2019-07-11 20:55:55 -0700 | [diff] [blame] | 272 | /* memory.events and memory.events.local */ |
Tejun Heo | 472912a | 2015-09-18 18:01:59 -0400 | [diff] [blame] | 273 | struct cgroup_file events_file; |
Shakeel Butt | 1e577f9 | 2019-07-11 20:55:55 -0700 | [diff] [blame] | 274 | struct cgroup_file events_local_file; |
Tejun Heo | 472912a | 2015-09-18 18:01:59 -0400 | [diff] [blame] | 275 | |
Tejun Heo | f3a53a3 | 2018-06-07 17:05:35 -0700 | [diff] [blame] | 276 | /* handle for "memory.swap.events" */ |
| 277 | struct cgroup_file swap_events_file; |
| 278 | |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 279 | /* protect arrays of thresholds */ |
| 280 | struct mutex thresholds_lock; |
| 281 | |
| 282 | /* thresholds for memory usage. RCU-protected */ |
| 283 | struct mem_cgroup_thresholds thresholds; |
| 284 | |
| 285 | /* thresholds for mem+swap usage. RCU-protected */ |
| 286 | struct mem_cgroup_thresholds memsw_thresholds; |
| 287 | |
| 288 | /* For oom notifier event fd */ |
| 289 | struct list_head oom_notify; |
| 290 | |
| 291 | /* |
| 292 | * Should we move charges of a task when a task is moved into this |
| 293 | * mem_cgroup ? And what type of charges should we move ? |
| 294 | */ |
| 295 | unsigned long move_charge_at_immigrate; |
Aaron Lu | e81bf97 | 2018-06-07 17:09:44 -0700 | [diff] [blame] | 296 | /* taken only while moving_account > 0 */ |
| 297 | spinlock_t move_lock; |
| 298 | unsigned long move_lock_flags; |
| 299 | |
| 300 | MEMCG_PADDING(_pad1_); |
| 301 | |
Johannes Weiner | 2d146aa | 2021-04-29 22:56:26 -0700 | [diff] [blame] | 302 | /* memory.stat */ |
| 303 | struct memcg_vmstats vmstats; |
Johannes Weiner | 42a3003 | 2019-05-14 15:47:12 -0700 | [diff] [blame] | 304 | |
Johannes Weiner | 815744d | 2019-06-13 15:55:46 -0700 | [diff] [blame] | 305 | /* memory.events */ |
Johannes Weiner | 42a3003 | 2019-05-14 15:47:12 -0700 | [diff] [blame] | 306 | atomic_long_t memory_events[MEMCG_NR_MEMORY_EVENTS]; |
Shakeel Butt | 1e577f9 | 2019-07-11 20:55:55 -0700 | [diff] [blame] | 307 | atomic_long_t memory_events_local[MEMCG_NR_MEMORY_EVENTS]; |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 308 | |
Johannes Weiner | d886f4e | 2016-01-20 15:02:47 -0800 | [diff] [blame] | 309 | unsigned long socket_pressure; |
| 310 | |
| 311 | /* Legacy tcp memory accounting */ |
Johannes Weiner | 0db1529 | 2016-01-20 15:02:50 -0800 | [diff] [blame] | 312 | bool tcpmem_active; |
| 313 | int tcpmem_pressure; |
Johannes Weiner | d886f4e | 2016-01-20 15:02:47 -0800 | [diff] [blame] | 314 | |
Kirill Tkhai | 84c07d1 | 2018-08-17 15:47:25 -0700 | [diff] [blame] | 315 | #ifdef CONFIG_MEMCG_KMEM |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 316 | int kmemcg_id; |
Roman Gushchin | bf4f059 | 2020-08-06 23:20:49 -0700 | [diff] [blame] | 317 | struct obj_cgroup __rcu *objcg; |
| 318 | struct list_head objcg_list; /* list of inherited objcgs */ |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 319 | #endif |
| 320 | |
Feng Tang | 4df9106 | 2020-11-25 13:22:21 +0800 | [diff] [blame] | 321 | MEMCG_PADDING(_pad2_); |
| 322 | |
| 323 | /* |
| 324 | * set > 0 if pages under this cgroup are moving to other cgroup. |
| 325 | */ |
| 326 | atomic_t moving_account; |
| 327 | struct task_struct *move_lock_task; |
| 328 | |
Feng Tang | 4df9106 | 2020-11-25 13:22:21 +0800 | [diff] [blame] | 329 | struct memcg_vmstats_percpu __percpu *vmstats_percpu; |
| 330 | |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 331 | #ifdef CONFIG_CGROUP_WRITEBACK |
| 332 | struct list_head cgwb_list; |
| 333 | struct wb_domain cgwb_domain; |
Tejun Heo | 97b2782 | 2019-08-26 09:06:56 -0700 | [diff] [blame] | 334 | struct memcg_cgwb_frn cgwb_frn[MEMCG_CGWB_FRN_CNT]; |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 335 | #endif |
| 336 | |
| 337 | /* List of events which userspace want to receive */ |
| 338 | struct list_head event_list; |
| 339 | spinlock_t event_list_lock; |
| 340 | |
Yang Shi | 87eaceb | 2019-09-23 15:38:15 -0700 | [diff] [blame] | 341 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 342 | struct deferred_split deferred_split_queue; |
| 343 | #endif |
| 344 | |
wenhuizhang | b51478a | 2021-06-28 19:38:12 -0700 | [diff] [blame] | 345 | struct mem_cgroup_per_node *nodeinfo[]; |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 346 | }; |
Johannes Weiner | 7d82860 | 2016-01-14 15:20:56 -0800 | [diff] [blame] | 347 | |
Johannes Weiner | a983b5e | 2018-01-31 16:16:45 -0800 | [diff] [blame] | 348 | /* |
| 349 | * size of first charge trial. "32" comes from vmscan.c's magic value. |
| 350 | * TODO: maybe necessary to use big numbers in big irons. |
| 351 | */ |
| 352 | #define MEMCG_CHARGE_BATCH 32U |
| 353 | |
Johannes Weiner | 7d82860 | 2016-01-14 15:20:56 -0800 | [diff] [blame] | 354 | extern struct mem_cgroup *root_mem_cgroup; |
Tejun Heo | 5616163 | 2015-05-22 17:13:20 -0400 | [diff] [blame] | 355 | |
Roman Gushchin | 87944e2 | 2020-12-01 13:58:29 -0800 | [diff] [blame] | 356 | enum page_memcg_data_flags { |
| 357 | /* page->memcg_data is a pointer to an objcgs vector */ |
| 358 | MEMCG_DATA_OBJCGS = (1UL << 0), |
Roman Gushchin | 18b2db3 | 2020-12-01 13:58:30 -0800 | [diff] [blame] | 359 | /* page has been accounted as a non-slab kernel page */ |
| 360 | MEMCG_DATA_KMEM = (1UL << 1), |
Roman Gushchin | 87944e2 | 2020-12-01 13:58:29 -0800 | [diff] [blame] | 361 | /* the next bit after the last actual flag */ |
Roman Gushchin | 18b2db3 | 2020-12-01 13:58:30 -0800 | [diff] [blame] | 362 | __NR_MEMCG_DATA_FLAGS = (1UL << 2), |
Roman Gushchin | 87944e2 | 2020-12-01 13:58:29 -0800 | [diff] [blame] | 363 | }; |
| 364 | |
| 365 | #define MEMCG_DATA_FLAGS_MASK (__NR_MEMCG_DATA_FLAGS - 1) |
| 366 | |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 367 | static inline bool folio_memcg_kmem(struct folio *folio); |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 368 | |
| 369 | /* |
| 370 | * After the initialization objcg->memcg is always pointing at |
| 371 | * a valid memcg, but can be atomically swapped to the parent memcg. |
| 372 | * |
| 373 | * The caller must ensure that the returned memcg won't be released: |
| 374 | * e.g. acquire the rcu_read_lock or css_set_lock. |
| 375 | */ |
| 376 | static inline struct mem_cgroup *obj_cgroup_memcg(struct obj_cgroup *objcg) |
| 377 | { |
| 378 | return READ_ONCE(objcg->memcg); |
| 379 | } |
| 380 | |
| 381 | /* |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 382 | * __folio_memcg - Get the memory cgroup associated with a non-kmem folio |
| 383 | * @folio: Pointer to the folio. |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 384 | * |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 385 | * Returns a pointer to the memory cgroup associated with the folio, |
| 386 | * or NULL. This function assumes that the folio is known to have a |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 387 | * proper memory cgroup pointer. It's not safe to call this function |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 388 | * against some type of folios, e.g. slab folios or ex-slab folios or |
| 389 | * kmem folios. |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 390 | */ |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 391 | static inline struct mem_cgroup *__folio_memcg(struct folio *folio) |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 392 | { |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 393 | unsigned long memcg_data = folio->memcg_data; |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 394 | |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 395 | VM_BUG_ON_FOLIO(folio_test_slab(folio), folio); |
| 396 | VM_BUG_ON_FOLIO(memcg_data & MEMCG_DATA_OBJCGS, folio); |
| 397 | VM_BUG_ON_FOLIO(memcg_data & MEMCG_DATA_KMEM, folio); |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 398 | |
| 399 | return (struct mem_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK); |
| 400 | } |
| 401 | |
| 402 | /* |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 403 | * __folio_objcg - get the object cgroup associated with a kmem folio. |
| 404 | * @folio: Pointer to the folio. |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 405 | * |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 406 | * Returns a pointer to the object cgroup associated with the folio, |
| 407 | * or NULL. This function assumes that the folio is known to have a |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 408 | * proper object cgroup pointer. It's not safe to call this function |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 409 | * against some type of folios, e.g. slab folios or ex-slab folios or |
| 410 | * LRU folios. |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 411 | */ |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 412 | static inline struct obj_cgroup *__folio_objcg(struct folio *folio) |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 413 | { |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 414 | unsigned long memcg_data = folio->memcg_data; |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 415 | |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 416 | VM_BUG_ON_FOLIO(folio_test_slab(folio), folio); |
| 417 | VM_BUG_ON_FOLIO(memcg_data & MEMCG_DATA_OBJCGS, folio); |
| 418 | VM_BUG_ON_FOLIO(!(memcg_data & MEMCG_DATA_KMEM), folio); |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 419 | |
| 420 | return (struct obj_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK); |
| 421 | } |
| 422 | |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 423 | /* |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 424 | * folio_memcg - Get the memory cgroup associated with a folio. |
| 425 | * @folio: Pointer to the folio. |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 426 | * |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 427 | * Returns a pointer to the memory cgroup associated with the folio, |
| 428 | * or NULL. This function assumes that the folio is known to have a |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 429 | * proper memory cgroup pointer. It's not safe to call this function |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 430 | * against some type of folios, e.g. slab folios or ex-slab folios. |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 431 | * |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 432 | * For a non-kmem folio any of the following ensures folio and memcg binding |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 433 | * stability: |
| 434 | * |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 435 | * - the folio lock |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 436 | * - LRU isolation |
| 437 | * - lock_page_memcg() |
| 438 | * - exclusive reference |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 439 | * |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 440 | * For a kmem folio a caller should hold an rcu read lock to protect memcg |
| 441 | * associated with a kmem folio from being released. |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 442 | */ |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 443 | static inline struct mem_cgroup *folio_memcg(struct folio *folio) |
| 444 | { |
| 445 | if (folio_memcg_kmem(folio)) |
| 446 | return obj_cgroup_memcg(__folio_objcg(folio)); |
| 447 | return __folio_memcg(folio); |
| 448 | } |
| 449 | |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 450 | static inline struct mem_cgroup *page_memcg(struct page *page) |
| 451 | { |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 452 | return folio_memcg(page_folio(page)); |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 453 | } |
| 454 | |
Matthew Wilcox (Oracle) | c5ce619 | 2021-05-04 17:19:13 -0400 | [diff] [blame] | 455 | /** |
| 456 | * folio_memcg_rcu - Locklessly get the memory cgroup associated with a folio. |
| 457 | * @folio: Pointer to the folio. |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 458 | * |
Matthew Wilcox (Oracle) | c5ce619 | 2021-05-04 17:19:13 -0400 | [diff] [blame] | 459 | * This function assumes that the folio is known to have a |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 460 | * proper memory cgroup pointer. It's not safe to call this function |
Matthew Wilcox (Oracle) | c5ce619 | 2021-05-04 17:19:13 -0400 | [diff] [blame] | 461 | * against some type of folios, e.g. slab folios or ex-slab folios. |
| 462 | * |
| 463 | * Return: A pointer to the memory cgroup associated with the folio, |
| 464 | * or NULL. |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 465 | */ |
Matthew Wilcox (Oracle) | c5ce619 | 2021-05-04 17:19:13 -0400 | [diff] [blame] | 466 | static inline struct mem_cgroup *folio_memcg_rcu(struct folio *folio) |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 467 | { |
Matthew Wilcox (Oracle) | c5ce619 | 2021-05-04 17:19:13 -0400 | [diff] [blame] | 468 | unsigned long memcg_data = READ_ONCE(folio->memcg_data); |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 469 | |
Matthew Wilcox (Oracle) | c5ce619 | 2021-05-04 17:19:13 -0400 | [diff] [blame] | 470 | VM_BUG_ON_FOLIO(folio_test_slab(folio), folio); |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 471 | WARN_ON_ONCE(!rcu_read_lock_held()); |
| 472 | |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 473 | if (memcg_data & MEMCG_DATA_KMEM) { |
| 474 | struct obj_cgroup *objcg; |
| 475 | |
| 476 | objcg = (void *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK); |
| 477 | return obj_cgroup_memcg(objcg); |
| 478 | } |
| 479 | |
| 480 | return (struct mem_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK); |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | /* |
| 484 | * page_memcg_check - get the memory cgroup associated with a page |
| 485 | * @page: a pointer to the page struct |
| 486 | * |
| 487 | * Returns a pointer to the memory cgroup associated with the page, |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 488 | * or NULL. This function unlike page_memcg() can take any page |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 489 | * as an argument. It has to be used in cases when it's not known if a page |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 490 | * has an associated memory cgroup pointer or an object cgroups vector or |
| 491 | * an object cgroup. |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 492 | * |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 493 | * For a non-kmem page any of the following ensures page and memcg binding |
| 494 | * stability: |
| 495 | * |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 496 | * - the page lock |
| 497 | * - LRU isolation |
| 498 | * - lock_page_memcg() |
| 499 | * - exclusive reference |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 500 | * |
| 501 | * For a kmem page a caller should hold an rcu read lock to protect memcg |
| 502 | * associated with a kmem page from being released. |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 503 | */ |
| 504 | static inline struct mem_cgroup *page_memcg_check(struct page *page) |
| 505 | { |
| 506 | /* |
| 507 | * Because page->memcg_data might be changed asynchronously |
| 508 | * for slab pages, READ_ONCE() should be used here. |
| 509 | */ |
| 510 | unsigned long memcg_data = READ_ONCE(page->memcg_data); |
| 511 | |
Roman Gushchin | 87944e2 | 2020-12-01 13:58:29 -0800 | [diff] [blame] | 512 | if (memcg_data & MEMCG_DATA_OBJCGS) |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 513 | return NULL; |
| 514 | |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 515 | if (memcg_data & MEMCG_DATA_KMEM) { |
| 516 | struct obj_cgroup *objcg; |
| 517 | |
| 518 | objcg = (void *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK); |
| 519 | return obj_cgroup_memcg(objcg); |
| 520 | } |
| 521 | |
Roman Gushchin | 18b2db3 | 2020-12-01 13:58:30 -0800 | [diff] [blame] | 522 | return (struct mem_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK); |
| 523 | } |
| 524 | |
Muchun Song | bd290e1 | 2021-04-29 22:56:58 -0700 | [diff] [blame] | 525 | #ifdef CONFIG_MEMCG_KMEM |
Roman Gushchin | 18b2db3 | 2020-12-01 13:58:30 -0800 | [diff] [blame] | 526 | /* |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 527 | * folio_memcg_kmem - Check if the folio has the memcg_kmem flag set. |
| 528 | * @folio: Pointer to the folio. |
Roman Gushchin | 18b2db3 | 2020-12-01 13:58:30 -0800 | [diff] [blame] | 529 | * |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 530 | * Checks if the folio has MemcgKmem flag set. The caller must ensure |
| 531 | * that the folio has an associated memory cgroup. It's not safe to call |
| 532 | * this function against some types of folios, e.g. slab folios. |
Roman Gushchin | 18b2db3 | 2020-12-01 13:58:30 -0800 | [diff] [blame] | 533 | */ |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 534 | static inline bool folio_memcg_kmem(struct folio *folio) |
Roman Gushchin | 18b2db3 | 2020-12-01 13:58:30 -0800 | [diff] [blame] | 535 | { |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 536 | VM_BUG_ON_PGFLAGS(PageTail(&folio->page), &folio->page); |
| 537 | VM_BUG_ON_FOLIO(folio->memcg_data & MEMCG_DATA_OBJCGS, folio); |
| 538 | return folio->memcg_data & MEMCG_DATA_KMEM; |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 539 | } |
| 540 | |
Roman Gushchin | 270c6a7 | 2020-12-01 13:58:28 -0800 | [diff] [blame] | 541 | |
Roman Gushchin | 270c6a7 | 2020-12-01 13:58:28 -0800 | [diff] [blame] | 542 | #else |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 543 | static inline bool folio_memcg_kmem(struct folio *folio) |
Muchun Song | bd290e1 | 2021-04-29 22:56:58 -0700 | [diff] [blame] | 544 | { |
| 545 | return false; |
| 546 | } |
| 547 | |
Roman Gushchin | 270c6a7 | 2020-12-01 13:58:28 -0800 | [diff] [blame] | 548 | #endif |
| 549 | |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 550 | static inline bool PageMemcgKmem(struct page *page) |
| 551 | { |
| 552 | return folio_memcg_kmem(page_folio(page)); |
| 553 | } |
| 554 | |
Kirill Tkhai | dfd2f10 | 2018-08-17 15:48:06 -0700 | [diff] [blame] | 555 | static inline bool mem_cgroup_is_root(struct mem_cgroup *memcg) |
| 556 | { |
| 557 | return (memcg == root_mem_cgroup); |
| 558 | } |
| 559 | |
Johannes Weiner | 23047a9 | 2016-03-15 14:57:16 -0700 | [diff] [blame] | 560 | static inline bool mem_cgroup_disabled(void) |
| 561 | { |
| 562 | return !cgroup_subsys_enabled(memory_cgrp_subsys); |
| 563 | } |
| 564 | |
Johannes Weiner | f56ce41 | 2021-08-19 19:04:21 -0700 | [diff] [blame] | 565 | static inline void mem_cgroup_protection(struct mem_cgroup *root, |
| 566 | struct mem_cgroup *memcg, |
| 567 | unsigned long *min, |
| 568 | unsigned long *low) |
Chris Down | 9783aa9 | 2019-10-06 17:58:32 -0700 | [diff] [blame] | 569 | { |
Johannes Weiner | f56ce41 | 2021-08-19 19:04:21 -0700 | [diff] [blame] | 570 | *min = *low = 0; |
| 571 | |
Chris Down | 1bc63fb | 2019-10-06 17:58:38 -0700 | [diff] [blame] | 572 | if (mem_cgroup_disabled()) |
Johannes Weiner | f56ce41 | 2021-08-19 19:04:21 -0700 | [diff] [blame] | 573 | return; |
Chris Down | 9783aa9 | 2019-10-06 17:58:32 -0700 | [diff] [blame] | 574 | |
Yafang Shao | 22f7496 | 2020-08-06 23:22:01 -0700 | [diff] [blame] | 575 | /* |
| 576 | * There is no reclaim protection applied to a targeted reclaim. |
| 577 | * We are special casing this specific case here because |
| 578 | * mem_cgroup_protected calculation is not robust enough to keep |
| 579 | * the protection invariant for calculated effective values for |
| 580 | * parallel reclaimers with different reclaim target. This is |
| 581 | * especially a problem for tail memcgs (as they have pages on LRU) |
| 582 | * which would want to have effective values 0 for targeted reclaim |
| 583 | * but a different value for external reclaim. |
| 584 | * |
| 585 | * Example |
| 586 | * Let's have global and A's reclaim in parallel: |
| 587 | * | |
| 588 | * A (low=2G, usage = 3G, max = 3G, children_low_usage = 1.5G) |
| 589 | * |\ |
| 590 | * | C (low = 1G, usage = 2.5G) |
| 591 | * B (low = 1G, usage = 0.5G) |
| 592 | * |
| 593 | * For the global reclaim |
| 594 | * A.elow = A.low |
| 595 | * B.elow = min(B.usage, B.low) because children_low_usage <= A.elow |
| 596 | * C.elow = min(C.usage, C.low) |
| 597 | * |
| 598 | * With the effective values resetting we have A reclaim |
| 599 | * A.elow = 0 |
| 600 | * B.elow = B.low |
| 601 | * C.elow = C.low |
| 602 | * |
| 603 | * If the global reclaim races with A's reclaim then |
| 604 | * B.elow = C.elow = 0 because children_low_usage > A.elow) |
| 605 | * is possible and reclaiming B would be violating the protection. |
| 606 | * |
| 607 | */ |
| 608 | if (root == memcg) |
Johannes Weiner | f56ce41 | 2021-08-19 19:04:21 -0700 | [diff] [blame] | 609 | return; |
Yafang Shao | 22f7496 | 2020-08-06 23:22:01 -0700 | [diff] [blame] | 610 | |
Johannes Weiner | f56ce41 | 2021-08-19 19:04:21 -0700 | [diff] [blame] | 611 | *min = READ_ONCE(memcg->memory.emin); |
| 612 | *low = READ_ONCE(memcg->memory.elow); |
Chris Down | 9783aa9 | 2019-10-06 17:58:32 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Chris Down | 45c7f7e | 2020-08-06 23:22:05 -0700 | [diff] [blame] | 615 | void mem_cgroup_calculate_protection(struct mem_cgroup *root, |
| 616 | struct mem_cgroup *memcg); |
| 617 | |
| 618 | static inline bool mem_cgroup_supports_protection(struct mem_cgroup *memcg) |
| 619 | { |
| 620 | /* |
| 621 | * The root memcg doesn't account charges, and doesn't support |
| 622 | * protection. |
| 623 | */ |
| 624 | return !mem_cgroup_disabled() && !mem_cgroup_is_root(memcg); |
| 625 | |
| 626 | } |
| 627 | |
| 628 | static inline bool mem_cgroup_below_low(struct mem_cgroup *memcg) |
| 629 | { |
| 630 | if (!mem_cgroup_supports_protection(memcg)) |
| 631 | return false; |
| 632 | |
| 633 | return READ_ONCE(memcg->memory.elow) >= |
| 634 | page_counter_read(&memcg->memory); |
| 635 | } |
| 636 | |
| 637 | static inline bool mem_cgroup_below_min(struct mem_cgroup *memcg) |
| 638 | { |
| 639 | if (!mem_cgroup_supports_protection(memcg)) |
| 640 | return false; |
| 641 | |
| 642 | return READ_ONCE(memcg->memory.emin) >= |
| 643 | page_counter_read(&memcg->memory); |
| 644 | } |
Johannes Weiner | 241994ed | 2015-02-11 15:26:06 -0800 | [diff] [blame] | 645 | |
Matthew Wilcox (Oracle) | 8f425e4 | 2021-06-25 09:27:04 -0400 | [diff] [blame] | 646 | int __mem_cgroup_charge(struct folio *folio, struct mm_struct *mm, gfp_t gfp); |
| 647 | |
| 648 | /** |
| 649 | * mem_cgroup_charge - Charge a newly allocated folio to a cgroup. |
| 650 | * @folio: Folio to charge. |
| 651 | * @mm: mm context of the allocating task. |
| 652 | * @gfp: Reclaim mode. |
| 653 | * |
| 654 | * Try to charge @folio to the memcg that @mm belongs to, reclaiming |
| 655 | * pages according to @gfp if necessary. If @mm is NULL, try to |
| 656 | * charge to the active memcg. |
| 657 | * |
| 658 | * Do not use this for folios allocated for swapin. |
| 659 | * |
| 660 | * Return: 0 on success. Otherwise, an error code is returned. |
| 661 | */ |
| 662 | static inline int mem_cgroup_charge(struct folio *folio, struct mm_struct *mm, |
| 663 | gfp_t gfp) |
Suren Baghdasaryan | 2c8d8f9 | 2021-09-02 14:54:50 -0700 | [diff] [blame] | 664 | { |
| 665 | if (mem_cgroup_disabled()) |
| 666 | return 0; |
Matthew Wilcox (Oracle) | 8f425e4 | 2021-06-25 09:27:04 -0400 | [diff] [blame] | 667 | return __mem_cgroup_charge(folio, mm, gfp); |
Suren Baghdasaryan | 2c8d8f9 | 2021-09-02 14:54:50 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Shakeel Butt | 0add0c7 | 2021-04-29 22:56:36 -0700 | [diff] [blame] | 670 | int mem_cgroup_swapin_charge_page(struct page *page, struct mm_struct *mm, |
| 671 | gfp_t gfp, swp_entry_t entry); |
| 672 | void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry); |
Johannes Weiner | 3fea5a4 | 2020-06-03 16:01:41 -0700 | [diff] [blame] | 673 | |
Matthew Wilcox (Oracle) | bbc6b70 | 2021-05-01 20:42:23 -0400 | [diff] [blame] | 674 | void __mem_cgroup_uncharge(struct folio *folio); |
| 675 | |
| 676 | /** |
| 677 | * mem_cgroup_uncharge - Uncharge a folio. |
| 678 | * @folio: Folio to uncharge. |
| 679 | * |
| 680 | * Uncharge a folio previously charged with mem_cgroup_charge(). |
| 681 | */ |
| 682 | static inline void mem_cgroup_uncharge(struct folio *folio) |
Suren Baghdasaryan | 2c8d8f9 | 2021-09-02 14:54:50 -0700 | [diff] [blame] | 683 | { |
| 684 | if (mem_cgroup_disabled()) |
| 685 | return; |
Matthew Wilcox (Oracle) | bbc6b70 | 2021-05-01 20:42:23 -0400 | [diff] [blame] | 686 | __mem_cgroup_uncharge(folio); |
Suren Baghdasaryan | 2c8d8f9 | 2021-09-02 14:54:50 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | void __mem_cgroup_uncharge_list(struct list_head *page_list); |
| 690 | static inline void mem_cgroup_uncharge_list(struct list_head *page_list) |
| 691 | { |
| 692 | if (mem_cgroup_disabled()) |
| 693 | return; |
| 694 | __mem_cgroup_uncharge_list(page_list); |
| 695 | } |
Johannes Weiner | 0a31bc9 | 2014-08-08 14:19:22 -0700 | [diff] [blame] | 696 | |
Matthew Wilcox (Oracle) | d21bba2 | 2021-05-06 18:14:59 -0400 | [diff] [blame] | 697 | void mem_cgroup_migrate(struct folio *old, struct folio *new); |
Johannes Weiner | 0a31bc9 | 2014-08-08 14:19:22 -0700 | [diff] [blame] | 698 | |
Johannes Weiner | 55779ec | 2016-07-28 15:45:10 -0700 | [diff] [blame] | 699 | /** |
Johannes Weiner | 867e5e1 | 2019-11-30 17:55:34 -0800 | [diff] [blame] | 700 | * mem_cgroup_lruvec - get the lru list vector for a memcg & node |
Johannes Weiner | 55779ec | 2016-07-28 15:45:10 -0700 | [diff] [blame] | 701 | * @memcg: memcg of the wanted lruvec |
Hui Su | 9a1ac22 | 2020-12-18 14:01:41 -0800 | [diff] [blame] | 702 | * @pgdat: pglist_data |
Johannes Weiner | 55779ec | 2016-07-28 15:45:10 -0700 | [diff] [blame] | 703 | * |
Johannes Weiner | 867e5e1 | 2019-11-30 17:55:34 -0800 | [diff] [blame] | 704 | * Returns the lru list vector holding pages for a given @memcg & |
Hui Su | 9a1ac22 | 2020-12-18 14:01:41 -0800 | [diff] [blame] | 705 | * @pgdat combination. This can be the node lruvec, if the memory |
Johannes Weiner | 867e5e1 | 2019-11-30 17:55:34 -0800 | [diff] [blame] | 706 | * controller is disabled. |
Johannes Weiner | 55779ec | 2016-07-28 15:45:10 -0700 | [diff] [blame] | 707 | */ |
Johannes Weiner | 867e5e1 | 2019-11-30 17:55:34 -0800 | [diff] [blame] | 708 | static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg, |
| 709 | struct pglist_data *pgdat) |
Johannes Weiner | 55779ec | 2016-07-28 15:45:10 -0700 | [diff] [blame] | 710 | { |
Mel Gorman | ef8f232 | 2016-07-28 15:46:05 -0700 | [diff] [blame] | 711 | struct mem_cgroup_per_node *mz; |
Johannes Weiner | 55779ec | 2016-07-28 15:45:10 -0700 | [diff] [blame] | 712 | struct lruvec *lruvec; |
| 713 | |
| 714 | if (mem_cgroup_disabled()) { |
Johannes Weiner | 867e5e1 | 2019-11-30 17:55:34 -0800 | [diff] [blame] | 715 | lruvec = &pgdat->__lruvec; |
Johannes Weiner | 55779ec | 2016-07-28 15:45:10 -0700 | [diff] [blame] | 716 | goto out; |
| 717 | } |
| 718 | |
Johannes Weiner | 1b05117 | 2019-11-30 17:55:52 -0800 | [diff] [blame] | 719 | if (!memcg) |
| 720 | memcg = root_mem_cgroup; |
| 721 | |
Johannes Weiner | a3747b5 | 2021-04-29 22:56:14 -0700 | [diff] [blame] | 722 | mz = memcg->nodeinfo[pgdat->node_id]; |
Johannes Weiner | 55779ec | 2016-07-28 15:45:10 -0700 | [diff] [blame] | 723 | lruvec = &mz->lruvec; |
| 724 | out: |
| 725 | /* |
| 726 | * Since a node can be onlined after the mem_cgroup was created, |
Mel Gorman | 599d0c9 | 2016-07-28 15:45:31 -0700 | [diff] [blame] | 727 | * we have to be prepared to initialize lruvec->pgdat here; |
Johannes Weiner | 55779ec | 2016-07-28 15:45:10 -0700 | [diff] [blame] | 728 | * and if offlined then reonlined, we need to reinitialize it. |
| 729 | */ |
Mel Gorman | ef8f232 | 2016-07-28 15:46:05 -0700 | [diff] [blame] | 730 | if (unlikely(lruvec->pgdat != pgdat)) |
| 731 | lruvec->pgdat = pgdat; |
Johannes Weiner | 55779ec | 2016-07-28 15:45:10 -0700 | [diff] [blame] | 732 | return lruvec; |
| 733 | } |
| 734 | |
Hui Su | 9a1ac22 | 2020-12-18 14:01:41 -0800 | [diff] [blame] | 735 | /** |
Matthew Wilcox (Oracle) | b1baabd | 2021-06-28 20:00:28 -0400 | [diff] [blame] | 736 | * folio_lruvec - return lruvec for isolating/putting an LRU folio |
| 737 | * @folio: Pointer to the folio. |
Hui Su | 9a1ac22 | 2020-12-18 14:01:41 -0800 | [diff] [blame] | 738 | * |
Matthew Wilcox (Oracle) | b1baabd | 2021-06-28 20:00:28 -0400 | [diff] [blame] | 739 | * This function relies on folio->mem_cgroup being stable. |
Hui Su | 9a1ac22 | 2020-12-18 14:01:41 -0800 | [diff] [blame] | 740 | */ |
Matthew Wilcox (Oracle) | b1baabd | 2021-06-28 20:00:28 -0400 | [diff] [blame] | 741 | static inline struct lruvec *folio_lruvec(struct folio *folio) |
Hui Su | 9a1ac22 | 2020-12-18 14:01:41 -0800 | [diff] [blame] | 742 | { |
Matthew Wilcox (Oracle) | b1baabd | 2021-06-28 20:00:28 -0400 | [diff] [blame] | 743 | struct mem_cgroup *memcg = folio_memcg(folio); |
Hui Su | 9a1ac22 | 2020-12-18 14:01:41 -0800 | [diff] [blame] | 744 | |
Matthew Wilcox (Oracle) | b1baabd | 2021-06-28 20:00:28 -0400 | [diff] [blame] | 745 | VM_WARN_ON_ONCE_FOLIO(!memcg && !mem_cgroup_disabled(), folio); |
| 746 | return mem_cgroup_lruvec(memcg, folio_pgdat(folio)); |
Hui Su | 9a1ac22 | 2020-12-18 14:01:41 -0800 | [diff] [blame] | 747 | } |
KAMEZAWA Hiroyuki | 569b846 | 2009-12-15 16:47:03 -0800 | [diff] [blame] | 748 | |
Michal Hocko | 6421999 | 2015-09-08 15:01:07 -0700 | [diff] [blame] | 749 | struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p); |
Vladimir Davydov | e993d90 | 2015-09-09 15:35:35 -0700 | [diff] [blame] | 750 | |
Shakeel Butt | d46eb14b | 2018-08-17 15:46:39 -0700 | [diff] [blame] | 751 | struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm); |
| 752 | |
Matthew Wilcox (Oracle) | e809c3f | 2021-06-28 21:59:47 -0400 | [diff] [blame] | 753 | struct lruvec *folio_lruvec_lock(struct folio *folio); |
| 754 | struct lruvec *folio_lruvec_lock_irq(struct folio *folio); |
| 755 | struct lruvec *folio_lruvec_lock_irqsave(struct folio *folio, |
Alex Shi | 6168d0d | 2020-12-15 12:34:29 -0800 | [diff] [blame] | 756 | unsigned long *flags); |
| 757 | |
| 758 | #ifdef CONFIG_DEBUG_VM |
Matthew Wilcox (Oracle) | e809c3f | 2021-06-28 21:59:47 -0400 | [diff] [blame] | 759 | void lruvec_memcg_debug(struct lruvec *lruvec, struct folio *folio); |
Alex Shi | 6168d0d | 2020-12-15 12:34:29 -0800 | [diff] [blame] | 760 | #else |
Matthew Wilcox (Oracle) | e809c3f | 2021-06-28 21:59:47 -0400 | [diff] [blame] | 761 | static inline |
| 762 | void lruvec_memcg_debug(struct lruvec *lruvec, struct folio *folio) |
Alex Shi | 6168d0d | 2020-12-15 12:34:29 -0800 | [diff] [blame] | 763 | { |
| 764 | } |
| 765 | #endif |
| 766 | |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 767 | static inline |
| 768 | struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *css){ |
| 769 | return css ? container_of(css, struct mem_cgroup, css) : NULL; |
| 770 | } |
| 771 | |
Roman Gushchin | bf4f059 | 2020-08-06 23:20:49 -0700 | [diff] [blame] | 772 | static inline bool obj_cgroup_tryget(struct obj_cgroup *objcg) |
| 773 | { |
| 774 | return percpu_ref_tryget(&objcg->refcnt); |
| 775 | } |
| 776 | |
| 777 | static inline void obj_cgroup_get(struct obj_cgroup *objcg) |
| 778 | { |
| 779 | percpu_ref_get(&objcg->refcnt); |
| 780 | } |
| 781 | |
Muchun Song | b4e0b68 | 2021-04-29 22:56:52 -0700 | [diff] [blame] | 782 | static inline void obj_cgroup_get_many(struct obj_cgroup *objcg, |
| 783 | unsigned long nr) |
| 784 | { |
| 785 | percpu_ref_get_many(&objcg->refcnt, nr); |
| 786 | } |
| 787 | |
Roman Gushchin | bf4f059 | 2020-08-06 23:20:49 -0700 | [diff] [blame] | 788 | static inline void obj_cgroup_put(struct obj_cgroup *objcg) |
| 789 | { |
| 790 | percpu_ref_put(&objcg->refcnt); |
| 791 | } |
| 792 | |
Roman Gushchin | dc0b586 | 2018-08-17 15:46:36 -0700 | [diff] [blame] | 793 | static inline void mem_cgroup_put(struct mem_cgroup *memcg) |
| 794 | { |
Shakeel Butt | d46eb14b | 2018-08-17 15:46:39 -0700 | [diff] [blame] | 795 | if (memcg) |
| 796 | css_put(&memcg->css); |
Roman Gushchin | dc0b586 | 2018-08-17 15:46:36 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Johannes Weiner | 8e8ae64 | 2016-01-14 15:21:32 -0800 | [diff] [blame] | 799 | #define mem_cgroup_from_counter(counter, member) \ |
| 800 | container_of(counter, struct mem_cgroup, member) |
| 801 | |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 802 | struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *, |
| 803 | struct mem_cgroup *, |
| 804 | struct mem_cgroup_reclaim_cookie *); |
| 805 | void mem_cgroup_iter_break(struct mem_cgroup *, struct mem_cgroup *); |
Vladimir Davydov | 7c5f64f | 2016-10-07 16:57:23 -0700 | [diff] [blame] | 806 | int mem_cgroup_scan_tasks(struct mem_cgroup *, |
| 807 | int (*)(struct task_struct *, void *), void *); |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 808 | |
Johannes Weiner | 23047a9 | 2016-03-15 14:57:16 -0700 | [diff] [blame] | 809 | static inline unsigned short mem_cgroup_id(struct mem_cgroup *memcg) |
| 810 | { |
| 811 | if (mem_cgroup_disabled()) |
| 812 | return 0; |
| 813 | |
Johannes Weiner | 73f576c | 2016-07-20 15:44:57 -0700 | [diff] [blame] | 814 | return memcg->id.id; |
Johannes Weiner | 23047a9 | 2016-03-15 14:57:16 -0700 | [diff] [blame] | 815 | } |
Johannes Weiner | 73f576c | 2016-07-20 15:44:57 -0700 | [diff] [blame] | 816 | struct mem_cgroup *mem_cgroup_from_id(unsigned short id); |
Johannes Weiner | 23047a9 | 2016-03-15 14:57:16 -0700 | [diff] [blame] | 817 | |
Chris Down | aa9694b | 2019-03-05 15:45:52 -0800 | [diff] [blame] | 818 | static inline struct mem_cgroup *mem_cgroup_from_seq(struct seq_file *m) |
| 819 | { |
| 820 | return mem_cgroup_from_css(seq_css(m)); |
| 821 | } |
| 822 | |
Roman Gushchin | 2262185 | 2017-07-06 15:40:25 -0700 | [diff] [blame] | 823 | static inline struct mem_cgroup *lruvec_memcg(struct lruvec *lruvec) |
| 824 | { |
| 825 | struct mem_cgroup_per_node *mz; |
| 826 | |
| 827 | if (mem_cgroup_disabled()) |
| 828 | return NULL; |
| 829 | |
| 830 | mz = container_of(lruvec, struct mem_cgroup_per_node, lruvec); |
| 831 | return mz->memcg; |
| 832 | } |
| 833 | |
Johannes Weiner | 8e8ae64 | 2016-01-14 15:21:32 -0800 | [diff] [blame] | 834 | /** |
| 835 | * parent_mem_cgroup - find the accounting parent of a memcg |
| 836 | * @memcg: memcg whose parent to find |
| 837 | * |
| 838 | * Returns the parent memcg, or NULL if this is the root or the memory |
| 839 | * controller is in legacy no-hierarchy mode. |
| 840 | */ |
| 841 | static inline struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg) |
| 842 | { |
| 843 | if (!memcg->memory.parent) |
| 844 | return NULL; |
| 845 | return mem_cgroup_from_counter(memcg->memory.parent, memory); |
| 846 | } |
| 847 | |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 848 | static inline bool mem_cgroup_is_descendant(struct mem_cgroup *memcg, |
| 849 | struct mem_cgroup *root) |
| 850 | { |
| 851 | if (root == memcg) |
| 852 | return true; |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 853 | return cgroup_is_descendant(memcg->css.cgroup, root->css.cgroup); |
| 854 | } |
Glauber Costa | e1aab16 | 2011-12-11 21:47:03 +0000 | [diff] [blame] | 855 | |
Johannes Weiner | 2314b42 | 2014-12-10 15:44:33 -0800 | [diff] [blame] | 856 | static inline bool mm_match_cgroup(struct mm_struct *mm, |
| 857 | struct mem_cgroup *memcg) |
Lai Jiangshan | 2e4d409 | 2009-01-07 18:08:07 -0800 | [diff] [blame] | 858 | { |
Johannes Weiner | 587af30 | 2012-10-08 16:34:12 -0700 | [diff] [blame] | 859 | struct mem_cgroup *task_memcg; |
Johannes Weiner | 413918b | 2014-12-10 15:44:30 -0800 | [diff] [blame] | 860 | bool match = false; |
Johannes Weiner | c3ac9a8 | 2012-05-29 15:06:25 -0700 | [diff] [blame] | 861 | |
Lai Jiangshan | 2e4d409 | 2009-01-07 18:08:07 -0800 | [diff] [blame] | 862 | rcu_read_lock(); |
Johannes Weiner | 587af30 | 2012-10-08 16:34:12 -0700 | [diff] [blame] | 863 | task_memcg = mem_cgroup_from_task(rcu_dereference(mm->owner)); |
Johannes Weiner | 413918b | 2014-12-10 15:44:30 -0800 | [diff] [blame] | 864 | if (task_memcg) |
Johannes Weiner | 2314b42 | 2014-12-10 15:44:33 -0800 | [diff] [blame] | 865 | match = mem_cgroup_is_descendant(task_memcg, memcg); |
Lai Jiangshan | 2e4d409 | 2009-01-07 18:08:07 -0800 | [diff] [blame] | 866 | rcu_read_unlock(); |
Johannes Weiner | c3ac9a8 | 2012-05-29 15:06:25 -0700 | [diff] [blame] | 867 | return match; |
Lai Jiangshan | 2e4d409 | 2009-01-07 18:08:07 -0800 | [diff] [blame] | 868 | } |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 869 | |
Michal Hocko | 6421999 | 2015-09-08 15:01:07 -0700 | [diff] [blame] | 870 | struct cgroup_subsys_state *mem_cgroup_css_from_page(struct page *page); |
Vladimir Davydov | 2fc0452 | 2015-09-09 15:35:28 -0700 | [diff] [blame] | 871 | ino_t page_cgroup_ino(struct page *page); |
Wu Fengguang | d324236 | 2009-12-16 12:19:59 +0100 | [diff] [blame] | 872 | |
Vladimir Davydov | eb01aaa | 2016-01-20 15:03:02 -0800 | [diff] [blame] | 873 | static inline bool mem_cgroup_online(struct mem_cgroup *memcg) |
| 874 | { |
| 875 | if (mem_cgroup_disabled()) |
| 876 | return true; |
| 877 | return !!(memcg->css.flags & CSS_ONLINE); |
| 878 | } |
| 879 | |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 880 | void mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru, |
Michal Hocko | b4536f0c8 | 2017-01-10 16:58:04 -0800 | [diff] [blame] | 881 | int zid, int nr_pages); |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 882 | |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 883 | static inline |
Michal Hocko | b4536f0c8 | 2017-01-10 16:58:04 -0800 | [diff] [blame] | 884 | unsigned long mem_cgroup_get_zone_lru_size(struct lruvec *lruvec, |
| 885 | enum lru_list lru, int zone_idx) |
| 886 | { |
| 887 | struct mem_cgroup_per_node *mz; |
| 888 | |
| 889 | mz = container_of(lruvec, struct mem_cgroup_per_node, lruvec); |
Qian Cai | e0e3f42 | 2020-08-14 17:31:37 -0700 | [diff] [blame] | 890 | return READ_ONCE(mz->lru_zone_size[zone_idx][lru]); |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 891 | } |
| 892 | |
Tejun Heo | b23afb9 | 2015-11-05 18:46:11 -0800 | [diff] [blame] | 893 | void mem_cgroup_handle_over_high(void); |
| 894 | |
Roman Gushchin | bbec2e1 | 2018-06-07 17:06:18 -0700 | [diff] [blame] | 895 | unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg); |
Vladimir Davydov | 7c5f64f | 2016-10-07 16:57:23 -0700 | [diff] [blame] | 896 | |
Chris Down | 9783aa9 | 2019-10-06 17:58:32 -0700 | [diff] [blame] | 897 | unsigned long mem_cgroup_size(struct mem_cgroup *memcg); |
| 898 | |
yuzhoujian | f0c867d | 2018-12-28 00:36:10 -0800 | [diff] [blame] | 899 | void mem_cgroup_print_oom_context(struct mem_cgroup *memcg, |
Michal Hocko | 6421999 | 2015-09-08 15:01:07 -0700 | [diff] [blame] | 900 | struct task_struct *p); |
KAMEZAWA Hiroyuki | 58ae83d | 2008-02-07 00:14:32 -0800 | [diff] [blame] | 901 | |
yuzhoujian | f0c867d | 2018-12-28 00:36:10 -0800 | [diff] [blame] | 902 | void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg); |
| 903 | |
Michal Hocko | 29ef680 | 2018-08-17 15:47:11 -0700 | [diff] [blame] | 904 | static inline void mem_cgroup_enter_user_fault(void) |
Johannes Weiner | 519e524 | 2013-09-12 15:13:42 -0700 | [diff] [blame] | 905 | { |
Michal Hocko | 29ef680 | 2018-08-17 15:47:11 -0700 | [diff] [blame] | 906 | WARN_ON(current->in_user_fault); |
| 907 | current->in_user_fault = 1; |
Johannes Weiner | 519e524 | 2013-09-12 15:13:42 -0700 | [diff] [blame] | 908 | } |
| 909 | |
Michal Hocko | 29ef680 | 2018-08-17 15:47:11 -0700 | [diff] [blame] | 910 | static inline void mem_cgroup_exit_user_fault(void) |
Johannes Weiner | 519e524 | 2013-09-12 15:13:42 -0700 | [diff] [blame] | 911 | { |
Michal Hocko | 29ef680 | 2018-08-17 15:47:11 -0700 | [diff] [blame] | 912 | WARN_ON(!current->in_user_fault); |
| 913 | current->in_user_fault = 0; |
Johannes Weiner | 519e524 | 2013-09-12 15:13:42 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Johannes Weiner | 3812c8c | 2013-09-12 15:13:44 -0700 | [diff] [blame] | 916 | static inline bool task_in_memcg_oom(struct task_struct *p) |
| 917 | { |
Tejun Heo | 626ebc4 | 2015-11-05 18:46:09 -0800 | [diff] [blame] | 918 | return p->memcg_in_oom; |
Johannes Weiner | 3812c8c | 2013-09-12 15:13:44 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Johannes Weiner | 4942642 | 2013-10-16 13:46:59 -0700 | [diff] [blame] | 921 | bool mem_cgroup_oom_synchronize(bool wait); |
Roman Gushchin | 3d8b38e | 2018-08-21 21:53:54 -0700 | [diff] [blame] | 922 | struct mem_cgroup *mem_cgroup_get_oom_group(struct task_struct *victim, |
| 923 | struct mem_cgroup *oom_domain); |
| 924 | void mem_cgroup_print_oom_group(struct mem_cgroup *memcg); |
Johannes Weiner | 3812c8c | 2013-09-12 15:13:44 -0700 | [diff] [blame] | 925 | |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 926 | #ifdef CONFIG_MEMCG_SWAP |
Johannes Weiner | eccb52e | 2020-06-03 16:02:11 -0700 | [diff] [blame] | 927 | extern bool cgroup_memory_noswap; |
KAMEZAWA Hiroyuki | c077719 | 2009-01-07 18:07:57 -0800 | [diff] [blame] | 928 | #endif |
Hirokazu Takahashi | f8d66542 | 2009-01-07 18:08:02 -0800 | [diff] [blame] | 929 | |
Matthew Wilcox (Oracle) | f70ad44 | 2021-06-28 17:26:00 -0400 | [diff] [blame] | 930 | void folio_memcg_lock(struct folio *folio); |
| 931 | void folio_memcg_unlock(struct folio *folio); |
Johannes Weiner | 1c824a6 | 2021-04-29 22:55:32 -0700 | [diff] [blame] | 932 | void lock_page_memcg(struct page *page); |
Johannes Weiner | 62cccb8 | 2016-03-15 14:57:22 -0700 | [diff] [blame] | 933 | void unlock_page_memcg(struct page *page); |
KAMEZAWA Hiroyuki | 89c06bd | 2012-03-21 16:34:25 -0700 | [diff] [blame] | 934 | |
Johannes Weiner | db9adbc | 2019-05-14 15:47:09 -0700 | [diff] [blame] | 935 | void __mod_memcg_state(struct mem_cgroup *memcg, int idx, int val); |
Johannes Weiner | 00f3ca2 | 2017-07-06 15:40:52 -0700 | [diff] [blame] | 936 | |
Matthias Kaehlcke | 04fecbf | 2017-09-06 16:22:09 -0700 | [diff] [blame] | 937 | /* idx can be of type enum memcg_stat_item or node_stat_item */ |
Johannes Weiner | ccda7f4 | 2017-05-03 14:55:16 -0700 | [diff] [blame] | 938 | static inline void mod_memcg_state(struct mem_cgroup *memcg, |
Matthias Kaehlcke | 04fecbf | 2017-09-06 16:22:09 -0700 | [diff] [blame] | 939 | int idx, int val) |
Johannes Weiner | 2a2e488 | 2017-05-03 14:55:03 -0700 | [diff] [blame] | 940 | { |
Johannes Weiner | c3cc391 | 2018-02-21 14:45:24 -0800 | [diff] [blame] | 941 | unsigned long flags; |
| 942 | |
| 943 | local_irq_save(flags); |
Johannes Weiner | a983b5e | 2018-01-31 16:16:45 -0800 | [diff] [blame] | 944 | __mod_memcg_state(memcg, idx, val); |
Johannes Weiner | c3cc391 | 2018-02-21 14:45:24 -0800 | [diff] [blame] | 945 | local_irq_restore(flags); |
Johannes Weiner | 2a2e488 | 2017-05-03 14:55:03 -0700 | [diff] [blame] | 946 | } |
| 947 | |
Shakeel Butt | 4e5aa1f | 2022-01-14 14:05:45 -0800 | [diff] [blame] | 948 | static inline void mod_memcg_page_state(struct page *page, |
| 949 | int idx, int val) |
| 950 | { |
| 951 | struct mem_cgroup *memcg; |
| 952 | |
| 953 | if (mem_cgroup_disabled()) |
| 954 | return; |
| 955 | |
| 956 | rcu_read_lock(); |
| 957 | memcg = page_memcg(page); |
| 958 | if (memcg) |
| 959 | mod_memcg_state(memcg, idx, val); |
| 960 | rcu_read_unlock(); |
| 961 | } |
| 962 | |
Shakeel Butt | 7490a2d | 2021-09-02 14:53:27 -0700 | [diff] [blame] | 963 | static inline unsigned long memcg_page_state(struct mem_cgroup *memcg, int idx) |
| 964 | { |
Shakeel Butt | 96e51cc | 2021-09-02 14:55:46 -0700 | [diff] [blame] | 965 | return READ_ONCE(memcg->vmstats.state[idx]); |
Shakeel Butt | 7490a2d | 2021-09-02 14:53:27 -0700 | [diff] [blame] | 966 | } |
| 967 | |
Johannes Weiner | 42a3003 | 2019-05-14 15:47:12 -0700 | [diff] [blame] | 968 | static inline unsigned long lruvec_page_state(struct lruvec *lruvec, |
| 969 | enum node_stat_item idx) |
| 970 | { |
| 971 | struct mem_cgroup_per_node *pn; |
Johannes Weiner | 42a3003 | 2019-05-14 15:47:12 -0700 | [diff] [blame] | 972 | |
| 973 | if (mem_cgroup_disabled()) |
| 974 | return node_page_state(lruvec_pgdat(lruvec), idx); |
| 975 | |
| 976 | pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec); |
Shakeel Butt | 96e51cc | 2021-09-02 14:55:46 -0700 | [diff] [blame] | 977 | return READ_ONCE(pn->lruvec_stats.state[idx]); |
Johannes Weiner | 42a3003 | 2019-05-14 15:47:12 -0700 | [diff] [blame] | 978 | } |
| 979 | |
Johannes Weiner | 205b20c | 2019-05-14 15:47:06 -0700 | [diff] [blame] | 980 | static inline unsigned long lruvec_page_state_local(struct lruvec *lruvec, |
| 981 | enum node_stat_item idx) |
Greg Thelen | 2a7106f | 2011-01-13 15:47:37 -0800 | [diff] [blame] | 982 | { |
Johannes Weiner | 00f3ca2 | 2017-07-06 15:40:52 -0700 | [diff] [blame] | 983 | struct mem_cgroup_per_node *pn; |
Johannes Weiner | 815744d | 2019-06-13 15:55:46 -0700 | [diff] [blame] | 984 | long x = 0; |
| 985 | int cpu; |
Johannes Weiner | 00f3ca2 | 2017-07-06 15:40:52 -0700 | [diff] [blame] | 986 | |
| 987 | if (mem_cgroup_disabled()) |
| 988 | return node_page_state(lruvec_pgdat(lruvec), idx); |
| 989 | |
| 990 | pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec); |
Johannes Weiner | 815744d | 2019-06-13 15:55:46 -0700 | [diff] [blame] | 991 | for_each_possible_cpu(cpu) |
Shakeel Butt | 7e1c0d6 | 2021-09-02 14:55:00 -0700 | [diff] [blame] | 992 | x += per_cpu(pn->lruvec_stats_percpu->state[idx], cpu); |
Johannes Weiner | a983b5e | 2018-01-31 16:16:45 -0800 | [diff] [blame] | 993 | #ifdef CONFIG_SMP |
| 994 | if (x < 0) |
| 995 | x = 0; |
| 996 | #endif |
| 997 | return x; |
Greg Thelen | 2a7106f | 2011-01-13 15:47:37 -0800 | [diff] [blame] | 998 | } |
| 999 | |
Shakeel Butt | aa48e47 | 2021-09-02 14:55:04 -0700 | [diff] [blame] | 1000 | void mem_cgroup_flush_stats(void); |
| 1001 | |
Roman Gushchin | eedc4e5 | 2020-08-06 23:20:32 -0700 | [diff] [blame] | 1002 | void __mod_memcg_lruvec_state(struct lruvec *lruvec, enum node_stat_item idx, |
| 1003 | int val); |
Muchun Song | da3ceef | 2020-12-14 19:07:04 -0800 | [diff] [blame] | 1004 | void __mod_lruvec_kmem_state(void *p, enum node_stat_item idx, int val); |
Shakeel Butt | 991e767 | 2020-08-06 23:21:37 -0700 | [diff] [blame] | 1005 | |
Muchun Song | da3ceef | 2020-12-14 19:07:04 -0800 | [diff] [blame] | 1006 | static inline void mod_lruvec_kmem_state(void *p, enum node_stat_item idx, |
Shakeel Butt | 991e767 | 2020-08-06 23:21:37 -0700 | [diff] [blame] | 1007 | int val) |
| 1008 | { |
| 1009 | unsigned long flags; |
| 1010 | |
| 1011 | local_irq_save(flags); |
Muchun Song | da3ceef | 2020-12-14 19:07:04 -0800 | [diff] [blame] | 1012 | __mod_lruvec_kmem_state(p, idx, val); |
Shakeel Butt | 991e767 | 2020-08-06 23:21:37 -0700 | [diff] [blame] | 1013 | local_irq_restore(flags); |
| 1014 | } |
| 1015 | |
Roman Gushchin | eedc4e5 | 2020-08-06 23:20:32 -0700 | [diff] [blame] | 1016 | static inline void mod_memcg_lruvec_state(struct lruvec *lruvec, |
| 1017 | enum node_stat_item idx, int val) |
| 1018 | { |
| 1019 | unsigned long flags; |
| 1020 | |
| 1021 | local_irq_save(flags); |
| 1022 | __mod_memcg_lruvec_state(lruvec, idx, val); |
| 1023 | local_irq_restore(flags); |
| 1024 | } |
| 1025 | |
Johannes Weiner | db9adbc | 2019-05-14 15:47:09 -0700 | [diff] [blame] | 1026 | void __count_memcg_events(struct mem_cgroup *memcg, enum vm_event_item idx, |
| 1027 | unsigned long count); |
Johannes Weiner | c9019e9 | 2018-01-31 16:16:37 -0800 | [diff] [blame] | 1028 | |
Roman Gushchin | 2262185 | 2017-07-06 15:40:25 -0700 | [diff] [blame] | 1029 | static inline void count_memcg_events(struct mem_cgroup *memcg, |
Johannes Weiner | e27be24 | 2018-04-10 16:29:45 -0700 | [diff] [blame] | 1030 | enum vm_event_item idx, |
| 1031 | unsigned long count) |
Roman Gushchin | 2262185 | 2017-07-06 15:40:25 -0700 | [diff] [blame] | 1032 | { |
Johannes Weiner | c3cc391 | 2018-02-21 14:45:24 -0800 | [diff] [blame] | 1033 | unsigned long flags; |
| 1034 | |
| 1035 | local_irq_save(flags); |
Johannes Weiner | a983b5e | 2018-01-31 16:16:45 -0800 | [diff] [blame] | 1036 | __count_memcg_events(memcg, idx, count); |
Johannes Weiner | c3cc391 | 2018-02-21 14:45:24 -0800 | [diff] [blame] | 1037 | local_irq_restore(flags); |
Roman Gushchin | 2262185 | 2017-07-06 15:40:25 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | static inline void count_memcg_page_event(struct page *page, |
Johannes Weiner | e27be24 | 2018-04-10 16:29:45 -0700 | [diff] [blame] | 1041 | enum vm_event_item idx) |
Roman Gushchin | 2262185 | 2017-07-06 15:40:25 -0700 | [diff] [blame] | 1042 | { |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 1043 | struct mem_cgroup *memcg = page_memcg(page); |
| 1044 | |
| 1045 | if (memcg) |
| 1046 | count_memcg_events(memcg, idx, 1); |
Roman Gushchin | 2262185 | 2017-07-06 15:40:25 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | static inline void count_memcg_event_mm(struct mm_struct *mm, |
| 1050 | enum vm_event_item idx) |
David Rientjes | 68ae564 | 2012-12-12 13:51:57 -0800 | [diff] [blame] | 1051 | { |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 1052 | struct mem_cgroup *memcg; |
| 1053 | |
David Rientjes | 68ae564 | 2012-12-12 13:51:57 -0800 | [diff] [blame] | 1054 | if (mem_cgroup_disabled()) |
| 1055 | return; |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 1056 | |
| 1057 | rcu_read_lock(); |
| 1058 | memcg = mem_cgroup_from_task(rcu_dereference(mm->owner)); |
Roman Gushchin | fe6bdfc | 2018-06-14 15:28:05 -0700 | [diff] [blame] | 1059 | if (likely(memcg)) |
Johannes Weiner | c9019e9 | 2018-01-31 16:16:37 -0800 | [diff] [blame] | 1060 | count_memcg_events(memcg, idx, 1); |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 1061 | rcu_read_unlock(); |
David Rientjes | 68ae564 | 2012-12-12 13:51:57 -0800 | [diff] [blame] | 1062 | } |
Johannes Weiner | c9019e9 | 2018-01-31 16:16:37 -0800 | [diff] [blame] | 1063 | |
Johannes Weiner | e27be24 | 2018-04-10 16:29:45 -0700 | [diff] [blame] | 1064 | static inline void memcg_memory_event(struct mem_cgroup *memcg, |
| 1065 | enum memcg_memory_event event) |
Johannes Weiner | c9019e9 | 2018-01-31 16:16:37 -0800 | [diff] [blame] | 1066 | { |
Muchun Song | 8b21ca02 | 2020-11-13 22:52:13 -0800 | [diff] [blame] | 1067 | bool swap_event = event == MEMCG_SWAP_HIGH || event == MEMCG_SWAP_MAX || |
| 1068 | event == MEMCG_SWAP_FAIL; |
| 1069 | |
Shakeel Butt | 1e577f9 | 2019-07-11 20:55:55 -0700 | [diff] [blame] | 1070 | atomic_long_inc(&memcg->memory_events_local[event]); |
Muchun Song | 8b21ca02 | 2020-11-13 22:52:13 -0800 | [diff] [blame] | 1071 | if (!swap_event) |
| 1072 | cgroup_file_notify(&memcg->events_local_file); |
Shakeel Butt | 1e577f9 | 2019-07-11 20:55:55 -0700 | [diff] [blame] | 1073 | |
Chris Down | 9852ae3 | 2019-05-31 22:30:22 -0700 | [diff] [blame] | 1074 | do { |
| 1075 | atomic_long_inc(&memcg->memory_events[event]); |
Muchun Song | 8b21ca02 | 2020-11-13 22:52:13 -0800 | [diff] [blame] | 1076 | if (swap_event) |
| 1077 | cgroup_file_notify(&memcg->swap_events_file); |
| 1078 | else |
| 1079 | cgroup_file_notify(&memcg->events_file); |
Chris Down | 9852ae3 | 2019-05-31 22:30:22 -0700 | [diff] [blame] | 1080 | |
Yafang Shao | 04fd61a4 | 2020-05-13 17:50:34 -0700 | [diff] [blame] | 1081 | if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) |
| 1082 | break; |
Chris Down | 9852ae3 | 2019-05-31 22:30:22 -0700 | [diff] [blame] | 1083 | if (cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_LOCAL_EVENTS) |
| 1084 | break; |
| 1085 | } while ((memcg = parent_mem_cgroup(memcg)) && |
| 1086 | !mem_cgroup_is_root(memcg)); |
Johannes Weiner | c9019e9 | 2018-01-31 16:16:37 -0800 | [diff] [blame] | 1087 | } |
| 1088 | |
Roman Gushchin | fe6bdfc | 2018-06-14 15:28:05 -0700 | [diff] [blame] | 1089 | static inline void memcg_memory_event_mm(struct mm_struct *mm, |
| 1090 | enum memcg_memory_event event) |
| 1091 | { |
| 1092 | struct mem_cgroup *memcg; |
| 1093 | |
| 1094 | if (mem_cgroup_disabled()) |
| 1095 | return; |
| 1096 | |
| 1097 | rcu_read_lock(); |
| 1098 | memcg = mem_cgroup_from_task(rcu_dereference(mm->owner)); |
| 1099 | if (likely(memcg)) |
| 1100 | memcg_memory_event(memcg, event); |
| 1101 | rcu_read_unlock(); |
| 1102 | } |
| 1103 | |
Zhou Guanghui | be6c898 | 2021-03-12 21:08:30 -0800 | [diff] [blame] | 1104 | void split_page_memcg(struct page *head, unsigned int nr); |
KAMEZAWA Hiroyuki | ca3e021 | 2011-01-20 14:44:24 -0800 | [diff] [blame] | 1105 | |
Johannes Weiner | 2d146aa | 2021-04-29 22:56:26 -0700 | [diff] [blame] | 1106 | unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, |
| 1107 | gfp_t gfp_mask, |
| 1108 | unsigned long *total_scanned); |
| 1109 | |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 1110 | #else /* CONFIG_MEMCG */ |
Johannes Weiner | 23047a9 | 2016-03-15 14:57:16 -0700 | [diff] [blame] | 1111 | |
| 1112 | #define MEM_CGROUP_ID_SHIFT 0 |
| 1113 | #define MEM_CGROUP_ID_MAX 0 |
| 1114 | |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 1115 | static inline struct mem_cgroup *folio_memcg(struct folio *folio) |
| 1116 | { |
| 1117 | return NULL; |
| 1118 | } |
| 1119 | |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 1120 | static inline struct mem_cgroup *page_memcg(struct page *page) |
| 1121 | { |
| 1122 | return NULL; |
| 1123 | } |
| 1124 | |
Matthew Wilcox (Oracle) | c5ce619 | 2021-05-04 17:19:13 -0400 | [diff] [blame] | 1125 | static inline struct mem_cgroup *folio_memcg_rcu(struct folio *folio) |
Roman Gushchin | bcfe06b | 2020-12-01 13:58:27 -0800 | [diff] [blame] | 1126 | { |
| 1127 | WARN_ON_ONCE(!rcu_read_lock_held()); |
| 1128 | return NULL; |
| 1129 | } |
| 1130 | |
| 1131 | static inline struct mem_cgroup *page_memcg_check(struct page *page) |
| 1132 | { |
| 1133 | return NULL; |
| 1134 | } |
| 1135 | |
Matthew Wilcox (Oracle) | 1b7e446 | 2021-06-28 14:59:26 -0400 | [diff] [blame] | 1136 | static inline bool folio_memcg_kmem(struct folio *folio) |
| 1137 | { |
| 1138 | return false; |
| 1139 | } |
| 1140 | |
Roman Gushchin | 18b2db3 | 2020-12-01 13:58:30 -0800 | [diff] [blame] | 1141 | static inline bool PageMemcgKmem(struct page *page) |
| 1142 | { |
| 1143 | return false; |
| 1144 | } |
| 1145 | |
Kirill Tkhai | dfd2f10 | 2018-08-17 15:48:06 -0700 | [diff] [blame] | 1146 | static inline bool mem_cgroup_is_root(struct mem_cgroup *memcg) |
| 1147 | { |
| 1148 | return true; |
| 1149 | } |
| 1150 | |
Johannes Weiner | 23047a9 | 2016-03-15 14:57:16 -0700 | [diff] [blame] | 1151 | static inline bool mem_cgroup_disabled(void) |
| 1152 | { |
| 1153 | return true; |
| 1154 | } |
| 1155 | |
Johannes Weiner | e27be24 | 2018-04-10 16:29:45 -0700 | [diff] [blame] | 1156 | static inline void memcg_memory_event(struct mem_cgroup *memcg, |
| 1157 | enum memcg_memory_event event) |
Johannes Weiner | 241994ed | 2015-02-11 15:26:06 -0800 | [diff] [blame] | 1158 | { |
| 1159 | } |
| 1160 | |
Roman Gushchin | fe6bdfc | 2018-06-14 15:28:05 -0700 | [diff] [blame] | 1161 | static inline void memcg_memory_event_mm(struct mm_struct *mm, |
| 1162 | enum memcg_memory_event event) |
| 1163 | { |
| 1164 | } |
| 1165 | |
Johannes Weiner | f56ce41 | 2021-08-19 19:04:21 -0700 | [diff] [blame] | 1166 | static inline void mem_cgroup_protection(struct mem_cgroup *root, |
| 1167 | struct mem_cgroup *memcg, |
| 1168 | unsigned long *min, |
| 1169 | unsigned long *low) |
Chris Down | 9783aa9 | 2019-10-06 17:58:32 -0700 | [diff] [blame] | 1170 | { |
Johannes Weiner | f56ce41 | 2021-08-19 19:04:21 -0700 | [diff] [blame] | 1171 | *min = *low = 0; |
Chris Down | 9783aa9 | 2019-10-06 17:58:32 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
Chris Down | 45c7f7e | 2020-08-06 23:22:05 -0700 | [diff] [blame] | 1174 | static inline void mem_cgroup_calculate_protection(struct mem_cgroup *root, |
| 1175 | struct mem_cgroup *memcg) |
Johannes Weiner | 241994ed | 2015-02-11 15:26:06 -0800 | [diff] [blame] | 1176 | { |
Chris Down | 45c7f7e | 2020-08-06 23:22:05 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | static inline bool mem_cgroup_below_low(struct mem_cgroup *memcg) |
| 1180 | { |
| 1181 | return false; |
| 1182 | } |
| 1183 | |
| 1184 | static inline bool mem_cgroup_below_min(struct mem_cgroup *memcg) |
| 1185 | { |
| 1186 | return false; |
Johannes Weiner | 241994ed | 2015-02-11 15:26:06 -0800 | [diff] [blame] | 1187 | } |
| 1188 | |
Matthew Wilcox (Oracle) | 8f425e4 | 2021-06-25 09:27:04 -0400 | [diff] [blame] | 1189 | static inline int mem_cgroup_charge(struct folio *folio, |
| 1190 | struct mm_struct *mm, gfp_t gfp) |
Johannes Weiner | 3fea5a4 | 2020-06-03 16:01:41 -0700 | [diff] [blame] | 1191 | { |
| 1192 | return 0; |
| 1193 | } |
| 1194 | |
Shakeel Butt | 0add0c7 | 2021-04-29 22:56:36 -0700 | [diff] [blame] | 1195 | static inline int mem_cgroup_swapin_charge_page(struct page *page, |
| 1196 | struct mm_struct *mm, gfp_t gfp, swp_entry_t entry) |
| 1197 | { |
| 1198 | return 0; |
| 1199 | } |
| 1200 | |
| 1201 | static inline void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry) |
| 1202 | { |
| 1203 | } |
| 1204 | |
Matthew Wilcox (Oracle) | bbc6b70 | 2021-05-01 20:42:23 -0400 | [diff] [blame] | 1205 | static inline void mem_cgroup_uncharge(struct folio *folio) |
Johannes Weiner | 0a31bc9 | 2014-08-08 14:19:22 -0700 | [diff] [blame] | 1206 | { |
| 1207 | } |
| 1208 | |
Johannes Weiner | 747db95 | 2014-08-08 14:19:24 -0700 | [diff] [blame] | 1209 | static inline void mem_cgroup_uncharge_list(struct list_head *page_list) |
KAMEZAWA Hiroyuki | 569b846 | 2009-12-15 16:47:03 -0800 | [diff] [blame] | 1210 | { |
| 1211 | } |
| 1212 | |
Matthew Wilcox (Oracle) | d21bba2 | 2021-05-06 18:14:59 -0400 | [diff] [blame] | 1213 | static inline void mem_cgroup_migrate(struct folio *old, struct folio *new) |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 1214 | { |
| 1215 | } |
| 1216 | |
Johannes Weiner | 867e5e1 | 2019-11-30 17:55:34 -0800 | [diff] [blame] | 1217 | static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg, |
| 1218 | struct pglist_data *pgdat) |
Johannes Weiner | 925b767 | 2012-01-12 17:18:15 -0800 | [diff] [blame] | 1219 | { |
Johannes Weiner | 867e5e1 | 2019-11-30 17:55:34 -0800 | [diff] [blame] | 1220 | return &pgdat->__lruvec; |
Johannes Weiner | 925b767 | 2012-01-12 17:18:15 -0800 | [diff] [blame] | 1221 | } |
| 1222 | |
Matthew Wilcox (Oracle) | b1baabd | 2021-06-28 20:00:28 -0400 | [diff] [blame] | 1223 | static inline struct lruvec *folio_lruvec(struct folio *folio) |
Minchan Kim | 3f58a82 | 2011-03-22 16:32:53 -0700 | [diff] [blame] | 1224 | { |
Matthew Wilcox (Oracle) | b1baabd | 2021-06-28 20:00:28 -0400 | [diff] [blame] | 1225 | struct pglist_data *pgdat = folio_pgdat(folio); |
Johannes Weiner | 867e5e1 | 2019-11-30 17:55:34 -0800 | [diff] [blame] | 1226 | return &pgdat->__lruvec; |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 1227 | } |
| 1228 | |
Matthew Wilcox (Oracle) | e809c3f | 2021-06-28 21:59:47 -0400 | [diff] [blame] | 1229 | static inline |
| 1230 | void lruvec_memcg_debug(struct lruvec *lruvec, struct folio *folio) |
Johannes Weiner | 2d146aa | 2021-04-29 22:56:26 -0700 | [diff] [blame] | 1231 | { |
| 1232 | } |
| 1233 | |
Johannes Weiner | b910718 | 2019-11-30 17:55:59 -0800 | [diff] [blame] | 1234 | static inline struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg) |
| 1235 | { |
| 1236 | return NULL; |
| 1237 | } |
| 1238 | |
Johannes Weiner | 587af30 | 2012-10-08 16:34:12 -0700 | [diff] [blame] | 1239 | static inline bool mm_match_cgroup(struct mm_struct *mm, |
Raghavendra K T | c0ff4b8 | 2011-11-02 13:38:15 -0700 | [diff] [blame] | 1240 | struct mem_cgroup *memcg) |
Balbir Singh | bed7161 | 2008-02-07 00:14:01 -0800 | [diff] [blame] | 1241 | { |
Johannes Weiner | 587af30 | 2012-10-08 16:34:12 -0700 | [diff] [blame] | 1242 | return true; |
Balbir Singh | bed7161 | 2008-02-07 00:14:01 -0800 | [diff] [blame] | 1243 | } |
| 1244 | |
Shakeel Butt | d46eb14b | 2018-08-17 15:46:39 -0700 | [diff] [blame] | 1245 | static inline struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm) |
| 1246 | { |
| 1247 | return NULL; |
| 1248 | } |
| 1249 | |
Dan Schatzberg | c74d40e | 2021-06-28 19:38:21 -0700 | [diff] [blame] | 1250 | static inline |
| 1251 | struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *css) |
| 1252 | { |
| 1253 | return NULL; |
| 1254 | } |
| 1255 | |
Roman Gushchin | dc0b586 | 2018-08-17 15:46:36 -0700 | [diff] [blame] | 1256 | static inline void mem_cgroup_put(struct mem_cgroup *memcg) |
| 1257 | { |
| 1258 | } |
| 1259 | |
Matthew Wilcox (Oracle) | e809c3f | 2021-06-28 21:59:47 -0400 | [diff] [blame] | 1260 | static inline struct lruvec *folio_lruvec_lock(struct folio *folio) |
Alex Shi | 6168d0d | 2020-12-15 12:34:29 -0800 | [diff] [blame] | 1261 | { |
Matthew Wilcox (Oracle) | e809c3f | 2021-06-28 21:59:47 -0400 | [diff] [blame] | 1262 | struct pglist_data *pgdat = folio_pgdat(folio); |
Alex Shi | 6168d0d | 2020-12-15 12:34:29 -0800 | [diff] [blame] | 1263 | |
| 1264 | spin_lock(&pgdat->__lruvec.lru_lock); |
| 1265 | return &pgdat->__lruvec; |
| 1266 | } |
| 1267 | |
Matthew Wilcox (Oracle) | e809c3f | 2021-06-28 21:59:47 -0400 | [diff] [blame] | 1268 | static inline struct lruvec *folio_lruvec_lock_irq(struct folio *folio) |
Alex Shi | 6168d0d | 2020-12-15 12:34:29 -0800 | [diff] [blame] | 1269 | { |
Matthew Wilcox (Oracle) | e809c3f | 2021-06-28 21:59:47 -0400 | [diff] [blame] | 1270 | struct pglist_data *pgdat = folio_pgdat(folio); |
Alex Shi | 6168d0d | 2020-12-15 12:34:29 -0800 | [diff] [blame] | 1271 | |
| 1272 | spin_lock_irq(&pgdat->__lruvec.lru_lock); |
| 1273 | return &pgdat->__lruvec; |
| 1274 | } |
| 1275 | |
Matthew Wilcox (Oracle) | e809c3f | 2021-06-28 21:59:47 -0400 | [diff] [blame] | 1276 | static inline struct lruvec *folio_lruvec_lock_irqsave(struct folio *folio, |
Alex Shi | 6168d0d | 2020-12-15 12:34:29 -0800 | [diff] [blame] | 1277 | unsigned long *flagsp) |
| 1278 | { |
Matthew Wilcox (Oracle) | e809c3f | 2021-06-28 21:59:47 -0400 | [diff] [blame] | 1279 | struct pglist_data *pgdat = folio_pgdat(folio); |
Alex Shi | 6168d0d | 2020-12-15 12:34:29 -0800 | [diff] [blame] | 1280 | |
| 1281 | spin_lock_irqsave(&pgdat->__lruvec.lru_lock, *flagsp); |
| 1282 | return &pgdat->__lruvec; |
| 1283 | } |
| 1284 | |
Johannes Weiner | 5660048 | 2012-01-12 17:17:59 -0800 | [diff] [blame] | 1285 | static inline struct mem_cgroup * |
| 1286 | mem_cgroup_iter(struct mem_cgroup *root, |
| 1287 | struct mem_cgroup *prev, |
| 1288 | struct mem_cgroup_reclaim_cookie *reclaim) |
| 1289 | { |
| 1290 | return NULL; |
| 1291 | } |
| 1292 | |
| 1293 | static inline void mem_cgroup_iter_break(struct mem_cgroup *root, |
| 1294 | struct mem_cgroup *prev) |
| 1295 | { |
| 1296 | } |
| 1297 | |
Vladimir Davydov | 7c5f64f | 2016-10-07 16:57:23 -0700 | [diff] [blame] | 1298 | static inline int mem_cgroup_scan_tasks(struct mem_cgroup *memcg, |
| 1299 | int (*fn)(struct task_struct *, void *), void *arg) |
| 1300 | { |
| 1301 | return 0; |
| 1302 | } |
| 1303 | |
Johannes Weiner | 23047a9 | 2016-03-15 14:57:16 -0700 | [diff] [blame] | 1304 | static inline unsigned short mem_cgroup_id(struct mem_cgroup *memcg) |
Hirokazu Takahashi | f8d66542 | 2009-01-07 18:08:02 -0800 | [diff] [blame] | 1305 | { |
Johannes Weiner | 23047a9 | 2016-03-15 14:57:16 -0700 | [diff] [blame] | 1306 | return 0; |
| 1307 | } |
| 1308 | |
| 1309 | static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id) |
| 1310 | { |
| 1311 | WARN_ON_ONCE(id); |
| 1312 | /* XXX: This should always return root_mem_cgroup */ |
| 1313 | return NULL; |
Hirokazu Takahashi | f8d66542 | 2009-01-07 18:08:02 -0800 | [diff] [blame] | 1314 | } |
KAMEZAWA Hiroyuki | a636b32 | 2009-01-07 18:08:08 -0800 | [diff] [blame] | 1315 | |
Chris Down | aa9694b | 2019-03-05 15:45:52 -0800 | [diff] [blame] | 1316 | static inline struct mem_cgroup *mem_cgroup_from_seq(struct seq_file *m) |
| 1317 | { |
| 1318 | return NULL; |
| 1319 | } |
| 1320 | |
Roman Gushchin | 2262185 | 2017-07-06 15:40:25 -0700 | [diff] [blame] | 1321 | static inline struct mem_cgroup *lruvec_memcg(struct lruvec *lruvec) |
| 1322 | { |
| 1323 | return NULL; |
| 1324 | } |
| 1325 | |
Vladimir Davydov | eb01aaa | 2016-01-20 15:03:02 -0800 | [diff] [blame] | 1326 | static inline bool mem_cgroup_online(struct mem_cgroup *memcg) |
KOSAKI Motohiro | 14797e2 | 2009-01-07 18:08:18 -0800 | [diff] [blame] | 1327 | { |
Yaowei Bai | 13308ca | 2015-11-05 18:47:40 -0800 | [diff] [blame] | 1328 | return true; |
KOSAKI Motohiro | 14797e2 | 2009-01-07 18:08:18 -0800 | [diff] [blame] | 1329 | } |
| 1330 | |
Michal Hocko | b4536f0c8 | 2017-01-10 16:58:04 -0800 | [diff] [blame] | 1331 | static inline |
| 1332 | unsigned long mem_cgroup_get_zone_lru_size(struct lruvec *lruvec, |
| 1333 | enum lru_list lru, int zone_idx) |
| 1334 | { |
| 1335 | return 0; |
| 1336 | } |
KOSAKI Motohiro | a3d8e05 | 2009-01-07 18:08:19 -0800 | [diff] [blame] | 1337 | |
Roman Gushchin | bbec2e1 | 2018-06-07 17:06:18 -0700 | [diff] [blame] | 1338 | static inline unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg) |
Vladimir Davydov | 7c5f64f | 2016-10-07 16:57:23 -0700 | [diff] [blame] | 1339 | { |
| 1340 | return 0; |
| 1341 | } |
| 1342 | |
Chris Down | 9783aa9 | 2019-10-06 17:58:32 -0700 | [diff] [blame] | 1343 | static inline unsigned long mem_cgroup_size(struct mem_cgroup *memcg) |
| 1344 | { |
| 1345 | return 0; |
| 1346 | } |
| 1347 | |
Balbir Singh | e222432 | 2009-04-02 16:57:39 -0700 | [diff] [blame] | 1348 | static inline void |
yuzhoujian | f0c867d | 2018-12-28 00:36:10 -0800 | [diff] [blame] | 1349 | mem_cgroup_print_oom_context(struct mem_cgroup *memcg, struct task_struct *p) |
| 1350 | { |
| 1351 | } |
| 1352 | |
| 1353 | static inline void |
| 1354 | mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg) |
Balbir Singh | e222432 | 2009-04-02 16:57:39 -0700 | [diff] [blame] | 1355 | { |
| 1356 | } |
| 1357 | |
Johannes Weiner | 1c824a6 | 2021-04-29 22:55:32 -0700 | [diff] [blame] | 1358 | static inline void lock_page_memcg(struct page *page) |
KAMEZAWA Hiroyuki | 89c06bd | 2012-03-21 16:34:25 -0700 | [diff] [blame] | 1359 | { |
| 1360 | } |
| 1361 | |
Johannes Weiner | 62cccb8 | 2016-03-15 14:57:22 -0700 | [diff] [blame] | 1362 | static inline void unlock_page_memcg(struct page *page) |
KAMEZAWA Hiroyuki | 89c06bd | 2012-03-21 16:34:25 -0700 | [diff] [blame] | 1363 | { |
| 1364 | } |
| 1365 | |
Matthew Wilcox (Oracle) | f70ad44 | 2021-06-28 17:26:00 -0400 | [diff] [blame] | 1366 | static inline void folio_memcg_lock(struct folio *folio) |
| 1367 | { |
| 1368 | } |
| 1369 | |
| 1370 | static inline void folio_memcg_unlock(struct folio *folio) |
| 1371 | { |
| 1372 | } |
| 1373 | |
Tejun Heo | b23afb9 | 2015-11-05 18:46:11 -0800 | [diff] [blame] | 1374 | static inline void mem_cgroup_handle_over_high(void) |
| 1375 | { |
| 1376 | } |
| 1377 | |
Michal Hocko | 29ef680 | 2018-08-17 15:47:11 -0700 | [diff] [blame] | 1378 | static inline void mem_cgroup_enter_user_fault(void) |
Johannes Weiner | 519e524 | 2013-09-12 15:13:42 -0700 | [diff] [blame] | 1379 | { |
| 1380 | } |
| 1381 | |
Michal Hocko | 29ef680 | 2018-08-17 15:47:11 -0700 | [diff] [blame] | 1382 | static inline void mem_cgroup_exit_user_fault(void) |
Johannes Weiner | 519e524 | 2013-09-12 15:13:42 -0700 | [diff] [blame] | 1383 | { |
| 1384 | } |
| 1385 | |
Johannes Weiner | 3812c8c | 2013-09-12 15:13:44 -0700 | [diff] [blame] | 1386 | static inline bool task_in_memcg_oom(struct task_struct *p) |
| 1387 | { |
| 1388 | return false; |
| 1389 | } |
| 1390 | |
Johannes Weiner | 4942642 | 2013-10-16 13:46:59 -0700 | [diff] [blame] | 1391 | static inline bool mem_cgroup_oom_synchronize(bool wait) |
Johannes Weiner | 3812c8c | 2013-09-12 15:13:44 -0700 | [diff] [blame] | 1392 | { |
| 1393 | return false; |
| 1394 | } |
| 1395 | |
Roman Gushchin | 3d8b38e | 2018-08-21 21:53:54 -0700 | [diff] [blame] | 1396 | static inline struct mem_cgroup *mem_cgroup_get_oom_group( |
| 1397 | struct task_struct *victim, struct mem_cgroup *oom_domain) |
| 1398 | { |
| 1399 | return NULL; |
| 1400 | } |
| 1401 | |
| 1402 | static inline void mem_cgroup_print_oom_group(struct mem_cgroup *memcg) |
| 1403 | { |
| 1404 | } |
| 1405 | |
Johannes Weiner | 00f3ca2 | 2017-07-06 15:40:52 -0700 | [diff] [blame] | 1406 | static inline void __mod_memcg_state(struct mem_cgroup *memcg, |
Matthias Kaehlcke | 04fecbf | 2017-09-06 16:22:09 -0700 | [diff] [blame] | 1407 | int idx, |
Johannes Weiner | 00f3ca2 | 2017-07-06 15:40:52 -0700 | [diff] [blame] | 1408 | int nr) |
| 1409 | { |
| 1410 | } |
| 1411 | |
Johannes Weiner | ccda7f4 | 2017-05-03 14:55:16 -0700 | [diff] [blame] | 1412 | static inline void mod_memcg_state(struct mem_cgroup *memcg, |
Matthias Kaehlcke | 04fecbf | 2017-09-06 16:22:09 -0700 | [diff] [blame] | 1413 | int idx, |
Johannes Weiner | ccda7f4 | 2017-05-03 14:55:16 -0700 | [diff] [blame] | 1414 | int nr) |
Johannes Weiner | 2a2e488 | 2017-05-03 14:55:03 -0700 | [diff] [blame] | 1415 | { |
| 1416 | } |
| 1417 | |
Shakeel Butt | 4e5aa1f | 2022-01-14 14:05:45 -0800 | [diff] [blame] | 1418 | static inline void mod_memcg_page_state(struct page *page, |
| 1419 | int idx, int val) |
| 1420 | { |
| 1421 | } |
| 1422 | |
Shakeel Butt | 7490a2d | 2021-09-02 14:53:27 -0700 | [diff] [blame] | 1423 | static inline unsigned long memcg_page_state(struct mem_cgroup *memcg, int idx) |
| 1424 | { |
| 1425 | return 0; |
| 1426 | } |
| 1427 | |
Johannes Weiner | 42a3003 | 2019-05-14 15:47:12 -0700 | [diff] [blame] | 1428 | static inline unsigned long lruvec_page_state(struct lruvec *lruvec, |
| 1429 | enum node_stat_item idx) |
| 1430 | { |
| 1431 | return node_page_state(lruvec_pgdat(lruvec), idx); |
| 1432 | } |
| 1433 | |
Johannes Weiner | 205b20c | 2019-05-14 15:47:06 -0700 | [diff] [blame] | 1434 | static inline unsigned long lruvec_page_state_local(struct lruvec *lruvec, |
| 1435 | enum node_stat_item idx) |
Greg Thelen | 2a7106f | 2011-01-13 15:47:37 -0800 | [diff] [blame] | 1436 | { |
Johannes Weiner | 00f3ca2 | 2017-07-06 15:40:52 -0700 | [diff] [blame] | 1437 | return node_page_state(lruvec_pgdat(lruvec), idx); |
Greg Thelen | 2a7106f | 2011-01-13 15:47:37 -0800 | [diff] [blame] | 1438 | } |
| 1439 | |
Shakeel Butt | aa48e47 | 2021-09-02 14:55:04 -0700 | [diff] [blame] | 1440 | static inline void mem_cgroup_flush_stats(void) |
| 1441 | { |
| 1442 | } |
| 1443 | |
Roman Gushchin | eedc4e5 | 2020-08-06 23:20:32 -0700 | [diff] [blame] | 1444 | static inline void __mod_memcg_lruvec_state(struct lruvec *lruvec, |
| 1445 | enum node_stat_item idx, int val) |
| 1446 | { |
| 1447 | } |
| 1448 | |
Muchun Song | da3ceef | 2020-12-14 19:07:04 -0800 | [diff] [blame] | 1449 | static inline void __mod_lruvec_kmem_state(void *p, enum node_stat_item idx, |
Roman Gushchin | ec9f023 | 2019-08-13 15:37:41 -0700 | [diff] [blame] | 1450 | int val) |
| 1451 | { |
| 1452 | struct page *page = virt_to_head_page(p); |
| 1453 | |
| 1454 | __mod_node_page_state(page_pgdat(page), idx, val); |
| 1455 | } |
| 1456 | |
Muchun Song | da3ceef | 2020-12-14 19:07:04 -0800 | [diff] [blame] | 1457 | static inline void mod_lruvec_kmem_state(void *p, enum node_stat_item idx, |
Shakeel Butt | 991e767 | 2020-08-06 23:21:37 -0700 | [diff] [blame] | 1458 | int val) |
| 1459 | { |
| 1460 | struct page *page = virt_to_head_page(p); |
| 1461 | |
| 1462 | mod_node_page_state(page_pgdat(page), idx, val); |
| 1463 | } |
| 1464 | |
Roman Gushchin | 2262185 | 2017-07-06 15:40:25 -0700 | [diff] [blame] | 1465 | static inline void count_memcg_events(struct mem_cgroup *memcg, |
| 1466 | enum vm_event_item idx, |
| 1467 | unsigned long count) |
| 1468 | { |
| 1469 | } |
| 1470 | |
Kirill Tkhai | 9851ac1 | 2019-05-13 17:16:54 -0700 | [diff] [blame] | 1471 | static inline void __count_memcg_events(struct mem_cgroup *memcg, |
| 1472 | enum vm_event_item idx, |
| 1473 | unsigned long count) |
| 1474 | { |
| 1475 | } |
| 1476 | |
Roman Gushchin | 2262185 | 2017-07-06 15:40:25 -0700 | [diff] [blame] | 1477 | static inline void count_memcg_page_event(struct page *page, |
Matthias Kaehlcke | 04fecbf | 2017-09-06 16:22:09 -0700 | [diff] [blame] | 1478 | int idx) |
Roman Gushchin | 2262185 | 2017-07-06 15:40:25 -0700 | [diff] [blame] | 1479 | { |
| 1480 | } |
| 1481 | |
Ying Han | 456f998 | 2011-05-26 16:25:38 -0700 | [diff] [blame] | 1482 | static inline |
Roman Gushchin | 2262185 | 2017-07-06 15:40:25 -0700 | [diff] [blame] | 1483 | void count_memcg_event_mm(struct mm_struct *mm, enum vm_event_item idx) |
Ying Han | 456f998 | 2011-05-26 16:25:38 -0700 | [diff] [blame] | 1484 | { |
| 1485 | } |
Alex Shi | 6168d0d | 2020-12-15 12:34:29 -0800 | [diff] [blame] | 1486 | |
Johannes Weiner | 2d146aa | 2021-04-29 22:56:26 -0700 | [diff] [blame] | 1487 | static inline void split_page_memcg(struct page *head, unsigned int nr) |
Alex Shi | 6168d0d | 2020-12-15 12:34:29 -0800 | [diff] [blame] | 1488 | { |
| 1489 | } |
Johannes Weiner | 2d146aa | 2021-04-29 22:56:26 -0700 | [diff] [blame] | 1490 | |
| 1491 | static inline |
| 1492 | unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, |
| 1493 | gfp_t gfp_mask, |
| 1494 | unsigned long *total_scanned) |
| 1495 | { |
| 1496 | return 0; |
| 1497 | } |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 1498 | #endif /* CONFIG_MEMCG */ |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 1499 | |
Muchun Song | da3ceef | 2020-12-14 19:07:04 -0800 | [diff] [blame] | 1500 | static inline void __inc_lruvec_kmem_state(void *p, enum node_stat_item idx) |
Roman Gushchin | ec9f023 | 2019-08-13 15:37:41 -0700 | [diff] [blame] | 1501 | { |
Muchun Song | da3ceef | 2020-12-14 19:07:04 -0800 | [diff] [blame] | 1502 | __mod_lruvec_kmem_state(p, idx, 1); |
Roman Gushchin | ec9f023 | 2019-08-13 15:37:41 -0700 | [diff] [blame] | 1503 | } |
| 1504 | |
Muchun Song | da3ceef | 2020-12-14 19:07:04 -0800 | [diff] [blame] | 1505 | static inline void __dec_lruvec_kmem_state(void *p, enum node_stat_item idx) |
Roman Gushchin | ec9f023 | 2019-08-13 15:37:41 -0700 | [diff] [blame] | 1506 | { |
Muchun Song | da3ceef | 2020-12-14 19:07:04 -0800 | [diff] [blame] | 1507 | __mod_lruvec_kmem_state(p, idx, -1); |
Roman Gushchin | ec9f023 | 2019-08-13 15:37:41 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
Johannes Weiner | 7cf111b | 2020-06-03 16:03:06 -0700 | [diff] [blame] | 1510 | static inline struct lruvec *parent_lruvec(struct lruvec *lruvec) |
| 1511 | { |
| 1512 | struct mem_cgroup *memcg; |
| 1513 | |
| 1514 | memcg = lruvec_memcg(lruvec); |
| 1515 | if (!memcg) |
| 1516 | return NULL; |
| 1517 | memcg = parent_mem_cgroup(memcg); |
| 1518 | if (!memcg) |
| 1519 | return NULL; |
| 1520 | return mem_cgroup_lruvec(memcg, lruvec_pgdat(lruvec)); |
| 1521 | } |
| 1522 | |
Alex Shi | 6168d0d | 2020-12-15 12:34:29 -0800 | [diff] [blame] | 1523 | static inline void unlock_page_lruvec(struct lruvec *lruvec) |
| 1524 | { |
| 1525 | spin_unlock(&lruvec->lru_lock); |
| 1526 | } |
| 1527 | |
| 1528 | static inline void unlock_page_lruvec_irq(struct lruvec *lruvec) |
| 1529 | { |
| 1530 | spin_unlock_irq(&lruvec->lru_lock); |
| 1531 | } |
| 1532 | |
| 1533 | static inline void unlock_page_lruvec_irqrestore(struct lruvec *lruvec, |
| 1534 | unsigned long flags) |
| 1535 | { |
| 1536 | spin_unlock_irqrestore(&lruvec->lru_lock, flags); |
| 1537 | } |
| 1538 | |
Muchun Song | 7467c39 | 2021-06-28 19:37:59 -0700 | [diff] [blame] | 1539 | /* Test requires a stable page->memcg binding, see page_memcg() */ |
Matthew Wilcox (Oracle) | 0de340c | 2021-06-29 22:27:31 -0400 | [diff] [blame] | 1540 | static inline bool folio_matches_lruvec(struct folio *folio, |
| 1541 | struct lruvec *lruvec) |
Muchun Song | f2e4d28 | 2021-06-28 19:37:56 -0700 | [diff] [blame] | 1542 | { |
Matthew Wilcox (Oracle) | 0de340c | 2021-06-29 22:27:31 -0400 | [diff] [blame] | 1543 | return lruvec_pgdat(lruvec) == folio_pgdat(folio) && |
| 1544 | lruvec_memcg(lruvec) == folio_memcg(folio); |
Muchun Song | f2e4d28 | 2021-06-28 19:37:56 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
Alexander Duyck | 2a5e4e3 | 2020-12-15 12:34:33 -0800 | [diff] [blame] | 1547 | /* Don't lock again iff page's lruvec locked */ |
Matthew Wilcox (Oracle) | 0de340c | 2021-06-29 22:27:31 -0400 | [diff] [blame] | 1548 | static inline struct lruvec *folio_lruvec_relock_irq(struct folio *folio, |
Alexander Duyck | 2a5e4e3 | 2020-12-15 12:34:33 -0800 | [diff] [blame] | 1549 | struct lruvec *locked_lruvec) |
| 1550 | { |
| 1551 | if (locked_lruvec) { |
Matthew Wilcox (Oracle) | 0de340c | 2021-06-29 22:27:31 -0400 | [diff] [blame] | 1552 | if (folio_matches_lruvec(folio, locked_lruvec)) |
Alexander Duyck | 2a5e4e3 | 2020-12-15 12:34:33 -0800 | [diff] [blame] | 1553 | return locked_lruvec; |
| 1554 | |
| 1555 | unlock_page_lruvec_irq(locked_lruvec); |
| 1556 | } |
| 1557 | |
Matthew Wilcox (Oracle) | e809c3f | 2021-06-28 21:59:47 -0400 | [diff] [blame] | 1558 | return folio_lruvec_lock_irq(folio); |
Alexander Duyck | 2a5e4e3 | 2020-12-15 12:34:33 -0800 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | /* Don't lock again iff page's lruvec locked */ |
Matthew Wilcox (Oracle) | 0de340c | 2021-06-29 22:27:31 -0400 | [diff] [blame] | 1562 | static inline struct lruvec *folio_lruvec_relock_irqsave(struct folio *folio, |
Alexander Duyck | 2a5e4e3 | 2020-12-15 12:34:33 -0800 | [diff] [blame] | 1563 | struct lruvec *locked_lruvec, unsigned long *flags) |
| 1564 | { |
| 1565 | if (locked_lruvec) { |
Matthew Wilcox (Oracle) | 0de340c | 2021-06-29 22:27:31 -0400 | [diff] [blame] | 1566 | if (folio_matches_lruvec(folio, locked_lruvec)) |
Alexander Duyck | 2a5e4e3 | 2020-12-15 12:34:33 -0800 | [diff] [blame] | 1567 | return locked_lruvec; |
| 1568 | |
| 1569 | unlock_page_lruvec_irqrestore(locked_lruvec, *flags); |
| 1570 | } |
| 1571 | |
Matthew Wilcox (Oracle) | e809c3f | 2021-06-28 21:59:47 -0400 | [diff] [blame] | 1572 | return folio_lruvec_lock_irqsave(folio, flags); |
Alexander Duyck | 2a5e4e3 | 2020-12-15 12:34:33 -0800 | [diff] [blame] | 1573 | } |
| 1574 | |
Tejun Heo | 52ebea7 | 2015-05-22 17:13:37 -0400 | [diff] [blame] | 1575 | #ifdef CONFIG_CGROUP_WRITEBACK |
Tejun Heo | 841710a | 2015-05-22 18:23:33 -0400 | [diff] [blame] | 1576 | |
Tejun Heo | 841710a | 2015-05-22 18:23:33 -0400 | [diff] [blame] | 1577 | struct wb_domain *mem_cgroup_wb_domain(struct bdi_writeback *wb); |
Tejun Heo | c5edf9c | 2015-09-29 13:04:26 -0400 | [diff] [blame] | 1578 | void mem_cgroup_wb_stats(struct bdi_writeback *wb, unsigned long *pfilepages, |
| 1579 | unsigned long *pheadroom, unsigned long *pdirty, |
| 1580 | unsigned long *pwriteback); |
Tejun Heo | 841710a | 2015-05-22 18:23:33 -0400 | [diff] [blame] | 1581 | |
Matthew Wilcox (Oracle) | 9d8053f | 2021-05-04 11:43:01 -0400 | [diff] [blame] | 1582 | void mem_cgroup_track_foreign_dirty_slowpath(struct folio *folio, |
Tejun Heo | 97b2782 | 2019-08-26 09:06:56 -0700 | [diff] [blame] | 1583 | struct bdi_writeback *wb); |
| 1584 | |
Matthew Wilcox (Oracle) | 203a315 | 2021-05-04 11:01:10 -0400 | [diff] [blame] | 1585 | static inline void mem_cgroup_track_foreign_dirty(struct folio *folio, |
Tejun Heo | 97b2782 | 2019-08-26 09:06:56 -0700 | [diff] [blame] | 1586 | struct bdi_writeback *wb) |
| 1587 | { |
Baoquan He | 08d1d0e | 2019-10-06 17:58:15 -0700 | [diff] [blame] | 1588 | if (mem_cgroup_disabled()) |
| 1589 | return; |
| 1590 | |
Matthew Wilcox (Oracle) | 9d8053f | 2021-05-04 11:43:01 -0400 | [diff] [blame] | 1591 | if (unlikely(&folio_memcg(folio)->css != wb->memcg_css)) |
| 1592 | mem_cgroup_track_foreign_dirty_slowpath(folio, wb); |
Tejun Heo | 97b2782 | 2019-08-26 09:06:56 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | void mem_cgroup_flush_foreign(struct bdi_writeback *wb); |
| 1596 | |
Tejun Heo | 841710a | 2015-05-22 18:23:33 -0400 | [diff] [blame] | 1597 | #else /* CONFIG_CGROUP_WRITEBACK */ |
| 1598 | |
| 1599 | static inline struct wb_domain *mem_cgroup_wb_domain(struct bdi_writeback *wb) |
| 1600 | { |
| 1601 | return NULL; |
| 1602 | } |
| 1603 | |
Tejun Heo | c2aa723 | 2015-05-22 18:23:35 -0400 | [diff] [blame] | 1604 | static inline void mem_cgroup_wb_stats(struct bdi_writeback *wb, |
Tejun Heo | c5edf9c | 2015-09-29 13:04:26 -0400 | [diff] [blame] | 1605 | unsigned long *pfilepages, |
| 1606 | unsigned long *pheadroom, |
Tejun Heo | c2aa723 | 2015-05-22 18:23:35 -0400 | [diff] [blame] | 1607 | unsigned long *pdirty, |
| 1608 | unsigned long *pwriteback) |
| 1609 | { |
| 1610 | } |
| 1611 | |
Matthew Wilcox (Oracle) | 203a315 | 2021-05-04 11:01:10 -0400 | [diff] [blame] | 1612 | static inline void mem_cgroup_track_foreign_dirty(struct folio *folio, |
Tejun Heo | 97b2782 | 2019-08-26 09:06:56 -0700 | [diff] [blame] | 1613 | struct bdi_writeback *wb) |
| 1614 | { |
| 1615 | } |
| 1616 | |
| 1617 | static inline void mem_cgroup_flush_foreign(struct bdi_writeback *wb) |
| 1618 | { |
| 1619 | } |
| 1620 | |
Tejun Heo | 841710a | 2015-05-22 18:23:33 -0400 | [diff] [blame] | 1621 | #endif /* CONFIG_CGROUP_WRITEBACK */ |
Tejun Heo | 52ebea7 | 2015-05-22 17:13:37 -0400 | [diff] [blame] | 1622 | |
Glauber Costa | e1aab16 | 2011-12-11 21:47:03 +0000 | [diff] [blame] | 1623 | struct sock; |
Wei Wang | 4b1327b | 2021-08-17 12:40:03 -0700 | [diff] [blame] | 1624 | bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages, |
| 1625 | gfp_t gfp_mask); |
Johannes Weiner | baac50b | 2016-01-14 15:21:17 -0800 | [diff] [blame] | 1626 | void mem_cgroup_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages); |
Johannes Weiner | d886f4e | 2016-01-20 15:02:47 -0800 | [diff] [blame] | 1627 | #ifdef CONFIG_MEMCG |
Johannes Weiner | ef12947 | 2016-01-14 15:21:34 -0800 | [diff] [blame] | 1628 | extern struct static_key_false memcg_sockets_enabled_key; |
| 1629 | #define mem_cgroup_sockets_enabled static_branch_unlikely(&memcg_sockets_enabled_key) |
Johannes Weiner | 2d75807 | 2016-10-07 17:00:58 -0700 | [diff] [blame] | 1630 | void mem_cgroup_sk_alloc(struct sock *sk); |
| 1631 | void mem_cgroup_sk_free(struct sock *sk); |
Johannes Weiner | baac50b | 2016-01-14 15:21:17 -0800 | [diff] [blame] | 1632 | static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg) |
Johannes Weiner | e805605 | 2016-01-14 15:21:14 -0800 | [diff] [blame] | 1633 | { |
Johannes Weiner | 0db1529 | 2016-01-20 15:02:50 -0800 | [diff] [blame] | 1634 | if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && memcg->tcpmem_pressure) |
Johannes Weiner | 8e8ae64 | 2016-01-14 15:21:32 -0800 | [diff] [blame] | 1635 | return true; |
Johannes Weiner | 8e8ae64 | 2016-01-14 15:21:32 -0800 | [diff] [blame] | 1636 | do { |
Yuanzheng Song | 7e6ec49 | 2021-11-05 13:42:52 -0700 | [diff] [blame] | 1637 | if (time_before(jiffies, READ_ONCE(memcg->socket_pressure))) |
Johannes Weiner | 8e8ae64 | 2016-01-14 15:21:32 -0800 | [diff] [blame] | 1638 | return true; |
| 1639 | } while ((memcg = parent_mem_cgroup(memcg))); |
| 1640 | return false; |
Johannes Weiner | e805605 | 2016-01-14 15:21:14 -0800 | [diff] [blame] | 1641 | } |
Yang Shi | 0a432dc | 2019-09-23 15:38:12 -0700 | [diff] [blame] | 1642 | |
Yang Shi | e4262c4 | 2021-05-04 18:36:23 -0700 | [diff] [blame] | 1643 | int alloc_shrinker_info(struct mem_cgroup *memcg); |
| 1644 | void free_shrinker_info(struct mem_cgroup *memcg); |
Yang Shi | 2bfd363 | 2021-05-04 18:36:11 -0700 | [diff] [blame] | 1645 | void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id); |
Yang Shi | a178015 | 2021-05-04 18:36:42 -0700 | [diff] [blame] | 1646 | void reparent_shrinker_deferred(struct mem_cgroup *memcg); |
Johannes Weiner | e805605 | 2016-01-14 15:21:14 -0800 | [diff] [blame] | 1647 | #else |
Johannes Weiner | 80e95fe | 2016-01-14 15:21:20 -0800 | [diff] [blame] | 1648 | #define mem_cgroup_sockets_enabled 0 |
Johannes Weiner | 2d75807 | 2016-10-07 17:00:58 -0700 | [diff] [blame] | 1649 | static inline void mem_cgroup_sk_alloc(struct sock *sk) { }; |
| 1650 | static inline void mem_cgroup_sk_free(struct sock *sk) { }; |
Johannes Weiner | baac50b | 2016-01-14 15:21:17 -0800 | [diff] [blame] | 1651 | static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg) |
Johannes Weiner | e805605 | 2016-01-14 15:21:14 -0800 | [diff] [blame] | 1652 | { |
| 1653 | return false; |
| 1654 | } |
Yang Shi | 0a432dc | 2019-09-23 15:38:12 -0700 | [diff] [blame] | 1655 | |
Yang Shi | 2bfd363 | 2021-05-04 18:36:11 -0700 | [diff] [blame] | 1656 | static inline void set_shrinker_bit(struct mem_cgroup *memcg, |
| 1657 | int nid, int shrinker_id) |
Yang Shi | 0a432dc | 2019-09-23 15:38:12 -0700 | [diff] [blame] | 1658 | { |
| 1659 | } |
Johannes Weiner | e805605 | 2016-01-14 15:21:14 -0800 | [diff] [blame] | 1660 | #endif |
Glauber Costa | 7ae1e1d | 2012-12-18 14:21:56 -0800 | [diff] [blame] | 1661 | |
Roman Gushchin | 9b6f7e1 | 2018-10-26 15:03:19 -0700 | [diff] [blame] | 1662 | #ifdef CONFIG_MEMCG_KMEM |
Roman Gushchin | 4d5c8ae | 2021-06-02 18:09:30 -0700 | [diff] [blame] | 1663 | bool mem_cgroup_kmem_disabled(void); |
Roman Gushchin | f4b00ea | 2020-04-01 21:06:46 -0700 | [diff] [blame] | 1664 | int __memcg_kmem_charge_page(struct page *page, gfp_t gfp, int order); |
| 1665 | void __memcg_kmem_uncharge_page(struct page *page, int order); |
Vladimir Davydov | 4526477 | 2016-07-26 15:24:21 -0700 | [diff] [blame] | 1666 | |
Roman Gushchin | bf4f059 | 2020-08-06 23:20:49 -0700 | [diff] [blame] | 1667 | struct obj_cgroup *get_obj_cgroup_from_current(void); |
| 1668 | |
| 1669 | int obj_cgroup_charge(struct obj_cgroup *objcg, gfp_t gfp, size_t size); |
| 1670 | void obj_cgroup_uncharge(struct obj_cgroup *objcg, size_t size); |
| 1671 | |
Johannes Weiner | ef12947 | 2016-01-14 15:21:34 -0800 | [diff] [blame] | 1672 | extern struct static_key_false memcg_kmem_enabled_key; |
Glauber Costa | 749c541 | 2012-12-18 14:23:01 -0800 | [diff] [blame] | 1673 | |
Vladimir Davydov | dbcf73e | 2015-02-12 14:58:57 -0800 | [diff] [blame] | 1674 | extern int memcg_nr_cache_ids; |
Michal Hocko | 6421999 | 2015-09-08 15:01:07 -0700 | [diff] [blame] | 1675 | void memcg_get_cache_ids(void); |
| 1676 | void memcg_put_cache_ids(void); |
Glauber Costa | ebe945c | 2012-12-18 14:23:10 -0800 | [diff] [blame] | 1677 | |
| 1678 | /* |
| 1679 | * Helper macro to loop through all memcg-specific caches. Callers must still |
| 1680 | * check if the cache is valid (it is either valid or NULL). |
| 1681 | * the slab_mutex must be held when looping through those caches |
| 1682 | */ |
Glauber Costa | 749c541 | 2012-12-18 14:23:01 -0800 | [diff] [blame] | 1683 | #define for_each_memcg_cache_index(_idx) \ |
Vladimir Davydov | dbcf73e | 2015-02-12 14:58:57 -0800 | [diff] [blame] | 1684 | for ((_idx) = 0; (_idx) < memcg_nr_cache_ids; (_idx)++) |
Glauber Costa | 749c541 | 2012-12-18 14:23:01 -0800 | [diff] [blame] | 1685 | |
Glauber Costa | 7ae1e1d | 2012-12-18 14:21:56 -0800 | [diff] [blame] | 1686 | static inline bool memcg_kmem_enabled(void) |
| 1687 | { |
Roman Gushchin | eda330e | 2020-08-06 23:21:47 -0700 | [diff] [blame] | 1688 | return static_branch_likely(&memcg_kmem_enabled_key); |
Glauber Costa | 7ae1e1d | 2012-12-18 14:21:56 -0800 | [diff] [blame] | 1689 | } |
| 1690 | |
Roman Gushchin | f4b00ea | 2020-04-01 21:06:46 -0700 | [diff] [blame] | 1691 | static inline int memcg_kmem_charge_page(struct page *page, gfp_t gfp, |
| 1692 | int order) |
Shakeel Butt | 60cd4bc | 2019-03-05 15:43:13 -0800 | [diff] [blame] | 1693 | { |
| 1694 | if (memcg_kmem_enabled()) |
Roman Gushchin | f4b00ea | 2020-04-01 21:06:46 -0700 | [diff] [blame] | 1695 | return __memcg_kmem_charge_page(page, gfp, order); |
Shakeel Butt | 60cd4bc | 2019-03-05 15:43:13 -0800 | [diff] [blame] | 1696 | return 0; |
| 1697 | } |
| 1698 | |
Roman Gushchin | f4b00ea | 2020-04-01 21:06:46 -0700 | [diff] [blame] | 1699 | static inline void memcg_kmem_uncharge_page(struct page *page, int order) |
Shakeel Butt | 60cd4bc | 2019-03-05 15:43:13 -0800 | [diff] [blame] | 1700 | { |
| 1701 | if (memcg_kmem_enabled()) |
Roman Gushchin | f4b00ea | 2020-04-01 21:06:46 -0700 | [diff] [blame] | 1702 | __memcg_kmem_uncharge_page(page, order); |
Shakeel Butt | 60cd4bc | 2019-03-05 15:43:13 -0800 | [diff] [blame] | 1703 | } |
| 1704 | |
Glauber Costa | 7ae1e1d | 2012-12-18 14:21:56 -0800 | [diff] [blame] | 1705 | /* |
Roman Gushchin | a7cb874 | 2020-12-14 19:06:45 -0800 | [diff] [blame] | 1706 | * A helper for accessing memcg's kmem_id, used for getting |
| 1707 | * corresponding LRU lists. |
Michal Hocko | 33398cf | 2015-09-08 15:01:02 -0700 | [diff] [blame] | 1708 | */ |
| 1709 | static inline int memcg_cache_id(struct mem_cgroup *memcg) |
| 1710 | { |
| 1711 | return memcg ? memcg->kmemcg_id : -1; |
| 1712 | } |
Vladimir Davydov | 5722d09 | 2014-04-07 15:39:24 -0700 | [diff] [blame] | 1713 | |
Roman Gushchin | 8380ce4 | 2020-03-28 19:17:25 -0700 | [diff] [blame] | 1714 | struct mem_cgroup *mem_cgroup_from_obj(void *p); |
| 1715 | |
Glauber Costa | 7ae1e1d | 2012-12-18 14:21:56 -0800 | [diff] [blame] | 1716 | #else |
Roman Gushchin | 4d5c8ae | 2021-06-02 18:09:30 -0700 | [diff] [blame] | 1717 | static inline bool mem_cgroup_kmem_disabled(void) |
| 1718 | { |
| 1719 | return true; |
| 1720 | } |
Roman Gushchin | 9b6f7e1 | 2018-10-26 15:03:19 -0700 | [diff] [blame] | 1721 | |
Roman Gushchin | f4b00ea | 2020-04-01 21:06:46 -0700 | [diff] [blame] | 1722 | static inline int memcg_kmem_charge_page(struct page *page, gfp_t gfp, |
| 1723 | int order) |
Roman Gushchin | 9b6f7e1 | 2018-10-26 15:03:19 -0700 | [diff] [blame] | 1724 | { |
| 1725 | return 0; |
| 1726 | } |
| 1727 | |
Roman Gushchin | f4b00ea | 2020-04-01 21:06:46 -0700 | [diff] [blame] | 1728 | static inline void memcg_kmem_uncharge_page(struct page *page, int order) |
Roman Gushchin | 9b6f7e1 | 2018-10-26 15:03:19 -0700 | [diff] [blame] | 1729 | { |
| 1730 | } |
| 1731 | |
Roman Gushchin | f4b00ea | 2020-04-01 21:06:46 -0700 | [diff] [blame] | 1732 | static inline int __memcg_kmem_charge_page(struct page *page, gfp_t gfp, |
| 1733 | int order) |
Shakeel Butt | 60cd4bc | 2019-03-05 15:43:13 -0800 | [diff] [blame] | 1734 | { |
| 1735 | return 0; |
| 1736 | } |
| 1737 | |
Roman Gushchin | f4b00ea | 2020-04-01 21:06:46 -0700 | [diff] [blame] | 1738 | static inline void __memcg_kmem_uncharge_page(struct page *page, int order) |
Shakeel Butt | 60cd4bc | 2019-03-05 15:43:13 -0800 | [diff] [blame] | 1739 | { |
| 1740 | } |
| 1741 | |
Glauber Costa | 749c541 | 2012-12-18 14:23:01 -0800 | [diff] [blame] | 1742 | #define for_each_memcg_cache_index(_idx) \ |
| 1743 | for (; NULL; ) |
| 1744 | |
Glauber Costa | b9ce5ef | 2012-12-18 14:22:46 -0800 | [diff] [blame] | 1745 | static inline bool memcg_kmem_enabled(void) |
| 1746 | { |
| 1747 | return false; |
| 1748 | } |
| 1749 | |
Glauber Costa | 2633d7a | 2012-12-18 14:22:34 -0800 | [diff] [blame] | 1750 | static inline int memcg_cache_id(struct mem_cgroup *memcg) |
| 1751 | { |
| 1752 | return -1; |
| 1753 | } |
| 1754 | |
Vladimir Davydov | 05257a1 | 2015-02-12 14:59:01 -0800 | [diff] [blame] | 1755 | static inline void memcg_get_cache_ids(void) |
| 1756 | { |
| 1757 | } |
| 1758 | |
| 1759 | static inline void memcg_put_cache_ids(void) |
| 1760 | { |
| 1761 | } |
| 1762 | |
Roman Gushchin | 8380ce4 | 2020-03-28 19:17:25 -0700 | [diff] [blame] | 1763 | static inline struct mem_cgroup *mem_cgroup_from_obj(void *p) |
| 1764 | { |
| 1765 | return NULL; |
| 1766 | } |
| 1767 | |
Kirill Tkhai | 84c07d1 | 2018-08-17 15:47:25 -0700 | [diff] [blame] | 1768 | #endif /* CONFIG_MEMCG_KMEM */ |
Johannes Weiner | 127424c | 2016-01-20 15:02:32 -0800 | [diff] [blame] | 1769 | |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1770 | #endif /* _LINUX_MEMCONTROL_H */ |