Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4661289rwd; Tue, 23 May 2023 10:33:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4oiXG808MVBZVWtMZWBoGug3mXCCssfViwPDVVnuBw5LS0jPYT3Tj6fYphx1OlUw25H6PL X-Received: by 2002:a17:902:ab42:b0:1ae:4ba0:af86 with SMTP id ij2-20020a170902ab4200b001ae4ba0af86mr10640644plb.64.1684863189218; Tue, 23 May 2023 10:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684863189; cv=none; d=google.com; s=arc-20160816; b=tUsAJgIGG11OBeUSApE0wc/8YNT785rOt+coK0rixg4TE6ROUYb4xxug4WgigyzUI5 A1mK7lhshcknsixJrJ6IXliLsWPy7Q9Y0syi/CTApbfZtFza+0Dfsy268EgnYy9huS0s tzQTJ4MW3XibNadRL8dxguQkZyCtELz9sKGDBbMzh3D+LPLzJlREP0I6v2Jobz2NFnOe 3FccOmG3Qa1wFhevuiI/Yy7QisbJmXKZiXxLY2ATqBEYgj1EqOXi8lzNtWR/IqRw3u0n /OR/cS3+2BwMUg80jjFp42mrWHAjtn37Y+zU7m+WC48SgJ+14Ckn4U2PQwOEgdabUPD+ Oicw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=7hNNgkYV/TU5kf6QHD9/L4s5xCAtSjEnYdGoNcUg3Ho=; b=jyC1k3/j5g1kFpxtPtQNFt5XaZ34kJr23c9kDzlyKHI90YMS05EhdFgBJlfsTSl6uA gk1jFc+w+zGUL+3cPoz8Up5ibTuMX+3lxAm9sVjFhevPrgpJM79bHE/Hxt6VPIAKAQr3 3uJE7i+3ijGzMVXlPs3Dz/ghomVabzpm1E8NDwX/rzAcalykqWBuosAigcsKT6YWfPMb 44TRNDaPCwX3phIFYTZm9uO4r/N3HPFmFm1fLa8LxGiGgCfj/QukBhy6iorAKpz1QGwj o0YtHRvAl9PX+lpzMA7kZvwQo4sM52xOVpOGTgTty+D9/1rNbxIVwWPXQh9r6A4LTDW3 5bHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PhDRPvYZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j7-20020a170902758700b001a6527f6adbsi6450344pll.137.2023.05.23.10.32.54; Tue, 23 May 2023 10:33:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PhDRPvYZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238008AbjEWRK4 (ORCPT + 99 others); Tue, 23 May 2023 13:10:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbjEWRKz (ORCPT ); Tue, 23 May 2023 13:10:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3546BB5 for ; Tue, 23 May 2023 10:10:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BF26D6347B for ; Tue, 23 May 2023 17:10:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0CA5C433EF; Tue, 23 May 2023 17:10:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684861853; bh=iYEi+B9sslkLJiksbVO2kVvlfMuA7iAdpf02AyS8igQ=; h=From:To:Cc:Subject:Date:From; b=PhDRPvYZILhYEYCmQtt/slf03Yh5MHR8+iyRxWyhTh0eq+BhqtiOWmp610Nbsl1oh zpMvW7cAZ7KmLytiPFn5OwUU7+NH2z0jMIFQ2xdKZU5QrSiMMsHbXcSToHXwnN33D2 R53shFR+HN4q3PTe3gqtoRz5M/oYvlNGV+NYyt+ctmKTaLaDcEtX1DL74HQRqGyg/d /IuV75WmSi2z9yzargQmPsWNyXPRCST0duDsSFI06XF9mPeBUnX3yVhu5b9AnzYHjx iK2GXx+uNq0FtyeDKxJjxeUxUhiE4/cDDyDuFbNVkvz0mZEpMEkOVfcoquSUIfTZpB nekLt4xeKLHQg== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Suren Baghdasaryan Subject: [PATCH] riscv: mm: try VMA lock-based page fault handling first Date: Wed, 24 May 2023 00:59:42 +0800 Message-Id: <20230523165942.2630-1-jszhang@kernel.org> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Attempt VMA lock-based page fault handling first, and fall back to the existing mmap_lock-based handling if that fails. A simple running the ebizzy benchmark on Lichee Pi 4A shows that PER_VMA_LOCK can improve the ebizzy benchmark by about 32.68%. In theory, the more CPUs, the bigger improvement, but I don't have any HW platform which has more than 4 CPUs. This is the riscv variant of "x86/mm: try VMA lock-based page fault handling first". Signed-off-by: Jisheng Zhang --- Any performance numbers are welcome! Especially the numbers on HW platforms with 8 or more CPUs. arch/riscv/Kconfig | 1 + arch/riscv/mm/fault.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 62e84fee2cfd..b958f67f9a12 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -42,6 +42,7 @@ config RISCV select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU select ARCH_SUPPORTS_HUGETLBFS if MMU select ARCH_SUPPORTS_PAGE_TABLE_CHECK if MMU + select ARCH_SUPPORTS_PER_VMA_LOCK if MMU select ARCH_USE_MEMTEST select ARCH_USE_QUEUED_RWLOCKS select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c index 8685f85a7474..eccdddf26f4b 100644 --- a/arch/riscv/mm/fault.c +++ b/arch/riscv/mm/fault.c @@ -286,6 +286,36 @@ void handle_page_fault(struct pt_regs *regs) flags |= FAULT_FLAG_WRITE; else if (cause == EXC_INST_PAGE_FAULT) flags |= FAULT_FLAG_INSTRUCTION; +#ifdef CONFIG_PER_VMA_LOCK + if (!(flags & FAULT_FLAG_USER)) + goto lock_mmap; + + vma = lock_vma_under_rcu(mm, addr); + if (!vma) + goto lock_mmap; + + if (unlikely(access_error(cause, vma))) { + vma_end_read(vma); + goto lock_mmap; + } + + fault = handle_mm_fault(vma, addr, flags | FAULT_FLAG_VMA_LOCK, regs); + vma_end_read(vma); + + if (!(fault & VM_FAULT_RETRY)) { + count_vm_vma_lock_event(VMA_LOCK_SUCCESS); + goto done; + } + count_vm_vma_lock_event(VMA_LOCK_RETRY); + + if (fault_signal_pending(fault, regs)) { + if (!user_mode(regs)) + no_context(regs, addr); + return; + } +lock_mmap: +#endif /* CONFIG_PER_VMA_LOCK */ + retry: mmap_read_lock(mm); vma = find_vma(mm, addr); @@ -355,6 +385,9 @@ void handle_page_fault(struct pt_regs *regs) mmap_read_unlock(mm); +#ifdef CONFIG_PER_VMA_LOCK +done: +#endif if (unlikely(fault & VM_FAULT_ERROR)) { tsk->thread.bad_cause = cause; mm_fault_error(regs, addr, fault); -- 2.40.1