Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 718b1f3

Browse files
osalvadorvilardagaakpm00
authored andcommitted
mm,page_owner: fix accounting of pages when migrating
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]>
1 parent f5c1210 commit 718b1f3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

mm/page_owner.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,12 @@ void __split_page_owner(struct page *page, int old_order, int new_order)
366366

367367
void __folio_copy_owner(struct folio *newfolio, struct folio *old)
368368
{
369+
int i;
369370
struct page_ext *old_ext;
370371
struct page_ext *new_ext;
371372
struct page_owner *old_page_owner;
373+
struct page_owner *new_page_owner;
374+
depot_stack_handle_t migrate_handle;
372375

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

383386
old_page_owner = get_page_owner(old_ext);
387+
new_page_owner = get_page_owner(new_ext);
388+
migrate_handle = new_page_owner->handle;
384389
__update_page_owner_handle(new_ext, old_page_owner->handle,
385390
old_page_owner->order, old_page_owner->gfp_mask,
386391
old_page_owner->last_migrate_reason,
@@ -395,6 +400,16 @@ void __folio_copy_owner(struct folio *newfolio, struct folio *old)
395400
old_page_owner->free_pid,
396401
old_page_owner->free_tgid,
397402
old_page_owner->free_ts_nsec);
403+
/*
404+
* We linked the original stack to the new folio, we need to do the same
405+
* for the new one and the old folio otherwise there will be an imbalance
406+
* when subtracting those pages from the stack.
407+
*/
408+
for (i = 0; i < (1 << new_page_owner->order); i++) {
409+
old_page_owner->handle = migrate_handle;
410+
old_ext = page_ext_next(old_ext);
411+
old_page_owner = get_page_owner(old_ext);
412+
}
398413

399414
page_ext_put(new_ext);
400415
page_ext_put(old_ext);

0 commit comments

Comments
 (0)