From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 239B5C433EF for ; Fri, 27 May 2022 14:53:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 952B98D001B; Fri, 27 May 2022 10:53:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 925AF8D000C; Fri, 27 May 2022 10:53:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79F598D001B; Fri, 27 May 2022 10:53:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 66E9D8D000C for ; Fri, 27 May 2022 10:53:51 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 30CFA1602 for ; Fri, 27 May 2022 14:53:51 +0000 (UTC) X-FDA: 79511817462.25.B423500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 3A5F040072 for ; Fri, 27 May 2022 14:53:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653663226; 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=YVxFOc3jqLU2qU8MwpEJ8BUGPKTFqMRa5/k6gGjoczP9YTIoEYVYoSegxsgL/29FZROCr0 E2ezH9bsk/oWh6OfWDF/pa2/Eg/M4vDru2W1aHMc9MegmtJ5ZPWmdM/tsSi9A5E5TNB83e 3HthpYqdwcBaQhgtXslqsywODgVsIZw= Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-53-CxEolxDHNdShwl_I9TiVgA-1; Fri, 27 May 2022 10:53:45 -0400 X-MC-Unique: CxEolxDHNdShwl_I9TiVgA-1 Received: by mail-il1-f197.google.com with SMTP id g8-20020a92cda8000000b002d15f63967eso3183322ild.21 for ; Fri, 27 May 2022 07:53:45 -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=s3lmwuuy6rB593XraeWK1a+RlT1wh9pf2amVJHD+t78iCW9uDo3mp5Quz/ltdW/1kB VpOrP4toS54vOFQjixIalLzWFxxQoXapapQiT2vg4cR8v3iDumBqGPJgsApcBJa0GO1w BaWx5tFPQG7VTKLjzNUmz5Y7gTTRxi0nVf9Gd17PYkKjWtmuRBHQl2o06pirLWGsgEjA 2C8fnXXaLgOfsBbqGu8K4YKhfw0UIwIPo3cHSp7MlEXWA4/4/JxgLLcwJXCQsvkFgc/e rhl2+Vzz0cVCJ/Ur/kySDDi4224DvLxWDcTYoerb7gC3XkThNOC3/LcLYIkSUC5M7ms0 2XHQ== X-Gm-Message-State: AOAM533VPN3CDtABHBsVgTzFxdlQhcznRC8mR9VuO8pP6wPrmD/ZC1Oq WdBc60ndM66ZjirgP/3rLdiz2ZuG6YTdnn7QviWv1ZdRYRoQfZk73LBzEYSeWsr1dTP0lX2BtmT x4ZyhbOA3zlI= X-Received: by 2002:a05:6e02:1a61:b0:2cf:8a90:7396 with SMTP id w1-20020a056e021a6100b002cf8a907396mr22761939ilv.256.1653663223411; Fri, 27 May 2022 07:53:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxG97+4KBIU6l93iytV0+qRm43dQQLHa2a/K8HbhfEtxo7G4J9rDpss95rHRYaCYZkQNmDyjQ== 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 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Stat-Signature: nytxhonhx6bspxpnaktytf7i78jcatfw Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YVxFOc3j; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf12.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3A5F040072 X-HE-Tag: 1653663189-514457 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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