public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Will Deacon <will@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Paul E . McKenney" <paulmck@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Matthew Wilcox <willy@infradead.org>,
	Minchan Kim <minchan@kernel.org>, Nitin Gupta <ngupta@vflare.org>,
	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Subject: Re: [PATCH v2 6/7] zram: Allocate struct zcomp_strm as per-CPU memory
Date: Mon, 25 May 2020 09:24:07 +0200	[thread overview]
Message-ID: <20200525072407.GE329373@gmail.com> (raw)
In-Reply-To: <20200524215739.551568-7-bigeasy@linutronix.de>


* Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:

> zcomp::stream is per-CPU pointer, pointing to struct zcomp_strm which
> contains two pointer. Having struct zcomp_strm allocated directly as
> per-CPU memory would avoid one additional memory allocation and a
> pointer dereference.
> This also also simplifies adding a local_lock to struct zcomp_strm.
> 
> Allocate zcomp::stream directly as per-CPU memory.

Various typo/spelling fixes:

> zcomp::stream is a per-CPU pointer, pointing to struct zcomp_strm 
> which contains two pointers. Having struct zcomp_strm allocated 
> directly as per-CPU memory would avoid one additional memory 
> allocation and a pointer dereference. This also simplifies the 
> addition of a local_lock to struct zcomp_strm.


> diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
> index 1a8564a79d8dc..ae6dc137a1ed8 100644
> --- a/drivers/block/zram/zcomp.c
> +++ b/drivers/block/zram/zcomp.c
> @@ -37,19 +37,17 @@ static void zcomp_strm_free(struct zcomp_strm *zstrm)
>  	if (!IS_ERR_OR_NULL(zstrm->tfm))
>  		crypto_free_comp(zstrm->tfm);
>  	free_pages((unsigned long)zstrm->buffer, 1);
> -	kfree(zstrm);
> +	zstrm->tfm = NULL;
> +	zstrm->buffer = NULL;
>  }
>  
>  /*
>   * allocate new zcomp_strm structure with ->tfm initialized by
>   * backend, return NULL on error
>   */
> -static struct zcomp_strm *zcomp_strm_alloc(struct zcomp *comp)
> +static int zcomp_strm_alloc(struct zcomp_strm *zstrm,
> +			    struct zcomp *comp)

There's no need to put these into two lines, in a single line it's 
only 73 columns long. Leftover from some earlier bloat?

>  void zcomp_stream_put(struct zcomp *comp)
> @@ -159,16 +157,14 @@ int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist_node *node)
>  {
>  	struct zcomp *comp = hlist_entry(node, struct zcomp, node);
>  	struct zcomp_strm *zstrm;
> +	int ret;
>  
> -	if (WARN_ON(*per_cpu_ptr(comp->stream, cpu)))
> -		return 0;
> -
> -	zstrm = zcomp_strm_alloc(comp);
> -	if (IS_ERR_OR_NULL(zstrm)) {
> +	zstrm = per_cpu_ptr(comp->stream, cpu);
> +	ret = zcomp_strm_alloc(zstrm, comp);
> +	if (ret) {
>  		pr_err("Can't allocate a compression stream\n");
>  		return -ENOMEM;

BTW., with the allocation being in a single place and us having a 
proper 'ret', the return -ENOMEM could turn into 'return ret'?

Thanks,

	Ingo

  reply	other threads:[~2020-05-25  7:24 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-24 21:57 [PATCH 0/7 v2] Introduce local_lock() Sebastian Andrzej Siewior
2020-05-24 21:57 ` [PATCH v2 1/7] locking: " Sebastian Andrzej Siewior
2020-05-25  7:01   ` Ingo Molnar
2020-05-25  7:12     ` Ingo Molnar
2020-05-25 11:27       ` Sebastian Andrzej Siewior
2020-05-25 11:26     ` Sebastian Andrzej Siewior
2020-05-24 21:57 ` [PATCH v2 2/7] radix-tree: Use local_lock for protection Sebastian Andrzej Siewior
2020-05-25  6:29   ` Ingo Molnar
2020-05-25 11:11     ` Matthew Wilcox
2020-05-25 13:26       ` Ingo Molnar
2020-05-25 11:17     ` Sebastian Andrzej Siewior
2020-05-24 21:57 ` [PATCH v2 3/7] mm/swap: " Sebastian Andrzej Siewior
2020-05-25  6:44   ` Ingo Molnar
2020-05-25 17:07     ` Sebastian Andrzej Siewior
2020-05-24 21:57 ` [PATCH v2 4/7] squashfs: make use of local lock in multi_cpu decompressor Sebastian Andrzej Siewior
2020-05-24 21:57 ` [PATCH v2 5/7] connector/cn_proc: Protect send_msg() with a local lock Sebastian Andrzej Siewior
2020-05-25  7:18   ` Ingo Molnar
2020-05-25 14:51     ` Sebastian Andrzej Siewior
2020-05-24 21:57 ` [PATCH v2 6/7] zram: Allocate struct zcomp_strm as per-CPU memory Sebastian Andrzej Siewior
2020-05-25  7:24   ` Ingo Molnar [this message]
2020-05-25 16:50     ` Sebastian Andrzej Siewior
2020-05-24 21:57 ` [PATCH v2 7/7] zram: Use local lock to protect per-CPU data Sebastian Andrzej Siewior
2020-05-25  7:26   ` Ingo Molnar
2020-05-25 16:51     ` Sebastian Andrzej Siewior

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=20200525072407.GE329373@gmail.com \
    --to=mingo@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=ngupta@vflare.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=will@kernel.org \
    --cc=willy@infradead.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