#include <linux/mm_types.h>
#include <linux/fs.h>
#include <linux/hugetlb_inline.h>
+#include <linux/cgroup.h>
struct ctl_table;
struct user_struct;
unsigned int nr_huge_pages_node[MAX_NUMNODES];
unsigned int free_huge_pages_node[MAX_NUMNODES];
unsigned int surplus_huge_pages_node[MAX_NUMNODES];
+#ifdef CONFIG_MEM_RES_CTLR_HUGETLB
+ /* mem cgroup control files */
+ struct cftype mem_cgroup_files[4];
+#endif
char name[HSTATE_NAME_LEN];
};
mem_cgroup_put(memcg);
}
+#ifdef CONFIG_MEM_RES_CTLR_HUGETLB
+static char *mem_fmt(char *buf, unsigned long n)
+{
+ if (n >= (1UL << 30))
+ sprintf(buf, "%luGB", n >> 30);
+ else if (n >= (1UL << 20))
+ sprintf(buf, "%luMB", n >> 20);
+ else
+ sprintf(buf, "%luKB", n >> 10);
+ return buf;
+}
+
+int __init mem_cgroup_hugetlb_file_init(int idx)
+{
+ char buf[32];
+ struct cftype *cft;
+ struct hstate *h = &hstates[idx];
+
+ /* format the size */
+ mem_fmt(buf, huge_page_size(h));
+
+ /* Add the limit file */
+ cft = &h->mem_cgroup_files[0];
+ snprintf(cft->name, MAX_CFTYPE_NAME, "hugetlb.%s.limit_in_bytes", buf);
+ cft->private = __MEMFILE_PRIVATE(idx, _MEMHUGETLB, RES_LIMIT);
+ cft->read = mem_cgroup_read;
+ cft->write_string = mem_cgroup_write;
+
+ /* Add the usage file */
+ cft = &h->mem_cgroup_files[1];
+ snprintf(cft->name, MAX_CFTYPE_NAME, "hugetlb.%s.usage_in_bytes", buf);
+ cft->private = __MEMFILE_PRIVATE(idx, _MEMHUGETLB, RES_USAGE);
+ cft->read = mem_cgroup_read;
+
+ /* Add the MAX usage file */
+ cft = &h->mem_cgroup_files[2];
+ snprintf(cft->name, MAX_CFTYPE_NAME, "hugetlb.%s.max_usage_in_bytes", buf);
+ cft->private = __MEMFILE_PRIVATE(idx, _MEMHUGETLB, RES_MAX_USAGE);
+ cft->trigger = mem_cgroup_reset;
+ cft->read = mem_cgroup_read;
+
+ /* NULL terminate the last cft */
+ cft = &h->mem_cgroup_files[3];
+ memset(cft, 0, sizeof(*cft));
+
+ WARN_ON(cgroup_add_cftypes(&mem_cgroup_subsys, h->mem_cgroup_files));
+
+ return 0;
+}
+#endif
+
#ifdef CONFIG_MMU
/* Handlers for move charge at task migration. */
#define PRECHARGE_COUNT_AT_ONCE 256