Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1152753imu; Fri, 9 Nov 2018 11:48:23 -0800 (PST) X-Google-Smtp-Source: AJdET5f2gipm8wY81hPpfZ6nONMRU2TNmr91i6aIHZiLI14CC5SwPu4erRL8+J4kxcDve3O0HYRp X-Received: by 2002:a63:82c6:: with SMTP id w189mr8769005pgd.344.1541792903870; Fri, 09 Nov 2018 11:48:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541792903; cv=none; d=google.com; s=arc-20160816; b=mP5gpQ6QXBBpGxgjqoy4X60AGBcbL+5fp8+eyxjsWhkG7gpQTfGzIbe50TdQBjuSXx LVwOCdf2Hvqn6R0LE+z3DsKeEn6Fd991VF4c8zFrU3y1m94JNoPohoOmkZodWBnG+8n8 bJKq1H923G3vW0yQll3Lw5nm2QkTLcgA05hJLcBN4CxsNCvgb9YhoROPJ9cfJ5E0gpfD pY0bZXEtiFUiLIxSxJ5hni3gNBjaeNrEoH27IbKUS5hZJq4X/5YKljTgJT+fLpqPlFnn sCv0O2Xb42GBWz0ZPxLTQcJaPRkmZZtojuGuLg6Ei1LTRw6wG1vIeo+8UOToSZthPyoC WxVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=BKYMu4/Vja5epBBtzMUUa0Ap2qbn150hsVACybBjsFE=; b=U7BDG5QXNvtrAKA/dAPTG+q104oTMQvhhLkmuLbUghhNRwxlcWoqi78m7yyxYVEDkc cZYurwTZEcAR39jhzzr79YHo4d4rP/sVmStkGPrMY7/XAZh573p8ErK9s4HW110Bg/zO HXO0NrpIvwAw3tKw6mU2kbbIJthQdRSSwMxb5gXBy2mNO9OKvTvPOWlAMPwnk7W/mMkC XGbxgnG2y2OYo+d1yvXdM7nLsxFVxtErjVOZ0ZtfJQoRlS6n6Pz046T8bGUz9hjx2nke fresIjLLAfa+Q1/w14M/5tM8Q8E+qfyyKXVJbENMy2zuVuA1vZgcL6XzzFQ7+pF3yIjK GkFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=F4XU8ewW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p25-v6si9898314pli.239.2018.11.09.11.48.07; Fri, 09 Nov 2018 11:48:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=F4XU8ewW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726953AbeKJF3p (ORCPT + 99 others); Sat, 10 Nov 2018 00:29:45 -0500 Received: from mail-ot1-f66.google.com ([209.85.210.66]:34792 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725883AbeKJF3p (ORCPT ); Sat, 10 Nov 2018 00:29:45 -0500 Received: by mail-ot1-f66.google.com with SMTP id t5so2714224otk.1 for ; Fri, 09 Nov 2018 11:47:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=BKYMu4/Vja5epBBtzMUUa0Ap2qbn150hsVACybBjsFE=; b=F4XU8ewW1rZr2ayXyFj2C7Nw4nMxAgNS2492P2hE8nPgHU16av1XLPFewEt7fTsY+L HWKNvOiWZoikAo83W4sYZv7vSAJ2DebOlsWNWjljAXcz9Fr47qLSiAhyBXhUrIGJuJ5R WdnVX8eL4UaLNxSZ2aounOkTFAGuzyY36oJFgjQMW1/Fr9mxF7pP9478G4Q/VLEbeTVw QdF5QdmHX2ldmZsNlWmgXWwihmocnwpyVEqKJxg2WISO3vsxT6q3exxuu9vLdie0FIz3 iuDQWXPg6IY+sTb5GHwDsEIXAILLs7oGFWB5VszR4jaCwSNM5lwoUU20kb/az83tdnGT wmTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=BKYMu4/Vja5epBBtzMUUa0Ap2qbn150hsVACybBjsFE=; b=kzAFmEFc+guzmDPPI5KFFpxAjJkvgdoJB9zpRwM6RJWk8UATS58hlZ+GAu4R51vGNc JAww4VNrVPR1tmp2HpzXruvLvQCJBBIVtv7Z1ztqJCl43O5CgIUmUp2RYmEaPTUU8Edf 3PXCWoZ7DgZvefa3Y+Cr/vrcFmAWDz+v3xID7Ac19sYYOnytiA3fJzKC+H/sIlqhswY8 ccqXeC51CMj6SlCEkTG8Gx5zO8Iq7kl/rpzgS64axeZWFrxnvT8M2XwpY68qlyflANzh SzmyNVTyhvSjeBeJyl7PGB0NcoEUqlhaC6BU/l5cLbcm1gbrrRZHX/fnyaKZFkI1SzEc bsMg== X-Gm-Message-State: AGRZ1gIC9rJcdQVzH3zDgfb1YfQUxdL24gL7Ljm8rC5iIBYe7x4WD1vw ++77aKKfr7/2Gc4DPEyfkZI= X-Received: by 2002:a9d:645:: with SMTP id 63mr6397671otn.125.1541792861503; Fri, 09 Nov 2018 11:47:41 -0800 (PST) Received: from simulacrum.agostinelli.home.saggio.net (cpe-66-68-97-1.austin.res.rr.com. [66.68.97.1]) by smtp.gmail.com with ESMTPSA id u143-v6sm3690290oie.38.2018.11.09.11.47.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 09 Nov 2018 11:47:40 -0800 (PST) Date: Fri, 9 Nov 2018 13:47:38 -0600 From: "Darryl T. Agostinelli" To: Vlastimil Babka Cc: Andrew Morton , David Laight , 'Bart Van Assche' , "linux-kernel@vger.kernel.org" , Mel Gorman , Christoph Lameter , Roman Gushchin Subject: Re: [PATCH] slab.h: Avoid using & for logical and of booleans Message-ID: <20181109194738.GA18649@simulacrum.agostinelli.home.saggio.net> References: <20181105204000.129023-1-bvanassche@acm.org> <62188a351f2249188ce654ee03c894b1@AcuMS.aculab.com> <3c9adab0f1f74c46a60b3d4401030337@AcuMS.aculab.com> <60deb90d-e521-39e5-5072-fc9efb98e365@suse.cz> <9af3ac1d43bb422cb3c41e7e8e422e6e@AcuMS.aculab.com> <20181109110019.c82fba8125d4e2891fbe4a6c@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 09, 2018 at 08:16:07PM +0100, Vlastimil Babka wrote: > On 11/9/18 8:00 PM, Andrew Morton wrote: > > On Fri, 9 Nov 2018 09:12:09 +0100 Vlastimil Babka wrote: > > > >> Multiple people have reported the following sparse warning: > >> > >> ./include/linux/slab.h:332:43: warning: dubious: x & !y > >> > >> The minimal fix would be to change the logical & to boolean &&, which emits the > >> same code, but Andrew has suggested that the branch-avoiding tricks are maybe > >> not worthwile. David Laight provided a nice comparison of disassembly of > >> multiple variants, which shows that the current version produces a 4 deep > >> dependency chain, and fixing the sparse warning by changing logical and to > >> multiplication emits an IMUL, making it even more expensive. > >> > >> The code as rewritten by this patch yielded the best disassembly, with a single > >> predictable branch for the most common case, and a ternary operator for the > >> rest, which gcc seems to compile without a branch or cmov by itself. > >> > >> The result should be more readable, without a sparse warning and probably also > >> faster for the common case. > >> > >> Reported-by: Bart Van Assche > >> Reported-by: Darryl T. Agostinelli > >> Suggested-by: Andrew Morton > >> Suggested-by: David Laight > >> Fixes: 1291523f2c1d ("mm, slab/slub: introduce kmalloc-reclaimable caches") > >> Signed-off-by: Vlastimil Babka > >> --- > >> include/linux/slab.h | 24 ++++++++++++------------ > >> 1 file changed, 12 insertions(+), 12 deletions(-) > >> > >> diff --git a/include/linux/slab.h b/include/linux/slab.h > >> index 918f374e7156..18c6920c2803 100644 > >> --- a/include/linux/slab.h > >> +++ b/include/linux/slab.h > >> @@ -304,6 +304,8 @@ enum kmalloc_cache_type { > >> KMALLOC_RECLAIM, > >> #ifdef CONFIG_ZONE_DMA > >> KMALLOC_DMA, > >> +#else > >> + KMALLOC_DMA = KMALLOC_NORMAL, > >> #endif > >> NR_KMALLOC_TYPES > >> }; > > > > I don't think this works correctly. Resetting KMALLOC_DMA to 0 will > > cause NR_KMALLOC_TYPES to have value 1. > > Doh, right! Thanks for catching this. > > This? Not terribly elegant, but I don't see a nicer way right now... > How about the solution I proposed yesterday? https://lkml.org/lkml/2018/11/9/750 It doesn't involve any tricks. As it is, this sparse warning is begging for a trick. Let's not oblidge it to much.