From nobody Wed Dec 17 06:14:33 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5DDC280CD5 for ; Fri, 5 Dec 2025 23:17:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764976678; cv=none; b=qYAse+gsvJWkBeiQQo5fpCD8YT+wYX7g+ikdaCtqYy9SVWxhhdOov9hdl3pDzz6ItbPKJegn4cVMc9fNn7d/edtWk8tFHTJN+gEYU8RYTRyIJMh3YPBcv2TU5jx7R6v50IFBLdHPgTw1ONtcZBxc8S8wrOWWGAPnuxfaSAak/xg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764976678; c=relaxed/simple; bh=nan9KhpEFlsVFTp0olruXscdrml2t6+ev+P1z4h2ov8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QPaykG2UpIWE2uC99TzCWFT3Zs6pJcQtaGiiaO5z8Cc5kBHFNTrI/uZLLD6mzOws7CSHw2mv6DCRTdTf6+Rn6a4V2pyKheXIKeju2VKI0Q+NqJXYEWFq0h2QaggCJ3r0IF1Pg+39Ju8kwGtsh51Aerz4T1sGIyM94RvMxgrwlBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=J0Kfx8j6; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="J0Kfx8j6" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Be4md6ScQBymbi4Un/wkCf1ZzGb3QrWFfwvJYmGp4QA=; b=J0Kfx8j6qgmtxY2QGR5psVlUo0 Qwq0ArB/OGaW+IIfAvafvihpE35uu3wwoNtff08tnGmd0Jw2Q6fKNOb4P6KcT98Zqj4Q3Zrc7wNuN hw0zTiLhHuwPydsGufe5WK3mwgWtqZwmMjR87MSY5SoWQit6RFZJMVjBmFOzhpox893jNm7nncDC5 bgq+RX+oLqnm0NSaMm/5IAhOpa2V3lttNq5pW9hL435oVes9BY+N7zE6nC2IMVMFGcYu2NW6RwLSJ J+7Ey35oI6ZEbBITAz2j4FvHMR5p5T6c9a14QDopQN6ykkhYgn7Wai3JzeGGB2OZa+Be49/r5L1uT Au90KcPw==; Received: from 186-249-144-101.shared.desktop.com.br ([186.249.144.101] helo=t470) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1vRf3f-009H1j-6A; Sat, 06 Dec 2025 00:17:51 +0100 From: Mauricio Faria de Oliveira To: Andrew Morton , David Hildenbrand Cc: Lorenzo Stoakes , Michal Hocko , Vlastimil Babka , Oscar Salvador , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com Subject: [PATCH RFC 6/9] mm/page_owner: report '(swapped)' pages in debugfs file 'page_owner' Date: Fri, 5 Dec 2025 20:17:18 -0300 Message-ID: <20251205231721.104505-7-mfo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251205231721.104505-1-mfo@igalia.com> References: <20251205231721.104505-1-mfo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Report whether a page has been swapped in /sys/kernel/debug/page_owner. This is helpful for stats, verifying the functionality, and debugging. Add the 'swapped' field to 'struct page_owner' to track whether the page has been swapped-in (and had allocation stack and some fields overridden). Clear it via __set_page_owner() (page allocation), __reset_page_owner() (page free), and init_pages_in_zone() (init). Set it in the swap_restore() swap hook (swap-in). Signed-off-by: Mauricio Faria de Oliveira --- mm/page_owner.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index d256f58deca4..589aa1d7b9b6 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -34,6 +34,9 @@ struct page_owner { pid_t tgid; pid_t free_pid; pid_t free_tgid; +#ifdef CONFIG_SWAP_PAGE_OWNER + bool swapped; +#endif }; =20 struct stack { @@ -275,7 +278,8 @@ static inline void __update_page_owner_handle(struct pa= ge *page, unsigned short order, gfp_t gfp_mask, short last_migrate_reason, u64 ts_nsec, - pid_t pid, pid_t tgid, char *comm) + pid_t pid, pid_t tgid, char *comm, + bool __maybe_unused swapped) { struct page_ext_iter iter; struct page_ext *page_ext; @@ -293,6 +297,9 @@ static inline void __update_page_owner_handle(struct pa= ge *page, page_owner->ts_nsec =3D ts_nsec; strscpy(page_owner->comm, comm, sizeof(page_owner->comm)); +#ifdef CONFIG_SWAP_PAGE_OWNER + page_owner->swapped =3D swapped; +#endif __set_bit(PAGE_EXT_OWNER, &page_ext->flags); __set_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags); } @@ -316,6 +323,9 @@ static inline void __update_page_owner_free_handle(stru= ct page *page, if (handle) { __clear_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags); page_owner->free_handle =3D handle; +#ifdef CONFIG_SWAP_PAGE_OWNER + page_owner->swapped =3D false; +#endif } page_owner->free_ts_nsec =3D free_ts_nsec; page_owner->free_pid =3D current->pid; @@ -370,7 +380,7 @@ noinline void __set_page_owner(struct page *page, unsig= ned short order, handle =3D save_stack(gfp_mask); __update_page_owner_handle(page, handle, order, gfp_mask, -1, ts_nsec, current->pid, current->tgid, - current->comm); + current->comm, false); inc_stack_record_count(handle, gfp_mask, 1 << order); } =20 @@ -428,7 +438,13 @@ void __folio_copy_owner(struct folio *newfolio, struct= folio *old) 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); + old_page_owner->tgid, old_page_owner->comm, +#ifdef CONFIG_SWAP_PAGE_OWNER + old_page_owner->swapped +#else + false +#endif + ); /* * 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 @@ -602,6 +618,7 @@ void __page_owner_swap_restore(swp_entry_t entry, struc= t folio *folio) =20 page_owner =3D get_page_owner(page_ext); copy_from_swap_page_owner(page_owner, spo); + page_owner->swapped =3D true; =20 if (!handle) handle =3D page_owner->handle; @@ -783,12 +800,20 @@ print_page_owner(char __user *buf, size_t count, unsi= gned long pfn, return -ENOMEM; =20 ret =3D scnprintf(kbuf, count, - "Page allocated via order %u, mask %#x(%pGg), pid %d, tgid %d (%s), ts = %llu ns\n", + "Page allocated via order %u, mask %#x(%pGg), pid %d, tgid %d (%s), ts = %llu ns", page_owner->order, page_owner->gfp_mask, &page_owner->gfp_mask, page_owner->pid, page_owner->tgid, page_owner->comm, page_owner->ts_nsec); =20 +#ifdef CONFIG_SWAP_PAGE_OWNER + if (static_branch_unlikely(&swap_page_owner_inited) && + page_owner->swapped) { + ret +=3D scnprintf(kbuf + ret, count - ret, " (swapped)"); + } +#endif + ret +=3D scnprintf(kbuf + ret, count - ret, "\n"); + /* Print information relevant to grouping pages by mobility */ pageblock_mt =3D get_pageblock_migratetype(page); page_mt =3D gfp_migratetype(page_owner->gfp_mask); @@ -1052,7 +1077,8 @@ static void init_pages_in_zone(struct zone *zone) /* Found early allocated page */ __update_page_owner_handle(page, early_handle, 0, 0, -1, local_clock(), current->pid, - current->tgid, current->comm); + current->tgid, current->comm, + false); count++; ext_put_continue: page_ext_put(page_ext); --=20 2.51.0