linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Miaohe Lin <linmiaohe@huawei.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/mempool: Add 'else' to split mutually exclusive case
Date: Mon, 24 Aug 2020 12:27:10 -0700	[thread overview]
Message-ID: <37bbda0e0d94d3324210fa807f4061a9e9bd66bc.camel@perches.com> (raw)
In-Reply-To: <20200824121840.4cd7eb3dce03e8e1473221b3@linux-foundation.org>

On Mon, 2020-08-24 at 12:18 -0700, Andrew Morton wrote:
> On Mon, 24 Aug 2020 07:53:54 -0400 Miaohe Lin <linmiaohe@huawei.com> wrote:
> 
> > Add else to split mutually exclusive case and avoid some unnecessary check.
> > 
> > --- a/mm/mempool.c
> > +++ b/mm/mempool.c
> > @@ -60,9 +60,8 @@ static void check_element(mempool_t *pool, void *element)
> >  	/* Mempools backed by slab allocator */
> >  	if (pool->free == mempool_free_slab || pool->free == mempool_kfree)
> >  		__check_element(pool, element, ksize(element));
> > -
> >  	/* Mempools backed by page allocator */
> > -	if (pool->free == mempool_free_pages) {
> > +	else if (pool->free == mempool_free_pages) {
> >  		int order = (int)(long)pool->pool_data;
> >  		void *addr = kmap_atomic((struct page *)element);
> >  
> 
> It doesn't seem to change code generation (compiler is smart), but I
> think it helps readability.

style: braces should be added to the first test.

Perhaps better as:
---
 mm/mempool.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/mm/mempool.c b/mm/mempool.c
index 79bff63ecf27..d0206eab86a4 100644
--- a/mm/mempool.c
+++ b/mm/mempool.c
@@ -57,12 +57,12 @@ static void __check_element(mempool_t *pool, void *element, size_t size)
 
 static void check_element(mempool_t *pool, void *element)
 {
-	/* Mempools backed by slab allocator */
-	if (pool->free == mempool_free_slab || pool->free == mempool_kfree)
+	if (pool->free == mempool_free_slab ||
+	    pool->free == mempool_kfree) {
+		/* Mempools backed by slab allocator */
 		__check_element(pool, element, ksize(element));
-
-	/* Mempools backed by page allocator */
-	if (pool->free == mempool_free_pages) {
+	} else if (pool->free == mempool_free_pages) {
+		/* Mempools backed by page allocator */
 		int order = (int)(long)pool->pool_data;
 		void *addr = kmap_atomic((struct page *)element);
 




      parent reply	other threads:[~2020-08-24 19:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-24 11:53 Miaohe Lin
2020-08-24 19:18 ` Andrew Morton
2020-08-24 19:22   ` Matthew Wilcox
2020-08-24 19:27   ` Joe Perches [this message]

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=37bbda0e0d94d3324210fa807f4061a9e9bd66bc.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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