Commit 3e14a57b authored by Huang Ying's avatar Huang Ying Committed by Linus Torvalds

memcg, THP, swap: support move mem cgroup charge for THP swapped out

PTE mapped THP (Transparent Huge Page) will be ignored when moving
memory cgroup charge.  But for THP which is in the swap cache, the
memory cgroup charge for the swap of a tail-page may be moved in current
implementation.  That isn't correct, because the swap charge for all
sub-pages of a THP should be moved together.  Following the processing
of the PTE mapped THP, the mem cgroup charge moving for the swap entry
for a tail-page of a THP is ignored too.

Link: default avatar"Huang, Ying" <>
Cc: Johannes Weiner <>
Cc: Minchan Kim <>
Cc: Michal Hocko <>
Cc: Andrea Arcangeli <>
Cc: "Kirill A . Shutemov" <>
Cc: Dan Williams <>
Cc: Hugh Dickins <>
Cc: Jens Axboe <>
Cc: Rik van Riel <>
Cc: Ross Zwisler <> [for brd.c, zram_drv.c, pmem.c]
Cc: Shaohua Li <>
Cc: Vishal L Verma <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 59807685
......@@ -4639,8 +4639,11 @@ static enum mc_target_type get_mctgt_type(struct vm_area_struct *vma,
if (!ret || !target)
/* There is a swap entry and a page doesn't exist or isn't charged */
if (ent.val && !ret &&
* There is a swap entry and a page doesn't exist or isn't charged.
* But we cannot move a tail-page in a THP.
if (ent.val && !ret && (!page || !PageTransCompound(page)) &&
mem_cgroup_id(mc.from) == lookup_swap_cgroup_id(ent)) {
if (target)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment