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=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 65135C10DCE for ; Wed, 18 Mar 2020 08:20:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 25BB42076D for ; Wed, 18 Mar 2020 08:20:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 25BB42076D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=SDF.ORG Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id ACABF6B0007; Wed, 18 Mar 2020 04:20:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A7BFF6B0008; Wed, 18 Mar 2020 04:20:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 990F86B000A; Wed, 18 Mar 2020 04:20:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0040.hostedemail.com [216.40.44.40]) by kanga.kvack.org (Postfix) with ESMTP id 7F5846B0007 for ; Wed, 18 Mar 2020 04:20:44 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5D6882C79 for ; Wed, 18 Mar 2020 08:20:44 +0000 (UTC) X-FDA: 76607786808.03.tub33_5db7183354243 X-HE-Tag: tub33_5db7183354243 X-Filterd-Recvd-Size: 2513 Received: from mx.sdf.org (mx.sdf.org [205.166.94.20]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Wed, 18 Mar 2020 08:20:43 +0000 (UTC) Received: from sdf.org (IDENT:lkml@otaku.sdf.org [205.166.94.8]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 02I8KZcB006930 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Wed, 18 Mar 2020 08:20:36 GMT Received: (from lkml@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 02I8KZNK014406; Wed, 18 Mar 2020 08:20:35 GMT Date: Wed, 18 Mar 2020 08:20:35 +0000 From: George Spelvin To: Dan Williams Cc: Kees Cook , Linux MM , Andrew Morton , lkml@sdf.org Subject: Re: [PATCH v2] mm/shuffle.c: Fix races in add_to_free_area_random() Message-ID: <20200318082035.GB2281@SDF.ORG> References: <20200317135035.GA19442@SDF.ORG> <202003171435.41F7F0DF9@keescook> <20200317230612.GB19442@SDF.ORG> <202003171619.23210A7E0@keescook> <20200318014410.GA2281@SDF.ORG> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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: On Tue, Mar 17, 2020 at 08:53:55PM -0700, Dan Williams wrote: > On Tue, Mar 17, 2020 at 6:44 PM George Spelvin wrote: >> - if (rand_bits == 0) { >> - rand_bits = 64; >> - rand = get_random_u64(); >> + if (unlikely(rshift == 0)) { > > I had the impression that unless unlikely is "mostly never" then it > can do more harm than good. Is a branch guaranteed to be taken every > BITS_PER_LONG'th occurrence really a candidate for unlikely() > annotation? I had to look this up. GCC manual: For the purposes of branch prediction optimizations, the probability that a '__builtin_expect' expression is 'true' is controlled by GCC's 'builtin-expect-probability' parameter, which defaults to 90%. You can also use '__builtin_expect_with_probability' to explicitly assign a probability value to individual expressions. So I think that <= 10% is good enough, which is true in this case. I was tring to encourage the compiler to: * Place this code path out of line, and * Not do the stack manipulations (build a frame, spill registers) needed for a non-leaf function if this path isn't taken.