Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp842578imu; Wed, 16 Jan 2019 08:27:10 -0800 (PST) X-Google-Smtp-Source: ALg8bN5FpggqWUtFgnSf91pdFzbdqGaNA+xaI53BrTKbrvmE1m9MK1a4SBg+s88B0azctmJmN8mt X-Received: by 2002:a63:5f89:: with SMTP id t131mr9765806pgb.26.1547656030840; Wed, 16 Jan 2019 08:27:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547656030; cv=none; d=google.com; s=arc-20160816; b=NFHgCjcx3VvQS4WmrRhEEKPdqIHa2jYYZoREDmK1sG0XZMO2avmJ7ws3RBdb55m5CW 2GhqVs9r4E/RzFSaYKZDu8qNGWWxrP+zsFEHLdcQuhk3t+WxjmMNgy4QcgpHtPEdAwCx hYQ4b9ft90AaMyyk2k2sC/S2cMsGN4sIzQiTWQwfVFlbHuIoulonEcMf68CGcd25Mah7 H3KbzLxB2BUWoK7qjbXQ/FdHsb03f7GBrsSOaFlOfFBUsehPfBil7VHhNmcTY1QAOpYu i9wNu34Q+RaBaG0QuYDqa9np+/flgB4hAY3Y622pmBytqPzw06lYtyIF6JYt5Tbps/xS 6xkg== 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:from:date; bh=mGhbe/CasEZjYyHO9s3xNl/7nM71zNovWd8vufyuc1M=; b=K8G09HeNecrIVBkvpcw3fgqWQyJKKMCGO1qRHahMmrkfm4w9MB16pC3NYRragvmw3L Yze+v0UnggQkD9N1Jw5sUXYD6XxcKNoGI/OGZ/bhdcn46Wrcsw14gBjow7tD9gMlROhx 3WFW4mObDm6M2/ysCLbUwcEltFgaWw0DIJ6tfq5MF3rVwJORHVZS0zg8+mp86JtJqBvn 32jiNyzvnUNNl6bkODG92y20bZviCkYZMsje/CtwUG/1qNiV2N4Wvi4b7cmAQHDI8JbB 20i3pF0AmMqWnhsfLlc65Tmcd2MBe5x7MfDFhCaHdoPsX2pJjZDUvG/OCT3wovlGzgQN 44PA== 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 69si6777688pla.75.2019.01.16.08.26.48; Wed, 16 Jan 2019 08:27:10 -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 S1731991AbfAPEfC (ORCPT + 99 others); Tue, 15 Jan 2019 23:35:02 -0500 Received: from ipmail03.adl6.internode.on.net ([150.101.137.143]:50043 "EHLO ipmail03.adl6.internode.on.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728227AbfAPEfB (ORCPT ); Tue, 15 Jan 2019 23:35:01 -0500 Received: from ppp59-167-129-252.static.internode.on.net (HELO dastard) ([59.167.129.252]) by ipmail03.adl6.internode.on.net with ESMTP; 16 Jan 2019 15:04:57 +1030 Received: from dave by dastard with local (Exim 4.80) (envelope-from ) id 1gjcul-00023Y-IG; Wed, 16 Jan 2019 15:34:55 +1100 Date: Wed, 16 Jan 2019 15:34:55 +1100 From: Dave Chinner To: Jerome Glisse Cc: Dan Williams , John Hubbard , Jan Kara , Matthew Wilcox , John Hubbard , Andrew Morton , Linux MM , tom@talpey.com, Al Viro , benve@cisco.com, Christoph Hellwig , Christopher Lameter , "Dalessandro, Dennis" , Doug Ledford , Jason Gunthorpe , Michal Hocko , Mike Marciniszyn , rcampbell@nvidia.com, Linux Kernel Mailing List , linux-fsdevel Subject: Re: [PATCH 1/2] mm: introduce put_user_page*(), placeholder versions Message-ID: <20190116043455.GP4205@dastard> References: <20190114145447.GJ13316@quack2.suse.cz> <20190114172124.GA3702@redhat.com> <20190115080759.GC29524@quack2.suse.cz> <20190115171557.GB3696@redhat.com> <752839e6-6cb3-a6aa-94cb-63d3d4265934@nvidia.com> <20190115221205.GD3696@redhat.com> <99110c19-3168-f6a9-fbde-0a0e57f67279@nvidia.com> <20190116015610.GH3696@redhat.com> <20190116022312.GJ3696@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190116022312.GJ3696@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 15, 2019 at 09:23:12PM -0500, Jerome Glisse wrote: > On Tue, Jan 15, 2019 at 06:01:09PM -0800, Dan Williams wrote: > > On Tue, Jan 15, 2019 at 5:56 PM Jerome Glisse wrote: > > > On Tue, Jan 15, 2019 at 04:44:41PM -0800, John Hubbard wrote: > > [..] > > > To make it clear. > > > > > > Lock code: > > > GUP() > > > ... > > > lock_page(page); > > > if (PageWriteback(page)) { > > > unlock_page(page); > > > wait_stable_page(page); > > > goto retry; > > > } > > > atomic_add(page->refcount, PAGE_PIN_BIAS); > > > unlock_page(page); > > > > > > test_set_page_writeback() > > > bool pinned = false; > > > ... > > > pinned = page_is_pin(page); // could be after TestSetPageWriteback > > > TestSetPageWriteback(page); > > > ... > > > return pinned; > > > > > > Memory barrier: > > > GUP() > > > ... > > > atomic_add(page->refcount, PAGE_PIN_BIAS); > > > smp_mb(); > > > if (PageWriteback(page)) { > > > atomic_add(page->refcount, -PAGE_PIN_BIAS); > > > wait_stable_page(page); > > > goto retry; > > > } > > > > > > test_set_page_writeback() > > > bool pinned = false; > > > ... > > > TestSetPageWriteback(page); > > > smp_wmb(); > > > pinned = page_is_pin(page); > > > ... > > > return pinned; > > > > > > > > > One is not more complex than the other. One can contend, the other > > > will _never_ contend. > > > > The complexity is in the validation of lockless algorithms. It's > > easier to reason about locks than barriers for the long term > > maintainability of this code. I'm with Jan and John on wanting to > > explore lock_page() before a barrier-based scheme. > > How is the above hard to validate ? Well, if you think it's so easy, then please write the test cases so we can add them to fstests and make sure that we don't break it in future. If you can't write filesystem test cases that exercise these race conditions reliably, then the answer to your question is "it is extremely hard to validate" and the correct thing to do is to start with the simple lock_page() based algorithm. Premature optimisation in code this complex is something we really, really need to avoid. -Dave. -- Dave Chinner david@fromorbit.com