Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp9626653ybc; Sat, 30 Nov 2019 10:58:09 -0800 (PST) X-Google-Smtp-Source: APXvYqy6489pRwDMFIHMfmrt/5cNEJ2J1WkxZSNN/yNiEhz3G/EiZoiPMbBDd5BzWU4kXPTmrF+N X-Received: by 2002:a17:906:6d94:: with SMTP id h20mr2592303ejt.253.1575140289135; Sat, 30 Nov 2019 10:58:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575140289; cv=none; d=google.com; s=arc-20160816; b=EOt3fL4enV2UZg003vgRWBl6qPntrRnAjGijHn1fRsNkYtLGMmuGgVrFL5bws1I4xd 195xa3Ix4lCFAWTbX2ulhsPMKmmz856wGxe2AmI3NKDb5F4A9LEQLnhWz7XnofrIU5/n 0zN/0UJkS2z3Yuin0kSQpII8cOId4c9A2Lz1gcm1IdHl/caM0FcG1oNuaqXMlgtReCfs ih0NR0+z1BEbqUmRL4NzJmSWIfoZdBFJKT1DDpuRBhZrvmlx1lymTcIos7veWiHQHA6b BUOWdqJlsYp7qyCDAc1xVHnMGdGFZ0xyZd2mwcPUuDyFnbecuJY3WBwUUsheWnS6rdMP wjEA== 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:date:from:dkim-signature; bh=0UHRKhmLt5buFa6gOweNrq+UrUlF6bhjJjwMgeW4uPI=; b=iAuaXu6LBIw09zrGmGK7fl1+4vuPyzdob13q8BXkP9xzeSE9qqGkMqNm95aiOjxbVH Um1qExxNppGJPj4daTX7VQPu+7M/aSPfLEOX0y6/iyEtxApXEiEdoOF4v831mcxlgu+Y oZy838OgtqXV0sOzYgb6vA6ckYo23dcx12R+gMi+oN6INQDerMI2Mg5TnmKeUsy7o6Jk SI25y4oSVioI+fjHl5EZj7/n8mP0s0F9/zL21oZJhMfl+sHAEJlGTebv2Fw7Eazez0OT b9p3DFW8RGz/jneDDZ/gPx8Q8c+GzN/f5746/BNsUn+4gNV/L8/k6MvWN1Mgj11zC4xL TZjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=PqIhJxKi; 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 bs15si18124594edb.408.2019.11.30.10.57.44; Sat, 30 Nov 2019 10:58:09 -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=fail header.i=@gmail.com header.s=20161025 header.b=PqIhJxKi; 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 S1727231AbfK3S4i (ORCPT + 99 others); Sat, 30 Nov 2019 13:56:38 -0500 Received: from mail-qv1-f67.google.com ([209.85.219.67]:43915 "EHLO mail-qv1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726799AbfK3S4i (ORCPT ); Sat, 30 Nov 2019 13:56:38 -0500 Received: by mail-qv1-f67.google.com with SMTP id p2so2574408qvo.10; Sat, 30 Nov 2019 10:56:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=0UHRKhmLt5buFa6gOweNrq+UrUlF6bhjJjwMgeW4uPI=; b=PqIhJxKij3aopu/sg/VlF9UH78PhXONkLROSSnUW1HD9S/4eBgKT3PaA1GG0n8vcKI +WNkJxTCoUEfdTbcUG1DR0uFrRmbrVboff+KtMRzvA5JBBMx0aiwDlqVfRaZhUwLPxKb myK0X3sGnVrWzBpY0DeBBRTXev+2PJ0q+IrRG5PPtB1h68O+C2DpaA1/J2omRptDmIq7 f317hUxmET+xBwvkjXBpF1jjjyENUbu5876u/c7VwIcygEhydyxk17A/6DKqQ4WhxmHb BT7jLRZPfeqJxWf4ZfdD90rs3UA2M2MuCfkg5yqErxymo+yVbFZrBB/0ClH1HpXyyQ5X u0cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=0UHRKhmLt5buFa6gOweNrq+UrUlF6bhjJjwMgeW4uPI=; b=WZ+vtg0LN2NljXeF75+UyN6LNAqALiX6Jd5he9E+St9H1PjG9BSROu0uPiNSWDJO2t BrIyZt3Wos0RWkUEds/esvoqyi13LOhoEHoYBUNBTgNX8IWgkVWD3nw3PnWlrWUBukJc XDMBIrx3cFkUy35oPe1w/cLubaKZD5MVF6p5JS3eLRPRdx9tPfqbxmJE/c2TXR9G8955 819+5Ep8Ecekc9RyA4lHwopOpNMA4pPUBapPfwSTCcm5IwP0kcuQ3iRuBEMBme+wQ42y KRHv6c0oy0R76QlVA2RnXboSxjXMrqmVoP93JppVLCcPCrQdnkgKtEmICQiTRF9IZits A62w== X-Gm-Message-State: APjAAAUR2QVMEWqSLCWnpekThn6RHbQTZtRbQnpqPhe2TkE4jGY5i9H8 d0M9zXQQGMGz0mo6/EAh7uk= X-Received: by 2002:a0c:9304:: with SMTP id d4mr14851306qvd.12.1575140197113; Sat, 30 Nov 2019 10:56:37 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id 40sm13502875qtc.95.2019.11.30.10.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Nov 2019 10:56:36 -0800 (PST) From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Sat, 30 Nov 2019 13:56:35 -0500 To: Pavel Begunkov Cc: Arvind Sankar , Jens Axboe , Ming Lei , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] block: optimise bvec_iter_advance() Message-ID: <20191130185634.GA1848835@rani.riverdale.lan> References: <06b1b796b8d9bcaa6d5b325668525b7a5663035b.1574974574.git.asml.silence@gmail.com> <20191129221709.GA1164864@rani.riverdale.lan> <71864178-27d6-c6fb-a66b-395dc46041ac@gmail.com> <20191129232445.GA1331087@rani.riverdale.lan> <7be4b7fb-5c14-3c3a-e7f1-c5cc6c047f60@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <7be4b7fb-5c14-3c3a-e7f1-c5cc6c047f60@gmail.com> 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 Sat, Nov 30, 2019 at 12:22:27PM +0300, Pavel Begunkov wrote: > On 30/11/2019 02:24, Arvind Sankar wrote: > > On Sat, Nov 30, 2019 at 01:47:16AM +0300, Pavel Begunkov wrote: > >> On 30/11/2019 01:17, Arvind Sankar wrote: > >>> > >>> The loop can be simplified a bit further, as done has to be 0 once we go > >>> beyond the current bio_vec. See below for the simplified version. > >>> > >> > >> Thanks for the suggestion! I thought about it, and decided to not > >> for several reasons. I prefer to not fine-tune and give compilers > >> more opportunity to do their job. And it's already fast enough with > >> modern architectures (MOVcc, complex addressing, etc). > >> > >> Also need to consider code clarity and the fact, that this is inline, > >> so should be brief and register-friendly. > >> > > > > It should be more register-friendly, as it uses fewer variables, and I > > think it's easier to see what the loop is doing, i.e. that we advance > > one bio_vec per iteration: in the existing code, it takes a bit of > > thinking to see that we won't spend more than one iteration within the > > same bio_vec. > > Yeah, may be. It's more the matter of preference then. I don't think > it's simpler, and performance is entirely depends on a compiler and > input. But, that's rather subjective and IMHO not worth of time. > > Anyway, thanks for thinking this through! > You don't find listing 1 simpler than listing 2? It does save one register, as it doesn't have to keep track of done independently from bytes. This is always going to be the case unless the compiler can eliminate done by transforming Listing 2 into Listing 1. Unfortunately, even if it gets much smarter, it's unlikely to be able to do that, because they're equivalent only if there is no overflow, so it would need to know that bytes + iter->bi_bvec_done cannot overflow, and that iter->bi_bvec_done must be smaller than cur->bv_len initially. Listing 1: bytes += iter->bi_bvec_done; while (bytes) { const struct bio_vec *cur = bv + idx; if (bytes < cur->bv_len) break; bytes -= cur->bv_len; idx++; } iter->bi_idx = idx; iter->bi_bvec_done = bytes; Listing 2: while (bytes) { const struct bio_vec *cur = bv + idx; unsigned int len = min(bytes, cur->bv_len - done); bytes -= len; done += len; if (done == cur->bv_len) { idx++; done = 0; } } iter->bi_idx = idx; iter->bi_bvec_done = done;