diff mbox series

[4/4] memcg: Use a folio in get_mctgt_type_thp

Message ID 20240111181219.3462852-5-willy@infradead.org (mailing list archive)
State New
Headers show
Series Convert memcontrol charge moving to use folios | expand

Commit Message

Matthew Wilcox Jan. 11, 2024, 6:12 p.m. UTC
Replace five calls to compound_head() with one.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 mm/memcontrol.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Roman Gushchin Jan. 12, 2024, 1:57 a.m. UTC | #1
On Thu, Jan 11, 2024 at 06:12:19PM +0000, Matthew Wilcox (Oracle) wrote:
> Replace five calls to compound_head() with one.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev>
for the series.

Looks good, thanks!
Muchun Song Jan. 15, 2024, 3:47 a.m. UTC | #2
> On Jan 12, 2024, at 02:12, Matthew Wilcox (Oracle) <willy@infradead.org> wrote:
> 
> Replace five calls to compound_head() with one.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Reviewed-by: Muchun Song <muchun.song@linux.dev>

Thanks.
diff mbox series

Patch

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index b6096c34b3e4..935f48c4d399 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6161,6 +6161,7 @@  static enum mc_target_type get_mctgt_type_thp(struct vm_area_struct *vma,
 		unsigned long addr, pmd_t pmd, union mc_target *target)
 {
 	struct page *page = NULL;
+	struct folio *folio;
 	enum mc_target_type ret = MC_TARGET_NONE;
 
 	if (unlikely(is_swap_pmd(pmd))) {
@@ -6170,17 +6171,18 @@  static enum mc_target_type get_mctgt_type_thp(struct vm_area_struct *vma,
 	}
 	page = pmd_page(pmd);
 	VM_BUG_ON_PAGE(!page || !PageHead(page), page);
+	folio = page_folio(page);
 	if (!(mc.flags & MOVE_ANON))
 		return ret;
-	if (page_memcg(page) == mc.from) {
+	if (folio_memcg(folio) == mc.from) {
 		ret = MC_TARGET_PAGE;
 		if (target) {
-			get_page(page);
-			if (!trylock_page(page)) {
-				put_page(page);
+			folio_get(folio);
+			if (!folio_trylock(folio)) {
+				folio_put(folio);
 				return MC_TARGET_NONE;
 			}
-			target->folio = page_folio(page);
+			target->folio = folio;
 		}
 	}
 	return ret;