linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mauricio Faria de Oliveira <mfo@igalia.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Michal Hocko <mhocko@suse.com>, Vlastimil Babka <vbabka@suse.cz>,
	Oscar Salvador <osalvador@suse.de>,
	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	[thread overview]
Message-ID: <20251205231721.104505-7-mfo@igalia.com> (raw)
In-Reply-To: <20251205231721.104505-1-mfo@igalia.com>

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 <mfo@igalia.com>
---
 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
 };
 
 struct stack {
@@ -275,7 +278,8 @@ static inline void __update_page_owner_handle(struct page *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 page *page,
 		page_owner->ts_nsec = ts_nsec;
 		strscpy(page_owner->comm, comm,
 			sizeof(page_owner->comm));
+#ifdef CONFIG_SWAP_PAGE_OWNER
+		page_owner->swapped = 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(struct page *page,
 		if (handle) {
 			__clear_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags);
 			page_owner->free_handle = handle;
+#ifdef CONFIG_SWAP_PAGE_OWNER
+			page_owner->swapped = false;
+#endif
 		}
 		page_owner->free_ts_nsec = free_ts_nsec;
 		page_owner->free_pid = current->pid;
@@ -370,7 +380,7 @@ noinline void __set_page_owner(struct page *page, unsigned short order,
 	handle = 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);
 }
 
@@ -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, struct folio *folio)
 
 		page_owner = get_page_owner(page_ext);
 		copy_from_swap_page_owner(page_owner, spo);
+		page_owner->swapped = true;
 
 		if (!handle)
 			handle = page_owner->handle;
@@ -783,12 +800,20 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn,
 		return -ENOMEM;
 
 	ret = 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);
 
+#ifdef CONFIG_SWAP_PAGE_OWNER
+	if (static_branch_unlikely(&swap_page_owner_inited) &&
+	    page_owner->swapped) {
+		ret += scnprintf(kbuf + ret, count - ret, " (swapped)");
+	}
+#endif
+	ret += scnprintf(kbuf + ret, count - ret, "\n");
+
 	/* Print information relevant to grouping pages by mobility */
 	pageblock_mt = get_pageblock_migratetype(page);
 	page_mt  = 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);
-- 
2.51.0



  parent reply	other threads:[~2025-12-05 23:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-05 23:17 [PATCH RFC 0/9] mm/page_owner: add support for pages in swap space Mauricio Faria de Oliveira
2025-12-05 23:17 ` [PATCH RFC 1/9] mm: add config option SWAP_PAGE_OWNER Mauricio Faria de Oliveira
2025-12-05 23:17 ` [PATCH RFC 2/9] mm/page_owner: add parameter option 'page_owner=on,swap' Mauricio Faria de Oliveira
2025-12-05 23:17 ` [PATCH RFC 3/9] mm/page_owner: add 'struct swap_page_owner' and helpers Mauricio Faria de Oliveira
2025-12-05 23:17 ` [PATCH RFC 4/9] mm/page_owner: add 'xarray swap_page_owners' " Mauricio Faria de Oliveira
2025-12-05 23:17 ` [PATCH RFC 5/9] mm/page_owner: add swap hooks Mauricio Faria de Oliveira
2025-12-05 23:17 ` Mauricio Faria de Oliveira [this message]
2025-12-05 23:17 ` [PATCH RFC 7/9] mm/page_owner: add debugfs file 'swap_page_owner' Mauricio Faria de Oliveira
2025-12-05 23:17 ` [PATCH RFC 8/9] mm: call arch-specific swap hooks from generic swap hooks Mauricio Faria de Oliveira
2025-12-05 23:17 ` [PATCH RFC 9/9] mm: call page_owner " Mauricio Faria de Oliveira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251205231721.104505-7-mfo@igalia.com \
    --to=mfo@igalia.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=kernel-dev@igalia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=osalvador@suse.de \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox