Skip to content

Commit d6810d7

Browse files
yhuang-inteltorvalds
authored andcommitted
memcg, THP, swap: make mem_cgroup_swapout() support THP
This patch makes mem_cgroup_swapout() works for the transparent huge page (THP). Which will move the memory cgroup charge from memory to swap for a THP. This will be used for the THP swap support. Where a THP may be swapped out as a whole to a set of (HPAGE_PMD_NR) continuous swap slots on the swap device. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: "Huang, Ying" <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: "Kirill A . Shutemov" <[email protected]> Cc: Dan Williams <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Jens Axboe <[email protected]> Cc: Rik van Riel <[email protected]> Cc: Ross Zwisler <[email protected]> [for brd.c, zram_drv.c, pmem.c] Cc: Shaohua Li <[email protected]> Cc: Vishal L Verma <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent abe2895 commit d6810d7

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

mm/memcontrol.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4654,8 +4654,8 @@ static enum mc_target_type get_mctgt_type(struct vm_area_struct *vma,
46544654

46554655
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
46564656
/*
4657-
* We don't consider swapping or file mapped pages because THP does not
4658-
* support them for now.
4657+
* We don't consider PMD mapped swapping or file mapped pages because THP does
4658+
* not support them for now.
46594659
* Caller should make sure that pmd_trans_huge(pmd) is true.
46604660
*/
46614661
static enum mc_target_type get_mctgt_type_thp(struct vm_area_struct *vma,
@@ -5913,6 +5913,7 @@ static struct mem_cgroup *mem_cgroup_id_get_online(struct mem_cgroup *memcg)
59135913
void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
59145914
{
59155915
struct mem_cgroup *memcg, *swap_memcg;
5916+
unsigned int nr_entries;
59165917
unsigned short oldid;
59175918

59185919
VM_BUG_ON_PAGE(PageLRU(page), page);
@@ -5933,19 +5934,24 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
59335934
* ancestor for the swap instead and transfer the memory+swap charge.
59345935
*/
59355936
swap_memcg = mem_cgroup_id_get_online(memcg);
5936-
oldid = swap_cgroup_record(entry, mem_cgroup_id(swap_memcg), 1);
5937+
nr_entries = hpage_nr_pages(page);
5938+
/* Get references for the tail pages, too */
5939+
if (nr_entries > 1)
5940+
mem_cgroup_id_get_many(swap_memcg, nr_entries - 1);
5941+
oldid = swap_cgroup_record(entry, mem_cgroup_id(swap_memcg),
5942+
nr_entries);
59375943
VM_BUG_ON_PAGE(oldid, page);
5938-
mem_cgroup_swap_statistics(swap_memcg, 1);
5944+
mem_cgroup_swap_statistics(swap_memcg, nr_entries);
59395945

59405946
page->mem_cgroup = NULL;
59415947

59425948
if (!mem_cgroup_is_root(memcg))
5943-
page_counter_uncharge(&memcg->memory, 1);
5949+
page_counter_uncharge(&memcg->memory, nr_entries);
59445950

59455951
if (memcg != swap_memcg) {
59465952
if (!mem_cgroup_is_root(swap_memcg))
5947-
page_counter_charge(&swap_memcg->memsw, 1);
5948-
page_counter_uncharge(&memcg->memsw, 1);
5953+
page_counter_charge(&swap_memcg->memsw, nr_entries);
5954+
page_counter_uncharge(&memcg->memsw, nr_entries);
59495955
}
59505956

59515957
/*
@@ -5955,7 +5961,8 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
59555961
* only synchronisation we have for udpating the per-CPU variables.
59565962
*/
59575963
VM_BUG_ON(!irqs_disabled());
5958-
mem_cgroup_charge_statistics(memcg, page, false, -1);
5964+
mem_cgroup_charge_statistics(memcg, page, PageTransHuge(page),
5965+
-nr_entries);
59595966
memcg_check_events(memcg, page);
59605967

59615968
if (!mem_cgroup_is_root(memcg))

0 commit comments

Comments
 (0)