Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17062442rwd; Mon, 26 Jun 2023 20:15:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7sRlRZa9ZzB/AH6gAN2WxQTer2xoD3cJhBHs2oDVNQAWwkaH4eja+AKN8v2/RuF46eH0yH X-Received: by 2002:a05:6358:c114:b0:132:f88f:ac4e with SMTP id fh20-20020a056358c11400b00132f88fac4emr4036813rwb.20.1687835745907; Mon, 26 Jun 2023 20:15:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687835745; cv=none; d=google.com; s=arc-20160816; b=INpbgvKIFk+LX9znRa/GTPS4IOfTa+B6r55vKdrhrs/DfjkJ8YSvjimc10KNzVq0W1 SckqR0HZc33rIidyJtxPWvr9PWjvbRQchgOh9+oSW5gmOqzqJzrkKSOqNeHFdESodvb8 rwyuBFesiBO6Y5DlOedSraUo/y/a7FX1on8UQnnVVDVM3pob+5IHTek1EPIBdG12NeH7 ShPNcgjAsJBj7SuTYT0n0lcZ8JOBjKrKL5JwDoADNuLBYS9bTvfkX2p1jE7jnRiPKNPs Poh0mfhdpgw31TSFehrL+mA/krsJ+orL899Nux9+6FPJjIOrxSA4jmB9wORecZF1PNUM pn+Q== 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=Dubf60A5K0NzNIP7xjDZqZozn3KVMPgogoe8ASnGAZg=; fh=zTYFNic+S8YlfmSZQ9M48CdblHrjHKKPw48r1IJBtXA=; b=k9HwOGxfzNZ1exWzqH3M6pFAdI+Owugc/iKx0g2GQ0Vpre3yt3Nw8IQiZgzOafOFiK E4/064Z8zAntF4DBGwgVBNttMiwTQ6kj7wULCCLT63XfQu94Vyqgmn7iLv2yBvi3R7a9 9QOlr4s58aAxeTaqRu8PxwAtT5XtqSZ2BBdDb/EjLvgKzYXUHqdjIEMWqc7hydV0A8ty 20qK8GrnyT+cSjXWUcSOT4mTd+tnO5odw6RNoMZA+lTbk1rjzvl9oK7TBZl/LK6jKYZN Jvjm7Z2glPe/k4B3PAUUq+haSXYQubsC8nEwYm3znFt7tvDLnYF0QRGuwF2wqL4mTVnl lZeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=PDCiQ+OM; 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 n17-20020a63e051000000b005573ed4beb7si6589614pgj.819.2023.06.26.20.15.33; Mon, 26 Jun 2023 20:15:45 -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=PDCiQ+OM; 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 S229629AbjF0DCE (ORCPT + 99 others); Mon, 26 Jun 2023 23:02:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229808AbjF0DCB (ORCPT ); Mon, 26 Jun 2023 23:02:01 -0400 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2638ED for ; Mon, 26 Jun 2023 20:01:59 -0700 (PDT) Received: by mail-qt1-x836.google.com with SMTP id d75a77b69052e-401d1d967beso137751cf.0 for ; Mon, 26 Jun 2023 20:01:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687834919; x=1690426919; 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=Dubf60A5K0NzNIP7xjDZqZozn3KVMPgogoe8ASnGAZg=; b=PDCiQ+OMm+ZYhItlBm9CJOAjt3arCBaIPefCRV+cRGlKtmTkgJuKH7kAOKyAbCQJzL BCdmcPnotA0n4v9avoXLaITUGQgCoZm0BKEirmoOrgdrv8GGmlOoIokTT8s6lPxZIxSr eePAgRbrFZroffClytmh37SqL9NSTT2FHr7ZtV7QGlDkmk6KAHHYcWPVhpXKOVGr8Tr7 Xvj/gX5em4lLmUFwa2ra0Yw/kozeJB+nK/9f/BgOWwSt6jpUIMH8XIdAtL1yeNznNHSz i5guqpOz9eCzUhqIk6gXiuPNKiSeUkePu5MwafnJai+nUz1Z0jF1fVOyqLoOaTDwUabC 0MkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687834919; x=1690426919; 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=Dubf60A5K0NzNIP7xjDZqZozn3KVMPgogoe8ASnGAZg=; b=iyefE0rR5FXX6IDEXgtHAduoHr2fmo8ZGOrCKS04xtdYwCoL8WyCpJtgRPQqV7La2D QmyEZt79ukA3G9JmArRQd3amdl7tyF+2BEmHqvOEhd7C6/Ld+QqhP5rNSN75euPZF6WJ d2Qw69I035TXKc1ntnoFYpAZH9uAfaIwuwl7IIxIddKTit7pEBJvPNcF9kSAk4xkB2U1 g0EW5ZbeaQreEreWOHLRJAzTVpSZCNaGsVl2sd5YoodrxN5h4B1N9qU8gK2OLw3KZ6hx oJOjXf4302meZQWOW9qmKIYxCs4rfHEqVqKJ9o1gmLTHFljCIIzNxxNrgIx4z3eWLck+ EExA== X-Gm-Message-State: AC+VfDyRXk5puFqLNwIP15lp+RKAu3QDfX7rqtSZisF6IWnOXL6he7oB K3HuBJTadEwv669PI5KdLiO/8F53Wcz2YhUcP85fJA== X-Received: by 2002:a05:622a:1a0e:b0:3f9:a73b:57bb with SMTP id f14-20020a05622a1a0e00b003f9a73b57bbmr69998qtb.4.1687834918926; Mon, 26 Jun 2023 20:01:58 -0700 (PDT) MIME-Version: 1.0 References: <20230626171430.3167004-1-ryan.roberts@arm.com> <20230626171430.3167004-11-ryan.roberts@arm.com> In-Reply-To: <20230626171430.3167004-11-ryan.roberts@arm.com> From: Yu Zhao Date: Mon, 26 Jun 2023 21:01:22 -0600 Message-ID: Subject: Re: [PATCH v1 10/10] mm: Allocate large folios for anonymous memory 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=unavailable 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: > > With all of the enabler patches in place, modify the anonymous memory > write allocation path so that it opportunistically attempts to allocate > a large folio up to `max_anon_folio_order()` size (This value is > ultimately configured by the architecture). This reduces the number of > page faults, reduces the size of (e.g. LRU) lists, and generally > improves performance by batching what were per-page operations into > per-(large)-folio operations. > > If CONFIG_LARGE_ANON_FOLIO is not enabled (the default) then > `max_anon_folio_order()` always returns 0, meaning we get the existing > allocation behaviour. > > Signed-off-by: Ryan Roberts > --- > mm/memory.c | 159 +++++++++++++++++++++++++++++++++++++++++++++++----- > 1 file changed, 144 insertions(+), 15 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index a8f7e2b28d7a..d23c44cc5092 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -3161,6 +3161,90 @@ static inline int max_anon_folio_order(struct vm_a= rea_struct *vma) > return CONFIG_LARGE_ANON_FOLIO_NOTHP_ORDER_MAX; > } > > +/* > + * Returns index of first pte that is not none, or nr if all are none. > + */ > +static inline int check_ptes_none(pte_t *pte, int nr) > +{ > + int i; > + > + for (i =3D 0; i < nr; i++) { > + if (!pte_none(ptep_get(pte++))) > + return i; > + } > + > + return nr; > +} > + > +static int calc_anon_folio_order_alloc(struct vm_fault *vmf, int order) As suggested previously in 03/10, we can leave this for later.