Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17046226rwd; Mon, 26 Jun 2023 19:59:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7B8B4/EWvbAYJ+MCffcPFzIC78zVsU16DvMH075M7pWwJmXpMFMCRgZn9QRTtwr1QxgnnE X-Received: by 2002:a17:907:778e:b0:98d:f4a7:71cf with SMTP id ky14-20020a170907778e00b0098df4a771cfmr7122381ejc.62.1687834748738; Mon, 26 Jun 2023 19:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687834748; cv=none; d=google.com; s=arc-20160816; b=OFhdp0vbA6nSHYbhSp1QKEvuKKccwGyejzrKq9Q5wcTWVTFj7b85NMBhaGiaXPVIaw SYx8eGAlAiN5FVqnli/xotfY7jcd6DcdeSkTxfdXOh9GRravxqhYuqBLW66Db1SQ2KDx vOw2edGWQVaSJubmQtcCgO6/n7Vze1JrXoktu/VIqWtWtDmtS3qw274Xmfot4jC9wG0L qIS330HTPdtFTOZnNF723tE8+JC8cFkHkikglZJ1o9MBNwF+aEPTt7DPQxqB0+RAkrhS +fP0r2xbiu6znh7DsyIRVYKvVW1aGRRYReQpMGf8aKxcqTwgBdtG2w6r+cadEi+6c5+P CFiw== 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=lOHMGk1IHW9nIXyoyhy6ScxjHGO05nJh9iYXmQJ8lRg=; fh=zTYFNic+S8YlfmSZQ9M48CdblHrjHKKPw48r1IJBtXA=; b=kTGH+sGdWaREoYNG+zkNtkP+D05VV2dHnQ/EA1NUyfccfTilJ3F/dcXOhUoKxT2gQR Ce/xgjUewVhao3V/FjdQkLEwRSVGtWzA03/bzoxWxKlMiaFpPi2jQJvxnfVAcYGI8MFK CLUa5WpLN+3Lg7xFK53U8O9NnDfM/wr9dteM0ffRgBvasWq9Ka2aX+ha8/YAnPymkCNm LaMLLEnf4ugIkOzxwZVIi/oY1zHJHv4CX94nKHYFCdqml3AkRb8IzcbwX4g4KSJiQPae UifrJnlgKmfxQ36d1CtNdljJUz6+iG0ZjieLIzHKrgtgCKgi2xJV6tOBKaCgghIzG66k fi0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=4Hxtqyz9; 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 b20-20020aa7c914000000b0051be7c581afsi3273584edt.45.2023.06.26.19.58.43; Mon, 26 Jun 2023 19:59:08 -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=4Hxtqyz9; 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 S229562AbjF0Cr5 (ORCPT + 99 others); Mon, 26 Jun 2023 22:47:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230016AbjF0Crz (ORCPT ); Mon, 26 Jun 2023 22:47:55 -0400 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4867A19A8 for ; Mon, 26 Jun 2023 19:47:54 -0700 (PDT) Received: by mail-qt1-x82b.google.com with SMTP id d75a77b69052e-40079620a83so134511cf.0 for ; Mon, 26 Jun 2023 19:47:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687834073; x=1690426073; 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=lOHMGk1IHW9nIXyoyhy6ScxjHGO05nJh9iYXmQJ8lRg=; b=4Hxtqyz9AC5uq4MuNdUiUTytvXCSHBztZ8M76g0ceKIjnz0PJbRxq4j9xf48iqBl8z uOAa0SjGLlNiOmuesNGIjV6ZEtAaql+t7LaLclTsqLdjWGgtUyTYHYxqyoUKW5PZ8+oA CPN8+kFMBzGza8w1PEdpNYj3T/H/D2g1+h2yVb1dOKdEkXl3MW7xWHGuBNIsJuI2dpbL u9j8wwh7+YY8qKVkw+4OZp6+QPdQwuDjHdLCq2f4ovoXXEUt0D33oYlhzfMu86LnMiFd H0aY0bwtPf9reOaOak+4TqM+JB8fShj+0qc6i2vJ8aAkdg1fOGJQnnkCnCjBag5lncQf /4HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687834073; x=1690426073; 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=lOHMGk1IHW9nIXyoyhy6ScxjHGO05nJh9iYXmQJ8lRg=; b=aPRKv5njxJ80fRhw2Chm2/ja55w5Vs9PiELsHYO6wR8d3/ucQKrvX7bEbzFvNlFu2I 7Y5fOROKrh89uCdl01MTUo8LX0/TOqrA/dmkuhx4lfGhOUDCpI0DcG/HZabyRAp3etS/ U5ScdHjcqEMHwB96EjpDUEJGWy7Wr5+5+URAlpEJTENs2PgEa10RCzg2te1Gq1ACQAsJ Cmy9h7x0jMUzGbxfXmpM+Gh8Q8Yq9vTjSCZJQwvC1Ke4uQzYHDBfrdyF30iZMDF75V58 +Ra8jF2q9jEXvExwAt9RSWa2zt0LSJj8ZP1pyxNV10Y0qso41aJhBGbtqn1X8OCx/oDU B1Rg== X-Gm-Message-State: AC+VfDxthl9IjGrRAXooKlkSTGoiUZOZ/e/g1WzkWAW2GZ5Pg0JSnpzE ea63TopGWrbIvlcDhqFms1mIP5xplTs8dsKf3NO5Ag== X-Received: by 2002:a05:622a:5c8:b0:3ef:3361:75d5 with SMTP id d8-20020a05622a05c800b003ef336175d5mr537286qtb.11.1687834073238; Mon, 26 Jun 2023 19:47:53 -0700 (PDT) MIME-Version: 1.0 References: <20230626171430.3167004-1-ryan.roberts@arm.com> <20230626171430.3167004-9-ryan.roberts@arm.com> In-Reply-To: <20230626171430.3167004-9-ryan.roberts@arm.com> From: Yu Zhao Date: Mon, 26 Jun 2023 20:47:17 -0600 Message-ID: Subject: Re: [PATCH v1 08/10] mm: Kconfig hooks to determine max anon folio allocation order To: Ryan Roberts Cc: Andrew Morton , "Matthew Wilcox (Oracle)" , "Kirill A. Shutemov" , Yin Fengwei , David Hildenbrand , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-s390@vger.kernel.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, Jun 26, 2023 at 11:15=E2=80=AFAM Ryan Roberts wrote: > > For variable-order anonymous folios, we need to determine the order that > we will allocate. From a SW perspective, the higher the order we > allocate, the less overhead we will have; fewer faults, fewer folios in > lists, etc. But of course there will also be more memory wastage as the > order increases. > > From a HW perspective, there are memory block sizes that can be > beneficial to reducing TLB pressure. arm64, for example, has the ability > to map "contpte" sized chunks (64K for a 4K base page, 2M for 16K and > 64K base pages) such that one of these chunks only uses a single TLB > entry. > > So we let the architecture specify the order of the maximally beneficial > mapping unit when PTE-mapped. Furthermore, because in some cases, this > order may be quite big (and therefore potentially wasteful of memory), > allow the arch to specify 2 values; One is the max order for a mapping > that _would not_ use THP if all size and alignment constraints were met, > and the other is the max order for a mapping that _would_ use THP if all > those constraints were met. > > Implement this with Kconfig by introducing some new options to allow the > architecture to declare that it supports large anonymous folios along > with these 2 preferred max order values. Then introduce a user-facing > option, LARGE_ANON_FOLIO, which defaults to disabled and can only be > enabled if the architecture has declared its support. When disabled, it > forces the max order values, LARGE_ANON_FOLIO_NOTHP_ORDER_MAX and > LARGE_ANON_FOLIO_THP_ORDER_MAX to 0, meaning only a single page is ever > allocated. > > Signed-off-by: Ryan Roberts > --- > mm/Kconfig | 39 +++++++++++++++++++++++++++++++++++++++ > mm/memory.c | 8 ++++++++ > 2 files changed, 47 insertions(+) > > diff --git a/mm/Kconfig b/mm/Kconfig > index 7672a22647b4..f4ba48c37b75 100644 > --- a/mm/Kconfig > +++ b/mm/Kconfig > @@ -1208,4 +1208,43 @@ config PER_VMA_LOCK > > source "mm/damon/Kconfig" > > +config ARCH_SUPPORTS_LARGE_ANON_FOLIO > + def_bool n > + help > + An arch should select this symbol if wants to allow LARGE_ANON_= FOLIO > + to be enabled. It must also set the following integer values: > + - ARCH_LARGE_ANON_FOLIO_NOTHP_ORDER_MAX > + - ARCH_LARGE_ANON_FOLIO_THP_ORDER_MAX > + > +config ARCH_LARGE_ANON_FOLIO_NOTHP_ORDER_MAX > + int > + help > + The maximum size of folio to allocate for an anonymous VMA PTE-= mapping > + that does not have the MADV_HUGEPAGE hint set. > + > +config ARCH_LARGE_ANON_FOLIO_THP_ORDER_MAX > + int > + help > + The maximum size of folio to allocate for an anonymous VMA PTE-= mapping > + that has the MADV_HUGEPAGE hint set. > + > +config LARGE_ANON_FOLIO > + bool "Allocate large folios for anonymous memory" > + depends on ARCH_SUPPORTS_LARGE_ANON_FOLIO > + default n > + help > + Use large (bigger than order-0) folios to back anonymous memory= where > + possible. This reduces the number of page faults, as well as ot= her > + per-page overheads to improve performance for many workloads. > + > +config LARGE_ANON_FOLIO_NOTHP_ORDER_MAX > + int > + default 0 if !LARGE_ANON_FOLIO > + default ARCH_LARGE_ANON_FOLIO_NOTHP_ORDER_MAX > + > +config LARGE_ANON_FOLIO_THP_ORDER_MAX > + int > + default 0 if !LARGE_ANON_FOLIO > + default ARCH_LARGE_ANON_FOLIO_THP_ORDER_MAX > + > endmenu I don't think an MVP should add this many Kconfigs. One Kconfig sounds reasonable to me for now.