Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp444879ybj; Thu, 19 Sep 2019 17:22:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqw15hUTvJ3ibAkpYtRbnddlry88grtm7R1yNFhimoDOcvd2ZKDYfyd+XAKQUoi3wkY4yLkc X-Received: by 2002:aa7:dad3:: with SMTP id x19mr7408782eds.59.1568938973181; Thu, 19 Sep 2019 17:22:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568938973; cv=none; d=google.com; s=arc-20160816; b=WsOaahG2Q4tIa+rIWOqu967//F9vIBzQpsBCiaz2s3o1kH2bBastm5Uu1JnSMQpcTX iOpFg5QnQJriCuaibARhCMI0OG3nVXF4AUg95kCmZ6TV1aUWJl1muiAa1GT5ehQ+Cczg hpQYJtMNq2iYOoAETjKSx+Xp66brWljU4C3USNiXLh67RKuBN00DABXmhDLDqyuh20BR CP30wUGueL8TvD7ChWOcg4ZshdzhTihRfU8YzQe10l57I8zTrToPGZave5G4uHmv6oCO xEQmGU4ufq8DQX8UcQOGU4g2RWVpHpBBb1U5CW26zDdjtsIgCtFrkqrzUZdJAjOI4iL3 h1pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=f8LYnz1vv5tI3GZ6Lq+k6CmiHNbJUTHYO30ZgPVV0WU=; b=zguxr/X4qqKnnfMw26uxIOHup0v4FekbXWm2VGYYzoh9R8Cn9OzNgkiwMoSF4xZGRa fKEDp2rcOtA5KDxD2Elfmg3Yvh1cV3+s7+oZ36l3Wa//OhqLHfwnMh9RsOfDpvuBkZM0 46P7YT9HtA+Ga3G0+JFxyWpzVbM4TzVMdy1mvQQQcHu3no+l/BI8SAdwAJxT6KGItpFx 2kF3PvfK/CLqfKcKEbgJpr3t32kuSeb6GKyKvyOWG+IOjnjIpQA0QedmHJGjLZi1FHLL CCUjGT0aUxmtvgGsdxsorazXXbN446e6QIUYyftQpkOpWjCT5z9v4iLFjTsu5hMotycY SKSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="T/6gIwbf"; 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 oq3si106080ejb.220.2019.09.19.17.22.30; Thu, 19 Sep 2019 17:22:53 -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=@linux-foundation.org header.s=google header.b="T/6gIwbf"; 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 S2404035AbfISP7o (ORCPT + 99 others); Thu, 19 Sep 2019 11:59:44 -0400 Received: from mail-lj1-f176.google.com ([209.85.208.176]:37195 "EHLO mail-lj1-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389202AbfISP7o (ORCPT ); Thu, 19 Sep 2019 11:59:44 -0400 Received: by mail-lj1-f176.google.com with SMTP id l21so4155607lje.4 for ; Thu, 19 Sep 2019 08:59:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=f8LYnz1vv5tI3GZ6Lq+k6CmiHNbJUTHYO30ZgPVV0WU=; b=T/6gIwbfpiXV3L6bav6DhQetuAMBXy/Bqgt8Bn//Ktv5A0ZlOwwdqUFvu2JOVs5YAL GW7fhEsoQl3YTPl3Lrs/5T4hqdFZPN1ThISPa9aW4ffAKtyS96xs7iMX8oXz1SyBa6v/ ZT+WNN1O02jjgKM8I1ZCBJsBj3YxaAZ5oaDws= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=f8LYnz1vv5tI3GZ6Lq+k6CmiHNbJUTHYO30ZgPVV0WU=; b=pUIvFgqDALjaTX3HqM26Yr/yY1BhTmfH/xBk3UX46uJ2hIQ9KSH4CLwiDqKbA9CvPg zRbBL7DmwbFYiUnQESAGD+v4/2XUvIqUxhidAnI+BgmNInT8rMw+4HSeApeaTGZy153i SOqV/Tk1kV48JK4sjjDJp9DJ0AtsbAph65ajXm9ZUWK8PmSOeqJ9B2rhw3uXkycy83yD L5/zwtCCN9lDXbtzCta2U3yKxSrv2RHERWEjfz5nFMjmKQG8cV9rWx2R8YQhfIXlYWGj aXJxIpsk64Cv+e9KIZIAMS06XQ5p2yY8lM8+EmlliYhcOAXzGgn337UHi0OEYJIsUZdR L2sg== X-Gm-Message-State: APjAAAVDRk6iXKdWFEaf0KOar7TL+gwSoklffXMH7BRGPhr+fVnm6+Ua drxSZa2v+pA0cZf+yviyJFV6eBHxhSA= X-Received: by 2002:a2e:9159:: with SMTP id q25mr5908521ljg.225.1568908781206; Thu, 19 Sep 2019 08:59:41 -0700 (PDT) Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com. [209.85.208.179]) by smtp.gmail.com with ESMTPSA id 21sm1718371ljq.15.2019.09.19.08.59.39 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Sep 2019 08:59:39 -0700 (PDT) Received: by mail-lj1-f179.google.com with SMTP id d5so4100247lja.10 for ; Thu, 19 Sep 2019 08:59:39 -0700 (PDT) X-Received: by 2002:a2e:8789:: with SMTP id n9mr5927834lji.52.1568908779394; Thu, 19 Sep 2019 08:59:39 -0700 (PDT) MIME-Version: 1.0 References: <20190915145905.hd5xkc7uzulqhtzr@willie-the-truck> <25289.1568379639@warthog.procyon.org.uk> <28447.1568728295@warthog.procyon.org.uk> <20190917170716.ud457wladfhhjd6h@willie-the-truck> <15228.1568821380@warthog.procyon.org.uk> <5385.1568901546@warthog.procyon.org.uk> In-Reply-To: <5385.1568901546@warthog.procyon.org.uk> From: Linus Torvalds Date: Thu, 19 Sep 2019 08:59:23 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Do we need to correct barriering in circular-buffers.rst? To: David Howells Cc: Will Deacon , "Paul E. McKenney" , Mark Rutland , Linux List Kernel Mailing , linux-fsdevel , Peter Zijlstra Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 19, 2019 at 6:59 AM David Howells wrote: > > But I don't agree with this. You're missing half the barriers. There should > be *four* barriers. The document mandates only 3 barriers, and uses > READ_ONCE() where the fourth should be, i.e.: > > thread #1 thread #2 > > smp_load_acquire(head) > ... read data from queue .. > smp_store_release(tail) > > READ_ONCE(tail) > ... add data to queue .. > smp_store_release(head) The document is right, but you shouldn't do this. The reason that READ_ONCE() is possible - instead of a smp_load_acquire() - is that there's now an address dependency chain from the READ_ONCE to the subsequent writes of the data. And while there isn't any barrier, a data or control dependency to a _write_ does end up ordering things (even on alpha - it's only the read->read dependencies that might be unordered on alpha). But again, don't do this. Also, you ignored the part where I told you to not do this because we already have locking. I'm not goign to discuss this further. Locking works. Spinlocks are cheap. Lockless algorithms that need atomics aren't even cheaper than spinlocks: they can in fact scale *worse*, because they don't have the nice queuing optimization that our spinlock have. Lockless algorithms are great if they can avoid the contention on the lock and instead only work on distributed data and avoid contention entirely. But in this case the lock would be right next to the data anyway, so even that case doesn't hold. Linus