blob: 6e0126230878621e56e3f6883898448a9e66a7e1 [file] [log] [blame]
Balbir Singh8cdea7c2008-02-07 00:13:50 -08001/* memcontrol.h - Memory Controller
2 *
3 * Copyright IBM Corporation, 2007
4 * Author Balbir Singh <balbir@linux.vnet.ibm.com>
5 *
Pavel Emelianov78fb7462008-02-07 00:13:51 -08006 * Copyright 2007 OpenVZ SWsoft Inc
7 * Author: Pavel Emelianov <xemul@openvz.org>
8 *
Balbir Singh8cdea7c2008-02-07 00:13:50 -08009 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
20#ifndef _LINUX_MEMCONTROL_H
21#define _LINUX_MEMCONTROL_H
Hirokazu Takahashif8d665422009-01-07 18:08:02 -080022#include <linux/cgroup.h>
Ying Han456f9982011-05-26 16:25:38 -070023#include <linux/vm_event_item.h>
Glauber Costa7ae1e1d2012-12-18 14:21:56 -080024#include <linux/hardirq.h>
Glauber Costaa8964b92012-12-18 14:22:09 -080025#include <linux/jump_label.h>
Michal Hocko33398cf2015-09-08 15:01:02 -070026#include <linux/page_counter.h>
27#include <linux/vmpressure.h>
28#include <linux/eventfd.h>
29#include <linux/mmzone.h>
30#include <linux/writeback.h>
Ying Han456f9982011-05-26 16:25:38 -070031
Pavel Emelianov78fb7462008-02-07 00:13:51 -080032struct mem_cgroup;
Balbir Singh8697d332008-02-07 00:13:59 -080033struct page;
34struct mm_struct;
Glauber Costa2633d7a2012-12-18 14:22:34 -080035struct kmem_cache;
Pavel Emelianov78fb7462008-02-07 00:13:51 -080036
Sha Zhengju68b48762013-09-12 15:13:50 -070037/*
38 * The corresponding mem_cgroup_stat_names is defined in mm/memcontrol.c,
39 * These two lists should keep in accord with each other.
40 */
41enum mem_cgroup_stat_index {
42 /*
43 * For MEM_CONTAINER_TYPE_ALL, usage = pagecache + rss.
44 */
45 MEM_CGROUP_STAT_CACHE, /* # of pages charged as cache */
46 MEM_CGROUP_STAT_RSS, /* # of pages charged as anon rss */
47 MEM_CGROUP_STAT_RSS_HUGE, /* # of pages charged as anon huge */
48 MEM_CGROUP_STAT_FILE_MAPPED, /* # of pages charged as file rss */
Greg Thelenc4843a72015-05-22 17:13:16 -040049 MEM_CGROUP_STAT_DIRTY, /* # of dirty pages in page cache */
Sha Zhengju3ea67d02013-09-12 15:13:53 -070050 MEM_CGROUP_STAT_WRITEBACK, /* # of pages under writeback */
Sha Zhengju68b48762013-09-12 15:13:50 -070051 MEM_CGROUP_STAT_SWAP, /* # of pages, swapped out */
52 MEM_CGROUP_STAT_NSTATS,
Greg Thelen2a7106f2011-01-13 15:47:37 -080053};
54
Johannes Weiner56600482012-01-12 17:17:59 -080055struct mem_cgroup_reclaim_cookie {
56 struct zone *zone;
57 int priority;
58 unsigned int generation;
59};
60
Johannes Weiner241994ed2015-02-11 15:26:06 -080061enum mem_cgroup_events_index {
62 MEM_CGROUP_EVENTS_PGPGIN, /* # of pages paged in */
63 MEM_CGROUP_EVENTS_PGPGOUT, /* # of pages paged out */
64 MEM_CGROUP_EVENTS_PGFAULT, /* # of page-faults */
65 MEM_CGROUP_EVENTS_PGMAJFAULT, /* # of major page-faults */
66 MEM_CGROUP_EVENTS_NSTATS,
67 /* default hierarchy events */
68 MEMCG_LOW = MEM_CGROUP_EVENTS_NSTATS,
69 MEMCG_HIGH,
70 MEMCG_MAX,
71 MEMCG_OOM,
72 MEMCG_NR_EVENTS,
73};
74
Michal Hocko33398cf2015-09-08 15:01:02 -070075/*
76 * Per memcg event counter is incremented at every pagein/pageout. With THP,
77 * it will be incremated by the number of pages. This counter is used for
78 * for trigger some periodic events. This is straightforward and better
79 * than using jiffies etc. to handle periodic memcg event.
80 */
81enum mem_cgroup_events_target {
82 MEM_CGROUP_TARGET_THRESH,
83 MEM_CGROUP_TARGET_SOFTLIMIT,
84 MEM_CGROUP_TARGET_NUMAINFO,
85 MEM_CGROUP_NTARGETS,
86};
87
Andrew Mortonc255a452012-07-31 16:43:02 -070088#ifdef CONFIG_MEMCG
Michal Hocko33398cf2015-09-08 15:01:02 -070089struct mem_cgroup_stat_cpu {
90 long count[MEM_CGROUP_STAT_NSTATS];
91 unsigned long events[MEMCG_NR_EVENTS];
92 unsigned long nr_page_events;
93 unsigned long targets[MEM_CGROUP_NTARGETS];
94};
95
96struct mem_cgroup_reclaim_iter {
97 struct mem_cgroup *position;
98 /* scan generation, increased every round-trip */
99 unsigned int generation;
100};
101
102/*
103 * per-zone information in memory controller.
104 */
105struct mem_cgroup_per_zone {
106 struct lruvec lruvec;
107 unsigned long lru_size[NR_LRU_LISTS];
108
109 struct mem_cgroup_reclaim_iter iter[DEF_PRIORITY + 1];
110
111 struct rb_node tree_node; /* RB tree node */
112 unsigned long usage_in_excess;/* Set to the value by which */
113 /* the soft limit is exceeded*/
114 bool on_tree;
115 struct mem_cgroup *memcg; /* Back pointer, we cannot */
116 /* use container_of */
117};
118
119struct mem_cgroup_per_node {
120 struct mem_cgroup_per_zone zoneinfo[MAX_NR_ZONES];
121};
122
123struct mem_cgroup_threshold {
124 struct eventfd_ctx *eventfd;
125 unsigned long threshold;
126};
127
128/* For threshold */
129struct mem_cgroup_threshold_ary {
130 /* An array index points to threshold just below or equal to usage. */
131 int current_threshold;
132 /* Size of entries[] */
133 unsigned int size;
134 /* Array of thresholds */
135 struct mem_cgroup_threshold entries[0];
136};
137
138struct mem_cgroup_thresholds {
139 /* Primary thresholds array */
140 struct mem_cgroup_threshold_ary *primary;
141 /*
142 * Spare threshold array.
143 * This is needed to make mem_cgroup_unregister_event() "never fail".
144 * It must be able to store at least primary->size - 1 entries.
145 */
146 struct mem_cgroup_threshold_ary *spare;
147};
148
Johannes Weiner567e9ab2016-01-20 15:02:24 -0800149enum memcg_kmem_state {
150 KMEM_NONE,
151 KMEM_ALLOCATED,
152 KMEM_ONLINE,
153};
154
Michal Hocko33398cf2015-09-08 15:01:02 -0700155/*
156 * The memory controller data structure. The memory controller controls both
157 * page cache and RSS per cgroup. We would eventually like to provide
158 * statistics based on the statistics developed by Rik Van Riel for clock-pro,
159 * to help the administrator determine what knobs to tune.
160 */
161struct mem_cgroup {
162 struct cgroup_subsys_state css;
163
164 /* Accounted resources */
165 struct page_counter memory;
Vladimir Davydov37e84352016-01-20 15:02:56 -0800166 struct page_counter swap;
Johannes Weiner0db15292016-01-20 15:02:50 -0800167
168 /* Legacy consumer-oriented counters */
Michal Hocko33398cf2015-09-08 15:01:02 -0700169 struct page_counter memsw;
170 struct page_counter kmem;
Johannes Weiner0db15292016-01-20 15:02:50 -0800171 struct page_counter tcpmem;
Michal Hocko33398cf2015-09-08 15:01:02 -0700172
173 /* Normal memory consumption range */
174 unsigned long low;
175 unsigned long high;
176
Johannes Weinerf7e1cb62016-01-14 15:21:29 -0800177 /* Range enforcement for interrupt charges */
178 struct work_struct high_work;
179
Michal Hocko33398cf2015-09-08 15:01:02 -0700180 unsigned long soft_limit;
181
182 /* vmpressure notifications */
183 struct vmpressure vmpressure;
184
Michal Hocko33398cf2015-09-08 15:01:02 -0700185 /*
186 * Should the accounting and control be hierarchical, per subtree?
187 */
188 bool use_hierarchy;
189
190 /* protected by memcg_oom_lock */
191 bool oom_lock;
192 int under_oom;
193
194 int swappiness;
195 /* OOM-Killer disable */
196 int oom_kill_disable;
197
Tejun Heo472912a2015-09-18 18:01:59 -0400198 /* handle for "memory.events" */
199 struct cgroup_file events_file;
200
Michal Hocko33398cf2015-09-08 15:01:02 -0700201 /* protect arrays of thresholds */
202 struct mutex thresholds_lock;
203
204 /* thresholds for memory usage. RCU-protected */
205 struct mem_cgroup_thresholds thresholds;
206
207 /* thresholds for mem+swap usage. RCU-protected */
208 struct mem_cgroup_thresholds memsw_thresholds;
209
210 /* For oom notifier event fd */
211 struct list_head oom_notify;
212
213 /*
214 * Should we move charges of a task when a task is moved into this
215 * mem_cgroup ? And what type of charges should we move ?
216 */
217 unsigned long move_charge_at_immigrate;
218 /*
219 * set > 0 if pages under this cgroup are moving to other cgroup.
220 */
221 atomic_t moving_account;
222 /* taken only while moving_account > 0 */
223 spinlock_t move_lock;
224 struct task_struct *move_lock_task;
225 unsigned long move_lock_flags;
226 /*
227 * percpu counter.
228 */
229 struct mem_cgroup_stat_cpu __percpu *stat;
Michal Hocko33398cf2015-09-08 15:01:02 -0700230
Johannes Weinerd886f4e2016-01-20 15:02:47 -0800231 unsigned long socket_pressure;
232
233 /* Legacy tcp memory accounting */
Johannes Weiner0db15292016-01-20 15:02:50 -0800234 bool tcpmem_active;
235 int tcpmem_pressure;
Johannes Weinerd886f4e2016-01-20 15:02:47 -0800236
Johannes Weiner127424c2016-01-20 15:02:32 -0800237#ifndef CONFIG_SLOB
Michal Hocko33398cf2015-09-08 15:01:02 -0700238 /* Index in the kmem_cache->memcg_params.memcg_caches array */
239 int kmemcg_id;
Johannes Weiner567e9ab2016-01-20 15:02:24 -0800240 enum memcg_kmem_state kmem_state;
Michal Hocko33398cf2015-09-08 15:01:02 -0700241#endif
242
243 int last_scanned_node;
244#if MAX_NUMNODES > 1
245 nodemask_t scan_nodes;
246 atomic_t numainfo_events;
247 atomic_t numainfo_updating;
248#endif
249
250#ifdef CONFIG_CGROUP_WRITEBACK
251 struct list_head cgwb_list;
252 struct wb_domain cgwb_domain;
253#endif
254
255 /* List of events which userspace want to receive */
256 struct list_head event_list;
257 spinlock_t event_list_lock;
258
259 struct mem_cgroup_per_node *nodeinfo[0];
260 /* WARNING: nodeinfo must be the last member here */
261};
Johannes Weiner7d828602016-01-14 15:20:56 -0800262
263extern struct mem_cgroup *root_mem_cgroup;
Tejun Heo56161632015-05-22 17:13:20 -0400264
Michal Hocko33398cf2015-09-08 15:01:02 -0700265/**
266 * mem_cgroup_events - count memory events against a cgroup
267 * @memcg: the memory cgroup
268 * @idx: the event index
269 * @nr: the number of events to account for
270 */
271static inline void mem_cgroup_events(struct mem_cgroup *memcg,
Johannes Weiner241994ed2015-02-11 15:26:06 -0800272 enum mem_cgroup_events_index idx,
Michal Hocko33398cf2015-09-08 15:01:02 -0700273 unsigned int nr)
274{
275 this_cpu_add(memcg->stat->events[idx], nr);
Tejun Heo472912a2015-09-18 18:01:59 -0400276 cgroup_file_notify(&memcg->events_file);
Michal Hocko33398cf2015-09-08 15:01:02 -0700277}
Johannes Weiner241994ed2015-02-11 15:26:06 -0800278
279bool mem_cgroup_low(struct mem_cgroup *root, struct mem_cgroup *memcg);
280
Johannes Weiner00501b52014-08-08 14:19:20 -0700281int mem_cgroup_try_charge(struct page *page, struct mm_struct *mm,
Kirill A. Shutemovf627c2f2016-01-15 16:52:20 -0800282 gfp_t gfp_mask, struct mem_cgroup **memcgp,
283 bool compound);
Johannes Weiner00501b52014-08-08 14:19:20 -0700284void mem_cgroup_commit_charge(struct page *page, struct mem_cgroup *memcg,
Kirill A. Shutemovf627c2f2016-01-15 16:52:20 -0800285 bool lrucare, bool compound);
286void mem_cgroup_cancel_charge(struct page *page, struct mem_cgroup *memcg,
287 bool compound);
Johannes Weiner0a31bc92014-08-08 14:19:22 -0700288void mem_cgroup_uncharge(struct page *page);
Johannes Weiner747db952014-08-08 14:19:24 -0700289void mem_cgroup_uncharge_list(struct list_head *page_list);
Johannes Weiner0a31bc92014-08-08 14:19:22 -0700290
Hugh Dickins45637ba2015-11-05 18:49:40 -0800291void mem_cgroup_replace_page(struct page *oldpage, struct page *newpage);
Johannes Weiner0a31bc92014-08-08 14:19:22 -0700292
Johannes Weiner925b7672012-01-12 17:18:15 -0800293struct lruvec *mem_cgroup_zone_lruvec(struct zone *, struct mem_cgroup *);
Hugh Dickinsfa9add62012-05-29 15:07:09 -0700294struct lruvec *mem_cgroup_page_lruvec(struct page *, struct zone *);
KAMEZAWA Hiroyuki569b8462009-12-15 16:47:03 -0800295
Johannes Weiner2314b422014-12-10 15:44:33 -0800296bool task_in_mem_cgroup(struct task_struct *task, struct mem_cgroup *memcg);
Michal Hocko64219992015-09-08 15:01:07 -0700297struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
Vladimir Davydove993d902015-09-09 15:35:35 -0700298
Michal Hocko33398cf2015-09-08 15:01:02 -0700299static inline
300struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *css){
301 return css ? container_of(css, struct mem_cgroup, css) : NULL;
302}
303
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800304#define mem_cgroup_from_counter(counter, member) \
305 container_of(counter, struct mem_cgroup, member)
306
Michal Hocko33398cf2015-09-08 15:01:02 -0700307struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *,
308 struct mem_cgroup *,
309 struct mem_cgroup_reclaim_cookie *);
310void mem_cgroup_iter_break(struct mem_cgroup *, struct mem_cgroup *);
311
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800312/**
313 * parent_mem_cgroup - find the accounting parent of a memcg
314 * @memcg: memcg whose parent to find
315 *
316 * Returns the parent memcg, or NULL if this is the root or the memory
317 * controller is in legacy no-hierarchy mode.
318 */
319static inline struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg)
320{
321 if (!memcg->memory.parent)
322 return NULL;
323 return mem_cgroup_from_counter(memcg->memory.parent, memory);
324}
325
Michal Hocko33398cf2015-09-08 15:01:02 -0700326static inline bool mem_cgroup_is_descendant(struct mem_cgroup *memcg,
327 struct mem_cgroup *root)
328{
329 if (root == memcg)
330 return true;
331 if (!root->use_hierarchy)
332 return false;
333 return cgroup_is_descendant(memcg->css.cgroup, root->css.cgroup);
334}
Glauber Costae1aab162011-12-11 21:47:03 +0000335
Johannes Weiner2314b422014-12-10 15:44:33 -0800336static inline bool mm_match_cgroup(struct mm_struct *mm,
337 struct mem_cgroup *memcg)
Lai Jiangshan2e4d4092009-01-07 18:08:07 -0800338{
Johannes Weiner587af302012-10-08 16:34:12 -0700339 struct mem_cgroup *task_memcg;
Johannes Weiner413918b2014-12-10 15:44:30 -0800340 bool match = false;
Johannes Weinerc3ac9a82012-05-29 15:06:25 -0700341
Lai Jiangshan2e4d4092009-01-07 18:08:07 -0800342 rcu_read_lock();
Johannes Weiner587af302012-10-08 16:34:12 -0700343 task_memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
Johannes Weiner413918b2014-12-10 15:44:30 -0800344 if (task_memcg)
Johannes Weiner2314b422014-12-10 15:44:33 -0800345 match = mem_cgroup_is_descendant(task_memcg, memcg);
Lai Jiangshan2e4d4092009-01-07 18:08:07 -0800346 rcu_read_unlock();
Johannes Weinerc3ac9a82012-05-29 15:06:25 -0700347 return match;
Lai Jiangshan2e4d4092009-01-07 18:08:07 -0800348}
Balbir Singh8a9f3cc2008-02-07 00:13:53 -0800349
Michal Hocko64219992015-09-08 15:01:07 -0700350struct cgroup_subsys_state *mem_cgroup_css_from_page(struct page *page);
Vladimir Davydov2fc04522015-09-09 15:35:28 -0700351ino_t page_cgroup_ino(struct page *page);
Wu Fengguangd3242362009-12-16 12:19:59 +0100352
Michal Hocko33398cf2015-09-08 15:01:02 -0700353static inline bool mem_cgroup_disabled(void)
354{
Tejun Heofc5ed1e2015-09-18 11:56:28 -0400355 return !cgroup_subsys_enabled(memory_cgrp_subsys);
Michal Hocko33398cf2015-09-08 15:01:02 -0700356}
Johannes Weiner56600482012-01-12 17:17:59 -0800357
KAMEZAWA Hiroyuki58ae83d2008-02-07 00:14:32 -0800358/*
359 * For memory reclaim.
360 */
Ying Han889976d2011-05-26 16:25:33 -0700361int mem_cgroup_select_victim_node(struct mem_cgroup *memcg);
Michal Hocko33398cf2015-09-08 15:01:02 -0700362
363void mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru,
364 int nr_pages);
365
366static inline bool mem_cgroup_lruvec_online(struct lruvec *lruvec)
367{
368 struct mem_cgroup_per_zone *mz;
369 struct mem_cgroup *memcg;
370
371 if (mem_cgroup_disabled())
372 return true;
373
374 mz = container_of(lruvec, struct mem_cgroup_per_zone, lruvec);
375 memcg = mz->memcg;
376
377 return !!(memcg->css.flags & CSS_ONLINE);
378}
379
380static inline
381unsigned long mem_cgroup_get_lru_size(struct lruvec *lruvec, enum lru_list lru)
382{
383 struct mem_cgroup_per_zone *mz;
384
385 mz = container_of(lruvec, struct mem_cgroup_per_zone, lruvec);
386 return mz->lru_size[lru];
387}
388
Yaowei Bai13308ca2015-11-05 18:47:40 -0800389static inline bool mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec)
Michal Hocko33398cf2015-09-08 15:01:02 -0700390{
391 unsigned long inactive_ratio;
392 unsigned long inactive;
393 unsigned long active;
394 unsigned long gb;
395
396 inactive = mem_cgroup_get_lru_size(lruvec, LRU_INACTIVE_ANON);
397 active = mem_cgroup_get_lru_size(lruvec, LRU_ACTIVE_ANON);
398
399 gb = (inactive + active) >> (30 - PAGE_SHIFT);
400 if (gb)
401 inactive_ratio = int_sqrt(10 * gb);
402 else
403 inactive_ratio = 1;
404
405 return inactive * inactive_ratio < active;
406}
407
Tejun Heob23afb92015-11-05 18:46:11 -0800408void mem_cgroup_handle_over_high(void);
409
Michal Hocko64219992015-09-08 15:01:07 -0700410void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
411 struct task_struct *p);
KAMEZAWA Hiroyuki58ae83d2008-02-07 00:14:32 -0800412
Johannes Weiner49426422013-10-16 13:46:59 -0700413static inline void mem_cgroup_oom_enable(void)
Johannes Weiner519e5242013-09-12 15:13:42 -0700414{
Tejun Heo626ebc42015-11-05 18:46:09 -0800415 WARN_ON(current->memcg_may_oom);
416 current->memcg_may_oom = 1;
Johannes Weiner519e5242013-09-12 15:13:42 -0700417}
418
Johannes Weiner49426422013-10-16 13:46:59 -0700419static inline void mem_cgroup_oom_disable(void)
Johannes Weiner519e5242013-09-12 15:13:42 -0700420{
Tejun Heo626ebc42015-11-05 18:46:09 -0800421 WARN_ON(!current->memcg_may_oom);
422 current->memcg_may_oom = 0;
Johannes Weiner519e5242013-09-12 15:13:42 -0700423}
424
Johannes Weiner3812c8c2013-09-12 15:13:44 -0700425static inline bool task_in_memcg_oom(struct task_struct *p)
426{
Tejun Heo626ebc42015-11-05 18:46:09 -0800427 return p->memcg_in_oom;
Johannes Weiner3812c8c2013-09-12 15:13:44 -0700428}
429
Johannes Weiner49426422013-10-16 13:46:59 -0700430bool mem_cgroup_oom_synchronize(bool wait);
Johannes Weiner3812c8c2013-09-12 15:13:44 -0700431
Andrew Mortonc255a452012-07-31 16:43:02 -0700432#ifdef CONFIG_MEMCG_SWAP
KAMEZAWA Hiroyukic0777192009-01-07 18:07:57 -0800433extern int do_swap_account;
434#endif
Hirokazu Takahashif8d665422009-01-07 18:08:02 -0800435
Johannes Weiner6de22612015-02-11 15:25:01 -0800436struct mem_cgroup *mem_cgroup_begin_page_stat(struct page *page);
Johannes Weiner6de22612015-02-11 15:25:01 -0800437void mem_cgroup_end_page_stat(struct mem_cgroup *memcg);
KAMEZAWA Hiroyuki89c06bd2012-03-21 16:34:25 -0700438
Michal Hocko33398cf2015-09-08 15:01:02 -0700439/**
440 * mem_cgroup_update_page_stat - update page state statistics
441 * @memcg: memcg to account against
442 * @idx: page state item to account
443 * @val: number of pages (positive or negative)
444 *
445 * See mem_cgroup_begin_page_stat() for locking requirements.
446 */
447static inline void mem_cgroup_update_page_stat(struct mem_cgroup *memcg,
448 enum mem_cgroup_stat_index idx, int val)
449{
450 VM_BUG_ON(!rcu_read_lock_held());
451
452 if (memcg)
453 this_cpu_add(memcg->stat->count[idx], val);
454}
455
Johannes Weinerd7365e72014-10-29 14:50:48 -0700456static inline void mem_cgroup_inc_page_stat(struct mem_cgroup *memcg,
Sha Zhengju68b48762013-09-12 15:13:50 -0700457 enum mem_cgroup_stat_index idx)
Greg Thelen2a7106f2011-01-13 15:47:37 -0800458{
Johannes Weinerd7365e72014-10-29 14:50:48 -0700459 mem_cgroup_update_page_stat(memcg, idx, 1);
Greg Thelen2a7106f2011-01-13 15:47:37 -0800460}
461
Johannes Weinerd7365e72014-10-29 14:50:48 -0700462static inline void mem_cgroup_dec_page_stat(struct mem_cgroup *memcg,
Sha Zhengju68b48762013-09-12 15:13:50 -0700463 enum mem_cgroup_stat_index idx)
Greg Thelen2a7106f2011-01-13 15:47:37 -0800464{
Johannes Weinerd7365e72014-10-29 14:50:48 -0700465 mem_cgroup_update_page_stat(memcg, idx, -1);
Greg Thelen2a7106f2011-01-13 15:47:37 -0800466}
467
Andrew Morton0608f432013-09-24 15:27:41 -0700468unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
469 gfp_t gfp_mask,
470 unsigned long *total_scanned);
David Rientjesa63d83f2010-08-09 17:19:46 -0700471
David Rientjes68ae5642012-12-12 13:51:57 -0800472static inline void mem_cgroup_count_vm_event(struct mm_struct *mm,
473 enum vm_event_item idx)
474{
Michal Hocko33398cf2015-09-08 15:01:02 -0700475 struct mem_cgroup *memcg;
476
David Rientjes68ae5642012-12-12 13:51:57 -0800477 if (mem_cgroup_disabled())
478 return;
Michal Hocko33398cf2015-09-08 15:01:02 -0700479
480 rcu_read_lock();
481 memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
482 if (unlikely(!memcg))
483 goto out;
484
485 switch (idx) {
486 case PGFAULT:
487 this_cpu_inc(memcg->stat->events[MEM_CGROUP_EVENTS_PGFAULT]);
488 break;
489 case PGMAJFAULT:
490 this_cpu_inc(memcg->stat->events[MEM_CGROUP_EVENTS_PGMAJFAULT]);
491 break;
492 default:
493 BUG();
494 }
495out:
496 rcu_read_unlock();
David Rientjes68ae5642012-12-12 13:51:57 -0800497}
KAMEZAWA Hiroyukica3e0212011-01-20 14:44:24 -0800498#ifdef CONFIG_TRANSPARENT_HUGEPAGE
KAMEZAWA Hiroyukie94c8a92012-01-12 17:18:20 -0800499void mem_cgroup_split_huge_fixup(struct page *head);
KAMEZAWA Hiroyukica3e0212011-01-20 14:44:24 -0800500#endif
501
Andrew Mortonc255a452012-07-31 16:43:02 -0700502#else /* CONFIG_MEMCG */
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -0800503struct mem_cgroup;
504
Johannes Weiner241994ed2015-02-11 15:26:06 -0800505static inline void mem_cgroup_events(struct mem_cgroup *memcg,
506 enum mem_cgroup_events_index idx,
507 unsigned int nr)
508{
509}
510
511static inline bool mem_cgroup_low(struct mem_cgroup *root,
512 struct mem_cgroup *memcg)
513{
514 return false;
515}
516
Johannes Weiner00501b52014-08-08 14:19:20 -0700517static inline int mem_cgroup_try_charge(struct page *page, struct mm_struct *mm,
518 gfp_t gfp_mask,
Kirill A. Shutemovf627c2f2016-01-15 16:52:20 -0800519 struct mem_cgroup **memcgp,
520 bool compound)
Balbir Singh8a9f3cc2008-02-07 00:13:53 -0800521{
Johannes Weiner00501b52014-08-08 14:19:20 -0700522 *memcgp = NULL;
Balbir Singh8a9f3cc2008-02-07 00:13:53 -0800523 return 0;
524}
525
Johannes Weiner00501b52014-08-08 14:19:20 -0700526static inline void mem_cgroup_commit_charge(struct page *page,
527 struct mem_cgroup *memcg,
Kirill A. Shutemovf627c2f2016-01-15 16:52:20 -0800528 bool lrucare, bool compound)
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -0800529{
530}
531
Johannes Weiner00501b52014-08-08 14:19:20 -0700532static inline void mem_cgroup_cancel_charge(struct page *page,
Kirill A. Shutemovf627c2f2016-01-15 16:52:20 -0800533 struct mem_cgroup *memcg,
534 bool compound)
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -0800535{
536}
537
Johannes Weiner0a31bc92014-08-08 14:19:22 -0700538static inline void mem_cgroup_uncharge(struct page *page)
539{
540}
541
Johannes Weiner747db952014-08-08 14:19:24 -0700542static inline void mem_cgroup_uncharge_list(struct list_head *page_list)
KAMEZAWA Hiroyuki569b8462009-12-15 16:47:03 -0800543{
544}
545
Hugh Dickins45637ba2015-11-05 18:49:40 -0800546static inline void mem_cgroup_replace_page(struct page *old, struct page *new)
KAMEZAWA Hiroyuki69029cd2008-07-25 01:47:14 -0700547{
548}
549
Johannes Weiner925b7672012-01-12 17:18:15 -0800550static inline struct lruvec *mem_cgroup_zone_lruvec(struct zone *zone,
551 struct mem_cgroup *memcg)
552{
553 return &zone->lruvec;
554}
555
Hugh Dickinsfa9add62012-05-29 15:07:09 -0700556static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page,
557 struct zone *zone)
Minchan Kim3f58a822011-03-22 16:32:53 -0700558{
Johannes Weiner925b7672012-01-12 17:18:15 -0800559 return &zone->lruvec;
Balbir Singh66e17072008-02-07 00:13:56 -0800560}
561
Johannes Weiner587af302012-10-08 16:34:12 -0700562static inline bool mm_match_cgroup(struct mm_struct *mm,
Raghavendra K Tc0ff4b82011-11-02 13:38:15 -0700563 struct mem_cgroup *memcg)
Balbir Singhbed71612008-02-07 00:14:01 -0800564{
Johannes Weiner587af302012-10-08 16:34:12 -0700565 return true;
Balbir Singhbed71612008-02-07 00:14:01 -0800566}
567
David Rientjesffbdccf2013-07-03 15:01:23 -0700568static inline bool task_in_mem_cgroup(struct task_struct *task,
569 const struct mem_cgroup *memcg)
David Rientjes4c4a2212008-02-07 00:14:06 -0800570{
David Rientjesffbdccf2013-07-03 15:01:23 -0700571 return true;
David Rientjes4c4a2212008-02-07 00:14:06 -0800572}
573
Johannes Weiner56600482012-01-12 17:17:59 -0800574static inline struct mem_cgroup *
575mem_cgroup_iter(struct mem_cgroup *root,
576 struct mem_cgroup *prev,
577 struct mem_cgroup_reclaim_cookie *reclaim)
578{
579 return NULL;
580}
581
582static inline void mem_cgroup_iter_break(struct mem_cgroup *root,
583 struct mem_cgroup *prev)
584{
585}
586
Hirokazu Takahashif8d665422009-01-07 18:08:02 -0800587static inline bool mem_cgroup_disabled(void)
588{
589 return true;
590}
KAMEZAWA Hiroyukia636b322009-01-07 18:08:08 -0800591
Yaowei Bai13308ca2015-11-05 18:47:40 -0800592static inline bool
Konstantin Khlebnikovc56d5c72012-05-29 15:07:00 -0700593mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec)
KOSAKI Motohiro14797e22009-01-07 18:08:18 -0800594{
Yaowei Bai13308ca2015-11-05 18:47:40 -0800595 return true;
KOSAKI Motohiro14797e22009-01-07 18:08:18 -0800596}
597
Vladimir Davydov90cbc252015-02-11 15:25:55 -0800598static inline bool mem_cgroup_lruvec_online(struct lruvec *lruvec)
599{
600 return true;
601}
602
KOSAKI Motohiroa3d8e052009-01-07 18:08:19 -0800603static inline unsigned long
Hugh Dickins4d7dcca2012-05-29 15:07:08 -0700604mem_cgroup_get_lru_size(struct lruvec *lruvec, enum lru_list lru)
KOSAKI Motohiroa3d8e052009-01-07 18:08:19 -0800605{
606 return 0;
607}
608
Hugh Dickinsfa9add62012-05-29 15:07:09 -0700609static inline void
610mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru,
611 int increment)
KOSAKI Motohiro3e2f41f2009-01-07 18:08:20 -0800612{
KOSAKI Motohiro3e2f41f2009-01-07 18:08:20 -0800613}
614
Balbir Singhe2224322009-04-02 16:57:39 -0700615static inline void
616mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
617{
618}
619
Johannes Weiner6de22612015-02-11 15:25:01 -0800620static inline struct mem_cgroup *mem_cgroup_begin_page_stat(struct page *page)
KAMEZAWA Hiroyuki89c06bd2012-03-21 16:34:25 -0700621{
Johannes Weinerd7365e72014-10-29 14:50:48 -0700622 return NULL;
KAMEZAWA Hiroyuki89c06bd2012-03-21 16:34:25 -0700623}
624
Johannes Weiner6de22612015-02-11 15:25:01 -0800625static inline void mem_cgroup_end_page_stat(struct mem_cgroup *memcg)
KAMEZAWA Hiroyuki89c06bd2012-03-21 16:34:25 -0700626{
627}
628
Tejun Heob23afb92015-11-05 18:46:11 -0800629static inline void mem_cgroup_handle_over_high(void)
630{
631}
632
Johannes Weiner49426422013-10-16 13:46:59 -0700633static inline void mem_cgroup_oom_enable(void)
Johannes Weiner519e5242013-09-12 15:13:42 -0700634{
635}
636
Johannes Weiner49426422013-10-16 13:46:59 -0700637static inline void mem_cgroup_oom_disable(void)
Johannes Weiner519e5242013-09-12 15:13:42 -0700638{
639}
640
Johannes Weiner3812c8c2013-09-12 15:13:44 -0700641static inline bool task_in_memcg_oom(struct task_struct *p)
642{
643 return false;
644}
645
Johannes Weiner49426422013-10-16 13:46:59 -0700646static inline bool mem_cgroup_oom_synchronize(bool wait)
Johannes Weiner3812c8c2013-09-12 15:13:44 -0700647{
648 return false;
649}
650
Johannes Weinerd7365e72014-10-29 14:50:48 -0700651static inline void mem_cgroup_inc_page_stat(struct mem_cgroup *memcg,
Sha Zhengju68b48762013-09-12 15:13:50 -0700652 enum mem_cgroup_stat_index idx)
Greg Thelen2a7106f2011-01-13 15:47:37 -0800653{
654}
655
Johannes Weinerd7365e72014-10-29 14:50:48 -0700656static inline void mem_cgroup_dec_page_stat(struct mem_cgroup *memcg,
Sha Zhengju68b48762013-09-12 15:13:50 -0700657 enum mem_cgroup_stat_index idx)
Balbir Singhd69b0422009-06-17 16:26:34 -0700658{
659}
660
Balbir Singh4e416952009-09-23 15:56:39 -0700661static inline
Andrew Morton0608f432013-09-24 15:27:41 -0700662unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
663 gfp_t gfp_mask,
664 unsigned long *total_scanned)
Balbir Singh4e416952009-09-23 15:56:39 -0700665{
Andrew Morton0608f432013-09-24 15:27:41 -0700666 return 0;
Balbir Singh4e416952009-09-23 15:56:39 -0700667}
668
KAMEZAWA Hiroyukie94c8a92012-01-12 17:18:20 -0800669static inline void mem_cgroup_split_huge_fixup(struct page *head)
KAMEZAWA Hiroyukica3e0212011-01-20 14:44:24 -0800670{
671}
672
Ying Han456f9982011-05-26 16:25:38 -0700673static inline
674void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx)
675{
676}
Andrew Mortonc255a452012-07-31 16:43:02 -0700677#endif /* CONFIG_MEMCG */
Pavel Emelianov78fb7462008-02-07 00:13:51 -0800678
Tejun Heo52ebea72015-05-22 17:13:37 -0400679#ifdef CONFIG_CGROUP_WRITEBACK
Tejun Heo841710a2015-05-22 18:23:33 -0400680
Tejun Heo52ebea72015-05-22 17:13:37 -0400681struct list_head *mem_cgroup_cgwb_list(struct mem_cgroup *memcg);
Tejun Heo841710a2015-05-22 18:23:33 -0400682struct wb_domain *mem_cgroup_wb_domain(struct bdi_writeback *wb);
Tejun Heoc5edf9c2015-09-29 13:04:26 -0400683void mem_cgroup_wb_stats(struct bdi_writeback *wb, unsigned long *pfilepages,
684 unsigned long *pheadroom, unsigned long *pdirty,
685 unsigned long *pwriteback);
Tejun Heo841710a2015-05-22 18:23:33 -0400686
687#else /* CONFIG_CGROUP_WRITEBACK */
688
689static inline struct wb_domain *mem_cgroup_wb_domain(struct bdi_writeback *wb)
690{
691 return NULL;
692}
693
Tejun Heoc2aa7232015-05-22 18:23:35 -0400694static inline void mem_cgroup_wb_stats(struct bdi_writeback *wb,
Tejun Heoc5edf9c2015-09-29 13:04:26 -0400695 unsigned long *pfilepages,
696 unsigned long *pheadroom,
Tejun Heoc2aa7232015-05-22 18:23:35 -0400697 unsigned long *pdirty,
698 unsigned long *pwriteback)
699{
700}
701
Tejun Heo841710a2015-05-22 18:23:33 -0400702#endif /* CONFIG_CGROUP_WRITEBACK */
Tejun Heo52ebea72015-05-22 17:13:37 -0400703
Glauber Costae1aab162011-12-11 21:47:03 +0000704struct sock;
Glauber Costae1aab162011-12-11 21:47:03 +0000705void sock_update_memcg(struct sock *sk);
706void sock_release_memcg(struct sock *sk);
Johannes Weinerbaac50b2016-01-14 15:21:17 -0800707bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages);
708void mem_cgroup_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages);
Johannes Weinerd886f4e2016-01-20 15:02:47 -0800709#ifdef CONFIG_MEMCG
Johannes Weineref129472016-01-14 15:21:34 -0800710extern struct static_key_false memcg_sockets_enabled_key;
711#define mem_cgroup_sockets_enabled static_branch_unlikely(&memcg_sockets_enabled_key)
Johannes Weinerbaac50b2016-01-14 15:21:17 -0800712static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg)
Johannes Weinere8056052016-01-14 15:21:14 -0800713{
Johannes Weiner0db15292016-01-20 15:02:50 -0800714 if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && memcg->tcpmem_pressure)
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800715 return true;
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800716 do {
717 if (time_before(jiffies, memcg->socket_pressure))
718 return true;
719 } while ((memcg = parent_mem_cgroup(memcg)));
720 return false;
Johannes Weinere8056052016-01-14 15:21:14 -0800721}
722#else
Johannes Weiner80e95fe2016-01-14 15:21:20 -0800723#define mem_cgroup_sockets_enabled 0
Johannes Weinerbaac50b2016-01-14 15:21:17 -0800724static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg)
Johannes Weinere8056052016-01-14 15:21:14 -0800725{
726 return false;
727}
728#endif
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800729
Johannes Weiner127424c2016-01-20 15:02:32 -0800730#if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB)
Johannes Weineref129472016-01-14 15:21:34 -0800731extern struct static_key_false memcg_kmem_enabled_key;
Glauber Costa749c5412012-12-18 14:23:01 -0800732
Vladimir Davydovdbcf73e2015-02-12 14:58:57 -0800733extern int memcg_nr_cache_ids;
Michal Hocko64219992015-09-08 15:01:07 -0700734void memcg_get_cache_ids(void);
735void memcg_put_cache_ids(void);
Glauber Costaebe945c2012-12-18 14:23:10 -0800736
737/*
738 * Helper macro to loop through all memcg-specific caches. Callers must still
739 * check if the cache is valid (it is either valid or NULL).
740 * the slab_mutex must be held when looping through those caches
741 */
Glauber Costa749c5412012-12-18 14:23:01 -0800742#define for_each_memcg_cache_index(_idx) \
Vladimir Davydovdbcf73e2015-02-12 14:58:57 -0800743 for ((_idx) = 0; (_idx) < memcg_nr_cache_ids; (_idx)++)
Glauber Costa749c5412012-12-18 14:23:01 -0800744
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800745static inline bool memcg_kmem_enabled(void)
746{
Johannes Weineref129472016-01-14 15:21:34 -0800747 return static_branch_unlikely(&memcg_kmem_enabled_key);
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800748}
749
Johannes Weiner567e9ab2016-01-20 15:02:24 -0800750static inline bool memcg_kmem_online(struct mem_cgroup *memcg)
Michal Hocko33398cf2015-09-08 15:01:02 -0700751{
Johannes Weiner567e9ab2016-01-20 15:02:24 -0800752 return memcg->kmem_state == KMEM_ONLINE;
Michal Hocko33398cf2015-09-08 15:01:02 -0700753}
Vladimir Davydovcb731d62015-02-12 14:58:54 -0800754
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800755/*
756 * In general, we'll do everything in our power to not incur in any overhead
757 * for non-memcg users for the kmem functions. Not even a function call, if we
758 * can avoid it.
759 *
760 * Therefore, we'll inline all those functions so that in the best case, we'll
761 * see that kmemcg is off for everybody and proceed quickly. If it is on,
762 * we'll still do most of the flag checking inline. We check a lot of
763 * conditions, but because they are pretty simple, they are expected to be
764 * fast.
765 */
Vladimir Davydovf3ccb2c42015-11-05 18:49:01 -0800766int __memcg_kmem_charge_memcg(struct page *page, gfp_t gfp, int order,
767 struct mem_cgroup *memcg);
Vladimir Davydovd05e83a2015-11-05 18:48:59 -0800768int __memcg_kmem_charge(struct page *page, gfp_t gfp, int order);
769void __memcg_kmem_uncharge(struct page *page, int order);
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800770
Michal Hocko33398cf2015-09-08 15:01:02 -0700771/*
772 * helper for acessing a memcg's index. It will be used as an index in the
773 * child cache array in kmem_cache, and also to derive its name. This function
774 * will return -1 when this is not a kmem-limited memcg.
775 */
776static inline int memcg_cache_id(struct mem_cgroup *memcg)
777{
778 return memcg ? memcg->kmemcg_id : -1;
779}
Vladimir Davydov5722d092014-04-07 15:39:24 -0700780
Vladimir Davydov230e9fc2016-01-14 15:18:15 -0800781struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp);
Vladimir Davydov8135be52014-12-12 16:56:38 -0800782void __memcg_kmem_put_cache(struct kmem_cache *cachep);
Glauber Costad7f25f82012-12-18 14:22:40 -0800783
Vladimir Davydov230e9fc2016-01-14 15:18:15 -0800784static inline bool __memcg_kmem_bypass(void)
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800785{
786 if (!memcg_kmem_enabled())
787 return true;
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800788 if (in_interrupt() || (!current->mm) || (current->flags & PF_KTHREAD))
789 return true;
Tejun Heocbfb4792015-11-05 18:46:14 -0800790 return false;
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800791}
792
793/**
Vladimir Davydovd05e83a2015-11-05 18:48:59 -0800794 * memcg_kmem_charge: charge a kmem page
795 * @page: page to charge
796 * @gfp: reclaim mode
797 * @order: allocation order
Tejun Heocbfb4792015-11-05 18:46:14 -0800798 *
Vladimir Davydovd05e83a2015-11-05 18:48:59 -0800799 * Returns 0 on success, an error code on failure.
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800800 */
Vladimir Davydovd05e83a2015-11-05 18:48:59 -0800801static __always_inline int memcg_kmem_charge(struct page *page,
802 gfp_t gfp, int order)
Tejun Heocbfb4792015-11-05 18:46:14 -0800803{
Vladimir Davydov230e9fc2016-01-14 15:18:15 -0800804 if (__memcg_kmem_bypass())
805 return 0;
806 if (!(gfp & __GFP_ACCOUNT))
Vladimir Davydovd05e83a2015-11-05 18:48:59 -0800807 return 0;
808 return __memcg_kmem_charge(page, gfp, order);
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800809}
810
811/**
Vladimir Davydovd05e83a2015-11-05 18:48:59 -0800812 * memcg_kmem_uncharge: uncharge a kmem page
813 * @page: page to uncharge
814 * @order: allocation order
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800815 */
Vladimir Davydovd05e83a2015-11-05 18:48:59 -0800816static __always_inline void memcg_kmem_uncharge(struct page *page, int order)
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800817{
818 if (memcg_kmem_enabled())
Vladimir Davydovd05e83a2015-11-05 18:48:59 -0800819 __memcg_kmem_uncharge(page, order);
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800820}
821
Glauber Costad7f25f82012-12-18 14:22:40 -0800822/**
823 * memcg_kmem_get_cache: selects the correct per-memcg cache for allocation
824 * @cachep: the original global kmem cache
Glauber Costad7f25f82012-12-18 14:22:40 -0800825 *
Vladimir Davydov5dfb4172014-06-04 16:06:38 -0700826 * All memory allocated from a per-memcg cache is charged to the owner memcg.
Glauber Costad7f25f82012-12-18 14:22:40 -0800827 */
828static __always_inline struct kmem_cache *
829memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp)
830{
Vladimir Davydov230e9fc2016-01-14 15:18:15 -0800831 if (__memcg_kmem_bypass())
Glauber Costad7f25f82012-12-18 14:22:40 -0800832 return cachep;
Vladimir Davydov230e9fc2016-01-14 15:18:15 -0800833 return __memcg_kmem_get_cache(cachep, gfp);
Glauber Costad7f25f82012-12-18 14:22:40 -0800834}
Vladimir Davydov8135be52014-12-12 16:56:38 -0800835
836static __always_inline void memcg_kmem_put_cache(struct kmem_cache *cachep)
837{
838 if (memcg_kmem_enabled())
839 __memcg_kmem_put_cache(cachep);
840}
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800841#else
Glauber Costa749c5412012-12-18 14:23:01 -0800842#define for_each_memcg_cache_index(_idx) \
843 for (; NULL; )
844
Glauber Costab9ce5ef2012-12-18 14:22:46 -0800845static inline bool memcg_kmem_enabled(void)
846{
847 return false;
848}
849
Johannes Weiner567e9ab2016-01-20 15:02:24 -0800850static inline bool memcg_kmem_online(struct mem_cgroup *memcg)
Vladimir Davydovcb731d62015-02-12 14:58:54 -0800851{
852 return false;
853}
854
Vladimir Davydovd05e83a2015-11-05 18:48:59 -0800855static inline int memcg_kmem_charge(struct page *page, gfp_t gfp, int order)
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800856{
Vladimir Davydovd05e83a2015-11-05 18:48:59 -0800857 return 0;
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800858}
859
Vladimir Davydovd05e83a2015-11-05 18:48:59 -0800860static inline void memcg_kmem_uncharge(struct page *page, int order)
Glauber Costa7ae1e1d2012-12-18 14:21:56 -0800861{
862}
Glauber Costa2633d7a2012-12-18 14:22:34 -0800863
864static inline int memcg_cache_id(struct mem_cgroup *memcg)
865{
866 return -1;
867}
868
Vladimir Davydov05257a12015-02-12 14:59:01 -0800869static inline void memcg_get_cache_ids(void)
870{
871}
872
873static inline void memcg_put_cache_ids(void)
874{
875}
876
Glauber Costad7f25f82012-12-18 14:22:40 -0800877static inline struct kmem_cache *
878memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp)
879{
880 return cachep;
881}
Vladimir Davydov8135be52014-12-12 16:56:38 -0800882
883static inline void memcg_kmem_put_cache(struct kmem_cache *cachep)
884{
885}
Johannes Weiner127424c2016-01-20 15:02:32 -0800886#endif /* CONFIG_MEMCG && !CONFIG_SLOB */
887
Balbir Singh8cdea7c2008-02-07 00:13:50 -0800888#endif /* _LINUX_MEMCONTROL_H */