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 25E3CE94113 for ; Fri, 6 Oct 2023 20:08:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ABF6C80018; Fri, 6 Oct 2023 16:08:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A481B80008; Fri, 6 Oct 2023 16:08:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C28380018; Fri, 6 Oct 2023 16:08:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7696D80008 for ; Fri, 6 Oct 2023 16:08:29 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4B2DFA02E2 for ; Fri, 6 Oct 2023 20:08:29 +0000 (UTC) X-FDA: 81316123938.16.CEC37D6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 15CC72000B for ; Fri, 6 Oct 2023 20:08:26 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="d9/SUkSp"; spf=pass (imf13.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696622907; a=rsa-sha256; cv=none; b=cw5mkZXIa6I12yE2BESFGFNWIMDIASBgLq8lcOWH514xFCLaZngn0PYEbpB1jhqCIjOB7a YM7B/pGZnAlPS5W1q0VRO4MOSV2kn4bflolGRJElvzokC76mAlJnGyZT1wnBsAbDWtTD6t OkC39Tknen+KRieSxyGLzq2I+939Q/s= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="d9/SUkSp"; spf=pass (imf13.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696622907; 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:dkim-signature; bh=ms/DXkkYNfaLBZlXzvAGFAiNgJdqqoDux/SIe2Qpatk=; b=cxlHM6a5fUiZQ3gfKwmLZX8c3SnpN2u+CVc+yqjvUMknRjT3ar/yYKgT87GMxoiJMHNPiu lxonhg8MdK32/h02h1GXDn+8+yYyD5HyCEOZC+dCJyKITUL0+xTAC1Qrj3rACjPDrwvJ3b ijtIXeR9EK5GziIAzrPNSL4EjQeQ9Lw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696622906; h=from:from: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=ms/DXkkYNfaLBZlXzvAGFAiNgJdqqoDux/SIe2Qpatk=; b=d9/SUkSpSdgWXyDxMmzSkfgOucBQtkUx5OjcBYNapvcl9Dfq6KQHjdYsiQaPkfzZXVlOAy XB7RZx2K6aXAR135OMyAYM9tpkgucBwCJu7bcLC6kkPDOEmRyLga4iId9cKQ/vBFbQITwi c6TQQEob99IH1rhSylS/2o9G80Cclrs= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-443-hcWoEScqOrmesuAVyv_WjA-1; Fri, 06 Oct 2023 16:08:23 -0400 X-MC-Unique: hcWoEScqOrmesuAVyv_WjA-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-40566c578b7so18530755e9.0 for ; Fri, 06 Oct 2023 13:08:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696622902; x=1697227702; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ms/DXkkYNfaLBZlXzvAGFAiNgJdqqoDux/SIe2Qpatk=; b=dtX1or6u6OTtNgJRn4ILj6HyHS21Bq5qO1Qx0nLDN8yzU6JS7NtsMafJYp9u8d8oMT XNA2tuz8JDzaawZUZc1yFO18lguNmz/SMPVQX0zbmZDOPMY7FYQk4NZVJBxjKeuULfZd Z226gx7Ki72yw2/Rm5KxYobkWHT/mcN7OIEtB0XF4vhGhQfYmuW8YpkzHWdAw5Z9KQQu veeqhxoTR0JdvbtdSkCtSfENOBMyevPT0DwmnBlVzcY2qwZqvXBtgf3w972nRo8HfB7m wfmABOg6OSt5pbY0HV1jLogDVotG+0yT0+7mfYtXKYyWjtXRheZNL9TjnCyHqnK4nJ19 Iuow== X-Gm-Message-State: AOJu0YyH93jnmTHwR9H517oeHsVLHHFBqDAPIK2in9yN/FDqwv9NrjWb zTTqqhcqZZih1y/xGwMy4OGp9isrOsd2LB3svlUmL211lRqNxueGZd781DDReH7Q4n+kP3S5ONz jdHV/nrQh8Wk= X-Received: by 2002:a05:600c:d1:b0:405:3a3d:6f42 with SMTP id u17-20020a05600c00d100b004053a3d6f42mr8171899wmm.39.1696622901970; Fri, 06 Oct 2023 13:08:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENTI2KRa9s/ItyJi1/4U0Y6qvQkJ3F+dDC3uabzJW4LFvFgnLD/TOZGvGmi56M5FncjAz+7Q== X-Received: by 2002:a05:600c:d1:b0:405:3a3d:6f42 with SMTP id u17-20020a05600c00d100b004053a3d6f42mr8171870wmm.39.1696622901443; Fri, 06 Oct 2023 13:08:21 -0700 (PDT) Received: from ?IPV6:2003:cb:c715:ee00:4e24:cf8e:3de0:8819? (p200300cbc715ee004e24cf8e3de08819.dip0.t-ipconnect.de. [2003:cb:c715:ee00:4e24:cf8e:3de0:8819]) by smtp.gmail.com with ESMTPSA id c19-20020a7bc853000000b004064288597bsm4411230wml.30.2023.10.06.13.08.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Oct 2023 13:08:21 -0700 (PDT) Message-ID: <2f64809e-0d0d-cc61-71ac-8d9b072efc3a@redhat.com> Date: Fri, 6 Oct 2023 22:08:19 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v6 6/9] mm: thp: Add "recommend" option for anon_orders To: Ryan Roberts , Andrew Morton , Matthew Wilcox , Yin Fengwei , Yu Zhao , 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 Cc: 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> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20230929114421.3761121-7-ryan.roberts@arm.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: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pSEkUcG0mf vB7F8n4N L7fF0jrkPcqGw4xcKQQLgNHli8b0LOZH060TwhRq2EhwCd3bTu5JKPKTxR+viEYPeSyZ4DQswVgpb00osRMZh9ndG8ZxJuwn0lte/fhuQO9LCsYB3rZsBUYDNGbAupv6RZxQ9LL3WtZoyJcHzcxglSa3lRsOO3rcHWVPvqNLkYNN3vw9Dab+yTjKuSqQAe5QD/VKKIUYdek1Cjs+Zs99Pdes27H2kJBm0skP2cE4Opj114VVeFTKWyX9senfmN033Puej8kp4SI33pdXYihmE8mqMkIqKx29OmqD6J7Ri6sYhg0zsEgG7L4j+anKeQpKpmqj8zFKgzwynlHuJsBwuZe5fl8QKw3SvLGIr0HCW4yjlmth5r7VQZf36O1G/IFqwwji3ZaS6el2NaBfdmxI5cZeimUd12P1jCweqC5KsEExs4Q2S41a+7RmAozWvdB5fuKdTe9UFboceQZVSEPIaVrWv0PUX0KHI+2BmDrKVUpeTwGh1Xj43sqDVnrBGJIpejT7J9OgNGP9t+8m6mRJQngoBm53zxc3bZdx1wWbEC+tR0Dhe1kY/JII3/Q== 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 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]. -- Cheers, David / dhildenb