Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2389273ioo; Sat, 28 May 2022 12:06:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpovCkcIhsi/ej//BdtPbh6J0kUWtk3QARdZABmZPg6znsafyWhQtscWKX9RDbdJIfl0yd X-Received: by 2002:a17:90b:4c91:b0:1df:c826:2d1d with SMTP id my17-20020a17090b4c9100b001dfc8262d1dmr14734711pjb.75.1653764812851; Sat, 28 May 2022 12:06:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653764812; cv=none; d=google.com; s=arc-20160816; b=B9lzGkPQD8wZ1qzB/Ah8KChzkckRIwdd0afdBrL04L4S6KYSdj/Z5+DCwkzekHg179 sguD8BYfAqHFDcz7waXabBKh+41k5dZo/amBSOqynVUWajgaroI4iYNDrUAotGSrMvwH pZhQSIIeLtcIsrYMe9nPm4oIZYc6P4/OC/cLpkgqdwFnd/AUfi8cY2Uq/ZasgxWsGwDy NQAW7KYC4uiQfiRFRobPzb0hVPZDyixbxA8BA/IQifyS+GdmWdA2sGYi0exxX9nZKbh6 oVFp12CVvLFP7O8Kf3MFKypdyK/j0CnHA61kB4/r+7gtSs0gk4Mpo12C8ZiA0G8AaLkW XfZw== 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=uLEQbfXieXddbws3ZtMPUo3kSGjUH1tIUFKal4fFd0k=; b=uA6wLgFzykUwpSU/YHi5a8aj4lmp2V4xOSjE+wrYrxq4AGdYourv856HmitP28gwvO 4Pxak9L/z0AI9HLumW2mpzpN5J1qpxG+kfUPVOMymfzx++4ZvxMwlXFe9UjoAn5mvqXs CVGCrpW1lnRg8npTx+Y0GAjaSRVekLCN9Ez9zXdnAyhlvyseHJ4xsegcfwGfsOkMsXaM WGCqjTy4H5xZxnm0bwKGanfo3GE1MOYgiuxxHIDCjIPJURPZC4ys011TG7ch1OozDiMQ O7anW3CSalva2F0zEnngzAFCm7nBBgNgdECbO+0FLIZ9ddZO0GG0LJESNpBAD3eq+w5O MAqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZUWXkMma; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id p3-20020a170902bd0300b001639977d222si5765020pls.406.2022.05.28.12.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 12:06:52 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZUWXkMma; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 401D43F328; Sat, 28 May 2022 11:46:19 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352352AbiE0Oxw (ORCPT + 99 others); Fri, 27 May 2022 10:53:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352061AbiE0Oxt (ORCPT ); Fri, 27 May 2022 10:53:49 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5BBD6129EEB for ; Fri, 27 May 2022 07:53:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653663225; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=uLEQbfXieXddbws3ZtMPUo3kSGjUH1tIUFKal4fFd0k=; b=ZUWXkMmaLR/WV6SaN23An4IjuzAIza1QX1t8JzsMALCVYB77n5xLXUBVTeDmXG4i9Rz8In 93SdTNCn3lvYQKzM1zI+gr5m3+U3u6Q3xuOoj9aE3GpQX8tvfmVao021lGneA/iU37e0Wi G7M7d7KrJBIJ1UlhRAr3ZuYKmDOg12A= Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-223-Mj4rRzI4O16BmMMv3qm2ag-1; Fri, 27 May 2022 10:53:44 -0400 X-MC-Unique: Mj4rRzI4O16BmMMv3qm2ag-1 Received: by mail-il1-f198.google.com with SMTP id q6-20020a056e0215c600b002c2c4091914so3200114ilu.14 for ; Fri, 27 May 2022 07:53:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=uLEQbfXieXddbws3ZtMPUo3kSGjUH1tIUFKal4fFd0k=; b=KliCCvi0LVi7oJusPzzUC292/p9jAOZovBivWW2zUXWxhc7HbJ9aJ56n09Kvo1v8zK W41d30Fi7Gig6YMLq+pYK6OdJ9FD19ba2FwVZS6yYctDykD4yIe8EN9goyNvUhB0I1P1 pWLe/D/SYCJr3iUtgHTd8puq69bj8DAzsyNLHANCbZO83Gg4VpGwt3rN8nYg/aASm4Bs +LQbeydjBJq7yOH675iYEDd4sB9AtiSbOQuKGVQWm5/04cr246cPP8FRD4PWMbHLadWZ h6h7QdNXkjVh7MmZhio4yD8I6f4B/aizoo7PAwQcatVjaav+NZat31lr6uKsJQ3GRMLi 61mA== X-Gm-Message-State: AOAM531nU4FlXWA6YJ7W5NRy1Zr93oAVF1il//bhwwh7gxmHDbzhPAfR 7snZFuOk0P160bSmtwrzcl2PuviSEEMvQn8in+bDW+vgg6P3NBjKLlYW8U920js6daLz3KyEGiA skwqensFM4IEn28s6KTKa+xLH X-Received: by 2002:a05:6e02:1a61:b0:2cf:8a90:7396 with SMTP id w1-20020a056e021a6100b002cf8a907396mr22761908ilv.256.1653663223386; Fri, 27 May 2022 07:53:43 -0700 (PDT) X-Received: by 2002:a05:6e02:1a61:b0:2cf:8a90:7396 with SMTP id w1-20020a056e021a6100b002cf8a907396mr22761868ilv.256.1653663222806; Fri, 27 May 2022 07:53:42 -0700 (PDT) Received: from xz-m1.local (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id d6-20020a023f06000000b00330efaf1161sm596380jaa.148.2022.05.27.07.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 May 2022 07:53:42 -0700 (PDT) Date: Fri, 27 May 2022 10:53:36 -0400 From: Peter Xu To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Richard Henderson , David Hildenbrand , Matt Turner , Albert Ou , Michal Simek , Russell King , Ivan Kokshaysky , linux-riscv@lists.infradead.org, Alexander Gordeev , Dave Hansen , Jonas Bonn , Will Deacon , "James E . J . Bottomley" , "H . Peter Anvin" , Andrea Arcangeli , openrisc@lists.librecores.org, linux-s390@vger.kernel.org, Ingo Molnar , linux-m68k@lists.linux-m68k.org, Palmer Dabbelt , Heiko Carstens , Chris Zankel , Peter Zijlstra , Alistair Popple , linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, Vlastimil Babka , Thomas Gleixner , sparclinux@vger.kernel.org, Christian Borntraeger , Stafford Horne , Michael Ellerman , x86@kernel.org, Thomas Bogendoerfer , Paul Mackerras , linux-arm-kernel@lists.infradead.org, Sven Schnelle , Benjamin Herrenschmidt , linux-xtensa@linux-xtensa.org, Nicholas Piggin , linux-sh@vger.kernel.org, Vasily Gorbik , Borislav Petkov , linux-mips@vger.kernel.org, Max Filippov , Helge Deller , Vineet Gupta , Al Viro , Paul Walmsley , Johannes Weiner , Anton Ivanov , Catalin Marinas , linux-um@lists.infradead.org, linux-alpha@vger.kernel.org, Johannes Berg , linux-ia64@vger.kernel.org, Geert Uytterhoeven , Dinh Nguyen , Guo Ren , linux-snps-arc@lists.infradead.org, Hugh Dickins , Rich Felker , Andy Lutomirski , Richard Weinberger , linuxppc-dev@lists.ozlabs.org, Brian Cain , Yoshinori Sato , Andrew Morton , Stefan Kristiansson , linux-parisc@vger.kernel.org, "David S . Miller" Subject: Re: [PATCH v3] mm: Avoid unnecessary page fault retires on shared memory types Message-ID: References: <20220524234531.1949-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Fri, May 27, 2022 at 12:46:31PM +0200, Ingo Molnar wrote: > > * Peter Xu wrote: > > > 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%) > > Nice! > > > arch/x86/mm/fault.c | 4 ++++ > > Reviewed-by: Ingo Molnar > > Minor comment typo: > > > + /* > > + * We should do the same as VM_FAULT_RETRY, but let's not > > + * return -EBUSY since that's not reflecting the reality on > > + * what has happened - we've just fully completed a page > > + * fault, with the mmap lock released. Use -EAGAIN to show > > + * that we want to take the mmap lock _again_. > > + */ > > s/reflecting the reality on what has happened > /reflecting the reality of what has happened Will fix. > > > ret = handle_mm_fault(vma, address, fault_flags, NULL); > > + > > + if (ret & VM_FAULT_COMPLETED) { > > + /* > > + * NOTE: it's a pity that we need to retake the lock here > > + * to pair with the unlock() in the callers. Ideally we > > + * could tell the callers so they do not need to unlock. > > + */ > > + mmap_read_lock(mm); > > + *unlocked = true; > > + return 0; > > Indeed that's a pity - I guess more performance could be gained here, > especially in highly parallel threaded workloads? Yes I think so. The patch avoids the page fault retry, including the mmap lock/unlock side. Now if we retake the lock for fixup_user_fault() we still safe time for pgtable walks but the lock overhead will be somehow kept, just with smaller critical sections. Some fixup_user_fault() callers won't be affected as long as unlocked==NULL is passed - e.g. the futex code path (fault_in_user_writeable). After all they never needed to retake the lock before/after this patch. It's about the other callers, and they may need some more touch-ups case by case. Examples are follow_fault_pfn() in vfio and hva_to_pfn_remapped() in KVM: both of them returns -EAGAIN when *unlocked==true. We need to teach them to know "*unlocked==true" does not necessarily mean a retry attempt. I think I can look into them if this patch can be accepted as a follow up. Thanks for taking a look! -- Peter Xu