blob: ada779f2417846bcee829c5e4f33a42f79a76b73 [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 Hiroyukica371c02009-06-12 10:33:53 +030021
22#ifdef CONFIG_SPARSEMEM
23static inline void __init page_cgroup_init_flatmem(void)
24{
25}
26extern void __init page_cgroup_init(void);
27#else
28void __init page_cgroup_init_flatmem(void);
29static inline void __init page_cgroup_init(void)
30{
31}
32#endif
33
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070034struct page_cgroup *lookup_page_cgroup(struct page *page);
35
36enum {
37 /* flags for mem_cgroup */
38 PCG_LOCK, /* page cgroup is locked */
39 PCG_CACHE, /* charged as cache */
40 PCG_USED, /* this object is in use. */
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070041};
42
43#define TESTPCGFLAG(uname, lname) \
44static inline int PageCgroup##uname(struct page_cgroup *pc) \
45 { return test_bit(PCG_##lname, &pc->flags); }
46
47#define SETPCGFLAG(uname, lname) \
48static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
49 { set_bit(PCG_##lname, &pc->flags); }
50
51#define CLEARPCGFLAG(uname, lname) \
52static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
53 { clear_bit(PCG_##lname, &pc->flags); }
54
55/* Cache flag is set only once (at allocation) */
56TESTPCGFLAG(Cache, CACHE)
57
58TESTPCGFLAG(Used, USED)
59CLEARPCGFLAG(Used, USED)
60
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070061static inline int page_cgroup_nid(struct page_cgroup *pc)
62{
63 return page_to_nid(pc->page);
64}
65
66static inline enum zone_type page_cgroup_zid(struct page_cgroup *pc)
67{
68 return page_zonenum(pc->page);
69}
70
71static inline void lock_page_cgroup(struct page_cgroup *pc)
72{
73 bit_spin_lock(PCG_LOCK, &pc->flags);
74}
75
76static inline int trylock_page_cgroup(struct page_cgroup *pc)
77{
78 return bit_spin_trylock(PCG_LOCK, &pc->flags);
79}
80
81static inline void unlock_page_cgroup(struct page_cgroup *pc)
82{
83 bit_spin_unlock(PCG_LOCK, &pc->flags);
84}
85
86#else /* CONFIG_CGROUP_MEM_RES_CTLR */
87struct page_cgroup;
88
Al Viro31168482008-11-22 17:33:24 +000089static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070090{
91}
92
93static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
94{
95 return NULL;
96}
KAMEZAWA Hiroyuki94b6da52008-10-22 14:15:05 -070097
98static inline void page_cgroup_init(void)
99{
100}
101
KAMEZAWA Hiroyukica371c02009-06-12 10:33:53 +0300102static inline void __init page_cgroup_init_flatmem(void)
103{
104}
105
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -0700106#endif
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800107
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800108#include <linux/swap.h>
Jaswinder Singh Rajput97572752009-09-20 16:20:44 +0530109
110#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
KAMEZAWA Hiroyukia3b2d692009-04-02 16:57:45 -0700111extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
112extern unsigned short lookup_swap_cgroup(swp_entry_t ent);
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800113extern int swap_cgroup_swapon(int type, unsigned long max_pages);
114extern void swap_cgroup_swapoff(int type);
115#else
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800116
117static inline
KAMEZAWA Hiroyukia3b2d692009-04-02 16:57:45 -0700118unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800119{
KAMEZAWA Hiroyukia3b2d692009-04-02 16:57:45 -0700120 return 0;
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800121}
122
123static inline
KAMEZAWA Hiroyukia3b2d692009-04-02 16:57:45 -0700124unsigned short lookup_swap_cgroup(swp_entry_t ent)
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800125{
KAMEZAWA Hiroyukia3b2d692009-04-02 16:57:45 -0700126 return 0;
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800127}
128
129static inline int
130swap_cgroup_swapon(int type, unsigned long max_pages)
131{
132 return 0;
133}
134
135static inline void swap_cgroup_swapoff(int type)
136{
137 return;
138}
139
140#endif
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -0700141#endif