Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp26660137rwd; Mon, 3 Jul 2023 12:57:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7LRF5Y5Kv8g15QJUo5cF+5lWl+iBuTtu+6sZJId6pUS7NUjD93wVzpxcdtPAG2V/r3F5R/ X-Received: by 2002:a05:6808:1496:b0:3a0:3144:dd3a with SMTP id e22-20020a056808149600b003a03144dd3amr12476537oiw.37.1688414222124; Mon, 03 Jul 2023 12:57:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688414222; cv=none; d=google.com; s=arc-20160816; b=t9rnhGBHwJ47hSL8AnHcutdZnblQlQNw7qFS7jlADBKLGZSS4rR7Gra7px5X/J9doH ENuHKmS8szIqa9YuyRTzJoljdOw5k0v5S+eeN672gEeZgwbo+SdBEv4HX3hIn5p6y9fU 2tcplSCJKgAOhzYz9oSLIsrM1XwiMQWuHp/fcBoYeIULuIQjc+ck6GAZ5rWSgZ0kW/gy dJJFIvuNhvlSqa+dmJcfZF79EqJuOLzvKlExtilBIA1v2CvEDEb9DCotvW97ZaeX0jDK pOUswcvsbotu40ILNBUdMVRIOKR7ERXH0ipDd+v9MPYorLoEfTWy1lHcswgdA+Ng7qCY hm6A== 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=YGUF+cNy4bxRpiXiVgsKLP+rYgkOF7DepfxvhKxQUiE=; fh=kTo85WoKt47EQARqmIND/zClTHXT6RmtP8CPylWsYEk=; b=g6NYWEyptP9hCAv08q5nvTFV9G5t5kVgo9AC9VfvoAHOP0p4OlKIFXKaKmuRd2bAI9 y9y4PdYqel00amxyVo3jmooDokFUM43uQbbm1d7d6uwFblqGuF8NNbj6ehAjy0LAFavN odjZcx+PKUrO8jsJe5dSYbslGBRewn1ywqkhypmkJf05YaYjYf9f6JBEgfwwk0H+beNx ALKOuLEQFEMt6kFi6Qjd2okz8Kp0bI4NQNmPiPZHTW5h9V5p1hNeVVKdWD0C+Zt98plg uAJltwm6kqSASBnfwOopHBirdNhlzMsPQslb8ePvRfbMZLJNVtKbvUdhL4VXRmlFm2qw g3Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="4vv7r/W3"; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s186-20020a632cc3000000b0055ad2d6c8aesi14107319pgs.772.2023.07.03.12.56.49; Mon, 03 Jul 2023 12:57:02 -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; dkim=pass header.i=@google.com header.s=20221208 header.b="4vv7r/W3"; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230216AbjGCTv2 (ORCPT + 99 others); Mon, 3 Jul 2023 15:51:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229793AbjGCTv1 (ORCPT ); Mon, 3 Jul 2023 15:51:27 -0400 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6C0BE5F for ; Mon, 3 Jul 2023 12:51:25 -0700 (PDT) Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-401f4408955so437301cf.1 for ; Mon, 03 Jul 2023 12:51:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688413885; x=1691005885; 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=YGUF+cNy4bxRpiXiVgsKLP+rYgkOF7DepfxvhKxQUiE=; b=4vv7r/W3oUFRIp8Pg+MWZ2njnLPT9nJVUjlbcjI2Oe9W41D7xmtuGQKUl+3ELaYqtf cf6JAMg/pkVcI935h7HsbRX0IATGAR9LM1NGW9N3vasZDYSUemUGEims1oomd+/DUZbl UMTd7Qobp4vXXUn2851yCwrX+MQW/9vbzeDmhAPqqOSLwwVy4L+FUPmIDJCgQzg2TrPi tt/Yf4Xe88HQ4iLC4PTDm7QNLoCvCh2TagpYco7SM6na7CDORRvBqw+d9OSe9TCbn7eB 7npLjl+f7TWwfFtrzUt+xmOgTpIalaIZT5MJNxXx3LLGQbW6AO947d2Yc5kWzlDahMkP c0Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688413885; x=1691005885; 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=YGUF+cNy4bxRpiXiVgsKLP+rYgkOF7DepfxvhKxQUiE=; b=DhAXJUhci1BwCJlqk7WkuR7ZCEtC0ZrlN/RRaffU8MvyeaLxPepk5ykQQQaJI/8szS AOui7OwqxnzEHbUPwo+qEHWcFGzxOSSjub/X7hljgzbS6PjlqJk/LclAKHSjRW6WXnR+ CDH/LH/uZItkQWXTlm20SXG3g4ci2oUxOiy9d9+YEhqhQoMucFA2i3aBml3t/OS6t++O 4m5f71+SnTqY4V6w0XROSY7B6N9sLoX6FBhfZEIZ6LdJ9vZXmoCEqqTXbdUuTGos79bc rr2nrkWZPNcA6c8pEGe59/WK0DFwAv6IgxgTT/mEJK4XKIiat0OqFwE2xOPQtMnrkzE1 ZKDA== X-Gm-Message-State: ABy/qLZU6+Pj8M2OiOyKqcIoDKUuRS5XUFbPj+yzTDOH3nWOVRkrBG9t aW06/NmTiU5IKb1R1eX49tpQBfdxYIZqWsKu9a8zuQ== X-Received: by 2002:a05:622a:15d5:b0:3ef:2f55:2204 with SMTP id d21-20020a05622a15d500b003ef2f552204mr15228qty.6.1688413884752; Mon, 03 Jul 2023 12:51:24 -0700 (PDT) MIME-Version: 1.0 References: <20230703135330.1865927-1-ryan.roberts@arm.com> <20230703135330.1865927-4-ryan.roberts@arm.com> In-Reply-To: <20230703135330.1865927-4-ryan.roberts@arm.com> From: Yu Zhao Date: Mon, 3 Jul 2023 13:50:48 -0600 Message-ID: Subject: Re: [PATCH v2 3/5] mm: Default implementation of arch_wants_pte_order() To: Ryan Roberts Cc: Andrew Morton , Matthew Wilcox , "Kirill A. Shutemov" , Yin Fengwei , David Hildenbrand , Catalin Marinas , Will Deacon , Anshuman Khandual , Yang Shi , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.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_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,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 On Mon, Jul 3, 2023 at 7:53=E2=80=AFAM Ryan Roberts = wrote: > > arch_wants_pte_order() can be overridden by the arch to return the > preferred folio order for pte-mapped memory. This is useful as some > architectures (e.g. arm64) can coalesce TLB entries when the physical > memory is suitably contiguous. > > The first user for this hint will be FLEXIBLE_THP, which aims to > allocate large folios for anonymous memory to reduce page faults and > other per-page operation costs. > > Here we add the default implementation of the function, used when the > architecture does not define it, which returns the order corresponding > to 64K. I don't really mind a non-zero default value. But people would ask why non-zero and why 64KB. Probably you could argue this is the large size all known archs support if they have TLB coalescing. For x86, AMD CPUs would want to override this. I'll leave it to Fengwei to decide whether Intel wants a different default value. Also I don't like the vma parameter because it makes arch_wants_pte_order() a mix of hw preference and vma policy. From my POV, the function should be only about the former; the latter should be decided by arch-independent MM code. However, I can live with it if ARM MM people think this is really what you want. ATM, I'm skeptical they do. > Signed-off-by: Ryan Roberts After another CPU vendor, e.g., Fengwei, and an ARM MM person, e.g., Will give the green light: Reviewed-by: Yu Zhao > --- > include/linux/pgtable.h | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h > index a661a17173fa..f7e38598f20b 100644 > --- a/include/linux/pgtable.h > +++ b/include/linux/pgtable.h > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > > #if 5 - defined(__PAGETABLE_P4D_FOLDED) - defined(__PAGETABLE_PUD_FOLDED= ) - \ > defined(__PAGETABLE_PMD_FOLDED) !=3D CONFIG_PGTABLE_LEVELS > @@ -336,6 +337,18 @@ static inline bool arch_has_hw_pte_young(void) > } > #endif > > +#ifndef arch_wants_pte_order > +/* > + * Returns preferred folio order for pte-mapped memory. Must be in range= [0, > + * PMD_SHIFT-PAGE_SHIFT) and must not be order-1 since THP requires larg= e folios The warning is helpful. > + * to be at least order-2. > + */ > +static inline int arch_wants_pte_order(struct vm_area_struct *vma) > +{ > + return ilog2(SZ_64K >> PAGE_SHIFT); > +} > +#endif > + > #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR > static inline pte_t ptep_get_and_clear(struct mm_struct *mm, > unsigned long address,