Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1105036imu; Fri, 9 Nov 2018 11:01:03 -0800 (PST) X-Google-Smtp-Source: AJdET5cA4qqtT3yRcUJJ/i9xpcGuFJ/kp9FJgkoconNPjXCO2BHO5Y6atIK+jgy4JkUuJds6+1ay X-Received: by 2002:a63:ac02:: with SMTP id v2-v6mr8491484pge.414.1541790063232; Fri, 09 Nov 2018 11:01:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541790063; cv=none; d=google.com; s=arc-20160816; b=WhrQbn540WFN/MjtEJkJr1PUgTpwum7fsTRMuLiXgZ1CJP94ROP65+lT6sCKqf6F7+ oikzmvpS0mv9AE0212o4LqGJvWC1AvKQGZv0HqH0y0cY869LB68kfJ9xJrgOZKOFRiqA oJNLbLRKHHzBjm336kDHD1XDSFD1Nc5fypykof2Fh8K7qb+xsMm0dH+GPeiiWh0MoaKR yubxI0DvhNl7TZ05aS/pl1V3pT5Abr6q7bCT0bk2X3H8oT1bASRENr+jQnPSNQng2UaZ FLufhhvvBaZ1cY3CbaA0TqaRjkZ6TD1HvHe5Mczx3iFTNZNGaDPnUYbnvt4xHPBlzsMO Js1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=RDL74qRKkETvsHjgi0JZa4rAhsqQfMWovPNmxkfz0UY=; b=PdAyXrZjxAGi1Qs1KfKJU8PEUFOlhfK7llwBpvu0lB9x88LgNNiEUBOQwczUP0sSDp mwebo2lLcNK+PCUC6vXL5Lvw4z6EjfSNua7T1iW14Z5gBz4SWVJXjjEP2Q2g5DS2fpi2 76sRT6m8N6jnBJZtZEQwbECCaTWAijBARBS0CmBBmqBx3YmRm+P5ZsR1KjBoifPIMDsT /WtTfWV/PX24ayeBVf8aMvVoXudNDE1nsEioivQgO7mjaQ2l0LcJJlWAEFfskFkn2hl9 GE3qoQ0gKYfJDdbQ9UUb5ddre6NpIkqpCgsQDlhTQQJJ27iG10smsA/ZWmoBSeM0rJlr PRXw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d20-v6si7900036pls.170.2018.11.09.11.00.44; Fri, 09 Nov 2018 11:01:03 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728590AbeKJEmO (ORCPT + 99 others); Fri, 9 Nov 2018 23:42:14 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34226 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728162AbeKJEmO (ORCPT ); Fri, 9 Nov 2018 23:42:14 -0500 Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5CA057A9; Fri, 9 Nov 2018 19:00:20 +0000 (UTC) Date: Fri, 9 Nov 2018 11:00:19 -0800 From: Andrew Morton To: Vlastimil Babka Cc: David Laight , "'Bart Van Assche'" , "linux-kernel@vger.kernel.org" , Mel Gorman , Christoph Lameter , Roman Gushchin , "Darryl T. Agostinelli" Subject: Re: [PATCH] slab.h: Avoid using & for logical and of booleans Message-Id: <20181109110019.c82fba8125d4e2891fbe4a6c@linux-foundation.org> In-Reply-To: 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> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. enum foo { a = 0, b, c = 0, d } main() { printf("%d %d %d %d\n", a, b, c, d); } akpm3> ./a.out 0 1 0 1