]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - include/linux/memcontrol.h
sparc32: do not include swap.h from pgtable_32.h
[mirror_ubuntu-zesty-kernel.git] / include / linux / memcontrol.h
CommitLineData
8cdea7c0
BS
1/* memcontrol.h - Memory Controller
2 *
3 * Copyright IBM Corporation, 2007
4 * Author Balbir Singh <balbir@linux.vnet.ibm.com>
5 *
78fb7466
PE
6 * Copyright 2007 OpenVZ SWsoft Inc
7 * Author: Pavel Emelianov <xemul@openvz.org>
8 *
8cdea7c0
BS
9 * 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
f8d66542 22#include <linux/cgroup.h>
456f998e 23#include <linux/vm_event_item.h>
7ae1e1d0 24#include <linux/hardirq.h>
a8964b9b 25#include <linux/jump_label.h>
456f998e 26
78fb7466 27struct mem_cgroup;
8697d331
BS
28struct page;
29struct mm_struct;
2633d7a0 30struct kmem_cache;
78fb7466 31
68b4876d
SZ
32/*
33 * The corresponding mem_cgroup_stat_names is defined in mm/memcontrol.c,
34 * These two lists should keep in accord with each other.
35 */
36enum mem_cgroup_stat_index {
37 /*
38 * For MEM_CONTAINER_TYPE_ALL, usage = pagecache + rss.
39 */
40 MEM_CGROUP_STAT_CACHE, /* # of pages charged as cache */
41 MEM_CGROUP_STAT_RSS, /* # of pages charged as anon rss */
42 MEM_CGROUP_STAT_RSS_HUGE, /* # of pages charged as anon huge */
43 MEM_CGROUP_STAT_FILE_MAPPED, /* # of pages charged as file rss */
c4843a75 44 MEM_CGROUP_STAT_DIRTY, /* # of dirty pages in page cache */
3ea67d06 45 MEM_CGROUP_STAT_WRITEBACK, /* # of pages under writeback */
68b4876d
SZ
46 MEM_CGROUP_STAT_SWAP, /* # of pages, swapped out */
47 MEM_CGROUP_STAT_NSTATS,
2a7106f2
GT
48};
49
5660048c
JW
50struct mem_cgroup_reclaim_cookie {
51 struct zone *zone;
52 int priority;
53 unsigned int generation;
54};
55
241994ed
JW
56enum mem_cgroup_events_index {
57 MEM_CGROUP_EVENTS_PGPGIN, /* # of pages paged in */
58 MEM_CGROUP_EVENTS_PGPGOUT, /* # of pages paged out */
59 MEM_CGROUP_EVENTS_PGFAULT, /* # of page-faults */
60 MEM_CGROUP_EVENTS_PGMAJFAULT, /* # of major page-faults */
61 MEM_CGROUP_EVENTS_NSTATS,
62 /* default hierarchy events */
63 MEMCG_LOW = MEM_CGROUP_EVENTS_NSTATS,
64 MEMCG_HIGH,
65 MEMCG_MAX,
66 MEMCG_OOM,
67 MEMCG_NR_EVENTS,
68};
69
c255a458 70#ifdef CONFIG_MEMCG
56161634
TH
71extern struct cgroup_subsys_state *mem_cgroup_root_css;
72
241994ed
JW
73void mem_cgroup_events(struct mem_cgroup *memcg,
74 enum mem_cgroup_events_index idx,
75 unsigned int nr);
76
77bool mem_cgroup_low(struct mem_cgroup *root, struct mem_cgroup *memcg);
78
00501b53
JW
79int mem_cgroup_try_charge(struct page *page, struct mm_struct *mm,
80 gfp_t gfp_mask, struct mem_cgroup **memcgp);
81void mem_cgroup_commit_charge(struct page *page, struct mem_cgroup *memcg,
82 bool lrucare);
83void mem_cgroup_cancel_charge(struct page *page, struct mem_cgroup *memcg);
0a31bc97 84void mem_cgroup_uncharge(struct page *page);
747db954 85void mem_cgroup_uncharge_list(struct list_head *page_list);
569b846d 86
0a31bc97
JW
87void mem_cgroup_migrate(struct page *oldpage, struct page *newpage,
88 bool lrucare);
569b846d 89
0a31bc97
JW
90struct lruvec *mem_cgroup_zone_lruvec(struct zone *, struct mem_cgroup *);
91struct lruvec *mem_cgroup_page_lruvec(struct page *, struct zone *);
c9b0ed51 92
2314b42d
JW
93bool mem_cgroup_is_descendant(struct mem_cgroup *memcg,
94 struct mem_cgroup *root);
95bool task_in_mem_cgroup(struct task_struct *task, struct mem_cgroup *memcg);
3062fc67 96
e42d9d5d 97extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
cf475ad2
BS
98extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
99
e1aab161 100extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
182446d0 101extern struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *css);
e1aab161 102
2314b42d
JW
103static inline bool mm_match_cgroup(struct mm_struct *mm,
104 struct mem_cgroup *memcg)
2e4d4091 105{
587af308 106 struct mem_cgroup *task_memcg;
413918bb 107 bool match = false;
c3ac9a8a 108
2e4d4091 109 rcu_read_lock();
587af308 110 task_memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
413918bb 111 if (task_memcg)
2314b42d 112 match = mem_cgroup_is_descendant(task_memcg, memcg);
2e4d4091 113 rcu_read_unlock();
c3ac9a8a 114 return match;
2e4d4091 115}
8a9f3ccd 116
c0ff4b85 117extern struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *memcg);
ad7fa852 118extern struct cgroup_subsys_state *mem_cgroup_css_from_page(struct page *page);
d324236b 119
694fbc0f
AM
120struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *,
121 struct mem_cgroup *,
122 struct mem_cgroup_reclaim_cookie *);
5660048c
JW
123void mem_cgroup_iter_break(struct mem_cgroup *, struct mem_cgroup *);
124
58ae83db
KH
125/*
126 * For memory reclaim.
127 */
c56d5c7d 128int mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec);
90cbc250 129bool mem_cgroup_lruvec_online(struct lruvec *lruvec);
889976db 130int mem_cgroup_select_victim_node(struct mem_cgroup *memcg);
4d7dcca2 131unsigned long mem_cgroup_get_lru_size(struct lruvec *lruvec, enum lru_list);
fa9add64 132void mem_cgroup_update_lru_size(struct lruvec *, enum lru_list, int);
e222432b
BS
133extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
134 struct task_struct *p);
58ae83db 135
49426420 136static inline void mem_cgroup_oom_enable(void)
519e5247 137{
49426420
JW
138 WARN_ON(current->memcg_oom.may_oom);
139 current->memcg_oom.may_oom = 1;
519e5247
JW
140}
141
49426420 142static inline void mem_cgroup_oom_disable(void)
519e5247 143{
49426420
JW
144 WARN_ON(!current->memcg_oom.may_oom);
145 current->memcg_oom.may_oom = 0;
519e5247
JW
146}
147
3812c8c8
JW
148static inline bool task_in_memcg_oom(struct task_struct *p)
149{
49426420 150 return p->memcg_oom.memcg;
3812c8c8
JW
151}
152
49426420 153bool mem_cgroup_oom_synchronize(bool wait);
3812c8c8 154
c255a458 155#ifdef CONFIG_MEMCG_SWAP
c077719b
KH
156extern int do_swap_account;
157#endif
f8d66542
HT
158
159static inline bool mem_cgroup_disabled(void)
160{
073219e9 161 if (memory_cgrp_subsys.disabled)
f8d66542
HT
162 return true;
163 return false;
164}
165
6de22619 166struct mem_cgroup *mem_cgroup_begin_page_stat(struct page *page);
d7365e78
JW
167void mem_cgroup_update_page_stat(struct mem_cgroup *memcg,
168 enum mem_cgroup_stat_index idx, int val);
6de22619 169void mem_cgroup_end_page_stat(struct mem_cgroup *memcg);
d7365e78
JW
170
171static inline void mem_cgroup_inc_page_stat(struct mem_cgroup *memcg,
68b4876d 172 enum mem_cgroup_stat_index idx)
2a7106f2 173{
d7365e78 174 mem_cgroup_update_page_stat(memcg, idx, 1);
2a7106f2
GT
175}
176
d7365e78 177static inline void mem_cgroup_dec_page_stat(struct mem_cgroup *memcg,
68b4876d 178 enum mem_cgroup_stat_index idx)
2a7106f2 179{
d7365e78 180 mem_cgroup_update_page_stat(memcg, idx, -1);
2a7106f2
GT
181}
182
0608f43d
AM
183unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
184 gfp_t gfp_mask,
185 unsigned long *total_scanned);
a63d83f4 186
68ae564b
DR
187void __mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx);
188static inline void mem_cgroup_count_vm_event(struct mm_struct *mm,
189 enum vm_event_item idx)
190{
191 if (mem_cgroup_disabled())
192 return;
193 __mem_cgroup_count_vm_event(mm, idx);
194}
ca3e0214 195#ifdef CONFIG_TRANSPARENT_HUGEPAGE
e94c8a9c 196void mem_cgroup_split_huge_fixup(struct page *head);
ca3e0214
KH
197#endif
198
c255a458 199#else /* CONFIG_MEMCG */
7a81b88c
KH
200struct mem_cgroup;
201
56161634
TH
202#define mem_cgroup_root_css ((struct cgroup_subsys_state *)ERR_PTR(-EINVAL))
203
241994ed
JW
204static inline void mem_cgroup_events(struct mem_cgroup *memcg,
205 enum mem_cgroup_events_index idx,
206 unsigned int nr)
207{
208}
209
210static inline bool mem_cgroup_low(struct mem_cgroup *root,
211 struct mem_cgroup *memcg)
212{
213 return false;
214}
215
00501b53
JW
216static inline int mem_cgroup_try_charge(struct page *page, struct mm_struct *mm,
217 gfp_t gfp_mask,
218 struct mem_cgroup **memcgp)
7a81b88c 219{
00501b53 220 *memcgp = NULL;
7a81b88c
KH
221 return 0;
222}
223
00501b53
JW
224static inline void mem_cgroup_commit_charge(struct page *page,
225 struct mem_cgroup *memcg,
226 bool lrucare)
7a81b88c
KH
227{
228}
229
00501b53
JW
230static inline void mem_cgroup_cancel_charge(struct page *page,
231 struct mem_cgroup *memcg)
7a81b88c
KH
232{
233}
234
0a31bc97 235static inline void mem_cgroup_uncharge(struct page *page)
569b846d
KH
236{
237}
238
747db954 239static inline void mem_cgroup_uncharge_list(struct list_head *page_list)
8a9f3ccd
BS
240{
241}
242
0a31bc97
JW
243static inline void mem_cgroup_migrate(struct page *oldpage,
244 struct page *newpage,
245 bool lrucare)
69029cd5
KH
246{
247}
248
925b7673
JW
249static inline struct lruvec *mem_cgroup_zone_lruvec(struct zone *zone,
250 struct mem_cgroup *memcg)
08e552c6 251{
925b7673 252 return &zone->lruvec;
08e552c6
KH
253}
254
fa9add64
HD
255static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page,
256 struct zone *zone)
66e1707b 257{
925b7673 258 return &zone->lruvec;
66e1707b
BS
259}
260
e42d9d5d
WF
261static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
262{
263 return NULL;
264}
265
587af308 266static inline bool mm_match_cgroup(struct mm_struct *mm,
c0ff4b85 267 struct mem_cgroup *memcg)
bed7161a 268{
587af308 269 return true;
bed7161a
BS
270}
271
ffbdccf5
DR
272static inline bool task_in_mem_cgroup(struct task_struct *task,
273 const struct mem_cgroup *memcg)
4c4a2214 274{
ffbdccf5 275 return true;
4c4a2214
DR
276}
277
c0ff4b85
R
278static inline struct cgroup_subsys_state
279 *mem_cgroup_css(struct mem_cgroup *memcg)
d324236b
WF
280{
281 return NULL;
282}
283
5660048c
JW
284static inline struct mem_cgroup *
285mem_cgroup_iter(struct mem_cgroup *root,
286 struct mem_cgroup *prev,
287 struct mem_cgroup_reclaim_cookie *reclaim)
288{
289 return NULL;
290}
291
292static inline void mem_cgroup_iter_break(struct mem_cgroup *root,
293 struct mem_cgroup *prev)
294{
295}
296
f8d66542
HT
297static inline bool mem_cgroup_disabled(void)
298{
299 return true;
300}
a636b327 301
14797e23 302static inline int
c56d5c7d 303mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec)
14797e23
KM
304{
305 return 1;
306}
307
90cbc250
VD
308static inline bool mem_cgroup_lruvec_online(struct lruvec *lruvec)
309{
310 return true;
311}
312
a3d8e054 313static inline unsigned long
4d7dcca2 314mem_cgroup_get_lru_size(struct lruvec *lruvec, enum lru_list lru)
a3d8e054
KM
315{
316 return 0;
317}
318
fa9add64
HD
319static inline void
320mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru,
321 int increment)
3e2f41f1 322{
3e2f41f1
KM
323}
324
e222432b
BS
325static inline void
326mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
327{
328}
329
6de22619 330static inline struct mem_cgroup *mem_cgroup_begin_page_stat(struct page *page)
89c06bd5 331{
d7365e78 332 return NULL;
89c06bd5
KH
333}
334
6de22619 335static inline void mem_cgroup_end_page_stat(struct mem_cgroup *memcg)
89c06bd5
KH
336{
337}
338
49426420 339static inline void mem_cgroup_oom_enable(void)
519e5247
JW
340{
341}
342
49426420 343static inline void mem_cgroup_oom_disable(void)
519e5247
JW
344{
345}
346
3812c8c8
JW
347static inline bool task_in_memcg_oom(struct task_struct *p)
348{
349 return false;
350}
351
49426420 352static inline bool mem_cgroup_oom_synchronize(bool wait)
3812c8c8
JW
353{
354 return false;
355}
356
d7365e78 357static inline void mem_cgroup_inc_page_stat(struct mem_cgroup *memcg,
68b4876d 358 enum mem_cgroup_stat_index idx)
2a7106f2
GT
359{
360}
361
d7365e78 362static inline void mem_cgroup_dec_page_stat(struct mem_cgroup *memcg,
68b4876d 363 enum mem_cgroup_stat_index idx)
d69b042f
BS
364{
365}
366
4e416953 367static inline
0608f43d
AM
368unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
369 gfp_t gfp_mask,
370 unsigned long *total_scanned)
4e416953 371{
0608f43d 372 return 0;
4e416953
BS
373}
374
e94c8a9c 375static inline void mem_cgroup_split_huge_fixup(struct page *head)
ca3e0214
KH
376{
377}
378
456f998e
YH
379static inline
380void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx)
381{
382}
c255a458 383#endif /* CONFIG_MEMCG */
78fb7466 384
e1aab161
GC
385enum {
386 UNDER_LIMIT,
387 SOFT_LIMIT,
388 OVER_LIMIT,
389};
390
52ebea74 391#ifdef CONFIG_CGROUP_WRITEBACK
841710aa 392
52ebea74 393struct list_head *mem_cgroup_cgwb_list(struct mem_cgroup *memcg);
841710aa 394struct wb_domain *mem_cgroup_wb_domain(struct bdi_writeback *wb);
c2aa723a
TH
395void mem_cgroup_wb_stats(struct bdi_writeback *wb, unsigned long *pavail,
396 unsigned long *pdirty, unsigned long *pwriteback);
841710aa
TH
397
398#else /* CONFIG_CGROUP_WRITEBACK */
399
400static inline struct wb_domain *mem_cgroup_wb_domain(struct bdi_writeback *wb)
401{
402 return NULL;
403}
404
c2aa723a
TH
405static inline void mem_cgroup_wb_stats(struct bdi_writeback *wb,
406 unsigned long *pavail,
407 unsigned long *pdirty,
408 unsigned long *pwriteback)
409{
410}
411
841710aa 412#endif /* CONFIG_CGROUP_WRITEBACK */
52ebea74 413
e1aab161 414struct sock;
cd59085a 415#if defined(CONFIG_INET) && defined(CONFIG_MEMCG_KMEM)
e1aab161
GC
416void sock_update_memcg(struct sock *sk);
417void sock_release_memcg(struct sock *sk);
418#else
419static inline void sock_update_memcg(struct sock *sk)
420{
421}
422static inline void sock_release_memcg(struct sock *sk)
423{
424}
cd59085a 425#endif /* CONFIG_INET && CONFIG_MEMCG_KMEM */
7ae1e1d0
GC
426
427#ifdef CONFIG_MEMCG_KMEM
a8964b9b 428extern struct static_key memcg_kmem_enabled_key;
749c5415 429
dbcf73e2 430extern int memcg_nr_cache_ids;
05257a1a
VD
431extern void memcg_get_cache_ids(void);
432extern void memcg_put_cache_ids(void);
ebe945c2
GC
433
434/*
435 * Helper macro to loop through all memcg-specific caches. Callers must still
436 * check if the cache is valid (it is either valid or NULL).
437 * the slab_mutex must be held when looping through those caches
438 */
749c5415 439#define for_each_memcg_cache_index(_idx) \
dbcf73e2 440 for ((_idx) = 0; (_idx) < memcg_nr_cache_ids; (_idx)++)
749c5415 441
7ae1e1d0
GC
442static inline bool memcg_kmem_enabled(void)
443{
a8964b9b 444 return static_key_false(&memcg_kmem_enabled_key);
7ae1e1d0
GC
445}
446
cb731d6c
VD
447bool memcg_kmem_is_active(struct mem_cgroup *memcg);
448
7ae1e1d0
GC
449/*
450 * In general, we'll do everything in our power to not incur in any overhead
451 * for non-memcg users for the kmem functions. Not even a function call, if we
452 * can avoid it.
453 *
454 * Therefore, we'll inline all those functions so that in the best case, we'll
455 * see that kmemcg is off for everybody and proceed quickly. If it is on,
456 * we'll still do most of the flag checking inline. We check a lot of
457 * conditions, but because they are pretty simple, they are expected to be
458 * fast.
459 */
460bool __memcg_kmem_newpage_charge(gfp_t gfp, struct mem_cgroup **memcg,
461 int order);
462void __memcg_kmem_commit_charge(struct page *page,
463 struct mem_cgroup *memcg, int order);
464void __memcg_kmem_uncharge_pages(struct page *page, int order);
465
2633d7a0 466int memcg_cache_id(struct mem_cgroup *memcg);
5722d094 467
8135be5a
VD
468struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep);
469void __memcg_kmem_put_cache(struct kmem_cache *cachep);
d7f25f8a 470
60d3fd32
VD
471struct mem_cgroup *__mem_cgroup_from_kmem(void *ptr);
472
dbf22eb6
VD
473int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp,
474 unsigned long nr_pages);
475void memcg_uncharge_kmem(struct mem_cgroup *memcg, unsigned long nr_pages);
5dfb4175 476
7ae1e1d0
GC
477/**
478 * memcg_kmem_newpage_charge: verify if a new kmem allocation is allowed.
479 * @gfp: the gfp allocation flags.
480 * @memcg: a pointer to the memcg this was charged against.
481 * @order: allocation order.
482 *
483 * returns true if the memcg where the current task belongs can hold this
484 * allocation.
485 *
486 * We return true automatically if this allocation is not to be accounted to
487 * any memcg.
488 */
489static inline bool
490memcg_kmem_newpage_charge(gfp_t gfp, struct mem_cgroup **memcg, int order)
491{
492 if (!memcg_kmem_enabled())
493 return true;
494
8f4fc071
VD
495 if (gfp & __GFP_NOACCOUNT)
496 return true;
7ae1e1d0
GC
497 /*
498 * __GFP_NOFAIL allocations will move on even if charging is not
499 * possible. Therefore we don't even try, and have this allocation
3e32cb2e
JW
500 * unaccounted. We could in theory charge it forcibly, but we hope
501 * those allocations are rare, and won't be worth the trouble.
7ae1e1d0 502 */
52383431 503 if (gfp & __GFP_NOFAIL)
7ae1e1d0
GC
504 return true;
505 if (in_interrupt() || (!current->mm) || (current->flags & PF_KTHREAD))
506 return true;
507
508 /* If the test is dying, just let it go. */
509 if (unlikely(fatal_signal_pending(current)))
510 return true;
511
512 return __memcg_kmem_newpage_charge(gfp, memcg, order);
513}
514
515/**
516 * memcg_kmem_uncharge_pages: uncharge pages from memcg
517 * @page: pointer to struct page being freed
518 * @order: allocation order.
7ae1e1d0
GC
519 */
520static inline void
521memcg_kmem_uncharge_pages(struct page *page, int order)
522{
523 if (memcg_kmem_enabled())
524 __memcg_kmem_uncharge_pages(page, order);
525}
526
527/**
528 * memcg_kmem_commit_charge: embeds correct memcg in a page
529 * @page: pointer to struct page recently allocated
530 * @memcg: the memcg structure we charged against
531 * @order: allocation order.
532 *
533 * Needs to be called after memcg_kmem_newpage_charge, regardless of success or
534 * failure of the allocation. if @page is NULL, this function will revert the
1306a85a 535 * charges. Otherwise, it will commit @page to @memcg.
7ae1e1d0
GC
536 */
537static inline void
538memcg_kmem_commit_charge(struct page *page, struct mem_cgroup *memcg, int order)
539{
540 if (memcg_kmem_enabled() && memcg)
541 __memcg_kmem_commit_charge(page, memcg, order);
542}
543
d7f25f8a
GC
544/**
545 * memcg_kmem_get_cache: selects the correct per-memcg cache for allocation
546 * @cachep: the original global kmem cache
547 * @gfp: allocation flags.
548 *
5dfb4175 549 * All memory allocated from a per-memcg cache is charged to the owner memcg.
d7f25f8a
GC
550 */
551static __always_inline struct kmem_cache *
552memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp)
553{
554 if (!memcg_kmem_enabled())
555 return cachep;
8f4fc071
VD
556 if (gfp & __GFP_NOACCOUNT)
557 return cachep;
d7f25f8a
GC
558 if (gfp & __GFP_NOFAIL)
559 return cachep;
560 if (in_interrupt() || (!current->mm) || (current->flags & PF_KTHREAD))
561 return cachep;
562 if (unlikely(fatal_signal_pending(current)))
563 return cachep;
564
056b7cce 565 return __memcg_kmem_get_cache(cachep);
d7f25f8a 566}
8135be5a
VD
567
568static __always_inline void memcg_kmem_put_cache(struct kmem_cache *cachep)
569{
570 if (memcg_kmem_enabled())
571 __memcg_kmem_put_cache(cachep);
572}
60d3fd32
VD
573
574static __always_inline struct mem_cgroup *mem_cgroup_from_kmem(void *ptr)
575{
576 if (!memcg_kmem_enabled())
577 return NULL;
578 return __mem_cgroup_from_kmem(ptr);
579}
7ae1e1d0 580#else
749c5415
GC
581#define for_each_memcg_cache_index(_idx) \
582 for (; NULL; )
583
b9ce5ef4
GC
584static inline bool memcg_kmem_enabled(void)
585{
586 return false;
587}
588
cb731d6c
VD
589static inline bool memcg_kmem_is_active(struct mem_cgroup *memcg)
590{
591 return false;
592}
593
7ae1e1d0
GC
594static inline bool
595memcg_kmem_newpage_charge(gfp_t gfp, struct mem_cgroup **memcg, int order)
596{
597 return true;
598}
599
600static inline void memcg_kmem_uncharge_pages(struct page *page, int order)
601{
602}
603
604static inline void
605memcg_kmem_commit_charge(struct page *page, struct mem_cgroup *memcg, int order)
606{
607}
2633d7a0
GC
608
609static inline int memcg_cache_id(struct mem_cgroup *memcg)
610{
611 return -1;
612}
613
05257a1a
VD
614static inline void memcg_get_cache_ids(void)
615{
616}
617
618static inline void memcg_put_cache_ids(void)
619{
620}
621
d7f25f8a
GC
622static inline struct kmem_cache *
623memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp)
624{
625 return cachep;
626}
8135be5a
VD
627
628static inline void memcg_kmem_put_cache(struct kmem_cache *cachep)
629{
630}
60d3fd32
VD
631
632static inline struct mem_cgroup *mem_cgroup_from_kmem(void *ptr)
633{
634 return NULL;
635}
7ae1e1d0 636#endif /* CONFIG_MEMCG_KMEM */
8cdea7c0
BS
637#endif /* _LINUX_MEMCONTROL_H */
638