[PATCH v5 2/4] mm: Introduce mem_cgroup_swapin_uncharge_swap_nr() helper for large folios swap-in

From: Barry Song
Date: Fri Jul 26 2024 - 05:47:37 EST


From: Barry Song <v-songbaohua@xxxxxxxx>

With large folios swap-in, we might need to uncharge multiple entries
all together, it is better to introduce a helper for that.

Signed-off-by: Barry Song <v-songbaohua@xxxxxxxx>
---
include/linux/memcontrol.h | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 1b79760af685..55958cbce61b 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -684,6 +684,14 @@ int mem_cgroup_swapin_charge_folio(struct folio *folio, struct mm_struct *mm,
gfp_t gfp, swp_entry_t entry);
void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry);

+static inline void mem_cgroup_swapin_uncharge_swap_nr(swp_entry_t entry, int nr)
+{
+ int i;
+
+ for (i = 0; i < nr; i++, entry.val++)
+ mem_cgroup_swapin_uncharge_swap(entry);
+}
+
void __mem_cgroup_uncharge(struct folio *folio);

/**
@@ -1185,6 +1193,10 @@ static inline void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry)
{
}

+static inline void mem_cgroup_swapin_uncharge_swap_nr(swp_entry_t entry, int nr)
+{
+}
+
static inline void mem_cgroup_uncharge(struct folio *folio)
{
}
--
2.34.1