Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp35056696rwd; Mon, 10 Jul 2023 01:46:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlFq1z1up62z6d9dHVTY6p8lnHzESa0bBMcDcJDKMl3a5eig3Olx18LZ30RKzhmotyEm4+dd X-Received: by 2002:a05:6512:158f:b0:4f8:a858:e60f with SMTP id bp15-20020a056512158f00b004f8a858e60fmr10867632lfb.59.1688978818996; Mon, 10 Jul 2023 01:46:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688978818; cv=none; d=google.com; s=arc-20160816; b=yAxfTIxco1EUZ9PLyKQICtsLCV2HQLuFgth+KWwPBqAarKJP44LNfM6PX84QibvefA YsjnUgqmkFjeaFrzFjJPMP86bPwinzM2XAj7VAfu1fxHQiLBKRIT5k2AWsHDNLK5hxTJ FOkur4OChCtSz7ZDHCMErGAyoNU5g2pl19IzkSsjcWpxec4+z4sinssM84ypv73gXC/K JdBNUAJuiy68kc825zoc5YRBEIYbfNQ/C3Tl1BFIcql7d+LS+qr/GUfOKnohmwCiLTM9 HD0PZtwW2MOj/L3WPi89cU/iB9oX/lW2BBOvoEimxOzc0yodEnM8sM5Lt784MGniQ4In 07Gw== 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=ZQtFguZwZlq3o8WFoRmsz2D9KNLIw/ikVq523sNtEZs=; fh=Asz1Z3/p40NlijwK1AhAzgE+K22Ja/zp2dugBd92vaE=; b=DCRy/CAq40LaWjMkAcwTGlKBkhuSbZySd9DfMcWrgJsCoCz7mHOm12fovdsELvFByQ xyCH3Kqw9nHJyP7yz0dABvUXA0JmjDobXweMI+5N5SxOcRagK5jN3/AJjLB7CY6WLyci 2EYFEBtI9crRcYeiI50vyM4dxMVGisd1WZUMZu+dLyPF+DtX5dzEI1StuM3mPfAI+aNY q7bTL+Ppa9N+4dUdrenVM4KR9F/O1AWhO5Sk+b2mSUvFPLfY0pBW9HWJpjpQcZanR+8D xoFZUQSNnAE/x17kWsmXm4dr3e+q51a6NkTLX6IpD46iwgGLF2v9Zq6bruT8Ug6bWCoR l9aw== 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 e11-20020a50fb8b000000b0051e247f2828si8408154edq.91.2023.07.10.01.46.35; Mon, 10 Jul 2023 01:46: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 S233231AbjGJIo7 (ORCPT + 99 others); Mon, 10 Jul 2023 04:44:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233293AbjGJInA (ORCPT ); Mon, 10 Jul 2023 04:43:00 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E1A5319A5 for ; Mon, 10 Jul 2023 01:41:44 -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 219322B; Mon, 10 Jul 2023 01:42:02 -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 2505B3F740; Mon, 10 Jul 2023 01:41:18 -0700 (PDT) Message-ID: Date: Mon, 10 Jul 2023 09:41:16 +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> <9dd036a8-9ba3-0cc4-b791-cb3178237728@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,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 20:06, David Hildenbrand wrote: >>>> 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? >>> >>> Thinking about desired 2 MiB flexible THP on aarch64 (64k kernel) vs, 2 MiB PMD >>> THP on aarch64 (4k kernel), how are they any different? Just the way they are >>> mapped ... >> >> The last patch in the series shows my current approach to that: >> >> int arch_wants_pte_order(struct vm_area_struct *vma) >> { >>     if (hugepage_vma_check(vma, vma->vm_flags, false, true, true)) >>         return CONFIG_ARM64_PTE_ORDER_THP; <<< always the contpte size >>     else >>         return CONFIG_ARM64_PTE_ORDER_NOTHP; <<< limited to 64K >> } >> >> But Yu has raised concerns that this type of policy needs to be in the core mm. >> So we could have the arch blindly return the preferred order from HW perspective >> (which would be contpte size for arm64). Then for !hugepage_vma_check(), mm >> could take the min of that value and some determined "acceptable" limit (which >> in my mind is 64K ;-). > > Yeah, it's really tricky. Because why should arm64 with 64k base pages *not* > return 2MiB (which is one possible cont-pte size IIRC) ? > > I share the idea that 64k might *currently* on *some platforms* be a reasonable > choice. But that's where the "fun" begins. > >> >>> >>> It's easy to say "64k vs. 2 MiB" is a difference and we want separate controls, >>> but how is "2MiB vs. 2 MiB" different? >>> >>> Having that said, I think we have to make up our mind how much control we want >>> to give user space. Again, the "2MiB vs. 2 MiB" case nicely shows that it's not >>> trivial: memory waste is a real issue on some systems where we limit THP to >>> madvise(). >>> >>> >>> Just throwing it out for discussing: >>> >>> What about keeping the "all / madvise / never" semantics (and MADV_NOHUGEPAGE >>> ...) but having an additional config knob that specifies in which cases we >>> *still* allow flexible THP even though the system was configured for "madvise". >>> >>> I can't come up with a good name for that, but something like >>> "max_auto_size=64k" could be something reasonable to set. We could have an >>> arch+hw specific default. >> >> Ahha, yes, that's essentially what I have above. I personally also like the idea >> of the limit being an absolute value rather than an order. Although I know Yu >> feels differently (see [1]). > > Exposed to user space I think it should be a human-readable value. Inside the > kernel, I don't particularly care. My point was less about human-readable vs not. It was about expressing a value that is relative to the base page size vs expressing a value that is independent of base page size. If the concern is about limiting internal fragmentation, I think its the absolute size that matters. > > (Having databases/VMs on arch64 with 64k in mind) I think it might be > interesting to have something like the following: > > thp=madvise > max_auto_size=64k/128k/256k > > > So in MADV_HUGEPAGE VMAs (such as under QEMU), we'd happily take any flexible > THP, especially ones < PMD THP (512 MiB) as well. 2 MiB or 4 MiB THP? sure, give > them to my VM. You're barely going to find 512 MiB THP either way in practice .... > > But for the remainder of my system, just do something reasonable and don't go > crazy on the memory waste. Yep, we're on the same page. I've got a v3 that's almost ready to go, based on Yu's prevuous round of review. I'm going to encorporate this mechanism into it then post hopefully later in the week. Now I just need to figure out a decent name for the max_auto_size control... > > > I'll try reading all the previous discussions next week. >