Skip to content

Commit 9a13715

Browse files
Ralph Campbelltorvalds
authored andcommitted
mm/memcg: fix device private memcg accounting
The code in mc_handle_swap_pte() checks for non_swap_entry() and returns NULL before checking is_device_private_entry() so device private pages are never handled. Fix this by checking for non_swap_entry() after handling device private swap PTEs. I assume the memory cgroup accounting would be off somehow when moving a process to another memory cgroup. Currently, the device private page is charged like a normal anonymous page when allocated and is uncharged when the page is freed so I think that path is OK. Signed-off-by: Ralph Campbell <rcampbell@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Vladimir Davydov <vdavydov.dev@gmail.com> Cc: Jerome Glisse <jglisse@redhat.com> Cc: Balbir Singh <bsingharora@gmail.com> Cc: Ira Weiny <ira.weiny@intel.com> Link: https://lkml.kernel.org/r/20201009215952.2726-1-rcampbell@nvidia.com xFixes: c733a82 ("mm/memcontrol: support MEMORY_DEVICE_PRIVATE") Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d1b2cf6 commit 9a13715

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

mm/memcontrol.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5516,7 +5516,7 @@ static struct page *mc_handle_swap_pte(struct vm_area_struct *vma,
55165516
struct page *page = NULL;
55175517
swp_entry_t ent = pte_to_swp_entry(ptent);
55185518

5519-
if (!(mc.flags & MOVE_ANON) || non_swap_entry(ent))
5519+
if (!(mc.flags & MOVE_ANON))
55205520
return NULL;
55215521

55225522
/*
@@ -5535,6 +5535,9 @@ static struct page *mc_handle_swap_pte(struct vm_area_struct *vma,
55355535
return page;
55365536
}
55375537

5538+
if (non_swap_entry(ent))
5539+
return NULL;
5540+
55385541
/*
55395542
* Because lookup_swap_cache() updates some statistics counter,
55405543
* we call find_get_page() with swapper_space directly.

0 commit comments

Comments
 (0)