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 D4A0B158538 for ; Fri, 5 Dec 2025 23:18:03 +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=1764976685; cv=none; b=cLpcfvz6SDPikOaBo3ii2aJ+E7bM2rM+JMdMR54NlqyrC0tZhMlTzDz3zNcJ1rrC2AwQeZh8yjl21UkkXzpqWOF0c2ObRxhAQ2jE6Rpkx6jEXpUOJIMhLMm+w0GWbiRP1J174gcK8Nc28b8l5Wg62E9dgnj9VrUMScgPB156CVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764976685; c=relaxed/simple; bh=Q7WECKEhdotJxOvfGvFOaK2nUyIXhYpdy7mbn0g5G4Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XayjfvJ4dPpv4gCQAaMHD1CVrZ40YaSFqopbP3OZodrESW6lbx5UZJVy5YbznB15n23ir48zVhIaNeFlfk8HGIHkm9WCihBWea1NiIEi97gcx26UPbXYYNuxNiJcXAB7w9JJGv7IgSEa77p7fBOhCn4hyEDxJd6EsudMK95lcHk= 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=hWRsVDh8; 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="hWRsVDh8" 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=5m86uI6zdc31l9i8DWlMxNqeujbcKifkCUIGcK+zMg4=; b=hWRsVDh8tHiVgbUP0WgUSUIE54 3mH+wH+c0mTMavD4noFY+F0LqtExnfdrJx6JDaRMlsM6CC9Nz/LuACLvJ1zYG0GWch1f19PdDXbQa a8A2W/Mkg8KLmuDPFiO5QRF+K1nf3GW+IC1pGUyo7ip3rSA7n5H0aQODPsh/etu/8RhWDQOh8lLdQ nTLaae9I9wl6E1MV1R+RiwK8NO1wNKkKJPBllifhC8t6gLlC3C1vMjUpDtAwSYPUDRP2OYPnP6hm8 YjmgTu6pBLapclrJcmv1J2jh2YPi7a7Wm4000qq2gA/WhJYQqlPUA2GfEpE8LDAMwf3akeA9mkzSu 2uhSUkNQ==; 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 1vRf3i-009H1j-Vc; Sat, 06 Dec 2025 00:17:55 +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 7/9] mm/page_owner: add debugfs file 'swap_page_owner' Date: Fri, 5 Dec 2025 20:17:19 -0300 Message-ID: <20251205231721.104505-8-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" Add debugfs file /sys/kernel/debug/swap_page_owner to report the allocation stack traces for pages in swap space (i.e., dump the XArray). Now, it is possible to list the allocation stack traces both for pages in memory and swap space, via /sys/kernel/debug/{page_owner,swap_page_owner}. Signed-off-by: Mauricio Faria de Oliveira --- mm/page_owner.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/mm/page_owner.c b/mm/page_owner.c index 589aa1d7b9b6..e014eb7caf56 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -1103,6 +1103,77 @@ static const struct file_operations page_owner_fops = =3D { .llseek =3D lseek_page_owner, }; =20 +#ifdef CONFIG_SWAP_PAGE_OWNER +static ssize_t print_swap_page_owner(char __user *buf, size_t count, + swp_entry_t entry, + struct swap_page_owner *spo) +{ + int ret; + char *kbuf; + + count =3D min_t(size_t, count, PAGE_SIZE); + kbuf =3D kmalloc(count, GFP_KERNEL); + if (!kbuf) + return -ENOMEM; + + ret =3D scnprintf(kbuf, count, + "Page allocated via pid %d, tgid %d (%s), ts %llu ns\n", + spo->pid, spo->tgid, spo->comm, spo->ts_nsec); + + ret +=3D scnprintf(kbuf + ret, count - ret, + "SWP entry 0x%lx\n", entry.val); + + ret +=3D stack_depot_snprint(spo->handle, kbuf + ret, count - ret, 0); + if (ret >=3D count) + goto err; + + ret +=3D snprintf(kbuf + ret, count - ret, "\n"); + if (ret >=3D count) + goto err; + + if (copy_to_user(buf, kbuf, ret)) + ret =3D -EFAULT; + + kfree(kbuf); + return ret; + +err: + kfree(kbuf); + return -ENOMEM; +} + +static ssize_t read_swap_page_owner(struct file *file, char __user *buf, + size_t count, loff_t *ppos) +{ + swp_entry_t entry =3D { .val =3D *ppos }; + void *spo; + XA_STATE(xa_state, &swap_page_owners, entry.val); + + if (!static_branch_unlikely(&swap_page_owner_inited)) + return -EINVAL; + + xa_lock(&swap_page_owners); + xas_for_each(&xa_state, spo, ULONG_MAX) { + + /* Resume after current index. */ + entry.val =3D xa_state.xa_index; + *ppos =3D entry.val + 1; + + xa_unlock(&swap_page_owners); + return print_swap_page_owner(buf, count, entry, + (struct swap_page_owner *) spo); + } + xa_unlock(&swap_page_owners); + + return 0; +} + +static const struct file_operations swap_page_owner_fops =3D { + .read =3D read_swap_page_owner, + .llseek =3D lseek_page_owner, +}; +#endif + static void *stack_start(struct seq_file *m, loff_t *ppos) { struct stack *stack; @@ -1247,6 +1318,10 @@ static int __init pageowner_init(void) &page_owner_stack_fops); debugfs_create_file("count_threshold", 0600, dir, NULL, &page_owner_threshold_fops); +#ifdef CONFIG_SWAP_PAGE_OWNER + debugfs_create_file("swap_page_owner", 0400, NULL, NULL, + &swap_page_owner_fops); +#endif return 0; } late_initcall(pageowner_init) --=20 2.51.0