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 7BF4CE95A91 for ; Mon, 9 Oct 2023 11:45:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EEBBE8D0059; Mon, 9 Oct 2023 07:45:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9BBE8D0031; Mon, 9 Oct 2023 07:45:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D8A5F8D0059; Mon, 9 Oct 2023 07:45:51 -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 C8A5F8D0031 for ; Mon, 9 Oct 2023 07:45:51 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 98F371A0209 for ; Mon, 9 Oct 2023 11:45:51 +0000 (UTC) X-FDA: 81325743702.12.FF8A6AA Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf10.hostedemail.com (Postfix) with ESMTP id C6517C0024 for ; Mon, 9 Oct 2023 11:45:49 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696851949; a=rsa-sha256; cv=none; b=oLIqGWJTVi26F2oQkcZcIHScd7mWWkRwtPSlKo6yKMrOnpkqmSWBxKDWHxleBCrDvNs6uz OnYclQj7k68WFO3VbDNYi6XUX6ZmI+M2BH7zTxK9XTYKb0elT+yrsId7t5v22urR+uPLTP nWUd0LlZNjBNm/Jm+WD7arrf1Ryh4Jk= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696851949; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YDYkEjWKhfelnZPVkzdGKJB09gEDrBQNdxgst2r7xWw=; b=FCxnz5OTDPwxCk8y1ln5xCEmjhyzuy2bgTZxU3VC0pEQ+4oxBkj/BGZxRGDicB9A3FVmbN m1TOW/m0YC5yXoF3LiWMJ2exR7eDcmOzOhRnnVVGc6bUjiQ3Hlizroj8vwJCvWG685am9+ 1sLX6E9pMCJ5kfKrMrvl0KanBoP3dhQ= 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 5B14E1FB; Mon, 9 Oct 2023 04:46:29 -0700 (PDT) Received: from [10.57.66.97] (unknown [10.57.66.97]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 205683F762; Mon, 9 Oct 2023 04:45:46 -0700 (PDT) Message-ID: <25d1cdee-3da8-4728-aa0d-dc07eb28ea95@arm.com> Date: Mon, 9 Oct 2023 12:45:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 6/9] mm: thp: Add "recommend" option for anon_orders Content-Language: en-GB To: Yu Zhao , David Hildenbrand Cc: Andrew Morton , Matthew Wilcox , Yin Fengwei , Catalin Marinas , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , Itaru Kitayama , "Kirill A. Shutemov" , John Hubbard , David Rientjes , Vlastimil Babka , Hugh Dickins , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20230929114421.3761121-1-ryan.roberts@arm.com> <20230929114421.3761121-7-ryan.roberts@arm.com> <2f64809e-0d0d-cc61-71ac-8d9b072efc3a@redhat.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C6517C0024 X-Stat-Signature: y8dsw14k91teckswz6g141t4b7u4ai4r X-HE-Tag: 1696851949-301246 X-HE-Meta: U2FsdGVkX19EeSECXERAVqgndLodIFjjNUK2aIHtim4S8RUAMXDkZuZB7eHhGGbmhl135leG6rxTyB3h+F+iAYQDMiN1f+uCZJaZcAqvvRPVJkAHAbkSUYPF38kMO0FMVK36jcO7LNFM2CTpa9xV1ER+eMcGM+QONIs4pIV++ZvQmHHj2x0fB4MD9uCVf8/NG3cXQu/K5ce9U4o676ties3TeWgeVZCBuSjVXheHKvOijFy2/eMF7Lu9dY1WqjLYqNdPq94+/cZE3ZHDhmloy8JP9EF3S+ojQe9Jn5jeO5pS+ptwEu0CpFdnjp5hI8jLsvKG+p++bzGlnUqrHE/pZxkye2zAIGVPxiKjs2yboaOn7OrGPKncFF4fLYr1mL18kopj1VLau+BQzUIoqpmFopn/ZEbuIaEdW6PZaL0MURsIWeqbnfUwPviH0fl8cFumJmolwRxQ9V22Wb2n2zXxZe7lCqRCIhHbAYPXJai3shZxHPn77nfvNTEmqn/FNd9lS+Gig3NAySDCL1Zc+wZBULzM4AnS1xkXIWsFSc7ZhptBKXeYn8XWKfptbySgNWZNGrUY1LVKs1g0PnoGkwWUnLUn1trf46/OMx9zaJPUI+gIGnyABX240i6m56l/Mj3EDSE7IIJ/BBgMkc9SZiYskJyjqb0HyLLFFPh8nRZ2b9wmrYDsFq6gM06jVa7su12Ozb6tO5UQIOD4h6BQOBDYAF8P8nQ77eDHZ0IMMo0vWZpxDbRM6MS+Y3dVu3ARSz5tUCpfJ/pD6umoGYnvyU7IywQQdNBOBMRDBiGU1ZejgdT4EbwccDRN7xs7PGeGzN3QRathohln6AoFQgeXvOXabiIELs4Tg2DDxUBzCM2TnYHP5PYGiisxtq5Qa3elQLKruhPm+2EHV0v1PJDb840aLIVZEPozVotr2pUqWXIjhzgHG6ZbbjgCN3xcoc9WSmPrjwKDO999/syJ3pdeVxi Q+UJagoV DsGYQqjx6oX2vK6mYzbiVCYFqTpWKvWoahkxpZPiEbBJPEu3uK7WuuIUyOeqx+t2ZmjctUq6AOcehBBQeUaXlyVa7lgLytS2c5+07tUhILO9avczQzq+4AHKpZpj2beGVA0vyfeXa7JAKPenwSRmq6ra1ZSTaW3+pyzgaRHVjUzDUkK2uV6BpJitkqcxP0uG2/OY87uOTC/Ny3w14cdsuYLBfKQ9yFyNEnWuANWvhLcXm87rG2cHsKo64pN/dspeFtiTFuYvzRrm7zr70TkHXqglA2z37JTaUshoZ+czC86LIRWcuMUCoPCL35I1y7bSz5cVCmM3MI9Gvk2tlopdrEPrJv33N5QJr2MB1TR47VzM4LTxJkxz86SqtXLvK3pcL0gB9jKcAo4NBMqw38hlBS/KX8su6mt+4gY/G/b/TguCBvhY9/X8Usd09jA== 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 06/10/2023 23:28, Yu Zhao wrote: > On Fri, Oct 6, 2023 at 2:08 PM David Hildenbrand wrote: >> >> On 29.09.23 13:44, Ryan Roberts wrote: >>> In addition to passing a bitfield of folio orders to enable for THP, >>> allow the string "recommend" to be written, which has the effect of >>> causing the system to enable the orders preferred by the architecture >>> and by the mm. The user can see what these orders are by subsequently >>> reading back the file. >>> >>> Note that these recommended orders are expected to be static for a given >>> boot of the system, and so the keyword "auto" was deliberately not used, >>> as I want to reserve it for a possible future use where the "best" order >>> is chosen more dynamically at runtime. >>> >>> Recommended orders are determined as follows: >>> - PMD_ORDER: The traditional THP size >>> - arch_wants_pte_order() if implemented by the arch >>> - PAGE_ALLOC_COSTLY_ORDER: The largest order kept on per-cpu free list >>> >>> arch_wants_pte_order() can be overridden by the architecture if desired. >>> Some architectures (e.g. arm64) can coalsece TLB entries if a contiguous >>> set of ptes map physically contigious, naturally aligned memory, so this >>> mechanism allows the architecture to optimize as required. >>> >>> Here we add the default implementation of arch_wants_pte_order(), used >>> when the architecture does not define it, which returns -1, implying >>> that the HW has no preference. >>> >>> Signed-off-by: Ryan Roberts >>> --- >>> Documentation/admin-guide/mm/transhuge.rst | 4 ++++ >>> include/linux/pgtable.h | 13 +++++++++++++ >>> mm/huge_memory.c | 14 +++++++++++--- >>> 3 files changed, 28 insertions(+), 3 deletions(-) >>> >>> diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst >>> index 732c3b2f4ba8..d6363d4efa3a 100644 >>> --- a/Documentation/admin-guide/mm/transhuge.rst >>> +++ b/Documentation/admin-guide/mm/transhuge.rst >>> @@ -187,6 +187,10 @@ pages (=16K if the page size is 4K). The example above enables order-9 >>> By enabling multiple orders, allocation of each order will be >>> attempted, highest to lowest, until a successful allocation is made. >>> If the PMD-order is unset, then no PMD-sized THPs will be allocated. >>> +It is also possible to enable the recommended set of orders, which >>> +will be optimized for the architecture and mm:: >>> + >>> + echo recommend >/sys/kernel/mm/transparent_hugepage/anon_orders >>> >>> The kernel will ignore any orders that it does not support so read the >>> file back to determine which orders are enabled:: >>> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h >>> index af7639c3b0a3..0e110ce57cc3 100644 >>> --- a/include/linux/pgtable.h >>> +++ b/include/linux/pgtable.h >>> @@ -393,6 +393,19 @@ static inline void arch_check_zapped_pmd(struct vm_area_struct *vma, >>> } >>> #endif >>> >>> +#ifndef arch_wants_pte_order >>> +/* >>> + * Returns preferred folio order for pte-mapped memory. Must be in range [0, >>> + * PMD_ORDER) and must not be order-1 since THP requires large folios to be at >>> + * least order-2. Negative value implies that the HW has no preference and mm >>> + * will choose it's own default order. >>> + */ >>> +static inline int arch_wants_pte_order(void) >>> +{ >>> + return -1; >>> +} >>> +#endif >>> + >>> #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR >>> static inline pte_t ptep_get_and_clear(struct mm_struct *mm, >>> unsigned long address, >>> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >>> index bcecce769017..e2e2d3906a21 100644 >>> --- a/mm/huge_memory.c >>> +++ b/mm/huge_memory.c >>> @@ -464,10 +464,18 @@ static ssize_t anon_orders_store(struct kobject *kobj, >>> int err; >>> int ret = count; >>> unsigned int orders; >>> + int arch; >>> >>> - err = kstrtouint(buf, 0, &orders); >>> - if (err) >>> - ret = -EINVAL; >>> + if (sysfs_streq(buf, "recommend")) { >>> + arch = max(arch_wants_pte_order(), PAGE_ALLOC_COSTLY_ORDER); >>> + orders = BIT(arch); >>> + orders |= BIT(PAGE_ALLOC_COSTLY_ORDER); >>> + orders |= BIT(PMD_ORDER); >>> + } else { >>> + err = kstrtouint(buf, 0, &orders); >>> + if (err) >>> + ret = -EINVAL; >>> + } >>> >>> if (ret > 0) { >>> orders &= THP_ORDERS_ALL_ANON; >> >> :/ don't really like that. Regarding my proposal, one could have >> something like that in an "auto" setting for the "enabled" value, or a >> "recommended" setting [not sure]. > > Me either. > > Again this is something I call random -- we only discussed "auto", > and yes, the commit message above explained why "recommended" here but > it has never surfaced in previous discussions, has it? The context in which we discussed "auto" was for a future aspiration to automatically determine the order that should be used for a given allocation to balance perf vs internal fragmentation. The case we are talking about here is completely different; I had a pre-existing feature from previous versions of the series, which would allow the arch to specify its preferred order (originally proposed by Yu, IIRC). In moving the allocation size decision to user space, I felt that we still needed a mechanism whereby the arch could express its preference. And "recommend" is what I came up with. All of the friction we are currently having is around this feature, I think? Certainly all the links you provided in the other thread all point to conversations skirting around it. How about I just drop it for this initial patch set? Just let user space decide what sizes it wants (per David's interface proposal)? I can see I'm trying to get a square peg into a round hole. > > If so, this reinforces what I said here [1]. > > [1] https://lore.kernel.org/mm-commits/CAOUHufYEKx5_zxRJkeqrmnStFjR+pVQdpZ40ATSTaxLA_iRPGw@mail.gmail.com/