Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#ifndef __LINUX_PAGE_CGROUP_H
2#define __LINUX_PAGE_CGROUP_H
3
4enum {
5 /* flags for mem_cgroup */
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 */
9};
10
11struct pglist_data;
12
13#ifdef CONFIG_MEMCG
14struct mem_cgroup;
15
16/*
17 * Page Cgroup can be considered as an extended mem_map.
18 * A page_cgroup page is associated with every page descriptor. The
19 * page_cgroup helps us identify information about the cgroup
20 * All page cgroups are allocated at boot or memory hotplug event,
21 * then the page cgroup for pfn always exists.
22 */
23struct page_cgroup {
24 unsigned long flags;
25 struct mem_cgroup *mem_cgroup;
26};
27
28extern void pgdat_page_cgroup_init(struct pglist_data *pgdat);
29
30#ifdef CONFIG_SPARSEMEM
31static inline void page_cgroup_init_flatmem(void)
32{
33}
34extern void page_cgroup_init(void);
35#else
36extern void page_cgroup_init_flatmem(void);
37static inline void page_cgroup_init(void)
38{
39}
40#endif
41
42struct page_cgroup *lookup_page_cgroup(struct page *page);
43
44static inline int PageCgroupUsed(struct page_cgroup *pc)
45{
46 return !!(pc->flags & PCG_USED);
47}
48#else /* !CONFIG_MEMCG */
49struct page_cgroup;
50
51static inline void pgdat_page_cgroup_init(struct pglist_data *pgdat)
52{
53}
54
55static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
56{
57 return NULL;
58}
59
60static inline void page_cgroup_init(void)
61{
62}
63
64static inline void page_cgroup_init_flatmem(void)
65{
66}
67#endif /* CONFIG_MEMCG */
68
69#include <linux/swap.h>
70
71#ifdef CONFIG_MEMCG_SWAP
72extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
73 unsigned short old, unsigned short new);
74extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
75extern unsigned short lookup_swap_cgroup_id(swp_entry_t ent);
76extern int swap_cgroup_swapon(int type, unsigned long max_pages);
77extern void swap_cgroup_swapoff(int type);
78#else
79
80static inline
81unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
82{
83 return 0;
84}
85
86static inline
87unsigned short lookup_swap_cgroup_id(swp_entry_t ent)
88{
89 return 0;
90}
91
92static inline int
93swap_cgroup_swapon(int type, unsigned long max_pages)
94{
95 return 0;
96}
97
98static inline void swap_cgroup_swapoff(int type)
99{
100 return;
101}
102
103#endif /* CONFIG_MEMCG_SWAP */
104
105#endif /* __LINUX_PAGE_CGROUP_H */