From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C021C433E2 for ; Sun, 6 Sep 2020 14:26:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 08DD120760 for ; Sun, 6 Sep 2020 14:26:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="cF69c5qc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 08DD120760 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 15FA36B0002; Sun, 6 Sep 2020 10:26:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 10E6C6B0037; Sun, 6 Sep 2020 10:26:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 022D26B0055; Sun, 6 Sep 2020 10:26:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0133.hostedemail.com [216.40.44.133]) by kanga.kvack.org (Postfix) with ESMTP id DE8E16B0002 for ; Sun, 6 Sep 2020 10:26:53 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A94A0180AD806 for ; Sun, 6 Sep 2020 14:26:53 +0000 (UTC) X-FDA: 77232863106.14.fog50_40062f9270c4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 7065F18229835 for ; Sun, 6 Sep 2020 14:26:53 +0000 (UTC) X-HE-Tag: fog50_40062f9270c4 X-Filterd-Recvd-Size: 3085 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Sun, 6 Sep 2020 14:26:52 +0000 (UTC) Received: from kernel.org (unknown [87.71.73.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A0FCB20714; Sun, 6 Sep 2020 14:26:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599402411; bh=kk8tvuDP9hC/7aRZ33FULqCWUjta7ZZ0o/f5KhDoo6Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=cF69c5qc4w5+kMLmw1DlRKZQdvFUM+3fCtjTMRqBaOO4ZE2JPgdAjLbDZClTteuhE wnpY2T1UVE7n9xSNdiKz7vnzyDd+uOOEd42tuQJRrtvBYONVwLKhXSi8xlFVTmerrx NgKaP2n5kRm1BCH/0vl1ZCXhfBxKLvs9s0HxJtVM= Date: Sun, 6 Sep 2020 17:26:45 +0300 From: Mike Rapoport 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 Message-ID: <20200906142645.GA1976319@kernel.org> References: <20200906114321.16493-1-mateusznosek0@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200906114321.16493-1-mateusznosek0@gmail.com> X-Rspamd-Queue-Id: 7065F18229835 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi, On Sun, Sep 06, 2020 at 01:43:21PM +0200, mateusznosek0@gmail.com wrote: > From: Mateusz Nosek > > 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 > --- > 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.