Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1971018pxb; Mon, 13 Sep 2021 09:12:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvgLfnrqXDOgw8fKI73kS3/ZFsPqAdC56fmUpyYx/I6vUizblKavueXo27lNKn5YdS4Qfp X-Received: by 2002:a17:906:2ac1:: with SMTP id m1mr13375416eje.518.1631549563868; Mon, 13 Sep 2021 09:12:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631549563; cv=none; d=google.com; s=arc-20160816; b=X6e4fKTQjwZIEjtPif15os7d0a+OOVhJ2NZWcmwV4eV+epWY7KH7MNf2mqElD+YhPG aT0/61l03Y4SHu9yshPo3463bi549JGPvwxNpXd7+t+YXqxtH/+fEaXprd3s/Y/5tHXC p6zi6Y5d9RMF1sTYsu4OaZymMo3C2R1pMkwiiOOA50DvwrDy/GCzjnYbw/YCSjj3HQRX Aw3cgUjFp3LCEZpdMqFqdKQ/HJgHLjbh8fCKxw7fzSnj0vdsTGtRqXdcZo8rAJDlhGJy IcvXaVVBGDJcTVc+TFFZoJSJoiQ5SfeVhUSgNU89CTKLw+1XMgPw1WOA71w3Z84ZL2sW 0Xuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=ATpdkY7nfx9lmc90IZwlVUxAMVDZdUSblKHwm1jeRBM=; b=Z6IlrVIoqqFjDHnD6IQ7LzOpnR3fCsnTzM35ETwKeedyGxGCHbhSCmAvFxkU4Wh+RW 7na04X9Gk5taXPrKGmhiaOV/wZ4bi+IqO7jAPB+57ZeKl06bSp/NVdY8PqFXkzXxA2rA TaIs3A466udNLV3byzFS7tt+dyFQB2KeSvp4oM/gUqNdhfSJv0H/JFLNK1Rnfy/qucE/ EdLRRHLIaku2OXBjZCe2ESINOSSosgO67C0QabO3hIwcIV4NWYrEjLwM4VoHd19Daere j94ifzTfXUE4CN4Ksd2156bVCU9A6KAQPX6gMlsmxxnqoXxvywmtR3j/gqfoZ4pcwXhx 4ohg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ga1si7383014ejc.128.2021.09.13.09.12.18; Mon, 13 Sep 2021 09:12:43 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345432AbhIMQLJ (ORCPT + 99 others); Mon, 13 Sep 2021 12:11:09 -0400 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:42113 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344663AbhIMQLH (ORCPT ); Mon, 13 Sep 2021 12:11:07 -0400 Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 18DG9jti002589; Mon, 13 Sep 2021 18:09:45 +0200 Date: Mon, 13 Sep 2021 18:09:45 +0200 From: Willy Tarreau To: David Laight Cc: Douglas Gilbert , LKML Subject: Re: how many memset(,0,) calls in kernel ? Message-ID: <20210913160945.GA2456@1wt.eu> References: <1c4a94df-fc2f-1bb2-8bce-2d71f9f1f5df@interlog.com> <20210912045608.GB16216@1wt.eu> <88976a40175c491fb5e3349f6686ad67@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <88976a40175c491fb5e3349f6686ad67@AcuMS.aculab.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 13, 2021 at 04:03:09PM +0000, David Laight wrote: > > 36: b9 06 00 00 00 mov $0x6,%ecx > > 3b: 4c 89 e7 mov %r12,%rdi > > 3e: f3 ab rep stos %eax,%es:(%rdi) > > > > The last line does exactly "memset(%rdi, %eax, %ecx)". Just two bytes > > for some code that modern processors are even able to optimize. > > Hmmm I'd bet that 6 stores will be faster on ~everything. > 'modern' processors do better than some older ones [1], but 6 > writes isn't enough to get into the really fast paths. > So you'll still take a few cycles of setup. The exact point is, here it's up to the compiler to decide thanks to its builtin what it considers best for the target CPU. It already knows the fixed size and the code is emitted accordingly. It may very well be a call to the memset() function when the size is large and a power of two because it knows alternate variants are available for example. The compiler might even decide to shrink that area if other bytes are written just after the memset(), leaving only holes touched by memset(). Willy