Received: by 10.213.65.68 with SMTP id h4csp696226imn; Fri, 6 Apr 2018 07:26:28 -0700 (PDT) X-Google-Smtp-Source: AIpwx48k9ba+JF8x7FBo3OSQ03b8DbFm+nFLEazrx3qvK5i9ucLRmTqTZr1kQvK+flEsobshXnCo X-Received: by 10.98.147.135 with SMTP id r7mr20952919pfk.31.1523024788833; Fri, 06 Apr 2018 07:26:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523024788; cv=none; d=google.com; s=arc-20160816; b=HNRpmFed5cdis7eX52KTIxO27IjRMlXLHGKdN7x6cSy0ddwoo+CD/T0WcW6oFe3cM4 cdPlPPlU5PEpXF4gFAnCldtGsW0sHZbXANIbhzt0HaWmnWfGrZ/eNgJJNMomKOYIgz0m dVqPJ26qy8f8XCvLb3oIA8b+6rToiZafN0iXia8rAXMon44/xmEu+yF39oa02x0hQ34Z o80ljuXPGJgfvh7TH++/CGTsRAFNq1vhELkxfR1L5umEpG5jy0eB++cwi5PI3pWAvb9X gji0j/Ez5L2F4vbev4cZjL5CoEUAvcq22fON58P04geNAYkqtbHZdOevb4ZlmPix1FZc vUeg== 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=IDPSz+2Aq7iBntgWBSsntH6Ipb6Et/Ol2e908n8VYvI=; b=l0Z83yRHUuGmTB/D7o/FDH/EIjCyHGTk3lP1almMPweom5zuboLQ4x8ln6bQ+wmhvX MaNqRRPbeCfgR+zP4yXBVF6zBv1KvZPPwYFqq6HBIWPVOkVgPoY2R7Iw6MkgkMnSotiB 3PSRlJZtV7uqiQeuk3sWDq6l5WKp1NVOBk4nPbR+vsxFSNJH211hMgbxtvq2MvP5Wut0 e7Et1XXLjUkgSTHEpuwsh1GSXjRjHa07DlDg3zthL5JDuyg9gywLbedFm7RLqdiOYUAr sZu7Y/YxUh3nUSwcqjxYvIRoQPwdEfykQwHrxu+TgThmyIdWhvv3G3HB+wkuB3Pi3sI/ UpFA== 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 12-v6si8341254plb.342.2018.04.06.07.26.14; Fri, 06 Apr 2018 07:26:28 -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 S1756683AbeDFOZD (ORCPT + 99 others); Fri, 6 Apr 2018 10:25:03 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:34322 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756730AbeDFOXc (ORCPT ); Fri, 6 Apr 2018 10:23:32 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w36ELSN4125171 for ; Fri, 6 Apr 2018 10:23:32 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0b-001b2d01.pphosted.com with ESMTP id 2h69tsadrh-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Fri, 06 Apr 2018 10:23:30 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 6 Apr 2018 15:23:28 +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; Fri, 6 Apr 2018 15:23:21 +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 w36ENLFM1311212; Fri, 6 Apr 2018 14:23:21 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DA382A4040; Fri, 6 Apr 2018 15:15:44 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C37D2A405F; Fri, 6 Apr 2018 15:15:42 +0100 (BST) Received: from [9.145.2.86] (unknown [9.145.2.86]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 6 Apr 2018 15:15:42 +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: Fri, 6 Apr 2018 16:23:18 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.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: 18040614-0044-0000-0000-00000544474A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18040614-0045-0000-0000-0000288469DD Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-04-06_07:,, 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-1804060147 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()? To be honest I didn't look at mm/nommu.c assuming that such architecture would probably be monothreaded. Am I wrong ?