From nobody Wed Dec 17 04:20:30 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 815D31684B4 for ; Fri, 5 Dec 2025 23:17:40 +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=1764976662; cv=none; b=q7/c7U+8EGPq9oGdtx9TApSySs9gvY5EtaiwsMktr70w9h0Qt25bTDj7y6j1fb/GELw97geTqOCFBmrdCMKJDApjCpdQglG+auKKZ7Rhn7L4wWOAOZneKkswXpMZUXpoMzhbb2I8q+cJnO2ffKqO0+Mr3ef4Wzfhgk/Quf+YnL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764976662; c=relaxed/simple; bh=fxaa5V7GeSrLrVyDaBXlqsmoqlCyemWaoEB6MYLLWZA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dcuzwv2mcm96eTsb/i0zkGOdyCa9587C04VTB4EVXy4EhhGe2IVbcOrjIs0cXE/xEtn5kewNWGZV0V32pUBrpFcY8vZHswNkbRo7Tx2bjKv6fPbpA5M3mFVbRgmqUXe65CBHAKQF686fqP2qaa3ZZisOK7L3qKWbxczT1FqUI2k= 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=hfF1JjKI; 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="hfF1JjKI" 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=tyEwemb7ChIFBMVkjszwjx9ZHzXx/zdKDJEwXVAG4Hc=; b=hfF1JjKIt+5N7QC9PdF0ma/KNM XUkV005Wzyo6znqnayCw/CPcZDrqmb8NtxxkYJV6XP0pYvj+AuWCkvErSnXKdfzgZJQtRV2sA6c6n b7V55udzFShRG+QW37aovTaGk6DWJthQp2OjpV/xOx3Bj+wZ7Q0pZwT6TdlwbHj3x2yfYlW8bw2ny 2oDCsajU0T/9fOkjtd/AKX0+G0x264dK2/zlK/2FKIdnvVV5xXNOw7iLX7LFwg4hu4Kj/osFwHXvU zl1B1CvZVSDAJ/HoG11lx83WBhcAmzLry3VZgPermw4Rcm/uaZgFH2DEIjKcFIzreDO3m5GOJ2NJT 2LtlGqeQ==; 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 1vRf3L-009H1j-0c; Sat, 06 Dec 2025 00:17:31 +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 1/9] mm: add config option SWAP_PAGE_OWNER Date: Fri, 5 Dec 2025 20:17:13 -0300 Message-ID: <20251205231721.104505-2-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 config option for page_owner support for pages in swap space. Signed-off-by: Mauricio Faria de Oliveira --- mm/Kconfig.debug | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug index 7638d75b27db..60bc0b6c3d69 100644 --- a/mm/Kconfig.debug +++ b/mm/Kconfig.debug @@ -119,6 +119,15 @@ config PAGE_OWNER =20 If unsure, say N. =20 +config SWAP_PAGE_OWNER + bool "Track page owner in swap space (EXPERIMENTAL)" + depends on PAGE_OWNER + help + This also keeps track of what call chain is the owner of a page + in swap space, maintaining the initial call chain over swap-out + and swap-in (otherwise lost at swap-out and reset at swap-in). + You should pass the "page_owner=3Don,swap" parameter to enable it. + config PAGE_TABLE_CHECK bool "Check for invalid mappings in user page tables" depends on ARCH_SUPPORTS_PAGE_TABLE_CHECK --=20 2.51.0 From nobody Wed Dec 17 04:20:30 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 C11562236F2 for ; Fri, 5 Dec 2025 23:17:42 +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=1764976664; cv=none; b=P3EcIJhmFYg8iO9czgw/uv05Nk8Yd8FKOgmUfnh1QxbO+QhIW5sZX6Cqm6mDNqiQaeWXwsF4sCRe6/n6gIdfn3ubGI7hWLt+ahNBn6lUdwwoOPDfm+sOgsLsXxRZdR4nAxgjpAKjWX8/fVRiYr1M2rE40/+X679FdfzWOfUPsSQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764976664; c=relaxed/simple; bh=ifSb8nlq9nVAyzV/KdKH4t+CZwG7Fr66ThermYs8kOM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b8LnJVtaIcMa5pvnuhnoGFuDpDFbAjZePfwp+FqHBoBZ3UgvTHvZmklgMKzFv73D7CFOmjgJWDf+N4tSurHz8Z5LerTsuM8Z2CyD2X/ceqQ57e1EuQ6oVLsNkU/3wF4BksnzcWN+Bxtcl4CdOoOjCjWkFw8aKpVQ3s3HpQzLFBU= 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=UDTOFCyk; 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="UDTOFCyk" 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=ejrce1XdxpWJWHE5Wtt1V02tXeXE+vjGDq8qzCrERNM=; b=UDTOFCykey2R4x2elUbcoVM3Rz MyYhKVZ/cUjO++zOwSPvfeiWj/kUke3gfaRIGzNP74ZI5YSuPqgPFX8IR2i7vOfslE+++i0/Fx5At YIJQvjSD6hSqmVX0lEZkxp4m8WUvW2AfRGRsRhD9urL9prArVeXKT46tqDebyx4ASMFX7A5Iw20rg Kau5ByoyZB++7okKue5brOeEzqXy9gEuv8RctToi9OqpawawA06uUpt+gGM4vns/f01WuRBwmvWdw TwjmqIm4uHHxjoUOb3rCwxCL1beCuLt5cH/DjulA2LeFDz0SmEzCpxIVp5kaRx03fe57afvIyOfbl YHAGRsMA==; 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 1vRf3P-009H1j-0J; Sat, 06 Dec 2025 00:17:35 +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 2/9] mm/page_owner: add parameter option 'page_owner=on,swap' Date: Fri, 5 Dec 2025 20:17:14 -0300 Message-ID: <20251205231721.104505-3-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" CONFIG_SWAP_PAGE_OWNER will introduce a behavior change in page_owner on systems with swap space. Thus, add the 'swap' option to the 'page_owner' parameter to enable it ('page_owner=3Don,swap'). Currently, the allocation stack trace of a page is lost at swap-out (the page is freed) and reset at swap-in (a new page is allocated). With the new feature, if this option is enabled, the (initial) allocation stack trace of a page is maintained over swap-out and swap-in, and the refcounts for the initial and swap-in allocation stack traces are adjusted. (Note: 'swap_page_owner_enabled' is parsed before 'page_owner_enabled', so 'page_owner=3Doff,swap' could set the former but not the latter, but this is a nop as then init_page_owner() returns early and doesn't enable anything.) Signed-off-by: Mauricio Faria de Oliveira --- mm/page_owner.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index a70245684206..a27958872b07 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -57,6 +57,11 @@ struct stack_print_ctx { static bool page_owner_enabled __initdata; DEFINE_STATIC_KEY_FALSE(page_owner_inited); =20 +#ifdef CONFIG_SWAP_PAGE_OWNER +static bool swap_page_owner_enabled __initdata; +DEFINE_STATIC_KEY_FALSE(swap_page_owner_inited); +#endif + static depot_stack_handle_t dummy_handle; static depot_stack_handle_t failure_handle; static depot_stack_handle_t early_handle; @@ -81,7 +86,18 @@ static inline void unset_current_in_page_owner(void) =20 static int __init early_page_owner_param(char *buf) { - int ret =3D kstrtobool(buf, &page_owner_enabled); + int ret; + +#ifdef CONFIG_SWAP_PAGE_OWNER + char *swap =3D strchr(buf, ','); + + if (swap) { + *swap++ =3D '\0'; + if (!strcmp(swap, "swap")) + swap_page_owner_enabled =3D true; + } +#endif + ret =3D kstrtobool(buf, &page_owner_enabled); =20 if (page_owner_enabled) stack_depot_request_early_init(); @@ -138,6 +154,10 @@ static __init void init_page_owner(void) dummy_stack.next =3D &failure_stack; stack_list =3D &dummy_stack; static_branch_enable(&page_owner_inited); +#ifdef CONFIG_SWAP_PAGE_OWNER + if (swap_page_owner_enabled) + static_branch_enable(&swap_page_owner_inited); +#endif } =20 struct page_ext_operations page_owner_ops =3D { --=20 2.51.0 From nobody Wed Dec 17 04:20:30 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 37A4A2FFFA4 for ; Fri, 5 Dec 2025 23:17:47 +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=1764976668; cv=none; b=DjY3eohIlmmsA0nrhvVJfDKccPyDkP+JVwVtVNd4plACbwrKQ60vp+gptgWIczSY1z4fY9ubJOK4ZnDVWc+GjAwHW66T6L7tjHcyLQaSfkKjDO2FXl49AVv4tpRIzth6+2drlLBkAH+bvfP8Omf/VXslOvVgAg7O1bu3TUKWLGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764976668; c=relaxed/simple; bh=c0SAIzpwWkQlWyLinhvIsYFal6Ucs3Inp2r6Xv+YCVk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NlYNujGa/wvCT1HvQf4XSk9ZmvfIGROKYpnF8mV+oXqEdHbV+HFjo0TmpsrwSAz+3/Hvm2Y57n5MLLDLwitLhLzTWsJomOnmf4m3l2lOOiVyx5KM2q/2g2f6XXamEmWCmYtzFDbGe1/pCCa3vOjpGf/QUDJqF/13SaobfXxzzsI= 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=MFRhopnH; 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="MFRhopnH" 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=6hgIhBjkcBdOpG4pdp5wLt2KON9r3FFTvP5A6zlmIso=; b=MFRhopnH0jY1D0S/Z7/HGXAz9z AFJgXWhDxsUzmz92x1f4LKTC2qYf2lf1Z07OBMpR0twyEDFI5y+OwCwfzkogf2q/aJsxxxC8A0wjR 9CpvorI1iExQ4K0v65ktrD1/4JEh1uR/sJVA8CF5Xt9G16IudoEKzoz6EOSGO0q4lo86oePKMjPMx G21vcrDKoOUITCUgrt9LmHA0tv8a3crh6EOzTYB4EIRhLW6xzJzZrWKqk5sVGnsV8/LcnARmtJP7e Uz4epEM62N1glMmnmGvxMwATI25W1dP2NTKjBfzjY65GOjDNZ5naiCBzDynRM2xVQvU58GxsbPomF 2Bj5sBdQ==; 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 1vRf3T-009H1j-6j; Sat, 06 Dec 2025 00:17:39 +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 3/9] mm/page_owner: add 'struct swap_page_owner' and helpers Date: Fri, 5 Dec 2025 20:17:15 -0300 Message-ID: <20251205231721.104505-4-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 'struct swap_page_owner' to store the (initial) allocation stack trace and some attributes, plus helpers to allocate, free, and copy it to/from 'struct page_owner'. Signed-off-by: Mauricio Faria de Oliveira --- mm/page_owner.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/mm/page_owner.c b/mm/page_owner.c index a27958872b07..19ccbda1c2a4 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -60,6 +60,14 @@ DEFINE_STATIC_KEY_FALSE(page_owner_inited); #ifdef CONFIG_SWAP_PAGE_OWNER static bool swap_page_owner_enabled __initdata; DEFINE_STATIC_KEY_FALSE(swap_page_owner_inited); + +struct swap_page_owner { + depot_stack_handle_t handle; + u64 ts_nsec; + char comm[TASK_COMM_LEN]; + pid_t pid; + pid_t tgid; +}; #endif =20 static depot_stack_handle_t dummy_handle; @@ -442,6 +450,38 @@ void __folio_copy_owner(struct folio *newfolio, struct= folio *old) rcu_read_unlock(); } =20 +#ifdef CONFIG_SWAP_PAGE_OWNER +static void *alloc_swap_page_owner(void) +{ + return kmalloc(sizeof(struct swap_page_owner), GFP_KERNEL); +} + +static void free_swap_page_owner(void *spo) +{ + kfree(spo); +} + +static void copy_to_swap_page_owner(struct swap_page_owner *spo, + struct page_owner *page_owner) +{ + spo->handle =3D page_owner->handle; + spo->ts_nsec =3D page_owner->ts_nsec; + spo->pid =3D page_owner->pid; + spo->tgid =3D page_owner->tgid; + strscpy(spo->comm, page_owner->comm, sizeof(page_owner->comm)); +} + +static void copy_from_swap_page_owner(struct page_owner *page_owner, + struct swap_page_owner *spo) +{ + page_owner->handle =3D spo->handle; + page_owner->ts_nsec =3D spo->ts_nsec; + page_owner->pid =3D spo->pid; + page_owner->tgid =3D spo->tgid; + strscpy(page_owner->comm, spo->comm, sizeof(page_owner->comm)); +} +#endif + void pagetypeinfo_showmixedcount_print(struct seq_file *m, pg_data_t *pgdat, struct zone *zone) { --=20 2.51.0 From nobody Wed Dec 17 04:20:30 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 B39692BE639 for ; Fri, 5 Dec 2025 23:17:51 +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=1764976673; cv=none; b=TqSGIH/HWELtLOTnmI/Fy8JdXB1lenH8Gl//P4OBFjkH9LFgA//yUyg+hF9BHeWscEFMd9zieirgAJorQXSOKaPTzrMPDY5puOpdqcroZUCKQUWGMPNxAAEh/RhRoiPuW6SBuiWSf2RUZc1Bd3c1y8gGztr1jeHwMDhbpguKG60= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764976673; c=relaxed/simple; bh=INIwFHcOedJyjJPsYEI9J6IcJSRAJY2JmETRAFKFTz8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cf8GSzhm0oGDucrJ8muQKwwjm+qbpIl3V3+9TeqY4Eqic9L1NRNg8XSOkdNZbL39lAw1W/gHGFUSU0UE+3pOrWDBwfah0YdVnJ64ILgOpZ+lnTlg3dRxzoBqVdr44T8wKG9cxD9gveqfVaj+Yf9Ijzhc/2AKxsU6Hx+7rtfX1vI= 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=Mct+QkEM; 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="Mct+QkEM" 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=goR+WqcbB55j9ZAy/tMbooRHEqLXnxJL/84hfNlIvBI=; b=Mct+QkEMlaca0HtaZSx95oFN1Z yvNsIXWNEtGq0Ov1m72JaqurgvEV9AqdX54sLUzE1SbV/uK8d8wLOJ/oEpgDsm4XkPJ5BzKbog56W d5/ufYWCE6PfDfJMo6lIXK0UkrU3tk03rZlWpbcdu0VvL+JKDCYM7Ee8tnPIQ462P8q/eidpKhEQ7 GzNkfpVz0X6RsU/4FiIzaQNOy67RGrY2/9LsKHwmr1ps/klgNB8tQWC6uQxulMGstuVJIZxGsgQXh 7lsgB8ESnjNldrE1WXLEVQRFyEoAcK4TikSvZTDo4SpyS6nDf4wSPtqC0cwUn/8ICWKIF4ROIwYcV GpTH2new==; 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 1vRf3X-009H1j-6m; Sat, 06 Dec 2025 00:17:43 +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 4/9] mm/page_owner: add 'xarray swap_page_owners' and helpers Date: Fri, 5 Dec 2025 20:17:16 -0300 Message-ID: <20251205231721.104505-5-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 'xarray swap_page_owners' to index 'struct swap_page_owner' objects by key 'swp_entry_t', and helpers to store, load, and erase. This is used to track the allocation stack trace of pages in swap space. Signed-off-by: Mauricio Faria de Oliveira --- mm/page_owner.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/mm/page_owner.c b/mm/page_owner.c index 19ccbda1c2a4..5cd7de1f8023 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -68,6 +68,7 @@ struct swap_page_owner { pid_t pid; pid_t tgid; }; +static DEFINE_XARRAY(swap_page_owners); #endif =20 static depot_stack_handle_t dummy_handle; @@ -461,6 +462,50 @@ static void free_swap_page_owner(void *spo) kfree(spo); } =20 +static int store_swap_page_owner(struct swap_page_owner *spo, swp_entry_t = entry) +{ + /* lookup the swap entry.val from the page */ + void *ret =3D xa_store(&swap_page_owners, entry.val, spo, GFP_KERNEL); + + if (WARN(xa_is_err(ret), + "page_owner: swap: swp_entry not stored (%lu)\n", entry.val)) { + free_swap_page_owner(spo); + return xa_err(ret); + } else if (ret) { + /* Entry is being replaced, free the old entry */ + free_swap_page_owner(ret); + } + + return 0; +} + +static void *load_swap_page_owner(swp_entry_t entry) +{ + void *spo =3D xa_load(&swap_page_owners, entry.val); + + if (WARN(!spo, + "page_owner: swap: swp_entry not loaded (%lu)\n", entry.val)) + return NULL; + + return spo; +} + +static void erase_swap_page_owner(swp_entry_t entry, bool lock) +{ + void *spo; + + if (lock) + spo =3D xa_erase(&swap_page_owners, entry.val); + else + spo =3D __xa_erase(&swap_page_owners, entry.val); + + if (WARN(!spo, + "page_owner: swap: swp_entry not erased (%lu)\n", entry.val)) + return; + + free_swap_page_owner(spo); +} + static void copy_to_swap_page_owner(struct swap_page_owner *spo, struct page_owner *page_owner) { --=20 2.51.0 From nobody Wed Dec 17 04:20:30 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 AB38F2236F2 for ; Fri, 5 Dec 2025 23:17:53 +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=1764976675; cv=none; b=F3FTuZY38QW7OqWDj5dKn1gbmU3+S/gffMnQCjgwACeCMeJGaaxnOFFkUFumt+n787oY4jxkJu8lKUCIcqtGUWW0xpCMUfLHENmpUTP+WsDHbKFkUj9PC15c41FreyHtG5wpqyza+yhISLtTRtZ6T/t/ai0SnRKiVerJmAbLvNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764976675; c=relaxed/simple; bh=p6UMBzRAIQhWn6OAA4QdzzqIulP8VRQX3vv9K07TeTo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C1IwyfsxbPkIfX8aBJ3NC+P7aGMzIM7hDcdP6XQtp+Iy/YOV22KSMEwS9e76ZCFjyxkvMa2RjmDYGeH6sZKDfH17f/D+DIrVXNW/bZacJwqbXfuJOxZwqBSYmn6IMiKq7qweaBwfV9WK4CDZPy1AHirvV4THOWHv2K4HRxTLOxw= 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=ZEZVYtx8; 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="ZEZVYtx8" 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=jVUnQStwfypeNS8SEXvjI0KB0EJuUa8gDW3BIXGvW00=; b=ZEZVYtx8JmELotkfzPfZwRAGeQ aQD9x3Awn7X1CqaMVjnE8zOjC61zuuvL4WOyGKOlt2L7uyQjCL5T0r8WaEtkUxeXdK5bXki41JbAx ljLLeTT4a3nZTKcMIEwowcRvklCLY3C78J2wZ33YM1XMrcJNhzwoKeB67+yxIRBhHuKX4vPiaVlPO BCQsVlFwhohsp6NYpMCU7i7bfeKetiEL/uNPVFlrGNg2Vurt6i8wSKNVY2dgr/lEHez7UThbRp0jp H8oLvmopyucEpdp+iAlaSRhcPwW7CiqIdIrsq6VgRi562ahwLZYXhVwnfKu85toh8zlDi/W/9GZ6e 5DCz7yOw==; 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 1vRf3b-009H1j-31; Sat, 06 Dec 2025 00:17:47 +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 5/9] mm/page_owner: add swap hooks Date: Fri, 5 Dec 2025 20:17:17 -0300 Message-ID: <20251205231721.104505-6-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 the swap hooks 'prepare_to_swap()' (before swap-out and page-free), 'swap_restore()' (after page-alloc and swap-in), and 'swap_invalidate()' for page and area. The first two hooks are the core of the new functionality. They store the (initial) allocation stack trace at swap-out and load it at swap-in, in order to 'maintain' the allocation stack trace over swap-out/swap-in. The refcounts for the initial allocation and the allocation at swap-in are adjusted/fixed-up (incremented and decremented, respectively), as the initial allocation is decremented at swap-out (page free) later, and the swap-in allocation is incremented at swap-in (page alloc) earlier. This is based on the swap hooks implementation for memory tags on arm64 ('arch/arm64/mm/mteswap.c'; thanks!) Signed-off-by: Mauricio Faria de Oliveira --- include/linux/page_owner.h | 49 +++++++++++++++ mm/page_owner.c | 120 +++++++++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+) diff --git a/include/linux/page_owner.h b/include/linux/page_owner.h index 3328357f6dba..cd95aacceba7 100644 --- a/include/linux/page_owner.h +++ b/include/linux/page_owner.h @@ -75,4 +75,53 @@ static inline void dump_page_owner(const struct page *pa= ge) { } #endif /* CONFIG_PAGE_OWNER */ + +#ifdef CONFIG_SWAP_PAGE_OWNER +extern struct static_key_false swap_page_owner_inited; + +extern int __page_owner_prepare_to_swap(struct folio *folio); +extern void __page_owner_swap_restore(swp_entry_t entry, struct folio *fol= io); +extern void __page_owner_swap_invalidate_page(int type, pgoff_t offset); +extern void __page_owner_swap_invalidate_area(int type); + +static inline int page_owner_prepare_to_swap(struct folio *folio) +{ + if (static_branch_unlikely(&swap_page_owner_inited)) + return __page_owner_prepare_to_swap(folio); + + return 0; +} + +static inline void page_owner_swap_restore(swp_entry_t entry, struct folio= *folio) +{ + if (static_branch_unlikely(&swap_page_owner_inited)) + return __page_owner_swap_restore(entry, folio); +} + +static inline void page_owner_swap_invalidate_page(int type, pgoff_t offse= t) +{ + if (static_branch_unlikely(&swap_page_owner_inited)) + return __page_owner_swap_invalidate_page(type, offset); +} + +static inline void page_owner_swap_invalidate_area(int type) +{ + if (static_branch_unlikely(&swap_page_owner_inited)) + return __page_owner_swap_invalidate_area(type); +} +#else +static inline int page_owner_prepare_to_swap(struct folio *folio) +{ + return 0; +} +static inline void page_owner_swap_restore(swp_entry_t entry, struct folio= *folio) +{ +} +static inline void page_owner_swap_invalidate_page(int type, pgoff_t offse= t) +{ +} +static inline void page_owner_swap_invalidate_area(int type) +{ +} +#endif /* CONFIG_SWAP_PAGE_OWNER */ #endif /* __LINUX_PAGE_OWNER_H */ diff --git a/mm/page_owner.c b/mm/page_owner.c index 5cd7de1f8023..d256f58deca4 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -525,6 +525,126 @@ static void copy_from_swap_page_owner(struct page_own= er *page_owner, page_owner->tgid =3D spo->tgid; strscpy(page_owner->comm, spo->comm, sizeof(page_owner->comm)); } + +/* Store the initial stack information from page_owner to xarray. */ +int __page_owner_prepare_to_swap(struct folio *folio) +{ + struct page_ext_iter iter; + struct page_ext *page_ext; + struct page_owner *page_owner; + struct swap_page_owner *spo; + depot_stack_handle_t handle =3D 0; + swp_entry_t entry; + long i =3D 0, nr_pages =3D folio_nr_pages(folio); + int err; + + rcu_read_lock(); + for_each_page_ext(&folio->page, nr_pages, page_ext, iter) { + spo =3D alloc_swap_page_owner(); + if (!spo) { + err =3D -ENOMEM; + goto out_locked; + } + + page_owner =3D get_page_owner(page_ext); + copy_to_swap_page_owner(spo, page_owner); + entry =3D page_swap_entry(folio_page(folio, i)); + err =3D store_swap_page_owner(spo, entry); + if (err) + goto out_locked; + + if (!handle) + handle =3D page_owner->handle; + i++; + } + rcu_read_unlock(); + + /* + * Fix-up: increment refcount of the initial allocation. + * It will be decremented by page-free at swap-out. + */ + inc_stack_record_count(handle, GFP_KERNEL, nr_pages); + + return 0; + +out_locked: + for_each_page_ext(&folio->page, nr_pages, page_ext, iter) { + if (!i--) + break; + + entry =3D page_swap_entry(folio_page(folio, i)); + erase_swap_page_owner(entry, true); + + page_owner =3D get_page_owner(page_ext); + + } + rcu_read_unlock(); + return err; +} + +/* Load the initial stack information from xarray to page_owner. */ +void __page_owner_swap_restore(swp_entry_t entry, struct folio *folio) +{ + struct page_ext_iter iter; + struct page_ext *page_ext; + struct page_owner *page_owner; + struct swap_page_owner *spo; + depot_stack_handle_t handle =3D 0; + long i =3D 0, nr_pages =3D folio_nr_pages(folio); + + rcu_read_lock(); + for_each_page_ext(&folio->page, nr_pages, page_ext, iter) { + spo =3D (struct swap_page_owner *) load_swap_page_owner(entry); + if (!spo) { + rcu_read_unlock(); + return; + } + + page_owner =3D get_page_owner(page_ext); + copy_from_swap_page_owner(page_owner, spo); + + if (!handle) + handle =3D page_owner->handle; + i++; + entry.val++; + } + rcu_read_unlock(); + + /* + * Fix-up: decrement refcount of the swap-in allocation. + * It was incremented by the page-alloc at swap-in. + * (early_handle: see __reset_page_owner().) + * + * FIXME(mfo): 'dec_stack_record_count: refcount went to 0 ...' + * with stack_depot oops is hit occasionaly on tests or shutdown. + */ + if (handle !=3D early_handle) + dec_stack_record_count(handle, nr_pages); +} + +void __page_owner_swap_invalidate_page(int type, pgoff_t offset) +{ + swp_entry_t entry =3D swp_entry(type, offset); + + erase_swap_page_owner(entry, true); +} + +void __page_owner_swap_invalidate_area(int type) +{ + swp_entry_t first_entry =3D swp_entry(type, 0); + swp_entry_t last_entry =3D swp_entry(type + 1, 0); + swp_entry_t entry; + void *spo; + + XA_STATE(xa_state, &swap_page_owners, first_entry.val); + + xa_lock(&swap_page_owners); + xas_for_each(&xa_state, spo, last_entry.val - 1) { + entry.val =3D xa_state.xa_index; + erase_swap_page_owner(entry, false); + } + xa_unlock(&swap_page_owners); +} #endif =20 void pagetypeinfo_showmixedcount_print(struct seq_file *m, --=20 2.51.0 From nobody Wed Dec 17 04:20:30 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 From nobody Wed Dec 17 04:20:30 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 From nobody Wed Dec 17 04:20:30 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 92F522BE639 for ; Fri, 5 Dec 2025 23:18:06 +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=1764976688; cv=none; b=YTpnL5nitNQK4nQFHp3S3ipF1Jqzrd34RkvMuXS6SWPtxTEZQ6m3S5FOCI0ph6O7pJBEDR429e9RyHxXq9eNHnrf7BVS9YCeaT/xeh0FnB8KC/fBVlOANfcgpH6MVrTuRe/4RCN+zGnNmCBx/132dZlqjyQ3G/dKdApVKphZWKk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764976688; c=relaxed/simple; bh=Gl2pQcxfdrpasi1iMuFBEaew5NxcBwl5P2Z4OihVUGM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XWT02CT73uN0oXvFt1pIwIOl42Y67+v9+XlXxZfwNV1+jNSK1Q6xa+VUosCO+gpCBhi6JQ7kxUt1Xc5e7FtDsRvwdb9mMlt+0xGkGmoApctqRhNxZGNKhKJQDR5h91ROa+ViDvdKj0FbWhtENQtyixeZHifanJdJGFxJ3t595N4= 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=C7VM/kX4; 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="C7VM/kX4" 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=ncR7zo6O4wM7dieNg4YaVMgDB/FRmYb+PM5XOoEML4w=; b=C7VM/kX4Z1GDZPeEFpANwu8M7s YGUKDqTs/z6yCu3N5z4MRfogDhl3scwtJSlSPWfviS8bVmnjERPsQMBe1G2lEV8H9n8HhJXxUWBy7 fwAoEbsDb07dZUDlPNJEtxSgJVhLPVowpa2xRfpAGplGdr3fIvX5NldwkEsSpfHhOmWlJ02BfC6gQ /JRkhF9hO+6oDKApbSy9/3ssvwOb1XNgKZeoToaaJGhctUM7DehUKPnJTQPMygkXkeqm1trMiPjgD QCug1kQ9Aqc4NE3qc1fA645nAW5Ef1Bys4mObsqoxpwehNu7eBnFRWEvF81lVF2Gd6rdkPTx8Bmd7 HjD5Z8Ww==; 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 1vRf3n-009H1j-5d; Sat, 06 Dec 2025 00:17:59 +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 8/9] mm: call arch-specific swap hooks from generic swap hooks Date: Fri, 5 Dec 2025 20:17:20 -0300 Message-ID: <20251205231721.104505-9-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 generic swap hooks that just call the arch-specific ones (e.g., arm64). Signed-off-by: Mauricio Faria de Oliveira --- include/linux/pgtable.h | 20 ++++++++++++++++++++ mm/memory.c | 2 +- mm/page_io.c | 2 +- mm/shmem.c | 2 +- mm/swapfile.c | 6 +++--- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 652f287c1ef6..23d30afe439e 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1220,6 +1220,26 @@ static inline void arch_swap_restore(swp_entry_t ent= ry, struct folio *folio) } #endif =20 +static inline int hook_prepare_to_swap(struct folio *folio) +{ + return arch_prepare_to_swap(folio); +} + +static inline void hook_swap_invalidate_page(int type, pgoff_t offset) +{ + arch_swap_invalidate_page(type, offset); +} + +static inline void hook_swap_invalidate_area(int type) +{ + arch_swap_invalidate_area(type); +} + +static inline void hook_swap_restore(swp_entry_t entry, struct folio *foli= o) +{ + arch_swap_restore(entry, folio); +} + #ifndef __HAVE_ARCH_MOVE_PTE #define move_pte(pte, old_addr, new_addr) (pte) #endif diff --git a/mm/memory.c b/mm/memory.c index 2a55edc48a65..6a5a5bd3eeed 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4945,7 +4945,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) * when reading from swap. This metadata may be indexed by swap entry * so this must be called before swap_free(). */ - arch_swap_restore(folio_swap(entry, folio), folio); + hook_swap_restore(folio_swap(entry, folio), folio); =20 /* * Remove the swap entry and conditionally try to free up the swapcache. diff --git a/mm/page_io.c b/mm/page_io.c index 3c342db77ce3..b62c53a86a59 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -248,7 +248,7 @@ int swap_writeout(struct folio *folio, struct swap_iocb= **swap_plug) * Arch code may have to preserve more data than just the page * contents, e.g. memory tags. */ - ret =3D arch_prepare_to_swap(folio); + ret =3D hook_prepare_to_swap(folio); if (ret) { folio_mark_dirty(folio); goto out_unlock; diff --git a/mm/shmem.c b/mm/shmem.c index 3f194c9842a8..ef53c14156fb 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2395,7 +2395,7 @@ static int shmem_swapin_folio(struct inode *inode, pg= off_t index, * Some architectures may have to restore extra metadata to the * folio after reading from swap. */ - arch_swap_restore(folio_swap(swap, folio), folio); + hook_swap_restore(folio_swap(swap, folio), folio); =20 if (shmem_should_replace_folio(folio, gfp)) { error =3D shmem_replace_folio(&folio, gfp, info, index, vma); diff --git a/mm/swapfile.c b/mm/swapfile.c index 46d2008e4b99..e156f5cb6e9f 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1270,7 +1270,7 @@ static void swap_range_free(struct swap_info_struct *= si, unsigned long offset, else swap_slot_free_notify =3D NULL; while (offset <=3D end) { - arch_swap_invalidate_page(si->type, offset); + hook_swap_invalidate_page(si->type, offset); if (swap_slot_free_notify) swap_slot_free_notify(si->bdev, offset); offset++; @@ -2196,7 +2196,7 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_= t *pmd, * when reading from swap. This metadata may be indexed by swap entry * so this must be called before swap_free(). */ - arch_swap_restore(folio_swap(entry, folio), folio); + hook_swap_restore(folio_swap(entry, folio), folio); =20 dec_mm_counter(vma->vm_mm, MM_SWAPENTS); inc_mm_counter(vma->vm_mm, MM_ANONPAGES); @@ -2931,7 +2931,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, special= file) p->cluster_info =3D NULL; spin_unlock(&p->lock); spin_unlock(&swap_lock); - arch_swap_invalidate_area(p->type); + hook_swap_invalidate_area(p->type); zswap_swapoff(p->type); mutex_unlock(&swapon_mutex); kfree(p->global_cluster); --=20 2.51.0 From nobody Wed Dec 17 04:20:30 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 5E445158538 for ; Fri, 5 Dec 2025 23:18:10 +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=1764976691; cv=none; b=n14yllKETEaAq18Xk/SqMqSBkdBXcVIxsMOwrRW2rC/suzTlrltohEUfsliMf3ax2FuUAP2i+0xE3wlBZG/I1UYODnAM5rYu+1kt5k4kISo2CuzsO2RrlG65SxLcaqf9po4VCBiwTOw20ljk8pbVbI31ZkxZ9N6WRVu05PtZwtE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764976691; c=relaxed/simple; bh=p/o412RguFkWr01YOrKM53b9cWNVDSHVFFPWEZqLh5s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hmfwFUM3objIRknLeK9bDgamzFHE+qG3rUPDjoT6rQYG9MPnxYmgJ7H83Mpi+GRiLO3hTj1EkBxIQu5lhFDRdAYkiAQU6eQiZhiDXoxzM+B67kXWbMamow3Z1B7XNJ0gufBgtrrNeHyC2VhyAqYziIimQRLO+y7UfATHSIWIHrY= 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=cKtcg3xR; 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="cKtcg3xR" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: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=4LFA2Xr7fMcablqz8itIRhQ151XIAZCDEKGvR05eMEs=; b=cKtcg3xRejri+aQdtkKyLd9t9N 2gbD13UjzVb/eq7Dtaj0Si9lRXYUo5xPQwNVwXqTgcUcggvPnCTIsnVcP/lJHgFyrw9e+j2YG8ijd fdUede/irfHVXPxKwpO8qmXNopCdGDhhiizfr7su/joYk5dGBCPYJzTPgbFjGeLoCGUN1qETxKJMK 9a1/N5DKH03U7NWAYPZVn7vpglikIhkilY2CcYz2L6AtV0WSAQLFHbjINi6zP3fmLaLDW7KtEMDCM D03yXQFO/AOInHDW8ZFGNBq8WPumFqLckFm1DxRG45xKgeU7RmzlbHNvNRYrM06qarIyCKUGIj78i rkKkzxUA==; 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 1vRf3r-009H1j-8q; Sat, 06 Dec 2025 00:18:03 +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 9/9] mm: call page_owner swap hooks from generic swap hooks Date: Fri, 5 Dec 2025 20:17:21 -0300 Message-ID: <20251205231721.104505-10-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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Finally, call the page_owner swap hooks from the generic swap hooks. This plugs the new functionality into the kernel. Add a missing include in 'page_owner.h' to fix build errors in files that include 'pgtable.h' (thus now 'page_owner.h') without an earlier include that provides 'pg_data_t': In file included from .../include/linux/pgtable.h:19, from .../arch/x86/boot/startup/map_kernel.c:7: .../include/linux/page_owner.h:20:41: error: unknown type name =E2=80= =98pg_data_t=E2=80=99 Signed-off-by: Mauricio Faria de Oliveira --- include/linux/page_owner.h | 1 + include/linux/pgtable.h | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/page_owner.h b/include/linux/page_owner.h index cd95aacceba7..d7029d1e41de 100644 --- a/include/linux/page_owner.h +++ b/include/linux/page_owner.h @@ -3,6 +3,7 @@ #define __LINUX_PAGE_OWNER_H =20 #include +#include =20 #ifdef CONFIG_PAGE_OWNER extern struct static_key_false page_owner_inited; diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 23d30afe439e..ae397f5884d5 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -16,6 +16,7 @@ #include #include #include +#include =20 #if 5 - defined(__PAGETABLE_P4D_FOLDED) - defined(__PAGETABLE_PUD_FOLDED) = - \ defined(__PAGETABLE_PMD_FOLDED) !=3D CONFIG_PGTABLE_LEVELS @@ -1222,22 +1223,31 @@ static inline void arch_swap_restore(swp_entry_t en= try, struct folio *folio) =20 static inline int hook_prepare_to_swap(struct folio *folio) { - return arch_prepare_to_swap(folio); + int ret; + + ret =3D arch_prepare_to_swap(folio); + if (ret) + return ret; + + return page_owner_prepare_to_swap(folio); } =20 static inline void hook_swap_invalidate_page(int type, pgoff_t offset) { arch_swap_invalidate_page(type, offset); + page_owner_swap_invalidate_page(type, offset); } =20 static inline void hook_swap_invalidate_area(int type) { arch_swap_invalidate_area(type); + page_owner_swap_invalidate_area(type); } =20 static inline void hook_swap_restore(swp_entry_t entry, struct folio *foli= o) { arch_swap_restore(entry, folio); + page_owner_swap_restore(entry, folio); } =20 #ifndef __HAVE_ARCH_MOVE_PTE --=20 2.51.0