From nobody Tue Oct 7 13:28:37 2025 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2073.outbound.protection.outlook.com [40.107.236.73]) (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 945E1283CA2; Thu, 10 Jul 2025 06:23:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752128633; cv=fail; b=ThKQsE1nbyNRly4woeZleTuADot1zzn5lNL5PvNx1zaaNcUs/vcNuAPklPyj0hHh13N/udh2e89CMIAuYHUlr4uXTX5wYS3QvBQ3EGFCL3vWgvpOLFkKuycQA8HxnbWQLh5PbJxBjXPyt9A6RiT96xBdmG5jdDBAeMS7VQuwqCA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752128633; c=relaxed/simple; bh=LTDtOFNbdPmq40CKWosW+UnqWPEd3BpAKnyMJ+9ZWdk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aEIr7rGEY53czZcw+bsDT8wgIwLg9L+BInDcwhcqkv2ZoMaSUdbda81gR15DVLPwspI7QcTVK8qar2UJSIaGmhnrzcKlNw/fEII0Ti6xjsGU+zyO6woXqTXyPcGCiICygg8YSOQp+UUr1sUotTSzz/uD3BLDZGoLWqib4ZZAz0c= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=IGsBjwn7; arc=fail smtp.client-ip=40.107.236.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="IGsBjwn7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BDWpRxjGs9eWHaHT2sWvZ2k7Xr5F29u6iXm9b1cqMUy5dhi/P9Bx4YQJhWmZDWks2gM5YN88oppFV2tRp7xQd9IFLEUogX/ULPkZg752R+K3HW9dRZtUEdgafAYrUAsLinfM1wKVrKw5sn1TWwFvC/P9zgenKwpck5poKu7bslUBWYY3ttbkc5+75A8UcRkm0HwxeP7wMkyBGx3lgDiuVASMNp1blEq+xvtaYo82C0fgoPVG45YxN93GVeuVkZ/Fr+npmm7DZrj/TXBRtf6s0gpeSVh3NCfMO/eursChHH7ZnvnHHcjnTc+j0+ir47cZjwodm91gXqzsYLkNS4wOEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cTT8ARgfjZ96BXHNzxfBs2erck2fbvYj4k+1BworKok=; b=gBO08F+SAJrwgy4MqmUCjUnJBRdfNIqf7an4UHZYlQcjEIDV/vCSFTE3nFpveZsQ+24nfBOwxJC2u8hxLbhF4hQczbv+DuSCUZuSRtEu8E33kByy4UOcNeM30nCd1Jcy1P4xZSA/iV/OhnC7iu/k6rAxshhRlJeeDlBaxke0ElFSMdIRjC0UxLMYxMpg+pmJkm6hDOlCPziixq5dN41Q6CSdta7ItrdwGjcsdkPnoCC0x+Gph8pcLWtEwctY/Wh433PYw1SA6mQhZJwMYDS2yrGvPKthCewQWY/yXTxZRMOennNq3EeFOf4VUyQxZz27lqqu7PRuaGy99kHCkqnU6w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cTT8ARgfjZ96BXHNzxfBs2erck2fbvYj4k+1BworKok=; b=IGsBjwn7OuXjCmovbEXmunM/4A2MzfeV2SIy1kczGsrQzy3+7o5GmqGGVx2GwuHiVBa/9Rbdwc9A7Kex8fE+U/Wx96OK9vTY5bx69+GCbObH2elUd5XlgiL/XkeDp1fEjHW1OX06Ch4qPpfCOc/hegfg1CTQCiIzVUi65+8tFZg= Received: from DS7PR06CA0006.namprd06.prod.outlook.com (2603:10b6:8:2a::7) by IA1PR12MB6386.namprd12.prod.outlook.com (2603:10b6:208:38a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.26; Thu, 10 Jul 2025 06:23:45 +0000 Received: from CY4PEPF0000FCC4.namprd03.prod.outlook.com (2603:10b6:8:2a:cafe::e7) by DS7PR06CA0006.outlook.office365.com (2603:10b6:8:2a::7) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8922.23 via Frontend Transport; Thu, 10 Jul 2025 06:23:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000FCC4.mail.protection.outlook.com (10.167.242.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Thu, 10 Jul 2025 06:23:45 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 10 Jul 2025 01:23:44 -0500 Received: from hjbog-srdc-41.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Thu, 10 Jul 2025 01:23:39 -0500 From: Samuel Zhang To: , , , , , , , , , , , , , , CC: , , , , , , , , , , "Samuel Zhang" Subject: [PATCH v6 3/5] PM: hibernate: shrink shmem pages after dev_pm_ops.prepare() Date: Thu, 10 Jul 2025 14:23:11 +0800 Message-ID: <20250710062313.3226149-4-guoqing.zhang@amd.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250710062313.3226149-1-guoqing.zhang@amd.com> References: <20250710062313.3226149-1-guoqing.zhang@amd.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 Received-SPF: None (SATLEXMB03.amd.com: guoqing.zhang@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC4:EE_|IA1PR12MB6386:EE_ X-MS-Office365-Filtering-Correlation-Id: 531c7048-ab70-403e-56f7-08ddbf7a52dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|376014|36860700013|7416014|921020|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?2c3BMtAdKXGlU2YTVuKDvba3jZ3EIz+1bxJgDHyZDjV0NBmJOUSNK+5soKVV?= =?us-ascii?Q?/YLMnoBEuart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I3ashylUpmpMUxq?= =?us-ascii?Q?e1fjJgTZD48Vyb+YRQzanbBRf2CJ8w12byo68nijEQPVBoWiEGitfmxRBrmX?= =?us-ascii?Q?STgjt3MH/L2PsqvolRtVLB0wZ33diwulkzbTyGXxHUV3rfvJCeYBklXI2QLD?= =?us-ascii?Q?Yx2QAjRgoTiTzQlGkZdaBXDFgkJJSE+L+O4H+XiaaizHeVWtmQhfbjbaFkkc?= =?us-ascii?Q?i5668j58bYqJT03P21KefrS2wP0Q4dJcVriwggCLOOPyYE6NZpyZ8i/tnEj8?= =?us-ascii?Q?YLY2pQVBWU3bw+c55IkqKBrsoXUErtTcmUjhnODKIfI7460ulvUHBKkwPsQb?= =?us-ascii?Q?tR26/E7M/8AZEy9xObTAt4AkMTvl45sK1D5G270zeVIPPFcOdKWKuEJ/GNrG?= =?us-ascii?Q?bwcKl537BqSrjCj8+YbVO+VgmqMiEKhzUOA5rA0yyL9C7QgDa/HfvTFFdi1q?= =?us-ascii?Q?POKupK9M+MVWbGKH5Thm1YeMabT+jZJN7mGhXQutfi0d769av1sj6LDwqKUS?= =?us-ascii?Q?FM7SeOPeFgBTrbZdZgQDWZejVlzsDBqm0c7SeHSTRuj4k46AwpzVUJAAfxmd?= =?us-ascii?Q?bMlkyQ9LudeNttwv2OabAw62E503Up04ZzCE21Rso4sWeOd98t0etyzdgw?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(376014)(36860700013)(7416014)(921020)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jul 2025 06:23:45.2730 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 531c7048-ab70-403e-56f7-08ddbf7a52dc X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000FCC4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6386 Content-Type: text/plain; charset="utf-8" When hibernate with data center dGPUs, huge number of VRAM data will be moved to shmem during dev_pm_ops.prepare(). These shmem pages take a lot of system memory so that there's no enough free memory for creating the hibernation image. This will cause hibernation fail and abort. After dev_pm_ops.prepare(), call shrink_all_memory() to force move shmem pages to swap disk and reclaim the pages, so that there's enough system memory for hibernation image and less pages needed to copy to the image. This patch can only flush and free about half shmem pages. It will be better to flush and free more pages, even all of shmem pages, so that there're less pages to be copied to the hibernation image and the overall hibernation time can be reduced. Signed-off-by: Samuel Zhang Acked-by: Rafael J. Wysocki --- kernel/power/hibernate.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index 9216e3b91d3b..1f1f30cca573 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -381,6 +381,23 @@ static int create_image(int platform_mode) return error; } =20 +static void shrink_shmem_memory(void) +{ + struct sysinfo info; + unsigned long nr_shmem_pages, nr_freed_pages; + + si_meminfo(&info); + nr_shmem_pages =3D info.sharedram; /* current page count used for shmem */ + /* + * The intent is to reclaim all shmem pages. Though shrink_all_memory() c= an + * only reclaim about half of them, it's enough for creating the hibernat= ion + * image. + */ + nr_freed_pages =3D shrink_all_memory(nr_shmem_pages); + pr_debug("requested to reclaim %lu shmem pages, actually freed %lu pages\= n", + nr_shmem_pages, nr_freed_pages); +} + /** * hibernation_snapshot - Quiesce devices and create a hibernation image. * @platform_mode: If set, use platform driver to prepare for the transiti= on. @@ -422,6 +439,15 @@ int hibernation_snapshot(int platform_mode) goto Thaw; } =20 + /* + * Device drivers may move lots of data to shmem in dpm_prepare(). The sh= mem + * pages will use lots of system memory, causing hibernation image creati= on + * fail due to insufficient free memory. + * This call is to force flush the shmem pages to swap disk and reclaim + * the system memory so that image creation can succeed. + */ + shrink_shmem_memory(); + console_suspend_all(); =20 error =3D dpm_suspend(PMSG_FREEZE); --=20 2.43.5