]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - include/linux/page_cgroup.h
mm: memcontrol: rewrite uncharge API
[mirror_ubuntu-zesty-kernel.git] / include / linux / page_cgroup.h
CommitLineData
52d4b9ac
KH
1#ifndef __LINUX_PAGE_CGROUP_H
2#define __LINUX_PAGE_CGROUP_H
3
6b3ae58e
JW
4enum {
5 /* flags for mem_cgroup */
0a31bc97
JW
6 PCG_USED = 0x01, /* This page is charged to a memcg */
7 PCG_MEM = 0x02, /* This page holds a memory charge */
8 PCG_MEMSW = 0x04, /* This page holds a memory+swap charge */
6b3ae58e
JW
9 __NR_PCG_FLAGS,
10};
11
12#ifndef __GENERATING_BOUNDS_H
13#include <generated/bounds.h>
14
c255a458 15#ifdef CONFIG_MEMCG
52d4b9ac 16#include <linux/bit_spinlock.h>
6b3ae58e 17
52d4b9ac
KH
18/*
19 * Page Cgroup can be considered as an extended mem_map.
20 * A page_cgroup page is associated with every page descriptor. The
21 * page_cgroup helps us identify information about the cgroup
22 * All page cgroups are allocated at boot or memory hotplug event,
23 * then the page cgroup for pfn always exists.
24 */
25struct page_cgroup {
26 unsigned long flags;
27 struct mem_cgroup *mem_cgroup;
52d4b9ac
KH
28};
29
31168481 30void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
ca371c0d
KH
31
32#ifdef CONFIG_SPARSEMEM
33static inline void __init page_cgroup_init_flatmem(void)
34{
35}
36extern void __init page_cgroup_init(void);
37#else
38void __init page_cgroup_init_flatmem(void);
39static inline void __init page_cgroup_init(void)
40{
41}
42#endif
43
52d4b9ac 44struct page_cgroup *lookup_page_cgroup(struct page *page);
6b3ae58e 45struct page *lookup_cgroup_page(struct page_cgroup *pc);
52d4b9ac 46
0a31bc97 47static inline int PageCgroupUsed(struct page_cgroup *pc)
52d4b9ac 48{
0a31bc97 49 return !!(pc->flags & PCG_USED);
52d4b9ac
KH
50}
51
c255a458 52#else /* CONFIG_MEMCG */
52d4b9ac
KH
53struct page_cgroup;
54
31168481 55static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
52d4b9ac
KH
56{
57}
58
59static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
60{
61 return NULL;
62}
94b6da5a
KH
63
64static inline void page_cgroup_init(void)
65{
66}
67
ca371c0d
KH
68static inline void __init page_cgroup_init_flatmem(void)
69{
70}
71
c255a458 72#endif /* CONFIG_MEMCG */
27a7faa0 73
27a7faa0 74#include <linux/swap.h>
97572751 75
c255a458 76#ifdef CONFIG_MEMCG_SWAP
02491447
DN
77extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
78 unsigned short old, unsigned short new);
a3b2d692 79extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
9fb4b7cc 80extern unsigned short lookup_swap_cgroup_id(swp_entry_t ent);
27a7faa0
KH
81extern int swap_cgroup_swapon(int type, unsigned long max_pages);
82extern void swap_cgroup_swapoff(int type);
83#else
27a7faa0
KH
84
85static inline
a3b2d692 86unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
27a7faa0 87{
a3b2d692 88 return 0;
27a7faa0
KH
89}
90
91static inline
9fb4b7cc 92unsigned short lookup_swap_cgroup_id(swp_entry_t ent)
27a7faa0 93{
a3b2d692 94 return 0;
27a7faa0
KH
95}
96
97static inline int
98swap_cgroup_swapon(int type, unsigned long max_pages)
99{
100 return 0;
101}
102
103static inline void swap_cgroup_swapoff(int type)
104{
105 return;
106}
107
c255a458 108#endif /* CONFIG_MEMCG_SWAP */
6b3ae58e
JW
109
110#endif /* !__GENERATING_BOUNDS_H */
111
112#endif /* __LINUX_PAGE_CGROUP_H */