[PATCH v2 4/9] mm/swap: always account swapped in page into current memcg

From: Kairui Song
Date: Tue Jan 02 2024 - 12:54:49 EST


From: Kairui Song <kasong@xxxxxxxxxxx>

Currently, mem_cgroup_swapin_charge_folio is always called with
mm argument as NULL, except in swapin_direct.

swapin_direct is used when swapin should skip readahead and
swapcache (SWP_SYNCHRONOUS_IO). Other caller paths of
mem_cgroup_swapin_charge_folio are for swapin that should
not skip readahead and cache.

This could cause swapin charging to behave differently depending
on swap device. This currently didn't happen because the only call
path of swapin_direct is the direct anon page fault path, where mm
equals to current->mm, but will no longer be true if swapin_direct
is shared and have other callers (eg, swapoff).

So make swapin_direct also passes NULL for mm, no feature change.

Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
---
mm/swap_state.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/swap_state.c b/mm/swap_state.c
index 6130de8d5226..d39c5369da21 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -881,7 +881,7 @@ struct folio *swapin_direct(swp_entry_t entry, gfp_t gfp_mask,
folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0,
vma, vmf->address, false);
if (folio) {
- if (mem_cgroup_swapin_charge_folio(folio, vma->vm_mm,
+ if (mem_cgroup_swapin_charge_folio(folio, NULL,
GFP_KERNEL, entry)) {
folio_put(folio);
return NULL;
--
2.43.0