Skip to content

Commit

Permalink
mm/memcg: Convert mem_cgroup_uncharge() to take a folio
Browse files Browse the repository at this point in the history
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: Matthew Wilcox (Oracle) <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Acked-by: Mike Rapoport <[email protected]>
Reviewed-by: David Howells <[email protected]>
Acked-by: Vlastimil Babka <[email protected]>
  • Loading branch information
Matthew Wilcox (Oracle) committed Sep 27, 2021
1 parent c4ed6eb commit bbc6b70
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 21 deletions.
15 changes: 11 additions & 4 deletions include/linux/memcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
}

Expand Down
2 changes: 1 addition & 1 deletion mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions mm/khugepaged.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 */
}

Expand Down
14 changes: 4 additions & 10 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion mm/memory-failure.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion mm/memremap.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ void free_devmap_managed_page(struct page *page)

__ClearPageWaiters(page);

mem_cgroup_uncharge(page);
mem_cgroup_uncharge(page_folio(page));

/*
* When a device_private page is freed, the page->mapping field
Expand Down
2 changes: 1 addition & 1 deletion mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ static inline void free_the_page(struct page *page, unsigned int order)

void free_compound_page(struct page *page)
{
mem_cgroup_uncharge(page);
mem_cgroup_uncharge(page_folio(page));
free_the_page(page, compound_order(page));
}

Expand Down
2 changes: 1 addition & 1 deletion mm/swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static void __page_cache_release(struct page *page)
static void __put_single_page(struct page *page)
{
__page_cache_release(page);
mem_cgroup_uncharge(page);
mem_cgroup_uncharge(page_folio(page));
free_unref_page(page, 0);
}

Expand Down

0 comments on commit bbc6b70

Please sign in to comment.