blob: 24154c26d469c60984020b5a0441fcb6dde3fcb0 [file] [log] [blame]
Aneesh Kumar K.V2bc64a22012-07-31 16:42:12 -07001/*
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
Sasha Levin309381fea2014-01-23 15:52:54 -080018#include <linux/mmdebug.h>
Aneesh Kumar K.V2bc64a22012-07-31 16:42:12 -070019
20struct hugetlb_cgroup;
Aneesh Kumar K.V9dd540e2012-07-31 16:42:15 -070021/*
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
Aneesh Kumar K.V2bc64a22012-07-31 16:42:12 -070026
27#ifdef CONFIG_CGROUP_HUGETLB
Aneesh Kumar K.V9dd540e2012-07-31 16:42:15 -070028
29static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
30{
Sasha Levin309381fea2014-01-23 15:52:54 -080031 VM_BUG_ON_PAGE(!PageHuge(page), page);
Aneesh Kumar K.V9dd540e2012-07-31 16:42:15 -070032
33 if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
34 return NULL;
Kirill A. Shutemov1d798ca2015-11-06 16:29:54 -080035 return (struct hugetlb_cgroup *)page[2].private;
Aneesh Kumar K.V9dd540e2012-07-31 16:42:15 -070036}
37
38static inline
39int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)
40{
Sasha Levin309381fea2014-01-23 15:52:54 -080041 VM_BUG_ON_PAGE(!PageHuge(page), page);
Aneesh Kumar K.V9dd540e2012-07-31 16:42:15 -070042
43 if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
44 return -1;
Kirill A. Shutemov1d798ca2015-11-06 16:29:54 -080045 page[2].private = (unsigned long)h_cg;
Aneesh Kumar K.V9dd540e2012-07-31 16:42:15 -070046 return 0;
47}
48
Aneesh Kumar K.V2bc64a22012-07-31 16:42:12 -070049static inline bool hugetlb_cgroup_disabled(void)
50{
Tejun Heofc5ed1e2015-09-18 11:56:28 -040051 return !cgroup_subsys_enabled(hugetlb_cgrp_subsys);
Aneesh Kumar K.V2bc64a22012-07-31 16:42:12 -070052}
53
Aneesh Kumar K.V6d76dcf2012-07-31 16:42:18 -070054extern int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
55 struct hugetlb_cgroup **ptr);
56extern void hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
57 struct hugetlb_cgroup *h_cg,
58 struct page *page);
59extern void hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages,
60 struct page *page);
61extern void hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages,
62 struct hugetlb_cgroup *h_cg);
Jianguo Wu7179e7b2012-12-18 14:23:19 -080063extern void hugetlb_cgroup_file_init(void) __init;
Aneesh Kumar K.V8e6ac7f2012-07-31 16:42:27 -070064extern void hugetlb_cgroup_migrate(struct page *oldhpage,
65 struct page *newhpage);
Aneesh Kumar K.V6d76dcf2012-07-31 16:42:18 -070066
Aneesh Kumar K.V2bc64a22012-07-31 16:42:12 -070067#else
Aneesh Kumar K.V9dd540e2012-07-31 16:42:15 -070068static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
69{
70 return NULL;
71}
72
73static inline
74int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)
75{
76 return 0;
77}
78
Aneesh Kumar K.V2bc64a22012-07-31 16:42:12 -070079static inline bool hugetlb_cgroup_disabled(void)
80{
81 return true;
82}
83
Aneesh Kumar K.V6d76dcf2012-07-31 16:42:18 -070084static inline int
85hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
86 struct hugetlb_cgroup **ptr)
87{
88 return 0;
89}
90
91static inline void
92hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
93 struct hugetlb_cgroup *h_cg,
94 struct page *page)
95{
96 return;
97}
98
99static inline void
100hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages, struct page *page)
101{
102 return;
103}
104
105static inline void
106hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages,
107 struct hugetlb_cgroup *h_cg)
108{
109 return;
110}
111
Jianguo Wu7179e7b2012-12-18 14:23:19 -0800112static inline void hugetlb_cgroup_file_init(void)
Aneesh Kumar K.Vabb82062012-07-31 16:42:24 -0700113{
Aneesh Kumar K.Vabb82062012-07-31 16:42:24 -0700114}
115
Aneesh Kumar K.V8e6ac7f2012-07-31 16:42:27 -0700116static inline void hugetlb_cgroup_migrate(struct page *oldhpage,
117 struct page *newhpage)
118{
119 return;
120}
121
Aneesh Kumar K.V2bc64a22012-07-31 16:42:12 -0700122#endif /* CONFIG_MEM_RES_CTLR_HUGETLB */
123#endif