blob: 602cc1fdee90c152dc458642256b623ce8cbfa78 [file] [log] [blame]
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -07001#ifndef __LINUX_PAGE_CGROUP_H
2#define __LINUX_PAGE_CGROUP_H
3
4#ifdef CONFIG_CGROUP_MEM_RES_CTLR
5#include <linux/bit_spinlock.h>
6/*
7 * Page Cgroup can be considered as an extended mem_map.
8 * A page_cgroup page is associated with every page descriptor. The
9 * page_cgroup helps us identify information about the cgroup
10 * All page cgroups are allocated at boot or memory hotplug event,
11 * then the page cgroup for pfn always exists.
12 */
13struct page_cgroup {
14 unsigned long flags;
15 struct mem_cgroup *mem_cgroup;
16 struct page *page;
17 struct list_head lru; /* per cgroup LRU list */
18};
19
Al Viro31168482008-11-22 17:33:24 +000020void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070021void __init page_cgroup_init(void);
22struct page_cgroup *lookup_page_cgroup(struct page *page);
23
24enum {
25 /* flags for mem_cgroup */
26 PCG_LOCK, /* page cgroup is locked */
27 PCG_CACHE, /* charged as cache */
28 PCG_USED, /* this object is in use. */
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070029};
30
31#define TESTPCGFLAG(uname, lname) \
32static inline int PageCgroup##uname(struct page_cgroup *pc) \
33 { return test_bit(PCG_##lname, &pc->flags); }
34
35#define SETPCGFLAG(uname, lname) \
36static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
37 { set_bit(PCG_##lname, &pc->flags); }
38
39#define CLEARPCGFLAG(uname, lname) \
40static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
41 { clear_bit(PCG_##lname, &pc->flags); }
42
43/* Cache flag is set only once (at allocation) */
44TESTPCGFLAG(Cache, CACHE)
45
46TESTPCGFLAG(Used, USED)
47CLEARPCGFLAG(Used, USED)
48
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070049static inline int page_cgroup_nid(struct page_cgroup *pc)
50{
51 return page_to_nid(pc->page);
52}
53
54static inline enum zone_type page_cgroup_zid(struct page_cgroup *pc)
55{
56 return page_zonenum(pc->page);
57}
58
59static inline void lock_page_cgroup(struct page_cgroup *pc)
60{
61 bit_spin_lock(PCG_LOCK, &pc->flags);
62}
63
64static inline int trylock_page_cgroup(struct page_cgroup *pc)
65{
66 return bit_spin_trylock(PCG_LOCK, &pc->flags);
67}
68
69static inline void unlock_page_cgroup(struct page_cgroup *pc)
70{
71 bit_spin_unlock(PCG_LOCK, &pc->flags);
72}
73
74#else /* CONFIG_CGROUP_MEM_RES_CTLR */
75struct page_cgroup;
76
Al Viro31168482008-11-22 17:33:24 +000077static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070078{
79}
80
81static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
82{
83 return NULL;
84}
KAMEZAWA Hiroyuki94b6da52008-10-22 14:15:05 -070085
86static inline void page_cgroup_init(void)
87{
88}
89
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070090#endif
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -080091
92#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
93#include <linux/swap.h>
94extern struct mem_cgroup *
95swap_cgroup_record(swp_entry_t ent, struct mem_cgroup *mem);
96extern struct mem_cgroup *lookup_swap_cgroup(swp_entry_t ent);
97extern int swap_cgroup_swapon(int type, unsigned long max_pages);
98extern void swap_cgroup_swapoff(int type);
99#else
100#include <linux/swap.h>
101
102static inline
103struct mem_cgroup *swap_cgroup_record(swp_entry_t ent, struct mem_cgroup *mem)
104{
105 return NULL;
106}
107
108static inline
109struct mem_cgroup *lookup_swap_cgroup(swp_entry_t ent)
110{
111 return NULL;
112}
113
114static inline int
115swap_cgroup_swapon(int type, unsigned long max_pages)
116{
117 return 0;
118}
119
120static inline void swap_cgroup_swapoff(int type)
121{
122 return;
123}
124
125#endif
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -0700126#endif