Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1321393rwe; Thu, 1 Sep 2022 16:52:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR7ZMv/vVwdOmehqEfQJlOzx50NsjNVwD5gv6JnCpXOo9jZCBmZi7/L8V0EoZjpAI5U/kt8c X-Received: by 2002:a17:907:d07:b0:72e:ec79:ad0f with SMTP id gn7-20020a1709070d0700b0072eec79ad0fmr26242777ejc.296.1662076348407; Thu, 01 Sep 2022 16:52:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662076348; cv=none; d=google.com; s=arc-20160816; b=ySH+SNmAd4GmCWbJ1dyK+FiY1JoEmf68g5Gaf1Kpoq5a6Y5P9/YwLMTkexh9c+d03q O36+3ptIAKw+/7Otx6LTkHtCE9GEpz4APMaecJt9gaNlFJI3CdTipRkNhYkW1p48+InH eBVkuZsKWj/cICaxF78kFw7+atip2z1zsPuDSldmRaa7qvlCEzwo0ybfqfoEuPU6KPHU Yl6e5LkmQHETo+NlAuSKIiFNE8/PTImWaIGIfJsfPW+n4GSXfCK2BOAiBTTfeF6ydPB0 9CwCWyq/mzRovDcgaXEkTyiUgJWlonu6dd+45uRuxCtmzeY0RkZjpTWHfY+B+x+6YbQs 8leg== 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:dkim-signature; bh=E/w20BQSdzic7HV/DXA4w/RdjxH6IBYdbHhBUiDju7A=; b=h/zo+ChO+O47UZmbGsXNoNAdGXAe5Pv6A51YbbrI72ZikkBUjCMeYMcClow+fPAh/g HiHu55xUDaJact+EzIcq3e5Yr0YORDaMy5tHbd2659Llbxusp8SV1jX9CNqe1Mp07pru naSypQG4rgqNTc6J3ieElwOtGFLhTyiFuEZb0FxxC4kbSiBaw24imYeTkNff2otu2jmy oZdSkTUGFgL9wE5V8HyMizrvMFqqKsbxY8Uf4INGuoD5QfdBXvDFA30IfOmoe1SsPJk2 G+e9LXIT9fFQCjXmblzYn3Law0i0TojM+EEFt7wZB4usPJG8qRKYM5335ErJ+Zw2FR7j xJFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=d64iMYOS; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a11-20020a50c30b000000b00445bd4d6989si328707edb.473.2022.09.01.16.52.02; Thu, 01 Sep 2022 16:52:28 -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; dkim=pass header.i=@google.com header.s=20210112 header.b=d64iMYOS; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229892AbiIAXou (ORCPT + 99 others); Thu, 1 Sep 2022 19:44:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232332AbiIAXol (ORCPT ); Thu, 1 Sep 2022 19:44:41 -0400 Received: from mail-vk1-xa34.google.com (mail-vk1-xa34.google.com [IPv6:2607:f8b0:4864:20::a34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E906A832F5 for ; Thu, 1 Sep 2022 16:44:40 -0700 (PDT) Received: by mail-vk1-xa34.google.com with SMTP id 134so257582vkz.11 for ; Thu, 01 Sep 2022 16:44:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=E/w20BQSdzic7HV/DXA4w/RdjxH6IBYdbHhBUiDju7A=; b=d64iMYOScRb/kfj6GTe+dCDg7yBC91L/fdLc+4cxP5Pvcgx6qaOMzL6WLG9T2Qx03q AOJzYfb8Saf9iYFBLzhpB5XfRHYTDsbwIk1HRF7sZ4yEIweU88mUcura4/ZUPzv/4NRf /fXuTOfD3ASnWYUUoXWlU6BZ40RgqoR981eHf0lL6q0L2Tuy8xIjXC4mJgvOJ8/6hoCb TiYPMTEkZ6mxnEupyokGjyQwusEhbNpXe4N1AO5jRXUQqYaHmKnn3ajjMdUsXacezMJ5 75x/FX2ZxhFjV1ivLvjjVGSjgXPHeiVdkEzWdRsF+WFhfH3KUckgvRvLwJY47vJe0SPX KY6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=E/w20BQSdzic7HV/DXA4w/RdjxH6IBYdbHhBUiDju7A=; b=yc4BElZagpK7PDEYWz3KStaisZZ1LOlu66SWi7SS1S18BurJmuHy6pFgzJ5tN3w/yN b+gttYzR1lfqWOsXRUphokZB5eAkZPCHs5VO1DFg7zXu8QuBGIAi/QZr3BeNnx60iApf HW82kc09d2U917Gncu/a1lxEXQm02r2LNvhcC87k0f8dC/fzL1DaLEFy3Q7NV0/Y/WwD V72S3bLv3rhIk6rpUGxFREbK51kXh11sBBiXK/jFtIMKeJtIxWHcA7qDbw0MRGUQPNr8 9CkZ8KLlsT2/3kxaHYz9SMQ96WH8cW2Q3ndTLafyDl5A6sOnPpbdowZweVdxEXLw8NH8 Kryg== X-Gm-Message-State: ACgBeo2YsaFBS6WEoMqFyBS/qeamO0P9ygE+TycLLWL9zziU41jij8GB hl0cHvGQGd8GKJFgK0btjkE4AwvIzi31X385Wv4FhQ== X-Received: by 2002:a1f:2c8c:0:b0:394:76ba:b08c with SMTP id s134-20020a1f2c8c000000b0039476bab08cmr6966094vks.32.1662075879803; Thu, 01 Sep 2022 16:44:39 -0700 (PDT) MIME-Version: 1.0 References: <20220826150807.723137-1-glider@google.com> <20220826150807.723137-5-glider@google.com> <20220826211729.e65d52e7919fee5c34d22efc@linux-foundation.org> <20220829122452.cce41f2754c4e063f3ae8b75@linux-foundation.org> <20220830150549.afa67340c2f5eb33ff9615f4@linux-foundation.org> In-Reply-To: <20220830150549.afa67340c2f5eb33ff9615f4@linux-foundation.org> From: Yu Zhao Date: Thu, 1 Sep 2022 17:44:03 -0600 Message-ID: Subject: Re: [PATCH v5 04/44] x86: asm: instrument usercopy in get_user() and put_user() To: Andrew Morton , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot Cc: Alexander Potapenko , Marco Elver , Alexander Viro , Alexei Starovoitov , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Jens Axboe , Joonsoo Kim , Kees Cook , Mark Rutland , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev , Linux Memory Management List , Linux-Arch , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 Tue, Aug 30, 2022 at 4:05 PM Andrew Morton wrote: ... > Yu, that inclusion is regrettable. I don't think mm_types.h is an > appropriate site for implementing lru_gen_use_mm() anyway. Adding a > new header is always the right fix for these things. I'd suggest > adding a new mglru.h (or whatever) and putting most/all of the mglru > material in there. > > Also, the addition to kernel/sched/core.c wasn't clearly changelogged, > is uncommented and I doubt if the sched developers know about it, let > alone reviewed it. Please give them a heads-up. Adding Ingo, Peter, Juri and Vincent. I added lru_gen_use_mm() (one store operation) to context_switch() in kernel/sched/core.c, and I would appreciate it if you could take a look and let me know if you have any concerns: https://lore.kernel.org/r/20220815071332.627393-9-yuzhao@google.com/ I'll resend the series in a week or so, and cc you when that happens. > The addition looks fairly benign, but core context_switch() is the > sort of thing which people get rather defensive about and putting > mm-specific stuff in there might be challenged. Some quantitative > justification of this optimization would be appropriate. The commit message (from the above link) touches on the theory only: This patch uses the following optimizations when walking page tables: 1. It tracks the usage of mm_struct's between context switches so that page table walkers can skip processes that have been sleeping since the last iteration. Let me expand on this. TLDR: lru_gen_use_mm() introduces an extra store operation whenever switching to a new mm_struct, which sets a flag for page reclaim to clear. For systems that are NOT under memory pressure: 1. This is a new overhead. 2. I don't think it's measurable, hence can't be the last straw. 3. Assume it can be measured, the belief is that underutilized systems should be sacrificed (to some degree) for the greater good. For systems that are under memory pressure: 1. When this flag is set on a mm_struct, page reclaim knows that this mm_struct has been used since the last time it cleared this flag. So it's worth checking out this mm_struct (to clear the accessed bit). 2. The similar idea has been used on Android and ChromeOS: when an app or a tab goes to the background, these systems (conditionally) call MADV_COLD. The majority of GUI applications don't implement this idea. MGLRU opts to do it for the benefit of them. How it benefits server applications is unknown (uninteresting). 3. This optimization benefits arm64 v8.2+ more than x86, since x86 supports the accessed bit in non-leaf entries and therefore the search space can be reduced based on that. On a 4GB ARM system with 40 Chrome tabs opened and 5 tabs in active use, this optimization improves page table walk performance by about 5%. The overall benefit is small but measurable under heavy memory pressure. 4. The idea can be reused by other MM components, e.g., khugepaged. Thanks.