Commit bbc6b703 authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle)
Browse files

mm/memcg: Convert mem_cgroup_uncharge() to take a folio



Convert all the callers to call page_folio().  Most of them were already
using a head page, but a few of them I can't prove were, so this may
actually fix a bug.

Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarMike Rapoport <rppt@linux.ibm.com>
Reviewed-by: default avatarDavid Howells <dhowells@redhat.com>
Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
parent c4ed6ebf
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -722,12 +722,19 @@ int mem_cgroup_swapin_charge_page(struct page *page, struct mm_struct *mm,
				  gfp_t gfp, swp_entry_t entry);
void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry);

void __mem_cgroup_uncharge(struct page *page);
static inline void mem_cgroup_uncharge(struct page *page)
void __mem_cgroup_uncharge(struct folio *folio);

/**
 * mem_cgroup_uncharge - Uncharge a folio.
 * @folio: Folio to uncharge.
 *
 * Uncharge a folio previously charged with mem_cgroup_charge().
 */
static inline void mem_cgroup_uncharge(struct folio *folio)
{
	if (mem_cgroup_disabled())
		return;
	__mem_cgroup_uncharge(page);
	__mem_cgroup_uncharge(folio);
}

void __mem_cgroup_uncharge_list(struct list_head *page_list);
@@ -1229,7 +1236,7 @@ static inline void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry)
{
}

static inline void mem_cgroup_uncharge(struct page *page)
static inline void mem_cgroup_uncharge(struct folio *folio)
{
}

+1 −1
Original line number Diff line number Diff line
@@ -940,7 +940,7 @@ noinline int __add_to_page_cache_locked(struct page *page,
	if (xas_error(&xas)) {
		error = xas_error(&xas);
		if (charged)
			mem_cgroup_uncharge(page);
			mem_cgroup_uncharge(page_folio(page));
		goto error;
	}

+2 −2
Original line number Diff line number Diff line
@@ -1211,7 +1211,7 @@ static void collapse_huge_page(struct mm_struct *mm,
	mmap_write_unlock(mm);
out_nolock:
	if (!IS_ERR_OR_NULL(*hpage))
		mem_cgroup_uncharge(*hpage);
		mem_cgroup_uncharge(page_folio(*hpage));
	trace_mm_collapse_huge_page(mm, isolated, result);
	return;
}
@@ -1975,7 +1975,7 @@ static void collapse_file(struct mm_struct *mm,
out:
	VM_BUG_ON(!list_empty(&pagelist));
	if (!IS_ERR_OR_NULL(*hpage))
		mem_cgroup_uncharge(*hpage);
		mem_cgroup_uncharge(page_folio(*hpage));
	/* TODO: tracepoints */
}

+4 −10
Original line number Diff line number Diff line
@@ -6858,22 +6858,16 @@ static void uncharge_folio(struct folio *folio, struct uncharge_gather *ug)
	css_put(&memcg->css);
}

/**
 * __mem_cgroup_uncharge - uncharge a page
 * @page: page to uncharge
 *
 * Uncharge a page previously charged with __mem_cgroup_charge().
 */
void __mem_cgroup_uncharge(struct page *page)
void __mem_cgroup_uncharge(struct folio *folio)
{
	struct uncharge_gather ug;

	/* Don't touch page->lru of any random page, pre-check: */
	if (!page_memcg(page))
	/* Don't touch folio->lru of any random page, pre-check: */
	if (!folio_memcg(folio))
		return;

	uncharge_gather_clear(&ug);
	uncharge_folio(page_folio(page), &ug);
	uncharge_folio(folio, &ug);
	uncharge_batch(&ug);
}

+1 −1
Original line number Diff line number Diff line
@@ -762,7 +762,7 @@ static int delete_from_lru_cache(struct page *p)
		 * Poisoned page might never drop its ref count to 0 so we have
		 * to uncharge it manually from its memcg.
		 */
		mem_cgroup_uncharge(p);
		mem_cgroup_uncharge(page_folio(p));

		/*
		 * drop the page count elevated by isolate_lru_page()
Loading