Received: by 10.192.165.148 with SMTP id m20csp434032imm; Thu, 3 May 2018 23:59:14 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpWX7r2gA5vtfuEr0Co0568ykklWWMbHmVUI91QPE8+2DajC8uyOSqgcemJ6O4XeYwZwTmG X-Received: by 10.98.110.136 with SMTP id j130mr25537540pfc.111.1525417154847; Thu, 03 May 2018 23:59:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525417154; cv=none; d=google.com; s=arc-20160816; b=pqvkzvnjAoGkNPeuTEN2sCbVABFQiAHlZpneZIyQNC/IOg6mxFkfp3ZqR8pYmhYo/q izLd0REs2NPCDbMFGm05av/0nWQMK8CLFLbGKhNY6c1o7Umekthq6Cwv7Vv51E0PijeZ xOTwOBWtXkoVG/XL0RVMg9e5H2olIl1nLR1m1mMY6pbNbmUZWmcGR/D2qmT5WAfkun2b qRhokmEI0qjj06gDDRYrOc5tyP17xkbYwVeW47axu0opmn+L28RxivdJyOhQtWfZLjc/ Oqqyb7hQYIqdbcmerDEfq/CU2ricE0UZ2KXV2DAsJdd8pSeFJb2aQVjpT+ik6VD9hcPv sc6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=jEdbOTaI9m7PNHd1fJWH+JX73cpNYLhM0ko0o7VzxCA=; b=Pq8WGTbB6PYTnwiNv9K42i9ebogKxPWGNss3ZIGP0qdyFuA+28b82yNnIYPwe2cWsx ngIKWTf+k65FxQgxeDVtBiE7LOH5+C1qJ3IGBbEN8gqa4LpRmbo/Zc7ZG4aGvAwD2XZX yXROXFUMhF7ywDqIxSQpRGKyA/sd3eup3j8pYxVF49d85BcvirV9lFYPNIxKmseSfBbB wshdVo60SqxFFAhiJgFX/SNQjtAZZOcw6uL+OGEK0WCm++YxdKqbroh/Xt0cLgxjalka 8budXn/UK3Mo5sbjmkATVa3zH3LFG2cbydYWpP2BSppXa4kj2jipHIxHZEHSE5GQefPp BcIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZWnQ+dHG; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k3-v6si4810888pld.45.2018.05.03.23.59.00; Thu, 03 May 2018 23:59:14 -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=@gmail.com header.s=20161025 header.b=ZWnQ+dHG; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751382AbeEDG6h (ORCPT + 99 others); Fri, 4 May 2018 02:58:37 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:41689 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751146AbeEDG6f (ORCPT ); Fri, 4 May 2018 02:58:35 -0400 Received: by mail-pf0-f195.google.com with SMTP id v63so16702888pfk.8 for ; Thu, 03 May 2018 23:58:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jEdbOTaI9m7PNHd1fJWH+JX73cpNYLhM0ko0o7VzxCA=; b=ZWnQ+dHGsJv5Lzil3i8Y324N7h03qLiLKSobkozWNJ4BTemwYeQcA9fkPMsij2F0/e KaR3CaBUZsPjYq5asdogXvKfSOSKYfSRTD/eJEvXG4ZrRC10Ohw6kIiRYDARAcDGn3O9 hYVdc5imnoiXb7rE0SctNyzjRAEIdi6U4NGCU+Mph5Jhcy0F0bFiUs6ZiECjx3luPYcp 5s9oII+oa1zBVbEikio7Uyj2MXkMs53RtKoDdpx9bQ8RONd4JHeNNw01AdO8nhwRSqLP iBmgwqIGHRTGb5xPLNCFWWgNPdGuWe1/Pg64qQFP4XCNoABFDE6TW5sQ8DZrzpCR0wIg rblA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jEdbOTaI9m7PNHd1fJWH+JX73cpNYLhM0ko0o7VzxCA=; b=smUZ3hpMjRZd3lwcaM+FC1Ya1Jecb+VMdGbuFJfRotOrvslSOx2RyHjgTVrzMEfyHo vDh3DH1In65N9PW0FnE0Yg7utyt2YA3R+iafhgRqh46WJwP6FelrjgcNPoRNdrK9uSix PybsQhR6MFxVE2fYrFjhzzLNcp/k/3GhwwcCk7DOP0hstgUDvgPQQVEZdW9/mPWWnCRq AxTnAW1KE1WI7tlpEfQzJm4dT6BnYnt7ZGEhDaxr213mWQA2O3FWMH3sNDZ5WLmEFLgg feE0RKLXxs0FXuXWgLffoP/LLFh4EAUvVeAOPA0HgFNB17LSD8pBpA67A1oBSnIMG0K4 7hLA== X-Gm-Message-State: ALQs6tBgXiRrbguZ5VnQSdlogQYYTfDLVRlUx8rGQbExrUdcDKxpkjzJ /vpmcoQVH8apvoMWFaoXivE= X-Received: by 2002:a17:902:b184:: with SMTP id s4-v6mr19048295plr.359.1525417115403; Thu, 03 May 2018 23:58:35 -0700 (PDT) Received: from localhost (outboundhk.mxmail.xiaomi.com. [207.226.244.124]) by smtp.gmail.com with ESMTPSA id p24sm20520473pfk.58.2018.05.03.23.58.34 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 03 May 2018 23:58:34 -0700 (PDT) From: Ganesh Mahendran To: ldufour@linux.vnet.ibm.com, catalin.marinas@arm.com, will.deacon@arm.com, mark.rutland@arm.com, cpandya@codeaurora.org, punit.agrawal@arm.com Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Ganesh Mahendran Subject: [PATCH v2 2/2] arm64/mm: add speculative page fault Date: Fri, 4 May 2018 14:57:49 +0800 Message-Id: <1525417069-27401-2-git-send-email-opensource.ganesh@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525417069-27401-1-git-send-email-opensource.ganesh@gmail.com> References: <1525417069-27401-1-git-send-email-opensource.ganesh@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch enables the speculative page fault on the arm64 architecture. I completed spf porting in 4.9. From the test result, we can see app launching time improved by about 10% in average. For the apps which have more than 50 threads, 15% or even more improvement can be got. Signed-off-by: Ganesh Mahendran --- v2: move find_vma() to do_page_fault() remove IS_ENABLED() remove fault != VM_FAULT_SIGSEGV check initilize vma = NULL --- arch/arm64/mm/fault.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 4165485..efd5956 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -320,14 +320,12 @@ static void do_bad_area(unsigned long addr, unsigned int esr, struct pt_regs *re #define VM_FAULT_BADMAP 0x010000 #define VM_FAULT_BADACCESS 0x020000 -static int __do_page_fault(struct mm_struct *mm, unsigned long addr, +static int __do_page_fault(struct vm_area_struct *vma, unsigned long addr, unsigned int mm_flags, unsigned long vm_flags, struct task_struct *tsk) { - struct vm_area_struct *vma; int fault; - vma = find_vma(mm, addr); fault = VM_FAULT_BADMAP; if (unlikely(!vma)) goto out; @@ -371,6 +369,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, int fault, major = 0; unsigned long vm_flags = VM_READ | VM_WRITE; unsigned int mm_flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; + struct vm_area_struct *vma = NULL; if (notify_page_fault(regs, esr)) return 0; @@ -410,6 +409,16 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr); /* + * let's try a speculative page fault without grabbing the + * mmap_sem. + */ + fault = handle_speculative_fault(mm, addr, mm_flags, &vma); + if (fault != VM_FAULT_RETRY) { + perf_sw_event(PERF_COUNT_SW_SPF, 1, regs, addr); + goto done; + } + + /* * As per x86, we may deadlock here. However, since the kernel only * validly references user space from well defined areas of the code, * we can bug out early if this is from code which shouldn't. @@ -431,7 +440,10 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, #endif } - fault = __do_page_fault(mm, addr, mm_flags, vm_flags, tsk); + if (!vma || !can_reuse_spf_vma(vma, addr)) + vma = find_vma(mm, addr); + + fault = __do_page_fault(vma, addr, mm_flags, vm_flags, tsk); major |= fault & VM_FAULT_MAJOR; if (fault & VM_FAULT_RETRY) { @@ -454,11 +466,20 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, if (mm_flags & FAULT_FLAG_ALLOW_RETRY) { mm_flags &= ~FAULT_FLAG_ALLOW_RETRY; mm_flags |= FAULT_FLAG_TRIED; + + /* + * Do not try to reuse this vma and fetch it + * again since we will release the mmap_sem. + */ + vma = NULL; + goto retry; } } up_read(&mm->mmap_sem); +done: + /* * Handle the "normal" (no error) case first. */ -- 1.9.1