Skip to content

Commit

Permalink
mm,page_owner: fix accounting of pages when migrating
Browse files Browse the repository at this point in the history
Upon migration, new allocated pages are being given the handle of the old
pages.  This is problematic because it means that for the stack which
allocated the old page, we will be substracting the old page + the new one
when that page is freed, creating an accounting imbalance.

There is an interest in keeping it that way, as otherwise the output will
biased towards migration stacks should those operations occur often, but
that is not really helpful.

The link from the new page to the old stack is being performed by calling
__update_page_owner_handle() in __folio_copy_owner().  The only thing that
is left is to link the migrate stack to the old page, so the old page will
be subtracted from the migrate stack, avoiding by doing so any possible
imbalance.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: 217b211 ("mm,page_owner: implement the tracking of the stacks count")
Signed-off-by: Oscar Salvador <[email protected]>
Reviewed-by: Vlastimil Babka <[email protected]>
Cc: Alexander Potapenko <[email protected]>
Cc: Alexandre Ghiti <[email protected]>
Cc: Andrey Konovalov <[email protected]>
Cc: Marco Elver <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Palmer Dabbelt <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
osalvadorvilardaga authored and akpm00 committed Apr 16, 2024
1 parent f5c1210 commit 718b1f3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mm/page_owner.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,12 @@ void __split_page_owner(struct page *page, int old_order, int new_order)

void __folio_copy_owner(struct folio *newfolio, struct folio *old)
{
int i;
struct page_ext *old_ext;
struct page_ext *new_ext;
struct page_owner *old_page_owner;
struct page_owner *new_page_owner;
depot_stack_handle_t migrate_handle;

old_ext = page_ext_get(&old->page);
if (unlikely(!old_ext))
Expand All @@ -381,6 +384,8 @@ void __folio_copy_owner(struct folio *newfolio, struct folio *old)
}

old_page_owner = get_page_owner(old_ext);
new_page_owner = get_page_owner(new_ext);
migrate_handle = new_page_owner->handle;
__update_page_owner_handle(new_ext, old_page_owner->handle,
old_page_owner->order, old_page_owner->gfp_mask,
old_page_owner->last_migrate_reason,
Expand All @@ -395,6 +400,16 @@ void __folio_copy_owner(struct folio *newfolio, struct folio *old)
old_page_owner->free_pid,
old_page_owner->free_tgid,
old_page_owner->free_ts_nsec);
/*
* We linked the original stack to the new folio, we need to do the same
* for the new one and the old folio otherwise there will be an imbalance
* when subtracting those pages from the stack.
*/
for (i = 0; i < (1 << new_page_owner->order); i++) {
old_page_owner->handle = migrate_handle;
old_ext = page_ext_next(old_ext);
old_page_owner = get_page_owner(old_ext);
}

page_ext_put(new_ext);
page_ext_put(old_ext);
Expand Down

0 comments on commit 718b1f3

Please sign in to comment.