Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp332442pxu; Fri, 11 Dec 2020 03:31:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYPJF5ONd4GT/2WG3msCYxCFcqVq6sr5DOeRAiVP/AdpREqPmf2tg8xJP/ykjyrAMaQiVL X-Received: by 2002:a17:906:8354:: with SMTP id b20mr10478071ejy.397.1607686297592; Fri, 11 Dec 2020 03:31:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607686297; cv=none; d=google.com; s=arc-20160816; b=Yfdk5H/NEl9w1om993KpAh1O4j7Ay0kNyV2MHhyMl18HomahtY7cywXkDaeiVwIkPx d+2M5Hcpx6FhqqmAcdebwk4GdemEzg5l578b0C0nlfArVTzCDaQdOi8xVPxS9N1Fmi54 cFkdzSzlb0lzW9xX/48ivrrHwxQSzxNkZBFHXg+EEXDpIB6ULSG6xWQLYRHZUUy6jj1V xGocl5kwduehaIW58s9R741Z2w1ypopmK7/ly7Mxbu/3cu38gClWmIbkNRIlg6F1flJ1 yTJbt8DJ1CmPa7/3G2ujby7QBDhyXMw5/5x/CziX2rPztoCOaaNFF+6kCO1BXfRysiJO 1S9Q== 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; bh=v10vH0JtTJ4QhOBzVIInc9C6D7wOqsviS/Xma3qCG+4=; b=EYhvHi45Ijraqj4VS7wMzA1oahIXbB3GZpPlHQQCm2cL+pND3Mohvhge+IndJ3xHLW hVINdhpejJSKtC52iEffe2KWog5riT594yhfpN7N1UTTQKJCA9wzbYmhEwzcng7QIBwS abHJoLYaQ3GPL+lNpgxHIMAmwb4sFLzRgQm96VKiTSsWnpYLAzZ6CHU+qdAtUmJq0xLv 0RDQrUMmwkkdrMYpfZHJCSGKiKMfWFKWx5yMFKD7QJ73hTZ4+EC83ii++qJPP7+oWfAJ 7NbV9mEIFvwxXgYjpWmmaYlHZ3r2KxQyGlElbvQJBzR+g+ujHYAVaGBMye6ZNyDT+QCJ 4xJQ== 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 bs24si4544551edb.519.2020.12.11.03.31.13; Fri, 11 Dec 2020 03:31:37 -0800 (PST) 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 S2395010AbgLKCCK (ORCPT + 99 others); Thu, 10 Dec 2020 21:02:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388458AbgLKCBs (ORCPT ); Thu, 10 Dec 2020 21:01:48 -0500 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE5D8C0613D6; Thu, 10 Dec 2020 18:01:07 -0800 (PST) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1knXjw-000Sct-GJ; Fri, 11 Dec 2020 02:01:00 +0000 Date: Fri, 11 Dec 2020 02:01:00 +0000 From: Al Viro To: Pavel Begunkov Cc: Christoph Hellwig , Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] iov_iter: optimise iter type checking Message-ID: <20201211020100.GB107834@ZenIV.linux.org.uk> References: <9bc27cb3ef6ab49b6b2ccee3db6613838aee17af.1605799583.git.asml.silence@gmail.com> <20201119170340.GA6179@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 19, 2020 at 05:12:44PM +0000, Pavel Begunkov wrote: > On 19/11/2020 17:03, Christoph Hellwig wrote: > > On Thu, Nov 19, 2020 at 03:29:43PM +0000, Pavel Begunkov wrote: > >> The problem here is that iov_iter_is_*() helpers check types for > >> equality, but all iterate_* helpers do bitwise ands. This confuses > >> a compiler, so even if some cases were handled separately with > >> iov_iter_is_*(), it can't eliminate and skip unreachable branches in > >> following iterate*(). > > > > I think we need to kill the iov_iter_is_* helpers, renumber to not do > > the pointless bitmask and just check for equality (might turn into a > > bunch of nice switch statements actually). > > There are uses like below though, and that would also add some overhead > on iov_iter_type(), so it's not apparent to me which version would be > cleaner/faster in the end. But yeah, we can experiment after landing > this patch. > > if (type & (ITER_BVEC|ITER_KVEC)) There are exactly 3 such places, and all of them would've been just as well with case ITER_BVEC: case ITER_KVEC: ... in a switch. Hmm... I wonder which would work better: enum iter_type { ITER_IOVEC = 0, ITER_KVEC = 2, ITER_BVEC = 4, ITER_PIPE = 6, ITER_DISCARD = 8, }; iov_iter_type(iter) (((iter)->type) & ~1) iov_iter_rw(iter) (((iter)->type) & 1) or enum iter_type { ITER_IOVEC, ITER_KVEC, ITER_BVEC, ITER_PIPE, ITER_DISCARD, }; iov_iter_type(iter) (((iter)->type) & (~0U>>1)) // callers of iov_iter_rw() are almost all comparing with explicit READ or WRITE iov_iter_rw(iter) (((iter)->type) & ~(~0U>>1) ? WRITE : READ) with places like iov_iter_kvec() doing i->type = ITER_KVEC | ((direction == WRITE) ? BIT(31) : 0); Preferences?