Received: by 10.213.65.68 with SMTP id h4csp4113248imn; Tue, 10 Apr 2018 09:25:10 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/vCCU8p8c9PDPC4qB+TMjpBbx/qfoiY3fiNpD/9CJHEGLjfaGiwlBCoWkAAMaYp9rbBvmP X-Received: by 10.101.88.196 with SMTP id e4mr783983pgu.143.1523377510640; Tue, 10 Apr 2018 09:25:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523377510; cv=none; d=google.com; s=arc-20160816; b=z8AXzJyJXjqML9gxxDDO6m3MPY6rvU0Qs+bCWt9Vc+3q4MjuC1ZQQbaWmcxXbXBNZl URyfyiKppgLlVN6DooUHbeTzBJTqld1K08JEzFCiI83VvpHTNaaEj9sR+1WoZfMmBbT1 B4woHJrGaT5vbhW4D3bZM/MgvnNzjTOGPakm+wnwXGI1QbZLNFujwH4lNhD5PSvHYb7A ZqYLwODZ2RUcTbApgT8nOoO/+bJK7+/962I8s3EgEtiPWS5NYz7h1apiGfdZbqyZlELm T0W1e5qA/hRxU+GontybwDzTsc/UPjnBQvOKonsapZiaUKiOW+k52lE6JiRbg8uz6EfH e6xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date:from :references:cc:to:subject:arc-authentication-results; bh=vDP/9Kt28NcLI/QA7DoxR/D5WXOui+EwNn2Vz4PyU2U=; b=aTXJA6KHsLFrmxTk8B7m2DzV7j+YVkd6MajN1nWqw794080VT77Cytz/81mzX7LF+T 3oiWyGJUQkTm0nBHaSRNqXZIil26oCD1f2SkPI/THcWXxEb1nwzBkFVQBJcz/gFMuucH rFaX7MFbAYffMR0TBtU+4jrCAC+LWuKBWguFCdbGEXHscP8Pb41jIqiJ50JFL0fSgxSA xGirYDF5w0rxL47sDdMbDpXdgBYicJGgi89v2/jtRFyWkS6s3+/lWHhxCGxjsUg3pv16 G3DgfrOKrhPtLTNIziE0gXFLHbf66A3y+4jctb9NJ0KzHvqC5sNlmn6tAlK9yoZjK/c2 hXnw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i6-v6si2875964plt.186.2018.04.10.09.24.33; Tue, 10 Apr 2018 09:25:10 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752081AbeDJQUm (ORCPT + 99 others); Tue, 10 Apr 2018 12:20:42 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:43714 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752009AbeDJQUk (ORCPT ); Tue, 10 Apr 2018 12:20:40 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3AGK6E0126535 for ; Tue, 10 Apr 2018 12:20:40 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2h90mmr8tb-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Tue, 10 Apr 2018 12:20:39 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 10 Apr 2018 17:20:35 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 10 Apr 2018 17:20:27 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3AGKRV38913318; Tue, 10 Apr 2018 16:20:27 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 621AAA4040; Tue, 10 Apr 2018 17:12:45 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 302B2A406B; Tue, 10 Apr 2018 17:12:44 +0100 (BST) Received: from [9.101.4.33] (unknown [9.101.4.33]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 10 Apr 2018 17:12:44 +0100 (BST) Subject: Re: [PATCH v9 17/24] mm: Protect mm_rb tree with a rwlock To: David Rientjes 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 References: <1520963994-28477-1-git-send-email-ldufour@linux.vnet.ibm.com> <1520963994-28477-18-git-send-email-ldufour@linux.vnet.ibm.com> From: Laurent Dufour Date: Tue, 10 Apr 2018 18:20:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 18041016-0044-0000-0000-00000545A61A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041016-0045-0000-0000-00002885D725 Message-Id: <8191409a-d7aa-6476-6aa9-1d1c4dced788@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-10_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804100155 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/04/2018 02:11, David Rientjes wrote: > 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()? Good question ! I guess if there is no mmu, there is no page fault, so no speculative page fault and this patch is clearly required by the speculative page fault handler. By the I should probably make CONFIG_SPECULATIVE_PAGE_FAULT dependent on CONFIG_MMU. This being said, if your idea is to extend the mm_rb tree rwlocking to the nommu case, then this is another story, and I wondering if there is a real need in such case. But I've to admit I'm not so familliar with kernel built for mmuless systems. Am I missing something ? Thanks, Laurent.