]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - mm/memcontrol.c
memcg: change defines to an enum
[mirror_ubuntu-bionic-kernel.git] / mm / memcontrol.c
index cf6d0df4849cc86ac15245f57ac1828c3ad1224c..c7b0b1b803a5c1ec81787b0193130de5edd0758a 100644 (file)
@@ -59,6 +59,8 @@
 #include <trace/events/vmscan.h>
 
 struct cgroup_subsys mem_cgroup_subsys __read_mostly;
+EXPORT_SYMBOL(mem_cgroup_subsys);
+
 #define MEM_CGROUP_RECLAIM_RETRIES     5
 static struct mem_cgroup *root_mem_cgroup __read_mostly;
 
@@ -386,9 +388,12 @@ enum charge_type {
 };
 
 /* for encoding cft->private value on file */
-#define _MEM                   (0)
-#define _MEMSWAP               (1)
-#define _OOM_TYPE              (2)
+enum res_type {
+       _MEM,
+       _MEMSWAP,
+       _OOM_TYPE,
+};
+
 #define MEMFILE_PRIVATE(x, val)        ((x) << 16 | (val))
 #define MEMFILE_TYPE(val)      ((val) >> 16 & 0xffff)
 #define MEMFILE_ATTR(val)      ((val) & 0xffff)
@@ -800,7 +805,7 @@ static unsigned long mem_cgroup_nr_lru_pages(struct mem_cgroup *memcg,
        int nid;
        u64 total = 0;
 
-       for_each_node_state(nid, N_HIGH_MEMORY)
+       for_each_node_state(nid, N_MEMORY)
                total += mem_cgroup_node_nr_lru_pages(memcg, nid, lru_mask);
        return total;
 }
@@ -1015,13 +1020,10 @@ void mem_cgroup_iter_break(struct mem_cgroup *root,
             iter != NULL;                              \
             iter = mem_cgroup_iter(NULL, iter, NULL))
 
-void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx)
+void __mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx)
 {
        struct mem_cgroup *memcg;
 
-       if (!mm)
-               return;
-
        rcu_read_lock();
        memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
        if (unlikely(!memcg))
@@ -1040,7 +1042,7 @@ void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx)
 out:
        rcu_read_unlock();
 }
-EXPORT_SYMBOL(mem_cgroup_count_vm_event);
+EXPORT_SYMBOL(__mem_cgroup_count_vm_event);
 
 /**
  * mem_cgroup_zone_lruvec - get the lru list vector for a zone and memcg
@@ -1644,9 +1646,9 @@ static void mem_cgroup_may_update_nodemask(struct mem_cgroup *memcg)
                return;
 
        /* make a nodemask where this memcg uses memory from */
-       memcg->scan_nodes = node_states[N_HIGH_MEMORY];
+       memcg->scan_nodes = node_states[N_MEMORY];
 
