Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp199887ybx; Wed, 30 Oct 2019 13:36:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvTTxtMnyUOG1EU7nsdoym+gPBUjUlnoDjwB3oq3k9NrAkmx2zHlU8khjgQKMjYwot8mTU X-Received: by 2002:a17:907:1118:: with SMTP id qu24mr147714ejb.235.1572467819736; Wed, 30 Oct 2019 13:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572467819; cv=none; d=google.com; s=arc-20160816; b=VZC9u8+gQjT3pYdij4h51G/iJUdXC9jDwugXUCvGW1oIX4JQD9RXNZmCEDD9lHVhY2 BiUiV9RPxkkd2cmjt5D1oxqXWG1qyj5dkOACUuGjc6L6m+J5Zj6k0YOTQJK+CJ+jMLXo QO25+ChKSS0TxiiAqEKE52QYbJOjyhEf6PwYLq6SuRMoUBZwhK1IGroktqEkxk366ubq dErKmQIp7ayeB5DGnR3Dfb4d7GZ+g2Bs5KjQfrzxE+aVOfNCUAx6RLNjHXY/3xDUqn0c 4Rb7JOJIG8PmoyspfA6eZH8GCBWGgJfQVqHoMKVINfrPtG1qWmhN19DayfXUrw+UCw3i RT0Q== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=GKB6Sx/IUizZ9IZiRwVYRZ7sZESLZmd5Upv0GbKgvpI=; b=jyOxLYlwPTDFGAXrLvgRQ4YcmmHr6/eqUcdifbha7bicqB0yW/+uE4dEQj4a3eMQfI xypFtMcauX1TRj+Pc94mbxKMIOZDp7kjnO5X3Zt8kxgS3AAna2LUB8ppDcjsjCQb4vC/ qFZANcMVrst0avsF8ltTeSEDCDpNoa277hHOjy0N8IlhsHyUqMoGxuCCZkxwAIkCav13 afmZTf54Elk3OTRX0VI+yZ1R1UFtcStkhsPTRvTTq8om50v/C5AjhuXXNDv3ClDx4ZNg i3JC0+cH0rMrRxFCwcuzxu0NmvZUe7HqtObroXthA1xjVk0O+y0XEKai7d1MJWxdLZ8h tD7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=h6STLAlg; 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 p29si2600745eda.104.2019.10.30.13.36.34; Wed, 30 Oct 2019 13:36:59 -0700 (PDT) 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=@rasmusvillemoes.dk header.s=google header.b=h6STLAlg; 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 S1726939AbfJ3UfP (ORCPT + 99 others); Wed, 30 Oct 2019 16:35:15 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:39915 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726882AbfJ3UfO (ORCPT ); Wed, 30 Oct 2019 16:35:14 -0400 Received: by mail-wr1-f67.google.com with SMTP id a11so3825832wra.6 for ; Wed, 30 Oct 2019 13:35:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=GKB6Sx/IUizZ9IZiRwVYRZ7sZESLZmd5Upv0GbKgvpI=; b=h6STLAlgZAIHahRpiOqt75+7YPhEervlfOHpzdNopczUpjoi/cznwsqOZegaIuJ4TM zdwrYQypkfpFaKGT8vusv604I2nbF1GOJZlwrB9ZKBgTEBjDOpLU6TSZRH/roP8sxwT+ LZ6HXtPlhEH+GSsavlv45TTL5baI9xO8kN71I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=GKB6Sx/IUizZ9IZiRwVYRZ7sZESLZmd5Upv0GbKgvpI=; b=R5+hbup4k+HWkGsKEGUbA3HuLoeX41URuBb798AeUQEaG1t9qwts/bYHeueTsyjuaA 7YZ2iO3SbX4atvsuxuJEDuLrOwvoeK67es3I0/cLLgyljavmxURl4U2e8HBY1JQB1wP6 nCsSeRX71EIVP3W/Wnc+sAFnms6TmJCmJy61KGmD7yvep/8zAbiyL5WG5tSy3sAy3hvG hHiwe/0/k9ptlkzKe9xzEcAY/5gbxnaNJxhmnj4BZlUHtiAbkWZaJq8b1/HIpheJ2Hsb etXSfUhZPh3K7dTSeTaZJRDq1CE1u+AfA6nARoN54K4B7Nfs/npNVUC9pIpoPe1bMCdh V35A== X-Gm-Message-State: APjAAAUluMBjiB7SXWCGQzHSXow5BWWRWKf6INo/UwLtSECnpFoBcDmG sHHzl2ROHuBRSSDbQCdSebmdiV1wz9XlY8iIcBg= X-Received: by 2002:adf:d18b:: with SMTP id v11mr1782349wrc.308.1572467711910; Wed, 30 Oct 2019 13:35:11 -0700 (PDT) Received: from [192.168.1.149] (ip-5-186-115-54.cgn.fibianet.dk. [5.186.115.54]) by smtp.gmail.com with ESMTPSA id a7sm1633681wrr.89.2019.10.30.13.35.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Oct 2019 13:35:10 -0700 (PDT) Subject: Re: [RFC PATCH 04/10] pipe: Use head and tail pointers for the ring, not cursor and length [ver #2] To: Ilya Dryomov , David Howells Cc: Linus Torvalds , Rasmus Villemoes , Greg Kroah-Hartman , Peter Zijlstra , nicolas.dichtel@6wind.com, raven@themaw.net, Christian Brauner , keyrings@vger.kernel.org, linux-usb@vger.kernel.org, linux-block , linux-security-module@vger.kernel.org, linux-fsdevel , linux-api@vger.kernel.org, LKML References: <157186182463.3995.13922458878706311997.stgit@warthog.procyon.org.uk> <157186186167.3995.7568100174393739543.stgit@warthog.procyon.org.uk> From: Rasmus Villemoes Message-ID: <4892d186-8eb0-a282-e7e6-e79958431a54@rasmusvillemoes.dk> Date: Wed, 30 Oct 2019 21:35:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30/10/2019 17.19, Ilya Dryomov wrote: > On Thu, Oct 24, 2019 at 11:49 AM David Howells wrote: >> /* >> - * We use a start+len construction, which provides full use of the >> - * allocated memory. >> - * -- Florian Coosmann (FGC) >> - * >> + * We use head and tail indices that aren't masked off, except at the point of >> + * dereference, but rather they're allowed to wrap naturally. This means there >> + * isn't a dead spot in the buffer, provided the ring size < INT_MAX. >> + * -- David Howells 2019-09-23. > > Hi David, > > Is "ring size < INT_MAX" constraint correct? No. As long as one always uses a[idx % size] to access the array, the only requirement is that size is representable in an unsigned int. Then because one also wants to do the % using simple bitmasking, that further restricts one to sizes that are a power of 2, so the end result is that the max size is 2^31 (aka INT_MAX+1). > I've never had to implement this free running indices scheme, but > the way I've always visualized it is that the top bit of the index is > used as a lap (as in a race) indicator, leaving 31 bits to work with > (in case of unsigned ints). Should that be > > ring size <= 2^31 > > or more precisely > > ring size is a power of two <= 2^31 Exactly. But it's kind of moot since the ring size would never be allowed to grow anywhere near that. Rasmus