Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp32110717rwd; Fri, 7 Jul 2023 08:50:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlH/g5XnMe4vZiTAmyeAyticowCntPgjy7PAJ5dn/agBSu2W8iQ8UB3liyNMMOxsqoz/s2hn X-Received: by 2002:a19:7711:0:b0:4f8:70d8:28f8 with SMTP id s17-20020a197711000000b004f870d828f8mr3734798lfc.55.1688745058408; Fri, 07 Jul 2023 08:50:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688745058; cv=none; d=google.com; s=arc-20160816; b=eiY1QIo/D0F0MOpvUHgqRevSUEVnSDakrRa98PSP7kXHuTdiAMov9QiHlvzhIZmWVj Xi6N6AKFUyhdXZ+Kqc8dmBEOqLi67Bey2mkznmYk3rxi2BMe3inEEGu6AUZfu/KHcNRt QacEufNgS1AWVD/xrQuScvKWdBMJwZmk9ltlOdgJ+8Nqvi7wcVWX8pxgXkxe8ABhVfqd Wj7GFmlYQkFqP+bQeQcJzVi6TqBsfyZpidTh9DyWYqR5MoYTHwB+pnhSGwMcrudimP6U Xx12XLhknvqXFjEX4di+2xjWpA+LEeZNv8vKDSMF6P5+axQULiiWFl8d/lKWCwCBI/LK GJIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=gzU65nEyHBfVflJlzP/Q7t+a6lbut57jeZiPs1IDcb4=; fh=Asz1Z3/p40NlijwK1AhAzgE+K22Ja/zp2dugBd92vaE=; b=hBTHvC4z+WrZ2K9PR3puWEc3GUvnGTCpurAZyX6HGRhKRXm9I0Bwy00+6NmQIqETAD z+49bfFxS35XjIYUSoib9K9ur9ClilPQEpYs9sfaklSdGR1slewVC8aeIxnM4lWTBv4w ljVqtILSAt6HgQGb6oa/OqZWtV5FFvrDzVoHhYgvUNR5a9zxKXS/hrnsHTwmpVd4hNKL 4AwIEGsZxyxveg9VcL6KmR6ldv/ThTkUBKr1u+5/pIosP8b8NR77qI3nz7SieEjFXeO5 wjZM56Ny7+Gv+StfTopPpKm6VhbT35LkRY222ITgFe79lbgIjKC0EmTiD3LlAiJYrRy1 4AxA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s9-20020aa7c549000000b0051deadf8cacsi2228008edr.181.2023.07.07.08.50.33; Fri, 07 Jul 2023 08:50:58 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229822AbjGGPN7 (ORCPT + 99 others); Fri, 7 Jul 2023 11:13:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbjGGPN6 (ORCPT ); Fri, 7 Jul 2023 11:13:58 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5E8772115 for ; Fri, 7 Jul 2023 08:13:56 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2F31FD75; Fri, 7 Jul 2023 08:14:38 -0700 (PDT) Received: from [10.57.77.63] (unknown [10.57.77.63]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 091EF3F762; Fri, 7 Jul 2023 08:13:53 -0700 (PDT) Message-ID: <9dd036a8-9ba3-0cc4-b791-cb3178237728@arm.com> Date: Fri, 7 Jul 2023 16:13:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v2 4/5] mm: FLEXIBLE_THP for improved performance To: David Hildenbrand , Matthew Wilcox Cc: "Huang, Ying" , Andrew Morton , "Kirill A. Shutemov" , Yin Fengwei , Yu Zhao , Catalin Marinas , Will Deacon , Anshuman Khandual , Yang Shi , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20230703135330.1865927-1-ryan.roberts@arm.com> <20230703135330.1865927-5-ryan.roberts@arm.com> <87edlkgnfa.fsf@yhuang6-desk2.ccr.corp.intel.com> <44e60630-5e9d-c8df-ab79-cb0767de680e@arm.com> <524bacd2-4a47-2b8b-6685-c46e31a01631@redhat.com> <1e406f04-78ef-6573-e1f1-f0d0e0d5246a@redhat.com> From: Ryan Roberts In-Reply-To: <1e406f04-78ef-6573-e1f1-f0d0e0d5246a@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 07/07/2023 15:07, David Hildenbrand wrote: > On 07.07.23 15:57, Matthew Wilcox wrote: >> On Fri, Jul 07, 2023 at 01:29:02PM +0200, David Hildenbrand wrote: >>> On 07.07.23 11:52, Ryan Roberts wrote: >>>> On 07/07/2023 09:01, Huang, Ying wrote: >>>>> Although we can use smaller page order for FLEXIBLE_THP, it's hard to >>>>> avoid internal fragmentation completely.  So, I think that finally we >>>>> will need to provide a mechanism for the users to opt out, e.g., >>>>> something like "always madvise never" via >>>>> /sys/kernel/mm/transparent_hugepage/enabled.  I'm not sure whether it's >>>>> a good idea to reuse the existing interface of THP. >>>> >>>> I wouldn't want to tie this to the existing interface, simply because that >>>> implies that we would want to follow the "always" and "madvise" advice too; >>>> That >>>> means that on a thp=madvise system (which is certainly the case for android and >>>> other client systems) we would have to disable large anon folios for VMAs that >>>> haven't explicitly opted in. That breaks the intention that this should be an >>>> invisible performance boost. I think it's important to set the policy for >>>> use of >>> >>> It will never ever be a completely invisible performance boost, just like >>> ordinary THP. >>> >>> Using the exact same existing toggle is the right thing to do. If someone >>> specify "never" or "madvise", then do exactly that. >>> >>> It might make sense to have more modes or additional toggles, but >>> "madvise=never" means no memory waste. >> >> I hate the existing mechanisms.  They are an abdication of our >> responsibility, and an attempt to blame the user (be it the sysadmin >> or the programmer) of our code for using it wrongly.  We should not >> replicate this mistake. > > I don't agree regarding the programmer responsibility. In some cases the > programmer really doesn't want to get more memory populated than requested -- > and knows exactly why setting MADV_NOHUGEPAGE is the right thing to do. > > Regarding the madvise=never/madvise/always (sys admin decision), memory waste > (and nailing down bugs or working around them in customer setups) have been very > good reasons to let the admin have a word. > >> >> Our code should be auto-tuning.  I posted a long, detailed outline here: >> https://lore.kernel.org/linux-mm/Y%2FU8bQd15aUO97vS@casper.infradead.org/ >> > > Well, "auto-tuning" also should be perfect for everybody, but once reality > strikes you know it isn't. > > If people don't feel like using THP, let them have a word. The "madvise" config > option is probably more controversial. But the "always vs. never" absolutely > makes sense to me. > >>> I remember I raised it already in the past, but you *absolutely* have to >>> respect the MADV_NOHUGEPAGE flag. There is user space out there (for >>> example, userfaultfd) that doesn't want the kernel to populate any >>> additional page tables. So if you have to respect that already, then also >>> respect MADV_HUGEPAGE, simple. >> >> Possibly having uffd enabled on a VMA should disable using large folios, > > There are cases where we enable uffd *after* already touching memory (postcopy > live migration in QEMU being the famous example). That doesn't fly. > >> I can get behind that.  But the notion that userspace knows what it's >> doing ... hahaha.  Just ignore the madvise flags.  Userspace doesn't >> know what it's doing. > > If user space sets MADV_NOHUGEPAGE, it exactly knows what it is doing ... in > some cases. And these include cases I care about messing with sparse VM memory :) > > I have strong opinions against populating more than required when user space set > MADV_NOHUGEPAGE. I can see your point about honouring MADV_NOHUGEPAGE, so think that it is reasonable to fallback to allocating an order-0 page in a VMA that has it set. The app has gone out of its way to explicitly set it, after all. I think the correct behaviour for the global thp controls (cmdline and sysfs) are less obvious though. I could get on board with disabling large anon folios globally when thp="never". But for other situations, I would prefer to keep large anon folios enabled (treat "madvise" as "always"), with the argument that their order is much smaller than traditional THP and therefore the internal fragmentation is significantly reduced. I really don't want to end up with user space ever having to opt-in (with MADV_HUGEPAGE) to see the benefits of large anon folios. I still feel that it would be better for the thp and large anon folio controls to be independent though - what's the argument for tying them together? >