hugetlb/cgroup: add the cgroup pointer to page lru
[firefly-linux-kernel-4.4.55.git] / include / linux / hugetlb_cgroup.h
1 /*
2  * Copyright IBM Corporation, 2012
3  * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2.1 of the GNU Lesser General Public License
7  * as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  */
14
15 #ifndef _LINUX_HUGETLB_CGROUP_H
16 #define _LINUX_HUGETLB_CGROUP_H
17
18 #include <linux/res_counter.h>
19
20 struct hugetlb_cgroup;
21 /*
22  * Minimum page order trackable by hugetlb cgroup.
23  * At least 3 pages are necessary for all the tracking information.
24  */
25 #define HUGETLB_CGROUP_MIN_ORDER        2
26
27 #ifdef CONFIG_CGROUP_HUGETLB
28
29 static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
30 {
31         VM_BUG_ON(!PageHuge(page));
32
33         if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
34                 return NULL;
35         return (struct hugetlb_cgroup *)page[2].lru.next;
36 }
37
38 static inline
39 int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)
40 {
41         VM_BUG_ON(!PageHuge(page));
42
43         if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
44                 return -1;
45         page[2].lru.next = (void *)h_cg;
46         return 0;
47 }
48
49 static inline bool hugetlb_cgroup_disabled(void)
50 {
51         if (hugetlb_subsys.disabled)
52                 return true;
53         return false;
54 }
55
56 #else
57 static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
58 {
59         return NULL;
60 }
61
62 static inline
63 int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)
64 {
65         return 0;
66 }
67
68 static inline bool hugetlb_cgroup_disabled(void)
69 {
70         return true;
71 }
72
73 #endif  /* CONFIG_MEM_RES_CTLR_HUGETLB */
74 #endif