Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp919249pxf; Wed, 7 Apr 2021 15:04:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvJk3cXD+hCLvCeokyPU1fQj+JDyG1mzoM/CcrKJkrNhzREy7Mp0nJtS6WVbIpa/21TH97 X-Received: by 2002:a62:1615:0:b029:243:fec5:6618 with SMTP id 21-20020a6216150000b0290243fec56618mr906963pfw.35.1617833063499; Wed, 07 Apr 2021 15:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617833063; cv=none; d=google.com; s=arc-20160816; b=rHB5920Cvwt2QKo4HNiIFtqC7k3aok8HNR8DpT0hbb+zfIJrhat9EVXa+0qAds5Yst 8q8Hf1QD6p9L1zgYmT5W/tWaZMMh8MoxJdRfLNn1aVDhxFe2G71HDUWHo78JLO+RwLhs NmEIyoHzUjsMTxJl+Jky/NZrIZ7GDzXt8U7qi6EYgljMCuf0ustkDj8hUxx1GHDJd8uF puFsFwOuE2qhl1lP8T0xBc+vj3JooHlJOUUYxtRgscBHMOrnCjheJtTc/y+Ugaxirl3K BjSiRtOMZWDEkqh2SpCF6Tu+t3mGQCPdbrmzBXLZwH0w9aiUFwdV7hy78R5S9pRyS5cG 3HEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature; bh=RuYCQ0DgIxUBi/wCmv1Y+yc2Ga4zVqxwcVcBP32mtAw=; b=CL/PI+JkZjoFKOk8qkH8NS6wxPWa7k1MRjY9w3KOK2OIaFmaP+YkX417fg4vyrTODb QcviLfRuwbodWMWOjYJQzVfYfkuOD4am42OAkIOGlFaVMpqX6bdGJ2liddWDOgR3XaBT t8PtEz3o/1ElwJHdMx0C1Vi4FoUG4V5y086nmLsdYzZBC0z6ASSgBPaa500YjN3KgdyA JqZ76Dn4OIKbkI9MLExCxroZ8ys0RAPVCbsG8wECVeIpyBDkkrQUTgazdsxbJxeQNF9W T5BckO77Zkf7thX2TpD07mzFqVVcncW58gF9TH7WufOGjwQ9Ho8u3JzxA9tUsD1slBsK Bs2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (no key) header.i=@lespinasse.org header.s=srv-11-ed header.b=Z7nAG5nM; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-11-rsa header.b=Wos9Vqgd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lespinasse.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w13si7810691pjg.114.2021.04.07.15.04.11; Wed, 07 Apr 2021 15:04:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=neutral (no key) header.i=@lespinasse.org header.s=srv-11-ed header.b=Z7nAG5nM; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-11-rsa header.b=Wos9Vqgd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lespinasse.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231489AbhDGUvB (ORCPT + 99 others); Wed, 7 Apr 2021 16:51:01 -0400 Received: from server.lespinasse.org ([63.205.204.226]:55091 "EHLO server.lespinasse.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231578AbhDGUuy (ORCPT ); Wed, 7 Apr 2021 16:50:54 -0400 DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-11-ed; t=1617828644; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to : from; bh=RuYCQ0DgIxUBi/wCmv1Y+yc2Ga4zVqxwcVcBP32mtAw=; b=Z7nAG5nMbI4MzkxVTEc2HHAJjn62lZp1Zw9XfJ9QePdfvwBY8+wMqzifzyp5Zwn3JhIVP LDMmT3hwpeoveGbAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-11-rsa; t=1617828644; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to : from; bh=RuYCQ0DgIxUBi/wCmv1Y+yc2Ga4zVqxwcVcBP32mtAw=; b=Wos9VqgdC2RFNH+S94wLjY1ICgF+Prad0ZeP1wvOmUyAOmS94nFg+oDwQHbF0c5T2S2x2 dJm7+FwWWH4Kuu5m9enACfQhhMc5maEUv4auILwgZ9hkvIdIr60gcr4g33z/Zj9JOaCE08e pk5B3/CzsTq5fTCG37AU9kYScyCap//+AE3HWIKhkrvmqt4dkxFePSx+OWYdkuFUdPA89cY 3DQZSFgOwuZQd3qep2WDwLX3hy2rFz81XNUFq/p/ji2vM9+0TFUGxo4Nxt5NbxbpNFWO5Wl LpylYnO6YmKpm24zu6AeQKLbfLOY538yYCTGgRyzJCHTL0vw7GQUyFQE4dcA== Received: by server.lespinasse.org (Postfix, from userid 1000) id 682BC160244; Wed, 7 Apr 2021 13:50:44 -0700 (PDT) Date: Wed, 7 Apr 2021 13:50:44 -0700 From: Michel Lespinasse To: Peter Zijlstra Cc: Michel Lespinasse , Linux-MM , Laurent Dufour , Michal Hocko , Matthew Wilcox , Rik van Riel , Paul McKenney , Andrew Morton , Suren Baghdasaryan , Joel Fernandes , Rom Lemarchand , Linux-Kernel Subject: Re: [RFC PATCH 09/37] mm: add per-mm mmap sequence counter for speculative page fault handling. Message-ID: <20210407205044.GD25738@lespinasse.org> References: <20210407014502.24091-1-michel@lespinasse.org> <20210407014502.24091-10-michel@lespinasse.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 07, 2021 at 04:47:34PM +0200, Peter Zijlstra wrote: > On Tue, Apr 06, 2021 at 06:44:34PM -0700, Michel Lespinasse wrote: > > The counter's write side is hooked into the existing mmap locking API: > > mmap_write_lock() increments the counter to the next (odd) value, and > > mmap_write_unlock() increments it again to the next (even) value. > > > > The counter's speculative read side is supposed to be used as follows: > > > > seq = mmap_seq_read_start(mm); > > if (seq & 1) > > goto fail; > > .... speculative handling here .... > > if (!mmap_seq_read_check(mm, seq) > > goto fail; > > > > This API guarantees that, if none of the "fail" tests abort > > speculative execution, the speculative code section did not run > > concurrently with any mmap writer. > > So this is obviously safe, but it's also super excessive. Any change, > anywhere, will invalidate and abort a SPF. > > Since you make a complete copy of the vma, you could memcmp it in its > entirety instead of this. Yeah, there is a deliberate choice here to start with the simplest possible approach, but this could lead to more SPF aborts than strictly necessary. It's not clear to me that just comparing original vs current vma attributes would always be sufficient - I think in some cases, we may also need to worry about attributes being changed back and forth concurrently with the fault. However, the comparison you suggest would be safe at least in the case where the original pte was pte_none. At some point, I did try implementing the optimization you suggest - if the global counter has changed, re-fetch the current vma and compare it against the old - but this was basically no help for the (Android) workloads I looked at. There were just too few aborts that were caused by the global counter in the first place. Note that my patchset only handles anon and page cache faults speculatively, so generally there wasn't very much time for the counter to change. But yes, this may not hold across all workloads, and maybe we'd want to do something smarter once/if a problem workload is identified.