staticinlinevoid set_current_in_page_owner(void)
{ /* * Avoid recursion. * * We might need to allocate more memory from page_owner code, so make * sure to signal it in order to avoid recursion.
*/
current->in_page_owner = 1;
}
spin_lock_irqsave(&stack_list_lock, flags);
stack->next = stack_list; /* * This pairs with smp_load_acquire() from function * stack_start(). This guarantees that stack_start() * will see an updated stack_list before starting to * traverse the list.
*/
smp_store_release(&stack_list, stack);
spin_unlock_irqrestore(&stack_list_lock, flags);
}
/* * New stack_record's that do not use STACK_DEPOT_FLAG_GET start * with REFCOUNT_SATURATED to catch spurious increments of their * refcount. * Since we do not use STACK_DEPOT_FLAG_GET API, let us * set a refcount of 1 ourselves.
*/ if (refcount_read(&stack_record->count) == REFCOUNT_SATURATED) { int old = REFCOUNT_SATURATED;
if (atomic_try_cmpxchg_relaxed(&stack_record->count.refs, &old, 1)) /* Add the new stack_record to our list */
add_stack_record_to_list(stack_record, gfp_mask);
}
refcount_add(nr_base_pages, &stack_record->count);
}
/* * Do not specify GFP_NOWAIT to make gfpflags_allow_spinning() == false * to prevent issues in stack_depot_save(). * This is similar to alloc_pages_nolock() gfp flags, but only used * to signal stack_depot to avoid spin_locks.
*/
handle = save_stack(__GFP_NOWARN);
__update_page_owner_free_handle(page, handle, order, current->pid,
current->tgid, free_ts_nsec);
if (alloc_handle != early_handle) /* * early_handle is being set as a handle for all those * early allocated pages. See init_pages_in_zone(). * Since their refcount is not being incremented because * the machinery is not ready yet, we cannot decrement * their refcount either.
*/
dec_stack_record_count(alloc_handle, 1 << order);
}
migrate_handle = new_page_owner->handle;
__update_page_owner_handle(&newfolio->page, old_page_owner->handle,
old_page_owner->order, old_page_owner->gfp_mask,
old_page_owner->last_migrate_reason,
old_page_owner->ts_nsec, old_page_owner->pid,
old_page_owner->tgid, old_page_owner->comm); /* * Do not proactively clear PAGE_EXT_OWNER{_ALLOCATED} bits as the folio * will be freed after migration. Keep them until then as they may be * useful.
*/
__update_page_owner_free_handle(&newfolio->page, 0, old_page_owner->order,
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.
*/
rcu_read_lock();
for_each_page_ext(&old->page, 1 << new_page_owner->order, page_ext, iter) {
old_page_owner = get_page_owner(page_ext);
old_page_owner->handle = migrate_handle;
}
rcu_read_unlock();
}
/* Scan block by block. First and last block may be incomplete */
pfn = zone->zone_start_pfn;
/* * Walk the zone in pageblock_nr_pages steps. If a page block spans * a zone boundary, it will be double counted between zones. This does * not matter as the mixed block count will still be correct
*/ for (; pfn < end_pfn; ) {
page = pfn_to_online_page(pfn); if (!page) {
pfn = ALIGN(pfn + 1, MAX_ORDER_NR_PAGES); continue;
}
ret = scnprintf(kbuf, count, "Page allocated via order %u, mask %#x(%pGg), pid %d, tgid %d (%s), ts %llu ns\n",
page_owner->order, page_owner->gfp_mask,
&page_owner->gfp_mask, page_owner->pid,
page_owner->tgid, page_owner->comm,
page_owner->ts_nsec);
/* Print information relevant to grouping pages by mobility */
pageblock_mt = get_pageblock_migratetype(page);
page_mt = gfp_migratetype(page_owner->gfp_mask);
ret += scnprintf(kbuf + ret, count - ret, "PFN 0x%lx type %s Block %lu type %s Flags %pGp\n",
pfn,
migratetype_names[page_mt],
pfn >> pageblock_order,
migratetype_names[pageblock_mt],
&page->flags);
ret += stack_depot_snprint(handle, kbuf + ret, count - ret, 0); if (ret >= count) goto err;
if (page_owner->last_migrate_reason != -1) {
ret += scnprintf(kbuf + ret, count - ret, "Page has been migrated, last migrate reason: %s\n",
migrate_reason_names[page_owner->last_migrate_reason]);
}
ret = print_page_owner_memcg(kbuf, count, ret, page);
ret += snprintf(kbuf + ret, count - ret, "\n"); if (ret >= count) goto err;
if (!test_bit(PAGE_EXT_OWNER, &page_ext->flags)) {
pr_alert("page_owner info is not present (never set?)\n");
page_ext_put(page_ext); return;
}
if (test_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags))
pr_alert("page_owner tracks the page as allocated\n"); else
pr_alert("page_owner tracks the page as freed\n");
pr_alert("page last allocated via order %u, migratetype %s, gfp_mask %#x(%pGg), pid %d, tgid %d (%s), ts %llu, free_ts %llu\n",
page_owner->order, migratetype_names[mt], gfp_mask, &gfp_mask,
page_owner->pid, page_owner->tgid, page_owner->comm,
page_owner->ts_nsec, page_owner->free_ts_nsec);
if (page_owner->last_migrate_reason != -1)
pr_alert("page has been migrated, last migrate reason: %s\n",
migrate_reason_names[page_owner->last_migrate_reason]);
page_ext_put(page_ext);
}
if (!static_branch_unlikely(&page_owner_inited)) return -EINVAL;
page = NULL; if (*ppos == 0)
pfn = min_low_pfn; else
pfn = *ppos; /* Find a valid PFN or the start of a MAX_ORDER_NR_PAGES area */ while (!pfn_valid(pfn) && (pfn & (MAX_ORDER_NR_PAGES - 1)) != 0)
pfn++;
/* Find an allocated page */ for (; pfn < max_pfn; pfn++) { /* * This temporary page_owner is required so * that we can avoid the context switches while holding * the rcu lock and copying the page owner information to * user through copy_to_user() or GFP_KERNEL allocations.
*/ struct page_owner page_owner_tmp;
/* * If the new page is in a new MAX_ORDER_NR_PAGES area, * validate the area as existing, skip it if not
*/ if ((pfn & (MAX_ORDER_NR_PAGES - 1)) == 0 && !pfn_valid(pfn)) {
pfn += MAX_ORDER_NR_PAGES - 1; continue;
}
page = pfn_to_page(pfn); if (PageBuddy(page)) { unsignedlong freepage_order = buddy_order_unsafe(page);
page_ext = page_ext_get(page); if (unlikely(!page_ext)) continue;
/* * Some pages could be missed by concurrent allocation or free, * because we don't hold the zone lock.
*/ if (!test_bit(PAGE_EXT_OWNER, &page_ext->flags)) goto ext_put_continue;
/* * Although we do have the info about past allocation of free * pages, it's not relevant for current memory usage.
*/ if (!test_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags)) goto ext_put_continue;
page_owner = get_page_owner(page_ext);
/* * Don't print "tail" pages of high-order allocations as that * would inflate the stats.
*/ if (!IS_ALIGNED(pfn, 1 << page_owner->order)) goto ext_put_continue;
/* * Access to page_ext->handle isn't synchronous so we should * be careful to access it.
*/
handle = READ_ONCE(page_owner->handle); if (!handle) goto ext_put_continue;
/* Record the next PFN to read in the file offset */
*ppos = pfn + 1;
/* * Walk the zone in pageblock_nr_pages steps. If a page block spans * a zone boundary, it will be double counted between zones. This does * not matter as the mixed block count will still be correct
*/ for (; pfn < end_pfn; ) { unsignedlong block_end_pfn;
/* * To avoid having to grab zone->lock, be a little * careful when reading buddy page order. The only * danger is that we skip too much and potentially miss * some early allocated pages, which is better than * heavy lock contention.
*/ if (PageBuddy(page)) { unsignedlong order = buddy_order_unsafe(page);
if (order > 0 && order <= MAX_PAGE_ORDER)
pfn += (1UL << order) - 1; continue;
}
if (PageReserved(page)) continue;
page_ext = page_ext_get(page); if (unlikely(!page_ext)) continue;
/* Maybe overlapping zone */ if (test_bit(PAGE_EXT_OWNER, &page_ext->flags)) goto ext_put_continue;
if (!*ppos) { /* * This pairs with smp_store_release() from function * add_stack_record_to_list(), so we get a consistent * value of stack_list.
*/
stack = smp_load_acquire(&stack_list);
m->private = stack;
} else {
stack = m->private;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.