Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp8897668rwd; Tue, 20 Jun 2023 23:45:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6QtG1BpQ49S+b6Np5pzejDwgG5KXHM1HUZINWvRNSBc+zAXnWT3k58ToouOrblIA1tJGzi X-Received: by 2002:a17:90a:3d0d:b0:259:b065:da4f with SMTP id h13-20020a17090a3d0d00b00259b065da4fmr14391142pjc.36.1687329927159; Tue, 20 Jun 2023 23:45:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687329927; cv=none; d=google.com; s=arc-20160816; b=X0b4QKgVY1G1YYtmtMcPNTJlsQ5bNAOpSvweDjrjaQ/cfIukujnvTyNn6PKfOn6bPd 9bjbHyYNN2xkq2qic2UbuyOrYlvID+z/FL1B6bMT1pr1dj+8ByoHmYCfYxHL38SL5qpK 0oLAcpBwLISuwIogtGl4ZaLFLmpIXUean9TCYEGLiiO0l9zYeHZ3zVRJ9nYdirNRo3ib rA4ZWU85fPgk2MlDSrMJSCythl0cxgUVw2KwRm/zn6rUJzN22HhAUBrfBMsZSRA+p38I Q5CQGWVEA7LgF7u4ytRi/Kg4qSdqzH48vYk6L9xIKvA5owMd/GYvK2dbaDD/emkraVsO 1vVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=x3885XwWgO4I80jOOz0290h2B8gIFRxHbl6tG2snT+w=; b=I054c6Zz6samvKqCFz/N2Iwz5RnAH0ByO6trkYYCMnZZvjHn8KQNZ/a3I1wIzRgmis 0+0421tB4M7Yo9KK4OVsqphuC/m4tql61YmowDAPQNz/sG6QWdZwqeVmnNA7MTiaG5Bq fcW5eQE8acPM7KackRN3BRsExHXXsB3Wut3+2EC4VY48cjiJhTeUX+v8BHAxyXg+7jYc rs7uHst0tWCfCfJB+FMtKcfmKomqcgMFUrJ7tTkX1v+DAtTE8u52XHdQA/GsjxEU8oAa a+uOw/eSpJChTsKBQ5/hZHmj+LvDmBSOY8nrZvKVtYlHH5rur9IVDib6hyJb2YY35FwV LBDA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t14-20020a17090a024e00b002594c8d950csi378182pje.89.2023.06.20.23.45.14; Tue, 20 Jun 2023 23:45:27 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230187AbjFUGPe (ORCPT + 99 others); Wed, 21 Jun 2023 02:15:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbjFUGPc (ORCPT ); Wed, 21 Jun 2023 02:15:32 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D4E510DA for ; Tue, 20 Jun 2023 23:15:29 -0700 (PDT) Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4QmCqY4CnszLmsC; Wed, 21 Jun 2023 14:13:29 +0800 (CST) Received: from [10.174.177.243] (10.174.177.243) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 21 Jun 2023 14:15:26 +0800 Message-ID: Date: Wed, 21 Jun 2023 14:15:26 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: [PATCH] riscv: mm: try VMA lock-based page fault handling first Content-Language: en-US To: Jisheng Zhang , Paul Walmsley , Palmer Dabbelt , Albert Ou CC: , , Suren Baghdasaryan References: <20230523165942.2630-1-jszhang@kernel.org> From: Kefeng Wang In-Reply-To: <20230523165942.2630-1-jszhang@kernel.org> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 On 2023/5/24 0:59, Jisheng Zhang wrote: > 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 no need if mmu, see PER_VMA_LOCK config PER_VMA_LOCK bool "allow VMA lock-based page fault" def_bool y depends on ARCH_SUPPORTS_PER_VMA_LOCK && MMU && SMP Reviewed-by: Kefeng Wang > 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);