From nobody Thu Dec 18 09:32:20 2025 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EF2D2F3607 for ; Tue, 21 Oct 2025 11:37:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761046673; cv=none; b=UNmdLyw+VBkTTRv5MLkeukJX/Erqt/IcrkUdnh1XLTWnqFOTlJ5+cmejRTya2Rv3Tv+8cXIOipDMT/CvTpMGpGaKZm8jr3qwFV93IUV3ncEHevVXSxvZ8AkDDEI5hRP1EsRMt9+ayh6EK4/RX+f3Ud2Pesz5b3rBRr4qsyihBJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761046673; c=relaxed/simple; bh=kuoE1FUvLeKFmLsCoNqOIkjJG2dB4pdTppXQYQPWGsQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EJf45bCrJfxzBT+u9BXadyC5WcdFhpxvdPxG1uD59qFBv86HJ6Y0opZtMzt/F8kEptg6ARGy29EpCBDr+dhFWCpcJ4Vpc8VLYAak04xrxAMWFcNxmjiszsfh2PFfi/gMlMUMadJH/IMZdLuCLON7Aq6JygmX33Q3PrTQ0ySd8aM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.215.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f195.google.com with SMTP id 41be03b00d2f7-b6a7d3040efso2023142a12.1 for ; Tue, 21 Oct 2025 04:37:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761046671; x=1761651471; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AKqpzOqhN5Ccg89sMbSx3T7qxxa8RixMmw1THiek4uU=; b=fDmljkoiCpD3FwQaD77AjwtBRvmJ2UVhNRvDGIJaUDctH6BoAOM7hMjZ2P8j1gGhO6 hSQPc3jG+myIv/CDkpWaVZ4swM0+QbHsNvN+OlOOgwgbYctL6uqdTQ37NaQJy80ljOe7 MB1tY+HtpH+qxYRyKyL9HHoFqocsta56VCf6QXLC4296Tf0IkzrMgnLIOnnVRLWiY4qW UsOMnZ8X0caMfU1wRph6TYUbVVnGLs2eS8/1auI5KvkNTF9az/GdJSW0Rj3iGaPZAg0Q 3ADQcz+k4gnr/sOdcFn2k1Q4iuxG+WyQKhvsUmXiiH291Lkz/DpyMK0qY50MvMl3Z/xy R6MQ== X-Forwarded-Encrypted: i=1; AJvYcCWnvvYPQ56gcXOCE6MMj7Jzaktc/EUdwRfwrPkg/3v1yE8nS+CjP02TnIypY+OJiK4XU6UKRq0gNBmRtNU=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7K4E0vG1jg1tiiUnfB1TCGcmYoZoPRXQCRxCBIqoWVTOGSwrb /k+oxVeD9RUugrghxTZCoMJNiWl3iL/ZoNSmXDSDZLNs/svilh7pysQM X-Gm-Gg: ASbGncvX/sJmRE1go0X5oTclUdhURHDqWin7wU0iyq9XU1zgFcvPeGo5P1FZb6139Wl VnSybSP5iCSWYNvIMab4wHu5AXOPOR1CW3rM7lT24CwdRVq8BQyk/+QZY5y98LCjqJn9tWtGH/f bXKmHF3wJaTV9XDN0oDGstvDaooHwHhG77PXUvFGgJDyaH/xrwhuMJt+IppYizcPJABDBfBBoNK bdt9MvWqs+sqg+9ZlmHc5FkCIWKsNhAONvo5vpFXGGIs6fsfNzdJrJqB0PhCqT/X6mgsGWBC9pu efYqA7A/5p7FsEnf0Jr29k1EQkwhMqtTYEi8h8WPYgaMlpkUfRbgqAaxl1jLdMDv4VN/RvJu2uz Nh5lK0TbaOFk1GB2RkZHEIcneT0gRZk+1/I2uPhb443DDIbYo5o+He1lwk8qflOxNTR7IuEheVJ nfPLiB3zBYfXA8sSCqcRNFFTI= X-Google-Smtp-Source: AGHT+IH0BjuvaA5viZ+OWbEEkQERqLhKzGcP5Kn0KUqxKXxImmXjbveExVU5QFyUBAqvyYVzJR7WmA== X-Received: by 2002:a17:902:f78b:b0:290:ab61:6a5e with SMTP id d9443c01a7336-290c9ce0ad2mr206036055ad.27.1761046671460; Tue, 21 Oct 2025 04:37:51 -0700 (PDT) Received: from power-ThinkBook-15-G2-ITL.. ([116.128.244.171]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-292471d5874sm107138825ad.54.2025.10.21.04.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Oct 2025 04:37:51 -0700 (PDT) From: Xueqin Luo To: rafael@kernel.org, pavel@kernel.org, lenb@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Xueqin Luo Subject: [PATCH v5 2/3] PM: hibernate: make compression threads configurable Date: Tue, 21 Oct 2025 19:37:27 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: 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 The number of compression/decompression threads has a direct impact on hibernate image generation and resume latency. Using more threads can reduce overall resume time, but on systems with fewer CPU cores it may also introduce contention and reduce efficiency. Performance was evaluated on an 8-core ARM system, averaged over 10 runs: Threads Hibernate(s) Resume(s) -------------------------------- 3 12.14 18.86 4 12.28 17.48 5 11.09 16.77 6 11.08 16.44 With 5=E2=80=936 threads, resume latency improves by approximately 12% comp= ared to the default 3-thread configuration, with negligible impact on hibernate time. Introduce a new kernel parameter `hibernate_compression_threads=3D` that allows users and integrators to tune the number of compression/decompression threads at boot. This provides a way to balance performance and CPU utilization across a wide range of hardware without recompiling the kernel. Signed-off-by: Xueqin Luo --- .../admin-guide/kernel-parameters.txt | 10 ++++++++ kernel/power/swap.c | 25 ++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index db84a629f7b1..fb577fb2c893 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1889,6 +1889,16 @@ /sys/power/pm_test). Only available when CONFIG_PM_DEBUG is set. Default value is 5. =20 + hibernate_compression_threads=3D + [HIBERNATION] + Set the number of threads used for compressing or decompressing + hibernation images. + + Format: + Default: 3 + Minimum: 1 + Example: hibernate_compression_threads=3D4 + highmem=3Dnn[KMG] [KNL,BOOT,EARLY] forces the highmem zone to have an exa= ct size of . This works even on boxes that have no highmem otherwise. This also works to reduce highmem diff --git a/kernel/power/swap.c b/kernel/power/swap.c index f8c13f5672ec..aa11576e92a9 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c @@ -519,8 +519,9 @@ static int swap_writer_finish(struct swap_map_handle *h= andle, CMP_HEADER, PAGE_SIZE) #define CMP_SIZE (CMP_PAGES * PAGE_SIZE) =20 -/* Maximum number of threads for compression/decompression. */ -#define CMP_THREADS 3 +/* Default number of threads for compression/decompression. */ +#define CMP_THREADS 3 +static unsigned int hibernate_compression_threads =3D CMP_THREADS; =20 /* Minimum/maximum number of pages for read buffering. */ #define CMP_MIN_RD_PAGES 1024 @@ -741,7 +742,7 @@ static int save_compressed_image(struct swap_map_handle= *handle, * footprint. */ nr_threads =3D num_online_cpus() - 1; - nr_threads =3D clamp_val(nr_threads, 1, CMP_THREADS); + nr_threads =3D clamp_val(nr_threads, 1, hibernate_compression_threads); =20 page =3D (void *)__get_free_page(GFP_NOIO | __GFP_HIGH); if (!page) { @@ -1257,7 +1258,7 @@ static int load_compressed_image(struct swap_map_hand= le *handle, * footprint. */ nr_threads =3D num_online_cpus() - 1; - nr_threads =3D clamp_val(nr_threads, 1, CMP_THREADS); + nr_threads =3D clamp_val(nr_threads, 1, hibernate_compression_threads); =20 page =3D vmalloc_array(CMP_MAX_RD_PAGES, sizeof(*page)); if (!page) { @@ -1697,3 +1698,19 @@ static int __init swsusp_header_init(void) } =20 core_initcall(swsusp_header_init); + +static int __init hibernate_compression_threads_setup(char *str) +{ + int rc =3D kstrtouint(str, 0, &hibernate_compression_threads); + + if (rc) + return rc; + + if (hibernate_compression_threads < 1) + hibernate_compression_threads =3D CMP_THREADS; + + return 1; + +} + +__setup("hibernate_compression_threads=3D", hibernate_compression_threads_= setup); --=20 2.43.0