Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp458757ioo; Thu, 26 May 2022 07:25:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/og/72431TF/StaLm2EQm62a6wlDx4ApphYNqq3Yf0pfsojJy02y410Q7eKsfFDKCTvFr X-Received: by 2002:a05:6402:1e93:b0:42b:5134:6bf6 with SMTP id f19-20020a0564021e9300b0042b51346bf6mr26117127edf.40.1653575159725; Thu, 26 May 2022 07:25:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653575159; cv=none; d=google.com; s=arc-20160816; b=f7IlIcToqufR/FiUsMCWYfX/lf0L7JzfvjBWTs3IpsAxML8AIYCC65eBwUPw8i1ds2 xBhrKKjGnUPeBCzqI5rGjz+wIOar9T/xMsBrVk3B2nX1eFPQ4tT46G1Z5tu6RSNif6qO B3pldbFCIUOR5eDzYWTr4HFPyjEM3U7eXtGCm+PYYK5Nyu0hJbtw45cWK5+t/yl4xS6n v/oj1WU0eVLVPBPbpD14p119xF+/RAkq0iqB3CwHqWAY7vCJUC5yHwge30JXzJk7Z2Sm CfzUrgxdOsXuBmg9DSg4ogzoq4+GUfw46vLxbt1dusXK7OvVFUvYPR+oSJHBSeKARvlL PTZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=AP6YAmjuideizUL7mupGqzQ5PgkASmXHUBF+HT7ISso=; b=FTRF8Afy6t1qq91oJJhXByzlLTMKktxRdSdARnUqaZMq02nVgtez3m3b2vghFDHkrJ zPba09TuVda8/0D+POAQmdm+ZIoBwV2G0NFfSH9fxwWkRmTomvCWeMhmJNUBISkSCMJc Dptcd/MI9ImvD4xCQtmWaOv3eyKxY/Ue1BC61flEu6LZmIiuLZVCbE0xLYmPoRU7DmKV 2Oe1rL+sWH9KZrdlj+YAuGCFCeMJ10a4lSlFEepQI4LuApBja0t5j1Blgm1/ngTqBbIg pMLo0wZtOEby0zhZlUfNRhvyUm0HA+wsd46LYeSXSL4xdN9UKCNtMp9TkUpmWfljvRF6 s5kg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o17-20020a056402439100b0042b5f20c62asi331539edc.70.2022.05.26.07.25.31; Thu, 26 May 2022 07:25:59 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235121AbiEYIJc (ORCPT + 99 others); Wed, 25 May 2022 04:09:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230115AbiEYIJ1 (ORCPT ); Wed, 25 May 2022 04:09:27 -0400 Received: from mail-vs1-f47.google.com (mail-vs1-f47.google.com [209.85.217.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C21B7CB62; Wed, 25 May 2022 01:09:26 -0700 (PDT) Received: by mail-vs1-f47.google.com with SMTP id 68so13045341vse.11; Wed, 25 May 2022 01:09:26 -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=uxJG7TB5ZJoieTVL9kZBV836edJKVAeT7i96N1Eig6qaN8mbelut5uQR+kc+K8v4Bw dkowdSspLVgOTKbgfz/5tlE4JY3hsccAG6cKlcL5+c93/euhtlRSlhexpfRCfevFIlWa 9rfIN6O2cHHmkMzRa4Jt66M6lUzWXaKo6ds0q2CpMvUDTE3jlDC4IcjInV/PbCZr3A0+ PpiO36GQjmCz8Sa7qHUT4p2WeLFLsEVcGj1Y3Rr5SL9TqWjDivfEq4nibmUqogpK36Eh gZ8kUA1kvAG2Ude0vxeWE/NuD7GNe8+PSZ9nJefR1OPK15H6f66/MoRoCW471Fr/e5xZ 81zw== X-Gm-Message-State: AOAM532SXnRLy1P6ElhzCgp42VJD+0kpKtI8URzsEnkGThEYBs2sYTKj 8B5PNvPN02xJ7eX3SV9e4uEmF4nzDasNGbhk X-Received: by 2002:a05:6102:f06:b0:337:9881:5031 with SMTP id v6-20020a0561020f0600b0033798815031mr8239948vss.67.1653466165429; Wed, 25 May 2022 01:09:25 -0700 (PDT) Received: from mail-ua1-f44.google.com (mail-ua1-f44.google.com. [209.85.222.44]) by smtp.gmail.com with ESMTPSA id u23-20020ab07037000000b003626f894df6sm163784ual.36.2022.05.25.01.09.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 May 2022 01:09:25 -0700 (PDT) Received: by mail-ua1-f44.google.com with SMTP id m18so7079159uao.9; Wed, 25 May 2022 01:09:25 -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-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, 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 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