Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp699540rdb; Sun, 3 Sep 2023 06:46:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPvLf571tQYEwrd8THc+fV5XxWqL3jr47jBW82vBKF99xbY7foHhUx5ILkIiaSW0+ps8/1 X-Received: by 2002:a17:906:1c:b0:9a2:1bd8:a6a with SMTP id 28-20020a170906001c00b009a21bd80a6amr5263444eja.41.1693748778816; Sun, 03 Sep 2023 06:46:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693748778; cv=none; d=google.com; s=arc-20160816; b=0Ko4PKs2xm6J25CDZV0rB3X82NIlPNLr2WZUwlS5MbS6+T+a45wChNfJnh+lIpH99O 3k56Dxvk8WzHfzDV67meQd2+WHxu2L6pl5j5kty/9T4XGnp0xopn5lsgTopIzTq4r9sN j/Xlv92Bb1rEQGIrHKkvZJLUlcBuWbalXutYUucoLNEAu0fB0lwYuDFYZEH6FGZPJpbM Xd+CFqTBhspTUNfTb7nMb/LRG4wL4iQHJUxEyOhIvmtyZzqpYD2Tt45nixGvtCJ8y3d3 v4w8AfOuzKELGq0llrl8sI6rO7Ftwhn0j+WdmP2QOWd/nVGN4gEsIVvil8oKJzWH3XyC wEFg== 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=qMHknYwipePMPg9mivxBhPSOU5ukXfE3oVZOzdjAQnE=; fh=BYhYPPMvVdxjoAF+TQO48NJb1wJ8YDD0lnFYvdIA8nw=; b=oNKkqXfa858MYcJY3/0uUp5sgTUePMPa4yxedd+r0zvIG9Rr5JVw5bD29FdIg6Q1Dm rh4vVgYxcF7kKfyvjKwQJdba00s9Y+Y8jPH/3ZLVI/EyIIBeSOPtq1WNGjVgCpLKPHdq wG5M79Mi3P3ZE4xNximpLnDqwV1d5BE2n21R0g3IWfz587i2H5IqG61X5cc+JgP0Assv db3CiKWVJenaUPqcrb4TIOnB7tczHJTMsLXD3dv4DVO43hX80HG49UsgyopXRS8Zfag5 SXkQ20KHS2RWVKUEcWkjpNTpcU55jSBUOHL7YksCXiP5HEUjWtV+ekFKHgZYiZ2zeSKo 4rlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=WJCAutwO; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qq7-20020a17090720c700b009a2154511efsi5029177ejb.155.2023.09.03.06.46.11; Sun, 03 Sep 2023 06:46:18 -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=@gmail.com header.s=20221208 header.b=WJCAutwO; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243958AbjHaRP0 (ORCPT + 30 others); Thu, 31 Aug 2023 13:15:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231409AbjHaRPZ (ORCPT ); Thu, 31 Aug 2023 13:15:25 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F003A3 for ; Thu, 31 Aug 2023 10:15:22 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-26f4bc74131so689083a91.1 for ; Thu, 31 Aug 2023 10:15:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693502122; x=1694106922; 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=qMHknYwipePMPg9mivxBhPSOU5ukXfE3oVZOzdjAQnE=; b=WJCAutwO3Kzc+qgnZCFdk2UWt65EffCd6XVvxaGJQyu4Cq07V2UgN6MRJtIObpFDIL U7Z3B64pnqR9sb3PRzOKAujPhvN+LusjcH8qG+RpR6y4PplATdpqJmhnsG0tqccwfC+S YlzFm9j4cwVurGYc5lwkErvgtjKOPYj4U+G8eZ6tj6kzCQqhvsrzHoTf0ErZ1+ncFytH 2xLyhHbPaynAMdvXElFGA4LVORitIVAU8fpuKZhE1coze/5Lu6axsE6U71/8ItSP4H9s n5FCQQXSaMdqAGDS712nfl0bWXy2T7vEiURMK1ZTM9lTDlYCGrBaMzjrTmjw/A3WZ4AS JnzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693502122; x=1694106922; 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=qMHknYwipePMPg9mivxBhPSOU5ukXfE3oVZOzdjAQnE=; b=T6GcdM1+emMebR6dcR/eVELv/ZaNjQUomucIGB00lvZCE9X6jDrogbNP+b5UMAnV1B GBUhbZSYFi+wdMk8cZ533Rcy1qfdbURhyuQWoMr+Mh0AvWsHFKaRMP4qG2wLW5E1V27D Q2EBzupP0bLN7Xe7xUQ2By5PNdOYhd6Fd6nJZ228yPowtMJ6izPnEjWpS2bFehhDpl/I wtd4PXVlwPvCI+vItpFYNqjV2Jejrh7Aae2I7bdfvsjUAn6l49y0qntglqUd4+ZONzUV 85pyHYgEDcFM67G6tMyf0opfzLTg298zkeUevbmMAqx5pKwbTO9ew/iVV6YKDiJlxrSS 6V1w== X-Gm-Message-State: AOJu0YwX2JmSsuNX0Mlh04MczgL1/QxT+0sXRsq160jHPceJf0oMyAta TnuYYCmqm3cD+iRaYmgCxrRP4sb/CaABQVtHayk= X-Received: by 2002:a17:90a:ff05:b0:26f:6f2a:a11 with SMTP id ce5-20020a17090aff0500b0026f6f2a0a11mr208538pjb.12.1693502121713; Thu, 31 Aug 2023 10:15:21 -0700 (PDT) MIME-Version: 1.0 References: <20230810142942.3169679-1-ryan.roberts@arm.com> <20230810142942.3169679-4-ryan.roberts@arm.com> <87v8dg6lfu.fsf@yhuang6-desk2.ccr.corp.intel.com> <5c9ba378-2920-4892-bdf0-174e47d528b7@arm.com> <87cyz43s63.fsf@yhuang6-desk2.ccr.corp.intel.com> <4e14730b-4e4c-de30-04bb-9f3ec4a93754@redhat.com> In-Reply-To: <4e14730b-4e4c-de30-04bb-9f3ec4a93754@redhat.com> From: Yang Shi Date: Thu, 31 Aug 2023 10:15:09 -0700 Message-ID: Subject: Re: [PATCH v5 3/5] mm: LARGE_ANON_FOLIO for improved performance To: David Hildenbrand Cc: "Huang, Ying" , Ryan Roberts , Andrew Morton , Matthew Wilcox , Yin Fengwei , Yu Zhao , Catalin Marinas , Anshuman Khandual , Zi Yan , Luis Chamberlain , Itaru Kitayama , "Kirill A. Shutemov" , 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=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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 Thu, Aug 31, 2023 at 12:57=E2=80=AFAM David Hildenbrand wrote: > > On 31.08.23 03:40, Huang, Ying wrote: > > Ryan Roberts writes: > > > >> On 15/08/2023 22:32, Huang, Ying wrote: > >>> Hi, Ryan, > >>> > >>> Ryan Roberts writes: > >>> > >>>> Introduce LARGE_ANON_FOLIO feature, which allows anonymous memory to= be > >>>> allocated in large folios of a determined order. All pages of the la= rge > >>>> folio are pte-mapped during the same page fault, significantly reduc= ing > >>>> the number of page faults. The number of per-page operations (e.g. r= ef > >>>> counting, rmap management lru list management) are also significantl= y > >>>> reduced since those ops now become per-folio. > >>>> > >>>> The new behaviour is hidden behind the new LARGE_ANON_FOLIO Kconfig, > >>>> which defaults to disabled for now; The long term aim is for this to > >>>> defaut to enabled, but there are some risks around internal > >>>> fragmentation that need to be better understood first. > >>>> > >>>> Large anonymous folio (LAF) allocation is integrated with the existi= ng > >>>> (PMD-order) THP and single (S) page allocation according to this pol= icy, > >>>> where fallback (>) is performed for various reasons, such as the > >>>> proposed folio order not fitting within the bounds of the VMA, etc: > >>>> > >>>> | prctl=3Ddis | prctl=3Dena | prctl=3Dena | p= rctl=3Dena > >>>> | sysfs=3DX | sysfs=3Dnever | sysfs=3Dmadvise | s= ysfs=3Dalways > >>>> ----------------|-----------|-------------|---------------|---------= ---- > >>>> no hint | S | LAF>S | LAF>S | THP>LAF>= S > >>>> MADV_HUGEPAGE | S | LAF>S | THP>LAF>S | THP>LAF>= S > >>>> MADV_NOHUGEPAGE | S | S | S | S > >>> > >>> IMHO, we should use the following semantics as you have suggested > >>> before. > >>> > >>> | prctl=3Ddis | prctl=3Dena | prctl=3Dena | pr= ctl=3Dena > >>> | sysfs=3DX | sysfs=3Dnever | sysfs=3Dmadvise | sy= sfs=3Dalways > >>> ----------------|-----------|-------------|---------------|----------= --- > >>> no hint | S | S | LAF>S | THP>LAF>S > >>> MADV_HUGEPAGE | S | S | THP>LAF>S | THP>LAF>S > >>> MADV_NOHUGEPAGE | S | S | S | S > >>> > >>> Or even, > >>> > >>> | prctl=3Ddis | prctl=3Dena | prctl=3Dena | pr= ctl=3Dena > >>> | sysfs=3DX | sysfs=3Dnever | sysfs=3Dmadvise | sy= sfs=3Dalways > >>> ----------------|-----------|-------------|---------------|----------= --- > >>> no hint | S | S | S | THP>LAF>S > >>> MADV_HUGEPAGE | S | S | THP>LAF>S | THP>LAF>S > >>> MADV_NOHUGEPAGE | S | S | S | S > >>> > >>> From the implementation point of view, PTE mapped PMD-sized THP has > >>> almost no difference with LAF (just some small sized THP). It will b= e > >>> confusing to distinguish them from the interface point of view. > >>> > >>> So, IMHO, the real difference is the policy. For example, prefer > >>> PMD-sized THP, prefer small sized THP, or fully auto. The sysfs > >>> interface is used to specify system global policy. In the long term,= it > >>> can be something like below, > >>> > >>> never: S # disable all THP > >>> madvise: # never by default, control via madvise() > >>> always: THP>LAF>S # prefer PMD-sized THP in fact > >>> small: LAF>S # prefer small sized THP > >>> auto: # use in-kernel heuristics for THP size > >>> > >>> But it may be not ready to add new policies now. So, before the new > >>> policies are ready, we can add a debugfs interface to override the > >>> original policy in /sys/kernel/mm/transparent_hugepage/enabled. Afte= r > >>> we have tuned enough workloads, collected enough data, we can add new > >>> policies to the sysfs interface. > >> > >> I think we can all imagine many policy options. But we don't really ha= ve much > >> evidence yet for what it best. The policy I'm currently using is inten= ded to > >> give some flexibility for testing (use LAF without THP by setting sysf= s=3Dnever, > >> use THP without LAF by compiling without LAF) without adding any new k= nobs at > >> all. Given that, surely we can defer these decisions until we have mor= e data? > >> > >> In the absence of data, your proposed solution sounds very sensible to= me. But > >> for the purposes of scaling up perf testing, I don't think its essenti= al given > >> the current policy will also produce the same options. > >> > >> If we were going to add a debugfs knob, I think the higher priority wo= uld be a > >> knob to specify the folio order. (but again, I would rather avoid if p= ossible). > > > > I totally understand we need some way to control PMD-sized THP and LAF > > to tune the workload, and nobody likes debugfs knob. > > > > My concern about interface is that we have no way to disable LAF > > system-wise without rebuilding the kernel. In the future, should we ad= d > > a new policy to /sys/kernel/mm/transparent_hugepage/enabled to be > > stricter than "never"? "really_never"? > > Let's talk about that in a bi-weekly MM session. (I proposed it as a > topic for next week). > > As raised in another mail, we can then discuss > * how we want to call this feature (transparent large pages? there is > the concern that "THP" might confuse users. Maybe we can consider > "large" the more generic version and "huge" only PMD-size, TBD) I tend to agree. "Huge" means PMD-mappable (transparent or HugeTLB), "Large" means any order but less than PMD-mappable order, "Gigantic" means PUD mappable. This should incur the least confusion IMHO. > * how to expose it in stats towards the user (e.g., /proc/meminfo) I recalled I suggested new statistics for each order, but was NAK'ed. > * which minimal toggles we want > > I think there *really* has to be a way to disable it for a running > system, otherwise no distro will dare pulling it in, even after we > figured out the other stuff. TBH I really don't like to tie large folio to THP toggles. THP (PMD-mappable) is just a special case of LAF. The large folio should be tried whenever it is possible ideally. But I do agree we may not be able to achieve the ideal case at the time being, and also understand the concern about regression in early adoption, so a knob that can disable large folio may be needed for now. But it should be just a simple binary knob (on/off), and should not be a part of kernel ABI (temporary and debugging only) IMHO. One more thing we may discuss is whether huge page madvise APIs should take effect for large folio or not. > > Note that for the pagecache, large folios can be disabled and > distributions are actively making use of that. > > -- > Cheers, > > David / dhildenb >