Aneesh Kumar K.V | 2bc64a2 | 2012-07-31 16:42:12 -0700 | [diff] [blame] | 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 | |
Sasha Levin | 309381fea | 2014-01-23 15:52:54 -0800 | [diff] [blame] | 18 | #include <linux/mmdebug.h> |
Aneesh Kumar K.V | 2bc64a2 | 2012-07-31 16:42:12 -0700 | [diff] [blame] | 19 | #include <linux/res_counter.h> |
| 20 | |
| 21 | struct hugetlb_cgroup; |
Aneesh Kumar K.V | 9dd540e | 2012-07-31 16:42:15 -0700 | [diff] [blame] | 22 | /* |
| 23 | * Minimum page order trackable by hugetlb cgroup. |
| 24 | * At least 3 pages are necessary for all the tracking information. |
| 25 | */ |
| 26 | #define HUGETLB_CGROUP_MIN_ORDER 2 |
Aneesh Kumar K.V | 2bc64a2 | 2012-07-31 16:42:12 -0700 | [diff] [blame] | 27 | |
| 28 | #ifdef CONFIG_CGROUP_HUGETLB |
Aneesh Kumar K.V | 9dd540e | 2012-07-31 16:42:15 -0700 | [diff] [blame] | 29 | |
| 30 | static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page) |
| 31 | { |
Sasha Levin | 309381fea | 2014-01-23 15:52:54 -0800 | [diff] [blame] | 32 | VM_BUG_ON_PAGE(!PageHuge(page), page); |
Aneesh Kumar K.V | 9dd540e | 2012-07-31 16:42:15 -0700 | [diff] [blame] | 33 | |
| 34 | if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER) |
| 35 | return NULL; |
| 36 | return (struct hugetlb_cgroup *)page[2].lru.next; |
| 37 | } |
| 38 | |
| 39 | static inline |
| 40 | int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg) |
| 41 | { |
Sasha Levin | 309381fea | 2014-01-23 15:52:54 -0800 | [diff] [blame] | 42 | VM_BUG_ON_PAGE(!PageHuge(page), page); |
Aneesh Kumar K.V | 9dd540e | 2012-07-31 16:42:15 -0700 | [diff] [blame] | 43 | |
| 44 | if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER) |
| 45 | return -1; |
| 46 | page[2].lru.next = (void *)h_cg; |
| 47 | return 0; |
| 48 | } |
| 49 | |
Aneesh Kumar K.V | 2bc64a2 | 2012-07-31 16:42:12 -0700 | [diff] [blame] | 50 | static inline bool hugetlb_cgroup_disabled(void) |
| 51 | { |
Tejun Heo | 073219e | 2014-02-08 10:36:58 -0500 | [diff] [blame] | 52 | if (hugetlb_cgrp_subsys.disabled) |
Aneesh Kumar K.V | 2bc64a2 | 2012-07-31 16:42:12 -0700 | [diff] [blame] | 53 | return true; |
| 54 | return false; |
| 55 | } |
| 56 | |
Aneesh Kumar K.V | 6d76dcf | 2012-07-31 16:42:18 -0700 | [diff] [blame] | 57 | extern int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages, |
| 58 | struct hugetlb_cgroup **ptr); |
| 59 | extern void hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages, |
| 60 | struct hugetlb_cgroup *h_cg, |
| 61 | struct page *page); |
| 62 | extern void hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages, |
| 63 | struct page *page); |
| 64 | extern void hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages, |
| 65 | struct hugetlb_cgroup *h_cg); |
Jianguo Wu | 7179e7b | 2012-12-18 14:23:19 -0800 | [diff] [blame] | 66 | extern void hugetlb_cgroup_file_init(void) __init; |
Aneesh Kumar K.V | 8e6ac7f | 2012-07-31 16:42:27 -0700 | [diff] [blame] | 67 | extern void hugetlb_cgroup_migrate(struct page *oldhpage, |
| 68 | struct page *newhpage); |
Aneesh Kumar K.V | 6d76dcf | 2012-07-31 16:42:18 -0700 | [diff] [blame] | 69 | |
Aneesh Kumar K.V | 2bc64a2 | 2012-07-31 16:42:12 -0700 | [diff] [blame] | 70 | #else |
Aneesh Kumar K.V | 9dd540e | 2012-07-31 16:42:15 -0700 | [diff] [blame] | 71 | static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page) |
| 72 | { |
| 73 | return NULL; |
| 74 | } |
| 75 | |
| 76 | static inline |
| 77 | int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg) |
| 78 | { |
| 79 | return 0; |
| 80 | } |
| 81 | |
Aneesh Kumar K.V | 2bc64a2 | 2012-07-31 16:42:12 -0700 | [diff] [blame] | 82 | static inline bool hugetlb_cgroup_disabled(void) |
| 83 | { |
| 84 | return true; |
| 85 | } |
| 86 | |
Aneesh Kumar K.V | 6d76dcf | 2012-07-31 16:42:18 -0700 | [diff] [blame] | 87 | static inline int |
| 88 | hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages, |
| 89 | struct hugetlb_cgroup **ptr) |
| 90 | { |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static inline void |
| 95 | hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages, |
| 96 | struct hugetlb_cgroup *h_cg, |
| 97 | struct page *page) |
| 98 | { |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | static inline void |
| 103 | hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages, struct page *page) |
| 104 | { |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | static inline void |
| 109 | hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages, |
| 110 | struct hugetlb_cgroup *h_cg) |
| 111 | { |
| 112 | return; |
| 113 | } |
| 114 | |
Jianguo Wu | 7179e7b | 2012-12-18 14:23:19 -0800 | [diff] [blame] | 115 | static inline void hugetlb_cgroup_file_init(void) |
Aneesh Kumar K.V | abb8206 | 2012-07-31 16:42:24 -0700 | [diff] [blame] | 116 | { |
Aneesh Kumar K.V | abb8206 | 2012-07-31 16:42:24 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Aneesh Kumar K.V | 8e6ac7f | 2012-07-31 16:42:27 -0700 | [diff] [blame] | 119 | static inline void hugetlb_cgroup_migrate(struct page *oldhpage, |
| 120 | struct page *newhpage) |
| 121 | { |
| 122 | return; |
| 123 | } |
| 124 | |
Aneesh Kumar K.V | 2bc64a2 | 2012-07-31 16:42:12 -0700 | [diff] [blame] | 125 | #endif /* CONFIG_MEM_RES_CTLR_HUGETLB */ |
| 126 | #endif |