Received: by 2002:a19:771d:0:0:0:0:0 with SMTP id s29csp1277794lfc; Wed, 1 Jun 2022 13:59:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLhG7M+PNyQtSmEuWc1RzMTvOoERsY/DFsweNC6b669Z/+qMvDk3Unor43MCaZZJQgJTfz X-Received: by 2002:a05:6a00:1a4a:b0:518:bbd5:3c1d with SMTP id h10-20020a056a001a4a00b00518bbd53c1dmr1415660pfv.64.1654117167922; Wed, 01 Jun 2022 13:59:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654117167; cv=none; d=google.com; s=arc-20160816; b=IG3bYQA8rr9lfaSUFkoMkmgHooiwvsu5Zg0yNgv7skNe5s3omAis3qw2owGIn8W/Q7 h1E8yCxKxu5tOIXM5Zwae/E1ZqZkIIsHsPn9dUC/epMyyBzfGxAGfUQE0mLNzdbytCsH Gv34VtLBntaaXIioTmzcXBiJm90yewFj610SD8L+WzaERBR3TAv4A0Jc9wMo3uuTaBIv ov+yBpXQHttTjt/udG2xDYmF50sx5y0ZS7NuTh9XP0f6tQGIOOPI2l73w6jB9HZku6HV NsAkBwsAMdatvyTZ43Wh+qhHYhSLar9FO24S8L8c/0YmbEO2EmW0jduFJgSSyep3LcdC LSlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=fCDCNg9Fl0rDsWI5cVbkr7yPCpu4aY2vi3Um9DXKuyo=; b=TsN6H+hZ67MQbl2yk1nSdnjMpcApxwRe9KmHJuC65FKG3xHsg+w0mdwv+IUbjmBwh0 I9NoT97oo4N3mzcL6tTsAD4lUzk3f0hJyLH+qJGpuXFcDVKCkkd2irMz17ZwfHlzizz+ 3D1RlR/ds94WIDOTDoDsZ4Q+AOir07y52jyLYZaE+WDE0kPggkqX4d6SMSK+hPx2txto pEsx0ZdJSieaYTt5tWMUaOi49LOEQReeVUBo8loO7jT3kK0cxrEMcSpGIwbMjzTNjtHy /RhRptInCEQN1pSYaePMDYcNa31R9/HuHtRm0tyZsAp4m5QzKAlCPRvToZM7AdmCoFOH au5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=TwuPNcBR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q20-20020a635c14000000b003c24b633c7esi3280294pgb.668.2022.06.01.13.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 13:59:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=TwuPNcBR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0547B2A3B96; Wed, 1 Jun 2022 13:02:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244724AbiEaIDV (ORCPT + 99 others); Tue, 31 May 2022 04:03:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244720AbiEaIDT (ORCPT ); Tue, 31 May 2022 04:03:19 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B7CC9155E; Tue, 31 May 2022 01:03:14 -0700 (PDT) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24V7pnxE010470; Tue, 31 May 2022 07:59:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=pp1; bh=fCDCNg9Fl0rDsWI5cVbkr7yPCpu4aY2vi3Um9DXKuyo=; b=TwuPNcBR4U1XYDHdlIDZYKqcL5KJT69oeeTAf0vy5m7ooDBj90SBRisXK63xMXHvK8l0 Ov/cquTEsxXxBim+UukTU2rsQcn6NprZ4HWRN68SlwYgZXcr9qZgM89RGc6MwoI/bqEL o6GOS/aiaC9dqiy4ahWeqSt5T6xN5hmciCI34Qmd0QVrEU1vbyvV2QBCOIg+JzaMgATb 8jaFh0BsNFxNOHSjg3UgeRvf/2N2Wujv9geXH5fdOj7Ye52btvKTOJPDKvku8NHfDMem dO2O0Q0YLPZWYG0qyBQJvfeeNv5XIulDxvgh2q56ULI3MONZBMZ+0s0xvmHu5XqW+/Ip CA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3gdf0hr3k5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 31 May 2022 07:59:47 +0000 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 24V7qjhT012512; Tue, 31 May 2022 07:59:46 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3gdf0hr3jn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 31 May 2022 07:59:46 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24V7rKjg027282; Tue, 31 May 2022 07:59:44 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma06ams.nl.ibm.com with ESMTP id 3gbbynkrfp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 31 May 2022 07:59:44 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24V7xfmo55443962 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 May 2022 07:59:41 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2FAF642041; Tue, 31 May 2022 07:59:41 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B44A34203F; Tue, 31 May 2022 07:59:38 +0000 (GMT) Received: from osiris (unknown [9.145.72.89]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Tue, 31 May 2022 07:59:38 +0000 (GMT) Date: Tue, 31 May 2022 09:59:37 +0200 From: Heiko Carstens To: Peter Xu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Ingo Molnar , Vasily Gorbik , linuxppc-dev@lists.ozlabs.org, Stafford Horne , "David S . Miller" , Johannes Berg , Brian Cain , x86@kernel.org, linux-parisc@vger.kernel.org, Richard Henderson , Christian Borntraeger , Richard Weinberger , linux-hexagon@vger.kernel.org, Benjamin Herrenschmidt , Thomas Gleixner , Janosch Frank , Albert Ou , Anton Ivanov , Dave Hansen , linux-ia64@vger.kernel.org, Borislav Petkov , Russell King , Sven Schnelle , Andrea Arcangeli , "James E . J . Bottomley" , Al Viro , Alexander Gordeev , Peter Zijlstra , Alistair Popple , Jonas Bonn , sparclinux@vger.kernel.org, linux-csky@vger.kernel.org, Will Deacon , Andrew Morton , Vlastimil Babka , linux-um@lists.infradead.org, Michal Simek , Matt Turner , linux-m68k@lists.linux-m68k.org, Paul Mackerras , linux-xtensa@linux-xtensa.org, Geert Uytterhoeven , David Hildenbrand , openrisc@lists.librecores.org, linux-arm-kernel@lists.infradead.org, Nicholas Piggin , Palmer Dabbelt , Michael Ellerman , Stefan Kristiansson , Paul Walmsley , Ivan Kokshaysky , Chris Zankel , Hugh Dickins , Vineet Gupta , Dinh Nguyen , Catalin Marinas , Rich Felker , "H . Peter Anvin" , linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-riscv@lists.infradead.org, Johannes Weiner , Andy Lutomirski , Max Filippov , Guo Ren , Thomas Bogendoerfer , linux-snps-arc@lists.infradead.org, linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, Helge Deller , Yoshinori Sato , Ingo Molnar Subject: Re: [PATCH v5] mm: Avoid unnecessary page fault retires on shared memory types Message-ID: References: <20220530183450.42886-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220530183450.42886-1-peterx@redhat.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: RLhB66egEP1T9U1MkMA8rdmyk-WXjxeE X-Proofpoint-ORIG-GUID: ToZrP-uDPxbUpDXuMZf7xPxYmVzsS7TL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-05-31_02,2022-05-30_03,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2205310038 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Mon, May 30, 2022 at 02:34:50PM -0400, Peter Xu wrote: > I observed that for each of the shared file-backed page faults, we're very > likely to retry one more time for the 1st write fault upon no page. It's > because we'll need to release the mmap lock for dirty rate limit purpose > with balance_dirty_pages_ratelimited() (in fault_dirty_shared_page()). > > Then after that throttling we return VM_FAULT_RETRY. > > We did that probably because VM_FAULT_RETRY is the only way we can return > to the fault handler at that time telling it we've released the mmap lock. > > However that's not ideal because it's very likely the fault does not need > to be retried at all since the pgtable was well installed before the > throttling, so the next continuous fault (including taking mmap read lock, > walk the pgtable, etc.) could be in most cases unnecessary. > > It's not only slowing down page faults for shared file-backed, but also add > more mmap lock contention which is in most cases not needed at all. > > To observe this, one could try to write to some shmem page and look at > "pgfault" value in /proc/vmstat, then we should expect 2 counts for each > shmem write simply because we retried, and vm event "pgfault" will capture > that. > > To make it more efficient, add a new VM_FAULT_COMPLETED return code just to > show that we've completed the whole fault and released the lock. It's also > a hint that we should very possibly not need another fault immediately on > this page because we've just completed it. > > This patch provides a ~12% perf boost on my aarch64 test VM with a simple > program sequentially dirtying 400MB shmem file being mmap()ed and these are > the time it needs: > > Before: 650.980 ms (+-1.94%) > After: 569.396 ms (+-1.38%) > > I believe it could help more than that. > > We need some special care on GUP and the s390 pgfault handler (for gmap > code before returning from pgfault), the rest changes in the page fault > handlers should be relatively straightforward. > > Another thing to mention is that mm_account_fault() does take this new > fault as a generic fault to be accounted, unlike VM_FAULT_RETRY. > > I explicitly didn't touch hmm_vma_fault() and break_ksm() because they do > not handle VM_FAULT_RETRY even with existing code, so I'm literally keeping > them as-is. > > Acked-by: Geert Uytterhoeven > Acked-by: Peter Zijlstra (Intel) > Acked-by: Johannes Weiner > Acked-by: Vineet Gupta > Acked-by: Guo Ren > Acked-by: Max Filippov > Acked-by: Christian Borntraeger > Acked-by: Michael Ellerman (powerpc) > Acked-by: Catalin Marinas > Reviewed-by: Alistair Popple > Reviewed-by: Ingo Molnar > Signed-off-by: Peter Xu > --- ... > arch/s390/mm/fault.c | 12 ++++++++++++ > diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c > index e173b6187ad5..973dcd05c293 100644 > --- a/arch/s390/mm/fault.c > +++ b/arch/s390/mm/fault.c > @@ -433,6 +433,17 @@ static inline vm_fault_t do_exception(struct pt_regs *regs, int access) > goto out_up; > goto out; > } > + > + /* The fault is fully completed (including releasing mmap lock) */ > + if (fault & VM_FAULT_COMPLETED) { > + if (gmap) { > + mmap_read_lock(mm); > + goto out_gmap; > + } > + fault = 0; > + goto out; > + } > + > if (unlikely(fault & VM_FAULT_ERROR)) > goto out_up; > > @@ -452,6 +463,7 @@ static inline vm_fault_t do_exception(struct pt_regs *regs, int access) > mmap_read_lock(mm); > goto retry; > } > +out_gmap: > if (IS_ENABLED(CONFIG_PGSTE) && gmap) { > address = __gmap_link(gmap, current->thread.gmap_addr, > address); FWIW: Acked-by: Heiko Carstens