-       for_each_node_mask(nid, node_states[N_HIGH_MEMORY]) {
+       for_each_node_mask(nid, node_states[N_MEMORY]) {
 
                if (!test_mem_cgroup_node_reclaimable(memcg, nid, false))
                        node_clear(nid, memcg->scan_nodes);
@@ -1717,7 +1719,7 @@ static bool mem_cgroup_reclaimable(struct mem_cgroup *memcg, bool noswap)
        /*
         * Check rest of nodes.
         */
-       for_each_node_state(nid, N_HIGH_MEMORY) {
+       for_each_node_state(nid, N_MEMORY) {
                if (node_isset(nid, memcg->scan_nodes))
                        continue;
                if (test_mem_cgroup_node_reclaimable(memcg, nid, noswap))
@@ -2061,20 +2063,28 @@ struct memcg_stock_pcp {
 static DEFINE_PER_CPU(struct memcg_stock_pcp, memcg_stock);
 static DEFINE_MUTEX(percpu_charge_mutex);
 
-/*
- * Try to consume stocked charge on this cpu. If success, one page is consumed
- * from local stock and true is returned. If the stock is 0 or charges from a
- * cgroup which is not current target, returns false. This stock will be
- * refilled.
+/**
+ * consume_stock: Try to consume stocked charge on this cpu.
+ * @memcg: memcg to consume from.
+ * @nr_pages: how many pages to charge.
+ *
+ * The charges will only happen if @memcg matches the current cpu's memcg
+ * stock, and at least @nr_pages are available in that stock.  Failure to
+ * service an allocation will refill the stock.
+ *
+ * returns true if successful, false otherwise.
  */
-static bool consume_stock(struct mem_cgroup *memcg)
+static bool consume_stock(struct mem_cgroup *memcg, unsigned int nr_pages)
 {
        struct memcg_stock_pcp *stock;
        bool ret = true;
 
+       if (nr_pages > CHARGE_BATCH)
+               return false;
+
        stock = &get_cpu_var(memcg_stock);
-       if (memcg == stock->cached && stock->nr_pages)
-               stock->nr_pages--;
+       if (memcg == stock->cached && stock->nr_pages >= nr_pages)
+               stock->nr_pages -= nr_pages;
        else /* need to call res_counter_charge */
                ret = false;
        put_cpu_var(memcg_stock);
@@ -2251,7 +2261,8 @@ enum {
 };
 
 static int mem_cgroup_do_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
-                               unsigned int nr_pages, bool oom_check)
+                               unsigned int nr_pages, unsigned int min_pages,
+                               bool oom_check)
 {
        unsigned long csize = nr_pages * PAGE_SIZE;
        struct mem_cgroup *mem_over_limit;
@@ -2274,18 +2285,18 @@ static int mem_cgroup_do_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
        } else
                mem_over_limit = mem_cgroup_from_res_counter(fail_res, res);
        /*
-        * nr_pages can be either a huge page (HPAGE_PMD_NR), a batch
-        * of regular pages (CHARGE_BATCH), or a single regular page (1).
-        *
         * Never reclaim on behalf of optional batching, retry with a
         * single page instead.
         */
-       if (nr_pages == CHARGE_BATCH)
+       if (nr_pages > min_pages)
                return CHARGE_RETRY;
 
        if (!(gfp_mask & __GFP_WAIT))
                return CHARGE_WOULDBLOCK;
 
+       if (gfp_mask & __GFP_NORETRY)
+               return CHARGE_NOMEM;
+
        ret = mem_cgroup_reclaim(mem_over_limit, gfp_mask, flags);
        if (mem_cgroup_margin(mem_over_limit) >= nr_pages)
                return CHARGE_RETRY;
@@ -2298,7 +2309,7 @@ static int mem_cgroup_do_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
         * unlikely to succeed so close to the limit, and we fall back
         * to regular pages anyway in case of failure.
         */
-       if (nr_pages == 1 && ret)
+       if (nr_pages <= (1 << PAGE_ALLOC_COSTLY_ORDER) && ret)
                return CHARGE_RETRY;
 
        /*
@@ -2370,10 +2381,9 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm,
 again:
        if (*ptr) { /* css should be a valid one */
                memcg = *ptr;
-               VM_BUG_ON(css_is_removed(&memcg->css));
                if (mem_cgroup_is_root(memcg))
                        goto done;
-               if (nr_pages == 1 && consume_stock(memcg))
+               if (consume_stock(memcg, nr_pages))
                        goto done;
                css_get(&memcg->css);
        } else {
@@ -2398,7 +2408,7 @@ again:
                        rcu_read_unlock();
                        goto done;
                }
-               if (nr_pages == 1 && consume_stock(memcg)) {
+               if (consume_stock(memcg, nr_pages)) {
                        /*
                         * It seems dagerous to access memcg without css_get().
                         * But considering how consume_stok works, it's not
@@ -2433,7 +2443,8 @@ again:
                        nr_oom_retries = MEM_CGROUP_RECLAIM_RETRIES;
                }
 
-               ret = mem_cgroup_do_charge(memcg, gfp_mask, batch, oom_check);
+               ret = mem_cgroup_do_charge(memcg, gfp_mask, batch, nr_pages,
+                   oom_check);
                switch (ret) {
                case CHARGE_OK:
                        break;
@@ -2510,9 +2521,9 @@ static void __mem_cgroup_cancel_local_charge(struct mem_cgroup *memcg,
 
 /*
  * A helper function to get mem_cgroup from ID. must be called under
- * rcu_read_lock(). The caller must check css_is_removed() or some if
- * it's concern. (dropping refcnt from swap can be called against removed
- * memcg.)
+ * rcu_read_lock().  The caller is responsible for calling css_tryget if
+ * the mem_cgroup is used for charging. (dropping refcnt from swap can be
+ * called against removed memcg.)
  */
 static struct mem_cgroup *mem_cgroup_lookup(unsigned short id)
 {
@@ -2709,13 +2720,6 @@ static int mem_cgroup_move_account(struct page *page,
        /* caller should have done css_get */
        pc->mem_cgroup = to;
        mem_cgroup_charge_statistics(to, anon, nr_pages);
-       /*
-        * We charges against "to" which may not have any tasks. Then, "to"
-        * can be under rmdir(). But in current implementation, caller of
-        * this function is just force_empty() and move charge, so it's
-        * guaranteed that "to" is never removed. So, we don't check rmdir
-        * status here.
-        */
        move_unlock_mem_cgroup(from, &flags);
        ret = 0;
 unlock:
@@ -2729,10 +2733,27 @@ out:
        return ret;
 }
 
-/*
- * move charges to its parent.
+/**
+ * mem_cgroup_move_parent - moves page to the parent group
+ * @page: the page to move
+ * @pc: page_cgroup of the page
+ * @child: page's cgroup
+ *
+ * move charges to its parent or the root cgroup if the group has no
+ * parent (aka use_hierarchy==0).
+ * Although this might fail (get_page_unless_zero, isolate_lru_page or
+ * mem_cgroup_move_account fails) the failure is always temporary and
+ * it signals a race with a page removal/uncharge or migration. In the
+ * first case the page is on the way out and it will vanish from the LRU
+ * on the next attempt and the call should be retried later.
+ * Isolation from the LRU fails only if page has been isolated from
+ * the LRU since we looked at it and that usually means either global
+ * reclaim or migration going on. The page will either get back to the
+ * LRU or vanish.
+ * Finaly mem_cgroup_move_account fails only if the page got uncharged
+ * (!PageCgroupUsed) or moved to a different group. The page will
+ * disappear in the next attempt.
  */
-
 static int mem_cgroup_move_parent(struct page *page,
                                  struct page_cgroup *pc,
                                  struct mem_cgroup *child)
@@ -2742,9 +2763,7 @@ static int mem_cgroup_move_parent(struct page *page,
        unsigned long uninitialized_var(flags);
        int ret;
 
-       /* Is ROOT ? */
-       if (mem_cgroup_is_root(child))
-               return -EINVAL;
+       VM_BUG_ON(mem_cgroup_is_root(child));
 
        ret = -EBUSY;
        if (!get_page_unless_zero(page))
@@ -2761,8 +2780,10 @@ static int mem_cgroup_move_parent(struct page *page,
        if (!parent)
                parent = root_mem_cgroup;
 
-       if (nr_pages > 1)
+       if (nr_pages > 1) {
+               VM_BUG_ON(!PageTransHuge(page));
                flags = compound_lock_irqsave(page);
+       }
 
        ret = mem_cgroup_move_account(page, nr_pages,
                                pc, child, parent);
@@ -2904,7 +2925,6 @@ __mem_cgroup_commit_charge_swapin(struct page *page, struct mem_cgroup *memcg,
                return;
        if (!memcg)
                return;
-       cgroup_exclude_rmdir(&memcg->css);
 
        __mem_cgroup_commit_charge(memcg, page, 1, ctype, true);
        /*
@@ -2918,12 +2938,6 @@ __mem_cgroup_commit_charge_swapin(struct page *page, struct mem_cgroup *memcg,
                swp_entry_t ent = {.val = page_private(page)};
                mem_cgroup_uncharge_swap(ent);
        }
-       /*
-        * At swapin, we may charge account against cgroup which has no tasks.
-        * So, rmdir()->pre_destroy() can be called while we do this charge.
-        * In that case, we need to call pre_destroy() again. check it here.
-        */
-       cgroup_release_and_wakeup_rmdir(&memcg->css);
 }
 
 void mem_cgroup_commit_charge_swapin(struct page *page,
@@ -3288,15 +3302,18 @@ void mem_cgroup_prepare_migration(struct page *page, struct page *newpage,
                                  struct mem_cgroup **memcgp)
 {
        struct mem_cgroup *memcg = NULL;
+       unsigned int nr_pages = 1;
        struct page_cgroup *pc;
        enum charge_type ctype;
 
        *memcgp = NULL;
 
-       VM_BUG_ON(PageTransHuge(page));
        if (mem_cgroup_disabled())
                return;
 
+       if (PageTransHuge(page))
+               nr_pages <<= compound_order(page);
+
        pc = lookup_page_cgroup(page);
        lock_page_cgroup(pc);
        if (PageCgroupUsed(pc)) {
@@ -3358,7 +3375,7 @@ void mem_cgroup_prepare_migration(struct page *page, struct page *newpage,
         * charged to the res_counter since we plan on replacing the
         * old one and only one page is going to be left afterwards.
         */
-       __mem_cgroup_commit_charge(memcg, newpage, 1, ctype, false);
+       __mem_cgroup_commit_charge(memcg, newpage, nr_pages, ctype, false);
 }
 
 /* remove redundant charge if migration failed*/
@@ -3371,8 +3388,7 @@ void mem_cgroup_end_migration(struct mem_cgroup *memcg,
 
        if (!memcg)
                return;
-       /* blocks rmdir() */
-       cgroup_exclude_rmdir(&memcg->css);
+
        if (!migration_ok) {
                used = oldpage;
                unused = newpage;
@@ -3406,13 +3422,6 @@ void mem_cgroup_end_migration(struct mem_cgroup *memcg,
         */
        if (anon)
                mem_cgroup_uncharge_page(used);
-       /*
-        * At migration, we may charge account against cgroup which has no
-        * tasks.
-        * So, rmdir()->pre_destroy() can be called while we do this charge.
-        * In that case, we need to call pre_destroy() again. check it here.
-        */
-       cgroup_release_and_wakeup_rmdir(&memcg->css);
 }
 
 /*
@@ -3712,17 +3721,22 @@ unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
        return nr_reclaimed;
 }
 
-/*
+/**
+ * mem_cgroup_force_empty_list - clears LRU of a group
+ * @memcg: group to clear
+ * @node: NUMA node
+ * @zid: zone id
+ * @lru: lru to to clear
+ *
  * Traverse a specified page_cgroup list and try to drop them all.  This doesn't
- * reclaim the pages page themselves - it just removes the page_cgroups.
- * Returns true if some page_cgroups were not freed, indicating that the caller
- * must retry this operation.
+ * reclaim the pages page themselves - pages are moved to the parent (or root)
+ * group.
  */
-static bool mem_cgroup_force_empty_list(struct mem_cgroup *memcg,
+static void mem_cgroup_force_empty_list(struct mem_cgroup *memcg,
                                int node, int zid, enum lru_list lru)
 {
        struct lruvec *lruvec;
-       unsigned long flags, loop;
+       unsigned long flags;
        struct list_head *list;
        struct page *busy;
        struct zone *zone;
@@ -3731,11 +3745,8 @@ static bool mem_cgroup_force_empty_list(struct mem_cgroup *memcg,
        lruvec = mem_cgroup_zone_lruvec(zone, memcg);
        list = &lruvec->lists[lru];
 
-       loop = mem_cgroup_get_lru_size(lruvec, lru);
-       /* give some margin against EBUSY etc...*/
-       loop += 256;
        busy = NULL;
-       while (loop--) {
+       do {
                struct page_cgroup *pc;
                struct page *page;
 
@@ -3761,76 +3772,72 @@ static bool mem_cgroup_force_empty_list(struct mem_cgroup *memcg,
                        cond_resched();
                } else
                        busy = NULL;
-       }
-       return !list_empty(list);
+       } while (!list_empty(list));
 }
 
 /*
- * make mem_cgroup's charge to be 0 if there is no task.
+ * make mem_cgroup's charge to be 0 if there is no task by moving
+ * all the charges and pages to the parent.
  * This enables deleting this mem_cgroup.
+ *
+ * Caller is responsible for holding css reference on the memcg.
  */
-static int mem_cgroup_force_empty(struct mem_cgroup *memcg, bool free_all)
+static void mem_cgroup_reparent_charges(struct mem_cgroup *memcg)
 {
-       int ret;
-       int node, zid, shrink;
-       int nr_retries = MEM_CGROUP_RECLAIM_RETRIES;
-       struct cgroup *cgrp = memcg->css.cgroup;
+       int node, zid;
 
-       css_get(&memcg->css);
-
-       shrink = 0;
-       /* should free all ? */
-       if (free_all)
-               goto try_to_free;
-move_account:
        do {
-               ret = -EBUSY;
-               if (cgroup_task_count(cgrp) || !list_empty(&cgrp->children))
-                       goto out;
                /* This is for making all *used* pages to be on LRU. */
                lru_add_drain_all();
                drain_all_stock_sync(memcg);
-               ret = 0;
                mem_cgroup_start_move(memcg);
-               for_each_node_state(node, N_HIGH_MEMORY) {
-                       for (zid = 0; !ret && zid < MAX_NR_ZONES; zid++) {
+               for_each_node_state(node, N_MEMORY) {
+                       for (zid = 0; zid < MAX_NR_ZONES; zid++) {
                                enum lru_list lru;
                                for_each_lru(lru) {
-                                       ret = mem_cgroup_force_empty_list(memcg,
+                                       mem_cgroup_force_empty_list(memcg,
                                                        node, zid, lru);
-                                       if (ret)
-                                               break;
                                }
                        }
-                       if (ret)
-                               break;
                }
                mem_cgroup_end_move(memcg);
                memcg_oom_recover(memcg);
                cond_resched();
-       /* "ret" should also be checked to ensure all lists are empty. */
-       } while (res_counter_read_u64(&memcg->res, RES_USAGE) > 0 || ret);
-out:
-       css_put(&memcg->css);
-       return ret;
 
-try_to_free:
+               /*
+                * This is a safety check because mem_cgroup_force_empty_list
+                * could have raced with mem_cgroup_replace_page_cache callers
+                * so the lru seemed empty but the page could have been added
+                * right after the check. RES_USAGE should be safe as we always
+                * charge before adding to the LRU.
+                */
+       } while (res_counter_read_u64(&memcg->res, RES_USAGE) > 0);
+}
+
+/*
+ * Reclaims as many pages from the given memcg as possible and moves
+ * the rest to the parent.
+ *
+ * Caller is responsible for holding css reference for memcg.
+ */
+static int mem_cgroup_force_empty(struct mem_cgroup *memcg)
+{
+       int nr_retries = MEM_CGROUP_RECLAIM_RETRIES;
+       struct cgroup *cgrp = memcg->css.cgroup;
+
        /* returns EBUSY if there is a task or if we come here twice. */
-       if (cgroup_task_count(cgrp) || !list_empty(&cgrp->children) || shrink) {
-               ret = -EBUSY;
-               goto out;
-       }
+       if (cgroup_task_count(cgrp) || !list_empty(&cgrp->children))
+               return -EBUSY;
+
        /* we call try-to-free pages for make this cgroup empty */
        lru_add_drain_all();
        /* try to free all pages in this cgroup */
-       shrink = 1;
        while (nr_retries && res_counter_read_u64(&memcg->res, RES_USAGE) > 0) {
                int progress;
 
-               if (signal_pending(current)) {
-                       ret = -EINTR;
-                       goto out;
-               }
+               if (signal_pending(current))
+                       return -EINTR;
+
                progress = try_to_free_mem_cgroup_pages(memcg, GFP_KERNEL,
                                                false);
                if (!progress) {
@@ -3841,13 +3848,23 @@ try_to_free:
 
        }
        lru_add_drain();
-       /* try move_account...there may be some *locked* pages. */
-       goto move_account;
+       mem_cgroup_reparent_charges(memcg);
+
+       return 0;
 }
 
 static int mem_cgroup_force_empty_write(struct cgroup *cont, unsigned int event)
 {
-       return mem_cgroup_force_empty(mem_cgroup_from_cont(cont), true);
+       struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
+       int ret;
+
+       if (mem_cgroup_is_root(memcg))
+               return -EINVAL;
+       css_get(&memcg->css);
+       ret = mem_cgroup_force_empty(memcg);
+       css_put(&memcg->css);
+
+       return ret;
 }
 
 
@@ -3938,7 +3955,8 @@ static ssize_t mem_cgroup_read(struct cgroup *cont, struct cftype *cft,
        struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
        char str[64];
        u64 val;
-       int type, name, len;
+       int name, len;
+       enum res_type type;
 
        type = MEMFILE_TYPE(cft->private);
        name = MEMFILE_ATTR(cft->private);
@@ -3974,7 +3992,8 @@ static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft,
                            const char *buffer)
 {
        struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
-       int type, name;
+       enum res_type type;
+       int name;
        unsigned long long val;
        int ret;
 
@@ -4050,7 +4069,8 @@ out:
 static int mem_cgroup_reset(struct cgroup *cont, unsigned int event)
 {
        struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
-       int type, name;
+       int name;
+       enum res_type type;
 
        type = MEMFILE_TYPE(event);
        name = MEMFILE_ATTR(event);
@@ -4120,7 +4140,7 @@ static int memcg_numa_stat_show(struct cgroup *cont, struct cftype *cft,
 
        total_nr = mem_cgroup_nr_lru_pages(memcg, LRU_ALL);
        seq_printf(m, "total=%lu", total_nr);
-       for_each_node_state(nid, N_HIGH_MEMORY) {
+       for_each_node_state(nid, N_MEMORY) {
                node_nr = mem_cgroup_node_nr_lru_pages(memcg, nid, LRU_ALL);
                seq_printf(m, " N%d=%lu", nid, node_nr);
        }
@@ -4128,7 +4148,7 @@ static int memcg_numa_stat_show(struct cgroup *cont, struct cftype *cft,
 
        file_nr = mem_cgroup_nr_lru_pages(memcg, LRU_ALL_FILE);
        seq_printf(m, "file=%lu", file_nr);
-       for_each_node_state(nid, N_HIGH_MEMORY) {
+       for_each_node_state(nid, N_MEMORY) {
                node_nr = mem_cgroup_node_nr_lru_pages(memcg, nid,
                                LRU_ALL_FILE);
                seq_printf(m, " N%d=%lu", nid, node_nr);
@@ -4137,7 +4157,7 @@ static int memcg_numa_stat_show(struct cgroup *cont, struct cftype *cft,
 
        anon_nr = mem_cgroup_nr_lru_pages(memcg, LRU_ALL_ANON);
        seq_printf(m, "anon=%lu", anon_nr);
-       for_each_node_state(nid, N_HIGH_MEMORY) {
+       for_each_node_state(nid, N_MEMORY) {
                node_nr = mem_cgroup_node_nr_lru_pages(memcg, nid,
                                LRU_ALL_ANON);
                seq_printf(m, " N%d=%lu", nid, node_nr);
@@ -4146,7 +4166,7 @@ static int memcg_numa_stat_show(struct cgroup *cont, struct cftype *cft,
 
        unevictable_nr = mem_cgroup_nr_lru_pages(memcg, BIT(LRU_UNEVICTABLE));
        seq_printf(m, "unevictable=%lu", unevictable_nr);
-       for_each_node_state(nid, N_HIGH_MEMORY) {
+       for_each_node_state(nid, N_MEMORY) {
                node_nr = mem_cgroup_node_nr_lru_pages(memcg, nid,
                                BIT(LRU_UNEVICTABLE));
                seq_printf(m, " N%d=%lu", nid, node_nr);
@@ -4386,7 +4406,7 @@ static int mem_cgroup_usage_register_event(struct cgroup *cgrp,
        struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
        struct mem_cgroup_thresholds *thresholds;
        struct mem_cgroup_threshold_ary *new;
-       int type = MEMFILE_TYPE(cft->private);
+       enum res_type type = MEMFILE_TYPE(cft->private);
        u64 threshold, usage;
        int i, size, ret;
 
@@ -4469,7 +4489,7 @@ static void mem_cgroup_usage_unregister_event(struct cgroup *cgrp,
        struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
        struct mem_cgroup_thresholds *thresholds;
        struct mem_cgroup_threshold_ary *new;
-       int type = MEMFILE_TYPE(cft->private);
+       enum res_type type = MEMFILE_TYPE(cft->private);
        u64 usage;
        int i, j, size;
 
@@ -4547,7 +4567,7 @@ static int mem_cgroup_oom_register_event(struct cgroup *cgrp,
 {
        struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
        struct mem_cgroup_eventfd_list *event;
-       int type = MEMFILE_TYPE(cft->private);
+       enum res_type type = MEMFILE_TYPE(cft->private);
 
        BUG_ON(type != _OOM_TYPE);
        event = kmalloc(sizeof(*event), GFP_KERNEL);
@@ -4572,7 +4592,7 @@ static void mem_cgroup_oom_unregister_event(struct cgroup *cgrp,
 {
        struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
        struct mem_cgroup_eventfd_list *ev, *tmp;
-       int type = MEMFILE_TYPE(cft->private);
+       enum res_type type = MEMFILE_TYPE(cft->private);
 
        BUG_ON(type != _OOM_TYPE);
 
@@ -4953,7 +4973,7 @@ err_cleanup:
 }
 
 static struct cgroup_subsys_state * __ref
-mem_cgroup_create(struct cgroup *cont)
+mem_cgroup_css_alloc(struct cgroup *cont)
 {
        struct mem_cgroup *memcg, *parent;
        long error = -ENOMEM;
@@ -5034,14 +5054,14 @@ free_out:
        return ERR_PTR(error);
 }
 
-static int mem_cgroup_pre_destroy(struct cgroup *cont)
+static void mem_cgroup_css_offline(struct cgroup *cont)
 {
        struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
 
-       return mem_cgroup_force_empty(memcg, false);
+       mem_cgroup_reparent_charges(memcg);
 }
 
-static void mem_cgroup_destroy(struct cgroup *cont)
+static void mem_cgroup_css_free(struct cgroup *cont)
 {
        struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
 
@@ -5631,16 +5651,15 @@ static void mem_cgroup_move_task(struct cgroup *cont,
 struct cgroup_subsys mem_cgroup_subsys = {
        .name = "memory",
        .subsys_id = mem_cgroup_subsys_id,
-       .create = mem_cgroup_create,
-       .pre_destroy = mem_cgroup_pre_destroy,
-       .destroy = mem_cgroup_destroy,
+       .css_alloc = mem_cgroup_css_alloc,
+       .css_offline = mem_cgroup_css_offline,
+       .css_free = mem_cgroup_css_free,
        .can_attach = mem_cgroup_can_attach,
        .cancel_attach = mem_cgroup_cancel_attach,
        .attach = mem_cgroup_move_task,
        .base_cftypes = mem_cgroup_files,
        .early_init = 0,
        .use_id = 1,
-       .__DEPRECATED_clear_css_refs = true,
 };
 
 #ifdef CONFIG_MEMCG_SWAP