Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp671394rdb; Fri, 6 Oct 2023 15:28:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEm87ngoGzAdVIPkzPLF7yYCzmcvs5CrcixWczGK8u8FmD0SzK2u21RbO0Oy+9QnWmbA/B X-Received: by 2002:a05:6a00:1912:b0:690:d2b0:1b37 with SMTP id y18-20020a056a00191200b00690d2b01b37mr11218793pfi.10.1696631331295; Fri, 06 Oct 2023 15:28:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696631331; cv=none; d=google.com; s=arc-20160816; b=vK7Vlz4dLVkMlCvxGl7jmr47Z4vohP4ljf6C3xbHZZoUH+VZvB8QqUoJ4golGSErUM /HwBy16xsby9c3aYpuhdkmch8FtnzQo4cLswZocFwxGgpMDusJ6R1R7YZUjANbLLXH6g lbxzJMlIJz9qFeZlds8FEaZAdFR0/2PcY9WpRt+/I6pS3em94lahVOFoJeT4je0Ak2px +zwgLRiqn4qWYPNzDxFG7V1sGOtyUilNbcfUH3+D4ymBdDuWsYzOUsEHTHv0UbMc5wdK 7edb4W0kWRuC0c53xaF4G9+jft6xUhdgj/wTtvGcgPGsjPPnzjTctVSzbagDo4IjvCoG qb1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=vNXo4Ck+cb5kMjLZ1w1gFPLnQ9WFu3luQ6DdPjjydeM=; fh=lAFjZl+rP6HD6bEXdKQET/0h9mYs06qGwwHivSs9T84=; b=IfUzsi9+h5Y9jdsVyE8d4Mnd4kM+/Ih/25H9rkhT+aDjfinhOJ63nI78Sd/C0MXST+ 3zifJhafzEgUqas7YZ5rv+l3iUbjGMeEzlUO0BgzhdfQXY3omhtK31Z06O5oaPB9azM6 XsZBzBNsrTZH6LcA+N0r1vV4BBLn6xOGPuQvUKr9LgZnSQ3bmxFa0h4/IpLTVtAEgkWK y9SkSwzYbyNI8YHN8oAP6HgyvKFbRmDYV1b9ug7uwQZGiGOyHPjNcGTEl7wgECmAjYDD S7bcA0FD06Z2I5AA2Ey3pmE7r7RYOj1G7msE+HD+TZikFudSXJEF+Q5LB9A7oBDbbOuC Lr+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ntg9VMDV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id bq17-20020a056a000e1100b0068a6f573f6asi2227708pfb.213.2023.10.06.15.28.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 15:28:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ntg9VMDV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 3BC26801B382; Fri, 6 Oct 2023 15:28:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233545AbjJFW2n (ORCPT + 99 others); Fri, 6 Oct 2023 18:28:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233248AbjJFW2m (ORCPT ); Fri, 6 Oct 2023 18:28:42 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77CEC8F for ; Fri, 6 Oct 2023 15:28:39 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id d75a77b69052e-419768e69dfso112061cf.0 for ; Fri, 06 Oct 2023 15:28:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696631318; x=1697236118; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vNXo4Ck+cb5kMjLZ1w1gFPLnQ9WFu3luQ6DdPjjydeM=; b=ntg9VMDVvnvOMQNunf8XVbum8pcXhm/XdTBaA+t4spIJp+4uH4umzoatHglzkFoM3P nJpKgzTCMe97ZotWGb+TjdLyC6c7i0ADVZawtnbBoBMTskuU3UkjtpjRNQQFC4V0kLJO cshyDnmgCS3YI3+xsIlnpMXT/87MJtb693/KRh/BAnDJoCt4xQu8zTar3P7wp3QfnUfm SHuU1YLexwOMDXQtWFmz5iJK/AuEENpQJOW//4SS86zNXQ2qJaem+Ye5rMz0q2psfLzU fktjOzuBSb7F5k5QcVnS4NpoI/mgQBX90CK+m5YQo63x5vW6WMk5cdoAmygFPCkHXxGI FKXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696631318; x=1697236118; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vNXo4Ck+cb5kMjLZ1w1gFPLnQ9WFu3luQ6DdPjjydeM=; b=eBTj/kbSHcpiIZu+kxRjkGNwQw7yhxcrqPV6KQm+VK4x3eii3NqOdyzTg0LqwOV/E7 NR4Jrs/J+ffZSgJV/i8GSyLjw5ey4LsvMjCq9DQVO78eLhKYoIhl+uSvFvvLCBPfh7Nv T9oD8hPnj6KfRBVpadEN0iowRUXOOedQpIJMAFLpdIOKZ05WjS3jYXpsL9urjbf4ehX5 yKFhAMDGhNQQp/xxAxEuHjqmKDMlEQfOW6cmAAuiNn7Ivjohi9GFJa7NRJTPbFCaP8mu 0RS3feH+2ZYk7MGp5yTaOfpm58QjYwyZM/6FVFJHar+LlzAmJwSBIrbOF9lG7GWW7Ulc Y3ow== X-Gm-Message-State: AOJu0YzPfgR5Vfri0fqvh8oMAWOJYSTaauLDGdHJIS6Zq73JBRLqb339 wn1BWJtprxs9ZwiA9X5IRYLeDbjcmJsh24Bxk3junQ== X-Received: by 2002:ac8:5981:0:b0:3e0:c2dd:fd29 with SMTP id e1-20020ac85981000000b003e0c2ddfd29mr513044qte.4.1696631318364; Fri, 06 Oct 2023 15:28:38 -0700 (PDT) MIME-Version: 1.0 References: <20230929114421.3761121-1-ryan.roberts@arm.com> <20230929114421.3761121-7-ryan.roberts@arm.com> <2f64809e-0d0d-cc61-71ac-8d9b072efc3a@redhat.com> In-Reply-To: <2f64809e-0d0d-cc61-71ac-8d9b072efc3a@redhat.com> From: Yu Zhao Date: Fri, 6 Oct 2023 16:28:02 -0600 Message-ID: Subject: Re: [PATCH v6 6/9] mm: thp: Add "recommend" option for anon_orders To: David Hildenbrand , Ryan Roberts 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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_BLOCKED,SPF_HELO_NONE,SPF_PASS, 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 06 Oct 2023 15:28:50 -0700 (PDT) On Fri, Oct 6, 2023 at 2:08=E2=80=AFPM 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 give= n > > 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" orde= r > > 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 li= st > > > > arch_wants_pte_order() can be overridden by the architecture if desired= . > > Some architectures (e.g. arm64) can coalsece TLB entries if a contiguou= s > > set of ptes map physically contigious, naturally aligned memory, so thi= s > > 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 (=3D16K 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 th= e > > 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 ran= ge [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 =3D count; > > unsigned int orders; > > + int arch; > > > > - err =3D kstrtouint(buf, 0, &orders); > > - if (err) > > - ret =3D -EINVAL; > > + if (sysfs_streq(buf, "recommend")) { > > + arch =3D max(arch_wants_pte_order(), PAGE_ALLOC_COSTLY_OR= DER); > > + orders =3D BIT(arch); > > + orders |=3D BIT(PAGE_ALLOC_COSTLY_ORDER); > > + orders |=3D BIT(PMD_ORDER); > > + } else { > > + err =3D kstrtouint(buf, 0, &orders); > > + if (err) > > + ret =3D -EINVAL; > > + } > > > > if (ret > 0) { > > orders &=3D 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? If so, this reinforces what I said here [1]. [1] https://lore.kernel.org/mm-commits/CAOUHufYEKx5_zxRJkeqrmnStFjR+pVQdpZ4= 0ATSTaxLA_iRPGw@mail.gmail.com/