Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2628369pxk; Sun, 6 Sep 2020 07:32:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBlqXgIoMqm6HrsGjVEa/AHWY4+A4v09W4bAF82/dhbzaKF5xhJ46a95HwDE4j99My9/vC X-Received: by 2002:a05:6402:1151:: with SMTP id g17mr17994977edw.227.1599402753105; Sun, 06 Sep 2020 07:32:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599402753; cv=none; d=google.com; s=arc-20160816; b=mgfU4wmClccrwEDh/cFHuuU/qujzw55ay3WN52K/mc5yuZMosBQp0ufsrvT2q9bDv9 StwV8qgEdo1WlJeD2DDftQ+/HUjOoOIwc8/9wxa8gNDRbb74UeqtjECb4arRfL5LKDJv DGp42LrBCwCVYs1GmaZAPoPjAyxIG8fiRgZ9eDia9XzYgLGLcFjgK0HwtezOA981184I Zv2eKtAIQZFPbShNkrAjtpec+StrJKuIMxfPW+ALqCMy2q/zvgQJ1bo1podKu7x/lfzb AjIRtD49dAhMTmjxqL6x/H+MKuIK4J0qpoTmyRXdOn/4YXfrzVNV6o7Wjuw7dxz7uC3W khfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=DUKCwOPEa+mIT8CkBzzimpq0h4WW28mGQ0Yzq+7+7Ho=; b=YkavkMry1B0zd24+f5n8C/vaFQjAcev9rEZIuAdptwIN4veF0pvNwDBolt3xicRJI+ Y9H6co7zBbkPq70q0r1Q2Div4owFQxLQ1Qd4LdOYyQchD61bFa7up6KEvF5UrP93+b5X sUmjl0MydLt92o26ls3ew3La9mYh64PgH/QzLeGPEnUmyOw+TrwKhIXwAxGJFQw36HU+ RSdHR1AZ6IQxzdhnLgu1CIzsK49T9xhlG4TrHSvaWZvZ3KryUbLa+jgCU2ItmROglCgp 07cfrzdDcZa+oZU+I8zUUWC9uS72/pBEFBfUN58fNe17hTiTcZr1/56cKYHdd1JdVcjn 4hAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cF69c5qc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n12si4338252ejx.468.2020.09.06.07.32.10; Sun, 06 Sep 2020 07:32:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cF69c5qc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728941AbgIFO14 (ORCPT + 99 others); Sun, 6 Sep 2020 10:27:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:59102 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728918AbgIFO1K (ORCPT ); Sun, 6 Sep 2020 10:27:10 -0400 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.