All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: mateusznosek0@gmail.com
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	akpm@linux-foundation.org
Subject: Re: [PATCH] mm/mmu_notifier.c: micro-optimization substitute kzalloc with kmalloc
Date: Sun, 6 Sep 2020 17:26:45 +0300	[thread overview]
Message-ID: <20200906142645.GA1976319@kernel.org> (raw)
In-Reply-To: <20200906114321.16493-1-mateusznosek0@gmail.com>

Hi,

On Sun, Sep 06, 2020 at 01:43:21PM +0200, mateusznosek0@gmail.com wrote:
> From: Mateusz Nosek <mateusznosek0@gmail.com>
> 
> Most fields in struct pointed by 'subscriptions' are initialized explicitly
> after the allocation. By changing kzalloc to kmalloc the call to memset
> is avoided. As the only new code consists of 2 simple memory accesses,
> the performance is increased.

Is there a measurable performance increase?

The __mmu_notifier_register() is not used that frequently to trade off
robustness of kzalloc() for slight (if visible at all) performance gain.

> Signed-off-by: Mateusz Nosek <mateusznosek0@gmail.com>
> ---
>  mm/mmu_notifier.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c
> index 4fc918163dd3..190e198dc5be 100644
> --- a/mm/mmu_notifier.c
> +++ b/mm/mmu_notifier.c
> @@ -625,7 +625,7 @@ int __mmu_notifier_register(struct mmu_notifier *subscription,
>  		 * know that mm->notifier_subscriptions can't change while we
>  		 * hold the write side of the mmap_lock.
>  		 */
> -		subscriptions = kzalloc(
> +		subscriptions = kmalloc(
>  			sizeof(struct mmu_notifier_subscriptions), GFP_KERNEL);
>  		if (!subscriptions)
>  			return -ENOMEM;
> @@ -636,6 +636,8 @@ int __mmu_notifier_register(struct mmu_notifier *subscription,
>  		subscriptions->itree = RB_ROOT_CACHED;
>  		init_waitqueue_head(&subscriptions->wq);
>  		INIT_HLIST_HEAD(&subscriptions->deferred_list);
> +		subscriptions->active_invalidate_ranges = 0;
> +		subscriptions->has_itree = false;
>  	}
>  
>  	ret = mm_take_all_locks(mm);
> -- 
> 2.20.1
> 
> 

-- 
Sincerely yours,
Mike.


  reply	other threads:[~2020-09-06 14:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-06 11:43 [PATCH] mm/mmu_notifier.c: micro-optimization substitute kzalloc with kmalloc mateusznosek0
2020-09-06 14:26 ` Mike Rapoport [this message]
2020-09-06 16:06   ` Mateusz Nosek
2020-09-08  6:42     ` Mike Rapoport
2020-09-08 23:32       ` Jason Gunthorpe

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=20200906142645.GA1976319@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mateusznosek0@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.