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 84566C433F5 for ; Wed, 25 May 2022 08:04:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 00C7A8D0003; Wed, 25 May 2022 04:04:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EFDD38D0002; Wed, 25 May 2022 04:04:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0ED48D0003; Wed, 25 May 2022 04:04:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id CCD308D0002 for ; Wed, 25 May 2022 04:04:10 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id A1C45120E92 for ; Wed, 25 May 2022 08:04:10 +0000 (UTC) X-FDA: 79503527460.06.0AE4781 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) by imf04.hostedemail.com (Postfix) with ESMTP id F38844001E for ; Wed, 25 May 2022 08:03:53 +0000 (UTC) Received: by mail-qk1-f173.google.com with SMTP id 135so14260811qkm.4 for ; Wed, 25 May 2022 01:04:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=AP6YAmjuideizUL7mupGqzQ5PgkASmXHUBF+HT7ISso=; b=UWgffQQyv6i0tKAsc63H74SeHgCICvuDiLwPWGmBlq4ml4S7CEQgE3b38UG89XS3z9 0UXJjAhJ5oBtgN1f0WfuvFdDFb1bBUVJa8iN5DcBmKQ/v9w+h/NVbZoBBTJc7+u34Hew OTyVPwu+QxFZgg1Zm6IXMlqnLKItVVtSmD+U1tq2EEmsa0CNTOOM+t77fALapS5bCxiW 1gXmFYqiywwS4sg3O4JlGee3ef5Q4mygQv96zsw+4YXWlBugzxbBCKWjVH2NK+NoGwPx hni5smzF4BojIhTNF3OxMU9hqOxvrCL8oMQKnyScgT38rF21G/DIgFwdbLJEuJON+waf nGOg== X-Gm-Message-State: AOAM532FC+i/odN1Enb/mb83nVgsNJJQUNAuf4gAW8sOc1V0n3lZrs5Z 5e5HWP4QXQuHqJS0XgluOA/SKI++DaSNkA== X-Google-Smtp-Source: ABdhPJxQfGIHzE34GYQ9LqMB72unYLgAeS1XKD8xX16K0/YZsEVqYfbANVaewmH+rappC6VT388GaQ== X-Received: by 2002:a37:64cb:0:b0:6a3:4444:9a0a with SMTP id y194-20020a3764cb000000b006a344449a0amr16542894qkb.401.1653465849062; Wed, 25 May 2022 01:04:09 -0700 (PDT) Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com. [209.85.219.173]) by smtp.gmail.com with ESMTPSA id p21-20020a05620a113500b006a34c152422sm838836qkk.64.2022.05.25.01.04.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 May 2022 01:04:07 -0700 (PDT) Received: by mail-yb1-f173.google.com with SMTP id q184so6071966ybg.11 for ; Wed, 25 May 2022 01:04:05 -0700 (PDT) X-Received: by 2002:a05:6902:120e:b0:634:6f29:6b84 with SMTP id s14-20020a056902120e00b006346f296b84mr30228977ybu.604.1653465845434; Wed, 25 May 2022 01:04:05 -0700 (PDT) MIME-Version: 1.0 References: <20220524234531.1949-1-peterx@redhat.com> In-Reply-To: <20220524234531.1949-1-peterx@redhat.com> From: Geert Uytterhoeven Date: Wed, 25 May 2022 10:03:53 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3] mm: Avoid unnecessary page fault retires on shared memory types To: Peter Xu Cc: Linux Kernel Mailing List , Linux MM , Richard Henderson , David Hildenbrand , Matt Turner , Albert Ou , Michal Simek , Russell King , Ivan Kokshaysky , linux-riscv , 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, 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" Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: F38844001E X-Stat-Signature: kfqosasb9u9w54jacsam14jg38icpuwq Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf04.hostedemail.com: domain of geert.uytterhoeven@gmail.com designates 209.85.222.173 as permitted sender) smtp.mailfrom=geert.uytterhoeven@gmail.com X-Rspam-User: X-HE-Tag: 1653465833-356782 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 Wed, May 25, 2022 at 1:45 AM 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. > > Signed-off-by: Peter Xu > arch/m68k/mm/fault.c | 4 ++++ Acked-by: Geert Uytterhoeven Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds