[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230821204425.2940496-5-willy@infradead.org>
Date: Mon, 21 Aug 2023 21:44:23 +0100
From: "Matthew Wilcox (Oracle)" <willy@...radead.org>
To: Mateusz Guzik <mjguzik@...il.com>, linux-kernel@...r.kernel.org,
dennis@...nel.org, tj@...nel.org, cl@...ux.com,
akpm@...ux-foundation.org, shakeelb@...gle.com, linux-mm@...ck.org
Cc: "Matthew Wilcox (Oracle)" <willy@...radead.org>
Subject: [PATCH 5/7] memcg: Add mem_cgroup_uncharge_batch()
Almost identical to mem_cgroup_uncharge_list(), except it takes a
folio_batch instead of a list_head.
Signed-off-by: Matthew Wilcox (Oracle) <willy@...radead.org>
---
include/linux/memcontrol.h | 12 ++++++++++++
mm/memcontrol.c | 13 +++++++++++++
2 files changed, 25 insertions(+)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 3bd00f224224..4ea6f8399b05 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -708,6 +708,14 @@ static inline void mem_cgroup_uncharge_list(struct list_head *page_list)
__mem_cgroup_uncharge_list(page_list);
}
+void __mem_cgroup_uncharge_batch(struct folio_batch *fbatch);
+static inline void mem_cgroup_uncharge_batch(struct folio_batch *fbatch)
+{
+ if (mem_cgroup_disabled())
+ return;
+ __mem_cgroup_uncharge_batch(fbatch);
+}
+
void mem_cgroup_migrate(struct folio *old, struct folio *new);
/**
@@ -1269,6 +1277,10 @@ static inline void mem_cgroup_uncharge_list(struct list_head *page_list)
{
}
+static inline void mem_cgroup_uncharge_batch(struct folio_batch *fbatch)
+{
+}
+
static inline void mem_cgroup_migrate(struct folio *old, struct folio *new)
{
}
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 67bda1ceedbe..205aa28c2672 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -33,6 +33,7 @@
#include <linux/shmem_fs.h>
#include <linux/hugetlb.h>
#include <linux/pagemap.h>
+#include <linux/pagevec.h>
#include <linux/vm_event_item.h>
#include <linux/smp.h>
#include <linux/page-flags.h>
@@ -7194,6 +7195,18 @@ void __mem_cgroup_uncharge_list(struct list_head *page_list)
uncharge_batch(&ug);
}
+void __mem_cgroup_uncharge_batch(struct folio_batch *fbatch)
+{
+ struct uncharge_gather ug;
+ unsigned int i;
+
+ uncharge_gather_clear(&ug);
+ for (i = 0; i < fbatch->nr; i++)
+ uncharge_folio(fbatch->folios[i], &ug);
+ if (ug.memcg)
+ uncharge_batch(&ug);
+}
+
/**
* mem_cgroup_migrate - Charge a folio's replacement.
* @old: Currently circulating folio.
--
2.40.1
Powered by blists - more mailing lists