Received: by 10.213.65.68 with SMTP id h4csp2923881imn; Mon, 2 Apr 2018 17:14:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx49vYUwVzKvTnDCndltSmKSCAMkQQw1oOW/JxLPM5/yVvRjq+PvGgzObxm08tQ+JhG6618Qv X-Received: by 10.98.246.26 with SMTP id x26mr8740911pfh.81.1522714445988; Mon, 02 Apr 2018 17:14:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522714445; cv=none; d=google.com; s=arc-20160816; b=CT6RNG0845SidbosrTmWtU3BVCA0eDbxPU86DEb9A4GvFjYfBAjbY+LLELcMZPPMPe H82kvAqwo+fr4rA3o935DV9tm7H+r+k9pv4215wm3JirV2OZsDIK9o3Le/wYHZaDECC7 4ua244xfTvNHJeEb6/kl7vMWkKdaHqqtoCdxAV8PtOwhqwaJm/Ja9n2pYw6am0rPJwGS cku3r9p2Vv18nGy49DilH7Up+Fh73QKlW3tjbFoADAAfIdvp8CVcSgH3zuM+kvW5dD9I iQmUJ5NKyM1YsJ3Tdlfj50FGrrgSUbtMGt1/dbJ+qVTOR8wFt9qm9v57dc4t310ZIqEB TptQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=t2LYDVl5SipmIaqSOXjEIb7xI2p0nKtxsYZtLLWI6qU=; b=YqHzTCzImTpJ+58IYWZBrcs1O6/5dfU/itXoDwhKWeUzJCUsPH7vEEa2RdpL/zRfRf zfb4NPm7E9DmDWaojCSz1U5g4uYb3nqzBxamMEXeMUkig/2sbPshH4ykMhT1yRyY7ak9 964zYKhca08+I5iij63KOgRfeHD3GpgoxbtY1esDuqPWji+V6tinx6fCvJkPP9iaot8x 5KCCs83Sd7uQgKPDExnnXLZoQ9Yhtvyo/yOkQ5Pfu5/RF+IZlttVUEVp1D2tvzl9E6jD tDmKU4lFAEW+3tplpZaze9Ec1aqRPOmLdKrwVWU6IrHUzRk3klT/iP2Co+k3sJzLyegx W/OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FJlhMrTv; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n190si972950pga.681.2018.04.02.17.13.37; Mon, 02 Apr 2018 17:14:05 -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=@google.com header.s=20161025 header.b=FJlhMrTv; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754694AbeDCALq (ORCPT + 99 others); Mon, 2 Apr 2018 20:11:46 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:41742 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754550AbeDCALo (ORCPT ); Mon, 2 Apr 2018 20:11:44 -0400 Received: by mail-pl0-f68.google.com with SMTP id bj1-v6so3934249plb.8 for ; Mon, 02 Apr 2018 17:11:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=t2LYDVl5SipmIaqSOXjEIb7xI2p0nKtxsYZtLLWI6qU=; b=FJlhMrTvkNR6Jc8/XwwbfaBlJF0+jADdicnJ6HAWMXPBSqDswPNL6v9uBipVeEDFUf BstFq8vrq6udW2tz/go33svedndKBza3S6C2FnH+VLONNLQBiICJv5zF+bc9Foc7HMzi iTaSEn0TZMB4b08HtMIw2h2SuHUYyMl0cVmun+9QvGsqQ15Bwt4jDFj9VcJAmnkxBJ4J Q8SeEETGRy8p47d+9HRVkL/ujeVWJfySOHMvmu/S4M2x9ofBlCscGRxbD5oQjsOLFBTS oBZpvHHroWlf1SRzlVOR2PxHMykX8dbMmuXLEhmuR7xIQ66pLphe6CQWBd3Vgs8P80hD RDyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=t2LYDVl5SipmIaqSOXjEIb7xI2p0nKtxsYZtLLWI6qU=; b=PFs0IXHC3ur6gMkQLO5f6xfhT2foBH/AqZz0zRDqw0EC0vXs10B4/PTZDBQkrVWy+J hMjZpppwnwdLoEviojRDr29603S3ce/IEP0GdTND6JYXd26dD0jVnvpXuTjuh+M6gOLr B1tXbrNgFFx9yohggu89OVAak/QcI+UAD4Hi+IQ2mKoE7ELpdjslmnUfiR9TsuwEfMae zbkWepCP7DGesPT7qJEAC9EnvKmrlB5Mnax0Fm6YwXPjdddsm8eDytY6NZD8+3IR1XfQ KFUUBFkucEf3GUTLGoKVcdExcX6T2nJiMiVW8VoemkWEKdqx395+SMR/4Ej7X7zKGSxp ebjw== X-Gm-Message-State: AElRT7FSkeDf36FX8JxerSc2Caa+N/KAgZCwmqXadWs73bznzJDUWRiI Fv5ViaNoyiVATrcywoVsEMKcwQ== X-Received: by 2002:a17:902:6b01:: with SMTP id o1-v6mr11539620plk.350.1522714303881; Mon, 02 Apr 2018 17:11:43 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id s3sm2130687pgo.93.2018.04.02.17.11.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Apr 2018 17:11:42 -0700 (PDT) Date: Mon, 2 Apr 2018 17:11:42 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Laurent Dufour cc: paulmck@linux.vnet.ibm.com, peterz@infradead.org, akpm@linux-foundation.org, kirill@shutemov.name, ak@linux.intel.com, mhocko@kernel.org, dave@stgolabs.net, jack@suse.cz, Matthew Wilcox , benh@kernel.crashing.org, mpe@ellerman.id.au, paulus@samba.org, Thomas Gleixner , Ingo Molnar , hpa@zytor.com, Will Deacon , Sergey Senozhatsky , Andrea Arcangeli , Alexei Starovoitov , kemi.wang@intel.com, sergey.senozhatsky.work@gmail.com, Daniel Jordan , linux-kernel@vger.kernel.org, linux-mm@kvack.org, haren@linux.vnet.ibm.com, khandual@linux.vnet.ibm.com, npiggin@gmail.com, bsingharora@gmail.com, Tim Chen , linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: Re: [PATCH v9 17/24] mm: Protect mm_rb tree with a rwlock In-Reply-To: <1520963994-28477-18-git-send-email-ldufour@linux.vnet.ibm.com> Message-ID: References: <1520963994-28477-1-git-send-email-ldufour@linux.vnet.ibm.com> <1520963994-28477-18-git-send-email-ldufour@linux.vnet.ibm.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 13 Mar 2018, Laurent Dufour wrote: > This change is inspired by the Peter's proposal patch [1] which was > protecting the VMA using SRCU. Unfortunately, SRCU is not scaling well in > that particular case, and it is introducing major performance degradation > due to excessive scheduling operations. > > To allow access to the mm_rb tree without grabbing the mmap_sem, this patch > is protecting it access using a rwlock. As the mm_rb tree is a O(log n) > search it is safe to protect it using such a lock. The VMA cache is not > protected by the new rwlock and it should not be used without holding the > mmap_sem. > > To allow the picked VMA structure to be used once the rwlock is released, a > use count is added to the VMA structure. When the VMA is allocated it is > set to 1. Each time the VMA is picked with the rwlock held its use count > is incremented. Each time the VMA is released it is decremented. When the > use count hits zero, this means that the VMA is no more used and should be > freed. > > This patch is preparing for 2 kind of VMA access : > - as usual, under the control of the mmap_sem, > - without holding the mmap_sem for the speculative page fault handler. > > Access done under the control the mmap_sem doesn't require to grab the > rwlock to protect read access to the mm_rb tree, but access in write must > be done under the protection of the rwlock too. This affects inserting and > removing of elements in the RB tree. > > The patch is introducing 2 new functions: > - vma_get() to find a VMA based on an address by holding the new rwlock. > - vma_put() to release the VMA when its no more used. > These services are designed to be used when access are made to the RB tree > without holding the mmap_sem. > > When a VMA is removed from the RB tree, its vma->vm_rb field is cleared and > we rely on the WMB done when releasing the rwlock to serialize the write > with the RMB done in a later patch to check for the VMA's validity. > > When free_vma is called, the file associated with the VMA is closed > immediately, but the policy and the file structure remained in used until > the VMA's use count reach 0, which may happens later when exiting an > in progress speculative page fault. > > [1] https://patchwork.kernel.org/patch/5108281/ > > Cc: Peter Zijlstra (Intel) > Cc: Matthew Wilcox > Signed-off-by: Laurent Dufour Can __free_vma() be generalized for mm/nommu.c's delete_vma() and do_mmap()?