Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17044334rwd; Mon, 26 Jun 2023 19:56:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Wa/oeMi4iZW38mrjYIbbK2UpE63PmOGNzXr/JwATqO2XqfqY6GSkDxvJh3y4/yThzNhfk X-Received: by 2002:a17:907:720e:b0:992:103c:43fa with SMTP id dr14-20020a170907720e00b00992103c43famr671421ejc.30.1687834607300; Mon, 26 Jun 2023 19:56:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687834607; cv=none; d=google.com; s=arc-20160816; b=qPUmHRYIHQqgvcUL9MNVl+rY+0HXjM6OFHMfPAHMTwRUw9rSASyzAIVezdXmrN1zw5 r2kCoAQwDN+9WCWpEfteuefeZddKcvwtBRmjDvHqoxDcp0v1E6bUjNlIe8DKGE0ZX9UO zYrQ5yinO53ZqIhNsNAzpXRoDB2ZBekNc3KkswKC7J5MbSIHuKLsG7XVctNGAk+3c7tn ZloPhIbaSLcH+2sU0lETB/TdIL0blJmW9UAm9+zrdcDjUc1Swvmn/zGvXOVttwTvSH1C AnRgwxjYM0wO+JfLYtX57aanQkrIi1XjMmoNg/JJxfVN4ayHnGjUD5jYxTDuSs4ZcyWM 8fmw== 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=xQTOkBN0GiMAgDG6ZOmDj9RulFsjN3i64Kvjq5jchlk=; fh=zTYFNic+S8YlfmSZQ9M48CdblHrjHKKPw48r1IJBtXA=; b=auTAd9A9HBd6QASNOglmpbClRFx/sHGcoirHkOBNxpQxFwqpcwQmGFHYcDHfDKyVPk pxsQwFWTG946LN6srlTpT5wSFtobI06IjpJbNTBVRRsrd/b5mY0Yid98wuKKNUduE329 ot7lFLTzkzGo4YJmJnGcbpP7RjYH2/F97/O8i4osRQFxUpC0MQWeqHRjXUdtzIjULghf Lefv13LdV0oJxZv/0vp66szEw0yXFhruDSyd9WNcM4rtHmIiViBCdCrnaKoXcVkas+c5 syOPFOiVyD3LHEfAf/i0NH9Tp1yyhSBi+U+X8qlbXLmiOAN61zueDoEKxm4a/JwVYXpp xyNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=2ONe3v1N; 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 ci22-20020a170906c35600b0098e1627c0e6si2933107ejb.789.2023.06.26.19.56.22; Mon, 26 Jun 2023 19:56:47 -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=2ONe3v1N; 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 S230183AbjF0Ce7 (ORCPT + 99 others); Mon, 26 Jun 2023 22:34:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230089AbjF0Ce5 (ORCPT ); Mon, 26 Jun 2023 22:34:57 -0400 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9358119AA for ; Mon, 26 Jun 2023 19:34:55 -0700 (PDT) Received: by mail-qt1-x82f.google.com with SMTP id d75a77b69052e-401f4408955so86941cf.1 for ; Mon, 26 Jun 2023 19:34:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687833294; x=1690425294; 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=xQTOkBN0GiMAgDG6ZOmDj9RulFsjN3i64Kvjq5jchlk=; b=2ONe3v1NzdXE0h5fj2MWjBVQiq6S1GdLr8eEH6r69uFRebt1NiaIjiqToWQ5+oQSIg deN/EOrGfQJTX8/IdlI46HYmmnUjOnsrxEv13aUKomZIkHWSGMAKvqYevb/K3QWcLbR9 uYFa99/05449KMzf049eKDYSuN8GMHKbyRc3dA/tpDmhB1dFdyQovn3/8ZOwws6k7JBz eiSy+SaSo4Ndcni6q+aCfD0OlX9EaJRWRRtbkqrZf+yUHqoDEIGNFR2AH3ma4yaceXsd OztHi2s5KfV5Yj8S0MHsmjPInWKZAWUFhMFQytcdDY0Yz3p6nPMmWy44dUIHb/wSpgHH azgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687833294; x=1690425294; 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=xQTOkBN0GiMAgDG6ZOmDj9RulFsjN3i64Kvjq5jchlk=; b=X0jqEMKNLWqyks6Ai3UhqaVo4BLtr/RBPTL/TaY3qwT5PaQlC2UmRMHv/Fdqrxn/aR l1u2QnPlfSsLlW/onZ9cbvROlqxOn8Xa8MDopUe+c/f8959+4cIV3eODJG/prmG9tcl6 Xv+qPieK1sGc3lOgoX6Qn/KFBQqK6WTJTE0rdQWfV5/8iB7HydXk7LI7SOwQr9kYiHE/ QckxFO8koRYlDMUpdxJZjHzhz8KusloJ3ZklMeXEqlFCnIRvNGk55cP8v6wAEqGJI73g lQVRqyULrM8JGPn1K2qrFb6aa0wuwyFtKehjAQiMCpwVdSO0flMoyRU5wtWDniY40xRM C3LQ== X-Gm-Message-State: AC+VfDzvDOvFDTdwjfsJhmICAxQRt6pljBq40h2M4ZDgNu9gpbRRMIAe bPKsmsovhrARwmSD3pEaaMRcIfl7I8Lua7iYDnJjiA== X-Received: by 2002:a05:622a:5c8:b0:3ef:3361:75d5 with SMTP id d8-20020a05622a05c800b003ef336175d5mr535403qtb.11.1687833294539; Mon, 26 Jun 2023 19:34:54 -0700 (PDT) MIME-Version: 1.0 References: <20230626171430.3167004-1-ryan.roberts@arm.com> <20230626171430.3167004-4-ryan.roberts@arm.com> In-Reply-To: <20230626171430.3167004-4-ryan.roberts@arm.com> From: Yu Zhao Date: Mon, 26 Jun 2023 20:34:18 -0600 Message-ID: Subject: Re: [PATCH v1 03/10] mm: Introduce try_vma_alloc_movable_folio() 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:14=E2=80=AFAM Ryan Roberts wrote: > > Opportunistically attempt to allocate high-order folios in highmem, > optionally zeroed. Retry with lower orders all the way to order-0, until > success. Although, of note, order-1 allocations are skipped since a > large folio must be at least order-2 to work with the THP machinery. The > user must check what they got with folio_order(). > > This will be used to oportunistically allocate large folios for > anonymous memory with a sensible fallback under memory pressure. > > For attempts to allocate non-0 orders, we set __GFP_NORETRY to prevent > high latency due to reclaim, instead preferring to just try for a lower > order. The same approach is used by the readahead code when allocating > large folios. > > Signed-off-by: Ryan Roberts > --- > mm/memory.c | 33 +++++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/mm/memory.c b/mm/memory.c > index 367bbbb29d91..53896d46e686 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -3001,6 +3001,39 @@ static vm_fault_t fault_dirty_shared_page(struct v= m_fault *vmf) > return 0; > } > > +static inline struct folio *vma_alloc_movable_folio(struct vm_area_struc= t *vma, > + unsigned long vaddr, int order, bool zero= ed) > +{ > + gfp_t gfp =3D order > 0 ? __GFP_NORETRY | __GFP_NOWARN : 0; > + > + if (zeroed) > + return vma_alloc_zeroed_movable_folio(vma, vaddr, gfp, or= der); > + else > + return vma_alloc_folio(GFP_HIGHUSER_MOVABLE | gfp, order,= vma, > + vaddr, fa= lse); > +} > + > +/* > + * Opportunistically attempt to allocate high-order folios, retrying wit= h lower > + * orders all the way to order-0, until success. order-1 allocations are= skipped > + * since a folio must be at least order-2 to work with the THP machinery= . The > + * user must check what they got with folio_order(). vaddr can be any vi= rtual > + * address that will be mapped by the allocated folio. > + */ > +static struct folio *try_vma_alloc_movable_folio(struct vm_area_struct *= vma, > + unsigned long vaddr, int order, bool zero= ed) > +{ > + struct folio *folio; > + > + for (; order > 1; order--) { > + folio =3D vma_alloc_movable_folio(vma, vaddr, order, zero= ed); > + if (folio) > + return folio; > + } > + > + return vma_alloc_movable_folio(vma, vaddr, 0, zeroed); > +} I'd drop this patch. Instead, in do_anonymous_page(): if (IS_ENABLED(CONFIG_ARCH_WANTS_PTE_ORDER)) folio =3D vma_alloc_zeroed_movable_folio(vma, addr, CONFIG_ARCH_WANTS_PTE_ORDER)) if (!folio) folio =3D vma_alloc_zeroed_movable_folio(vma, addr, 0);