memcontrol.c (6caa6a0703e03236f46461342e31ca53d0e3c091) memcontrol.c (3fea5a499d57dec46043fcdb08e38eac1767bb0d)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/* memcontrol.c - Memory Controller
3 *
4 * Copyright IBM Corporation, 2007
5 * Author Balbir Singh <balbir@linux.vnet.ibm.com>
6 *
7 * Copyright 2007 OpenVZ SWsoft Inc
8 * Author: Pavel Emelianov <xemul@openvz.org>

--- 6623 unchanged lines hidden (view full) ---

6632 * from swapcache already, so we can't check PageSwapCache().
6633 */
6634 if (!memcg)
6635 return;
6636
6637 cancel_charge(memcg, nr_pages);
6638}
6639
1// SPDX-License-Identifier: GPL-2.0-or-later
2/* memcontrol.c - Memory Controller
3 *
4 * Copyright IBM Corporation, 2007
5 * Author Balbir Singh <balbir@linux.vnet.ibm.com>
6 *
7 * Copyright 2007 OpenVZ SWsoft Inc
8 * Author: Pavel Emelianov <xemul@openvz.org>

--- 6623 unchanged lines hidden (view full) ---

6632 * from swapcache already, so we can't check PageSwapCache().
6633 */
6634 if (!memcg)
6635 return;
6636
6637 cancel_charge(memcg, nr_pages);
6638}
6639
6640/**
6641 * mem_cgroup_charge - charge a newly allocated page to a cgroup
6642 * @page: page to charge
6643 * @mm: mm context of the victim
6644 * @gfp_mask: reclaim mode
6645 * @lrucare: page might be on the LRU already
6646 *
6647 * Try to charge @page to the memcg that @mm belongs to, reclaiming
6648 * pages according to @gfp_mask if necessary.
6649 *
6650 * Returns 0 on success. Otherwise, an error code is returned.
6651 */
6652int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask,
6653 bool lrucare)
6654{
6655 struct mem_cgroup *memcg;
6656 int ret;
6657
6658 VM_BUG_ON_PAGE(!page->mapping, page);
6659
6660 ret = mem_cgroup_try_charge(page, mm, gfp_mask, &memcg);
6661 if (ret)
6662 return ret;
6663 mem_cgroup_commit_charge(page, memcg, lrucare);
6664 return 0;
6665}
6666
6640struct uncharge_gather {
6641 struct mem_cgroup *memcg;
6642 unsigned long pgpgout;
6643 unsigned long nr_anon;
6644 unsigned long nr_file;
6645 unsigned long nr_kmem;
6646 unsigned long nr_huge;
6647 unsigned long nr_shmem;

--- 31 unchanged lines hidden (view full) ---

6679
6680 if (!mem_cgroup_is_root(ug->memcg))
6681 css_put_many(&ug->memcg->css, nr_pages);
6682}
6683
6684static void uncharge_page(struct page *page, struct uncharge_gather *ug)
6685{
6686 VM_BUG_ON_PAGE(PageLRU(page), page);
6667struct uncharge_gather {
6668 struct mem_cgroup *memcg;
6669 unsigned long pgpgout;
6670 unsigned long nr_anon;
6671 unsigned long nr_file;
6672 unsigned long nr_kmem;
6673 unsigned long nr_huge;
6674 unsigned long nr_shmem;

--- 31 unchanged lines hidden (view full) ---

6706
6707 if (!mem_cgroup_is_root(ug->memcg))
6708 css_put_many(&ug->memcg->css, nr_pages);
6709}
6710
6711static void uncharge_page(struct page *page, struct uncharge_gather *ug)
6712{
6713 VM_BUG_ON_PAGE(PageLRU(page), page);
6687 VM_BUG_ON_PAGE(page_count(page) && !is_zone_device_page(page) &&
6688 !PageHWPoison(page) , page);
6689
6690 if (!page->mem_cgroup)
6691 return;
6692
6693 /*
6694 * Nobody should be changing or seriously looking at
6695 * page->mem_cgroup at this point, we have fully
6696 * exclusive access to the page.

--- 651 unchanged lines hidden ---
6714
6715 if (!page->mem_cgroup)
6716 return;
6717
6718 /*
6719 * Nobody should be changing or seriously looking at
6720 * page->mem_cgroup at this point, we have fully
6721 * exclusive access to the page.

--- 651 unchanged lines hidden ---