Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5267175rwd; Tue, 23 May 2023 22:11:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Rm9/GH/Dr2poZgStWZ0Dc6dBCB8Bh9AAEqdDgGJPLwo+ueFNXsRQyi+Tq0211b8HlVS1+ X-Received: by 2002:a17:902:7891:b0:1ad:fa2e:17f8 with SMTP id q17-20020a170902789100b001adfa2e17f8mr13406622pll.12.1684905067394; Tue, 23 May 2023 22:11:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684905067; cv=none; d=google.com; s=arc-20160816; b=Z8HGXmz+jx6CqupR2Xp2+QQmFA9vUFbWGvwyl4gnIsbHXXrV6CIQvKpQy1bARqf+5x 8lc5SUONTcR9OaufrHj5a/rtWx5+1vySaMTgmZwlFqRWUGr3ecebi3kCEbVwYpCWH2N2 SMYFfS1S3r7qPVay3syg2CBkhjpX3Xgx7VnBaKFaBK2YPaYpXUKLWq8IAfZ/l0fVRn9S pHjaOss031PXJulZqMD/HpVEMjKa7SYft43IobA9/MnlG93AH6B4uhLf3rj29wMsngub 6HsrPL3vgKnIelpAx7EGvaFvjdPUR+MKShQ0avWPJAdw507t5pTiXawNotcSeqNGmgIH 1SUA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=g5LV2BSgdfFfKK4mfcGqLQISINWanMF/ALukZRrYtxo=; b=MXX/u11NXD7hmI0dibQhwVWTkR8Q1A+8GgwVIo3zm9cY+Nszd+I9/8+KtXNk2wx4YC tqjpH3cqBDO/yBrFKJcnbGGl3dBoBeBxhHDNsUepnDX8DmB9JskKnea9Kbzljv7J8xHx Muvra+EyLLnHUxIIeTCuW2qWQKVf6RkFG2TLQ1s1svwwDH+T6LpQUfQU26/G5xat3Nq5 2ts5ehhmXHNINsktgCzB/OmiPqLjt7LqEohhyEX0QLx159Xa2Sddmig7Cm6eAAaGrGZy I7ubN5EB2nxWZObvNV4Bkr5MdXh79vGCFcyiCLOMo2NmG0oMt9tHbn+Z4gFCuIaOMZBm +e4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IQaMOUkG; 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 f1-20020a170902860100b001afd8120d26si1295884plo.35.2023.05.23.22.10.44; Tue, 23 May 2023 22:11:07 -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=IQaMOUkG; 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 S236309AbjEXFDQ (ORCPT + 99 others); Wed, 24 May 2023 01:03:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232705AbjEXFDL (ORCPT ); Wed, 24 May 2023 01:03:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10BE611D for ; Tue, 23 May 2023 22:03:10 -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 9BB76638DA for ; Wed, 24 May 2023 05:03:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E5C1C433D2; Wed, 24 May 2023 05:03:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684904589; bh=LFVxfFwT67gFaNdLM975ekdnnjw9GiT6JhuN19MxRFg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IQaMOUkGsS803kSJ7OEW66RhxhdwNAEpSpUeNwErbtoEPLw5wGLKALFnjVKymMn2/ MlM4a6bPPckxXBmo810IYOnPAY2SezZZAU19lbRT68ZHQIGmvGg2cV2Sa/suRyKQ/w /n+toXz9Yl03D/w7IJa0pFkHaMDWL8iYb85nDozSFoTrfsSVVteKmNRwUQDIrA6To3 /NVmYv7H30+FXV088YQeVgYMHlXfO9itWSo2Nf5etrhh8+7/pSnMkL5ukXssIs8Z+/ dY+SJpaJNKsxWdZlpFflYHNOJ+2/XQLuZeBvfQykoj6OIs2kFPuY3ZaWyM9AtLrREP a2k72aXibXXmg== From: guoren@kernel.org To: jszhang@kernel.org Cc: aou@eecs.berkeley.edu, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, palmer@dabbelt.com, paul.walmsley@sifive.com, surenb@google.com, chenhuacai@kernel.org, Guo Ren Subject: Re: [PATCH] riscv: mm: try VMA lock-based page fault handling first Date: Wed, 24 May 2023 01:02:59 -0400 Message-Id: <20230524050259.104358-1-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20230523165942.2630-1-jszhang@kernel.org> References: <20230523165942.2630-1-jszhang@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 Good improvement, I think VMA lock is worth to support in riscv. Please give more details about ebizzy, Is it https://github.com/linux-test-project/ltp/blob/master/utils/benchmark/ebizzy-0.3/ebizzy.c ? > 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". > How about add Link tag here: Link: https://lwn.net/Articles/906852/ > 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 It's very close to cd7f176aea5f ("arm64/mm: try VMA lock-based page fault handling first"), and I didn't find any problem. So: Reviewed-by: Guo Ren F.Y.I Huacai Chen, maybe he also would be interesting this new feature. > if (unlikely(fault & VM_FAULT_ERROR)) { > tsk->thread.bad_cause = cause; > mm_fault_error(regs, addr, fault); > -- > 2.40.1