mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Xueqin Luo <luoxueqin@kylinos.cn>,
	rafael@kernel.org, pavel@kernel.org, lenb@kernel.org,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] PM: hibernate: dynamically allocate crc->unc_len/unc for configurable threads
Date: Thu, 11 Sep 2025 18:56:27 +0200	[thread overview]
Message-ID: <888ce9cc-787b-4deb-87a6-d69cb7e04593@wanadoo.fr> (raw)
In-Reply-To: <86d4e558707e7b03c248ef67cb76ec635a875d9b.1757577879.git.luoxueqin@kylinos.cn>

Le 11/09/2025 à 10:09, Xueqin Luo a écrit :
> The current implementation uses fixed-size arrays for crc->unc_len and
> crc->unc, which limits the number of compression threads to a compile-time
> constant (CMP_THREADS). This patch converts them to dynamically allocated
> arrays, sized according to the actual number of threads selected at runtime.
> 
> Signed-off-by: Xueqin Luo <luoxueqin@kylinos.cn>
> ---
>   kernel/power/swap.c | 44 ++++++++++++++++++++++++++++++++++++++++----
>   1 file changed, 40 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/power/swap.c b/kernel/power/swap.c
> index 0beff7eeaaba..bd149a54c081 100644
> --- a/kernel/power/swap.c
> +++ b/kernel/power/swap.c
> @@ -585,8 +585,8 @@ struct crc_data {
>   	wait_queue_head_t go;                     /* start crc update */
>   	wait_queue_head_t done;                   /* crc update done */
>   	u32 *crc32;                               /* points to handle's crc32 */
> -	size_t *unc_len[CMP_THREADS];             /* uncompressed lengths */
> -	unsigned char *unc[CMP_THREADS];          /* uncompressed data */
> +	size_t **unc_len;			              /* uncompressed lengths */
> +	unsigned char **unc;			          /* uncompressed data */

spaces and tabulations now make things look unaligned.

>   };
>   
>   /*
> @@ -721,7 +721,21 @@ static int save_compressed_image(struct swap_map_handle *handle,
>   
>   	crc = kzalloc(sizeof(*crc), GFP_KERNEL);
>   	if (!crc) {
> -		pr_err("Failed to allocate crc\n");
> +		pr_err("Failed to allocate crc structure\n");

Usually, it is not needed to log messages for memory allocation 
failures, because such failures are already verbose.

checkpatch.pl should complain about it.

CJ

> +		ret = -ENOMEM;
> +		goto out_clean;
> +	}
> +
> +	crc->unc_len = kcalloc(nr_threads, sizeof(size_t *), GFP_KERNEL);
> +	if (!crc->unc_len) {
> +		pr_err("Failed to allocate crc->unc_len for %d threads\n", nr_threads);
> +		ret = -ENOMEM;
> +		goto out_clean;
> +	}
> +
> +	crc->unc = kcalloc(nr_threads, sizeof(unsigned char *), GFP_KERNEL);
> +	if (!crc->unc) {
> +		pr_err("Failed to allocate crc->unc for %d threads\n", nr_threads);
>   		ret = -ENOMEM;
>   		goto out_clean;
>   	}
> @@ -886,6 +900,10 @@ static int save_compressed_image(struct swap_map_handle *handle,
>   out_clean:
>   	hib_finish_batch(&hb);
>   	if (crc) {
> +		if (crc->unc)
> +			kfree(crc->unc);
> +		if (crc->unc_len)
> +			kfree(crc->unc_len);
>   		if (crc->thr)
>   			kthread_stop(crc->thr);
>   		kfree(crc);
> @@ -1241,7 +1259,21 @@ static int load_compressed_image(struct swap_map_handle *handle,
>   
>   	crc = kzalloc(sizeof(*crc), GFP_KERNEL);
>   	if (!crc) {
> -		pr_err("Failed to allocate crc\n");
> +		pr_err("Failed to allocate crc structure\n");
> +		ret = -ENOMEM;
> +		goto out_clean;
> +	}
> +
> +	crc->unc_len = kcalloc(nr_threads, sizeof(size_t *), GFP_KERNEL);
> +	if (!crc->unc_len) {
> +		pr_err("Failed to allocate crc->unc_len for %d threads\n", nr_threads);
> +		ret = -ENOMEM;
> +		goto out_clean;
> +	}
> +
> +	crc->unc = kcalloc(nr_threads, sizeof(unsigned char *), GFP_KERNEL);
> +	if (!crc->unc) {
> +		pr_err("Failed to allocate crc->unc for %d threads\n", nr_threads);
>   		ret = -ENOMEM;
>   		goto out_clean;
>   	}
> @@ -1507,6 +1539,10 @@ static int load_compressed_image(struct swap_map_handle *handle,
>   	for (i = 0; i < ring_size; i++)
>   		free_page((unsigned long)page[i]);
>   	if (crc) {
> +		if (crc->unc)
> +			kfree(crc->unc);
> +		if (crc->unc_len)
> +			kfree(crc->unc_len);
>   		if (crc->thr)
>   			kthread_stop(crc->thr);
>   		kfree(crc);


  parent reply	other threads:[~2025-09-11 17:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1757577879.git.luoxueqin@kylinos.cn>
2025-09-11  8:09 ` Xueqin Luo
2025-09-11 13:10   ` Rafael J. Wysocki
2025-09-11 16:56   ` Christophe JAILLET [this message]
2025-09-11  8:09 ` [PATCH v2 2/2] PM: hibernate: make compression threads configurable Xueqin Luo

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=888ce9cc-787b-4deb-87a6-d69cb7e04593@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=luoxueqin@kylinos.cn \
    --cc=pavel@kernel.org \
    --cc=rafael@kernel.org \
    /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

all inboxes | Powered by JetHome®