From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7D8CC433ED for ; Thu, 8 Apr 2021 08:37:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7FFA161004 for ; Thu, 8 Apr 2021 08:37:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7FFA161004 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=lespinasse.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0C4E06B0078; Thu, 8 Apr 2021 04:37:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 075CA6B007E; Thu, 8 Apr 2021 04:37:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E57F26B0080; Thu, 8 Apr 2021 04:37:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0006.hostedemail.com [216.40.44.6]) by kanga.kvack.org (Postfix) with ESMTP id C90366B0078 for ; Thu, 8 Apr 2021 04:37:36 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 842ED1825FC63 for ; Thu, 8 Apr 2021 08:37:36 +0000 (UTC) X-FDA: 78008546112.22.0A7A819 Received: from server.lespinasse.org (server.lespinasse.org [63.205.204.226]) by imf07.hostedemail.com (Postfix) with ESMTP id D389BA000392 for ; Thu, 8 Apr 2021 08:37:35 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-11-ed; t=1617871054; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to : from; bh=gH+b4I4bYfVPVRG0SYb4pP96/w8P3/5+22wPxKEwskg=; b=pgoXWpws4/PUCkj+rX0Qwd2+X7AYlNZlVOFvVF2tPzXLBl1jIJZaH9K9VkPgLmUouITnT AmkqIjnpxE/dUenDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-11-rsa; t=1617871054; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to : from; bh=gH+b4I4bYfVPVRG0SYb4pP96/w8P3/5+22wPxKEwskg=; b=MGs3R/B2t569QkXYWkSa9xq6ocgFqad1DlVj99zaBgEeiY+fGwpmjYuw1tUeWPhq+6jRf hHWHDBekGKfZTzaK+tA9qPr4pSKjWXzlRuhNcSbiPnCIwsJPjQl66v0J4WSD5uR8C9wGS+x EdB2A3cCPenSiMmsEQIzFGEKTcrIWj1EDSRlvvGI6YOwhKpxq+hEY15KStk1rI4alDoluCQ nuxQU/5fCd/vdpIJeaPwg4fjZB2lqAB4iXLmLrPHTvlN5imkREPxgpv81XG5n4aoTooiKma R31H2elk0i5vhPbeSvB8TSKG/31y5GkEMnK8kDG5iVUSvZ1B/RB2xmLfSXhg== Received: by server.lespinasse.org (Postfix, from userid 1000) id D8EDB160253; Thu, 8 Apr 2021 01:37:34 -0700 (PDT) Date: Thu, 8 Apr 2021 01:37:34 -0700 From: Michel Lespinasse To: Matthew Wilcox Cc: Peter Zijlstra , Michel Lespinasse , Linux-MM , Laurent Dufour , Michal Hocko , Rik van Riel , Paul McKenney , Andrew Morton , Suren Baghdasaryan , Joel Fernandes , Rom Lemarchand , Linux-Kernel Subject: Re: [RFC PATCH 24/37] mm: implement speculative handling in __do_fault() Message-ID: <20210408083734.GB27824@lespinasse.org> References: <20210407014502.24091-1-michel@lespinasse.org> <20210407014502.24091-25-michel@lespinasse.org> <20210407212027.GE25738@lespinasse.org> <20210407212712.GH2531743@casper.infradead.org> <20210408071343.GJ2531743@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210408071343.GJ2531743@casper.infradead.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Queue-Id: D389BA000392 X-Stat-Signature: 63d1gn1nxuweb6r5xu6znrgi1cn1fcya X-Rspamd-Server: rspam02 Received-SPF: none (lespinasse.org>: No applicable sender policy available) receiver=imf07; identity=mailfrom; envelope-from=""; helo=server.lespinasse.org; client-ip=63.205.204.226 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617871055-336811 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Apr 08, 2021 at 08:13:43AM +0100, Matthew Wilcox wrote: > On Thu, Apr 08, 2021 at 09:00:26AM +0200, Peter Zijlstra wrote: > > On Wed, Apr 07, 2021 at 10:27:12PM +0100, Matthew Wilcox wrote: > > > Doing I/O without any lock held already works; it just uses the file > > > refcount. It would be better to use a vma refcount, as I already said. > > > > The original workload that I developed SPF for (waaaay back when) was > > prefaulting a single huge vma. Using a vma refcount was a total loss > > because it resulted in the same cacheline contention that down_read() > > was having. > > > > As such, I'm always incredibly sad to see mention of vma refcounts. > > They're fundamentally not solving the problem :/ > > OK, let me outline my locking scheme because I think it's rather better > than Michel's. The vma refcount is the slow path. > > 1. take the RCU read lock > 2. walk the pgd/p4d/pud/pmd > 3. allocate page tables if necessary. *handwave GFP flags*. > 4. walk the vma tree > 5. call ->map_pages > 6. take ptlock > 7. insert page(s) > 8. drop ptlock > if this all worked out, we're done, drop the RCU read lock and return. > 9. increment vma refcount > 10. drop RCU read lock > 11. call ->fault > 12. decrement vma refcount Note that most of your proposed steps seem similar in principle to mine. Looking at the fast path (steps 1-8): - step 2 sounds like the speculative part of __handle_mm_fault() - (step 3 not included in my proposal) - step 4 is basically the lookup I currently have in the arch fault handler - step 6 sounds like the speculative part of map_pte_lock() I have working implementations for each step, while your proposal summarizes each as a point item. It's not clear to me what to make of it; presumably you would be "filling in the blanks" in a different way than I have but you are not explaining how. Are you suggesting that the precautions taken in each step to avoid races with mmap writers would not be necessary in your proposal ? if that is the case, what is the alternative mechanism would you use to handle such races ? Going back to the source of this, you suggested not copying the VMA, what is your proposed alternative ? Do you suggest that fault handlers should deal with the vma potentially mutating under them ? Or should mmap writers consider vmas as immutable and copy them whenever they want to change them ? or are you implying a locking mechanism that would prevent mmap writers from executing while the fault is running ? > Compared to today, where we bump the refcount on the file underlying the > vma, this is _better_ scalability -- different mappings of the same file > will not contend on the file's refcount. > > I suspect your huge VMA was anon, and that wouldn't need a vma refcount > as faulting in new pages doesn't need to do I/O, just drop the RCU > lock, allocate and retry.