From patchwork Mon Jul 3 13:53:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 115377 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp545160vqx; Mon, 3 Jul 2023 07:01:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5J3jUjZ8Hvvk1KINRC8t/Izr3VRpWjyCleUoKlamNWfKXmarkOmb8gAwz5ZPemXmGD1dWN X-Received: by 2002:a05:6a20:8e19:b0:11a:efaa:eb88 with SMTP id y25-20020a056a208e1900b0011aefaaeb88mr14204642pzj.3.1688392900232; Mon, 03 Jul 2023 07:01:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688392900; cv=none; d=google.com; s=arc-20160816; b=VFPLkcDB5a9e38W/cpFDArnWnpPGhdIKasi+NEEntdZ0kbsGxFZ2LSawc7GiotRXFE wi2V4UmpjpeSk5a9kCRBbvDvLpW+m6sRArW6Fn/vZCJpgitdVLdZnuV2/wRv/D1TD5TI e31swDiyHQBIoR/yWOlttmll3wN+ZsyTP2LVrV2oBPDfxg9oEohKTlE3NoGJaonpQ8IB ayxwgOwlj7gh/MocYQy1QBdo2xjBD/DnA/NNP/7sA/pAx2ijHoImP1XltQZLx0y6In6S DoZ49Jx/dXItwLFdIvIbJqyaFbuDHxFR9jpESalPDJJDkvX4igu6m2hE0U3cTa3Jl6LC Aqqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=USdbSWQAhhNgz/kbRbFMcj5UNwofuLjMnykBwRvmpy4=; fh=W2gTym8Tes+4XZMJyNdq9yGC4n1yJ+vTSxJnRC1NAwA=; b=XbCpRYA2PlB5D6lVTCmyMFwXW691VYUGsNKdxMK6lB0cryGnP0C+NpusPsRpUWV808 uOFMLngundKPu0JQByGrMPGejnwOD4evFWZp1WOf7RPOs2cuNjX0Ti8sCp5R3uq9Z1xE LSN5AevFkSTTQuv7WxwBCvZ9LEtlxb1TvQzV3ol71YT0887vzYgxNv6ZZUDZnYJ5Dlc5 QCFkZpxOiDD2NloIvD8DDUENFHvgBJZVNRXF+TY2KXUeYcjE5SOo00++lFdmUFFc6Gh8 8AW/HUdAYqlxbq9BpjRECOsUzHXH7MUdtKQ2s0F/DZ/lpQcyulGq1Y5SZSG3wlTAf3+r LlHQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b21-20020a056a000cd500b0067c2b7b23e3si13719076pfv.345.2023.07.03.07.01.21; Mon, 03 Jul 2023 07:01:40 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231139AbjGCNyI (ORCPT + 99 others); Mon, 3 Jul 2023 09:54:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230037AbjGCNyF (ORCPT ); Mon, 3 Jul 2023 09:54:05 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7B94910FA for ; Mon, 3 Jul 2023 06:53:49 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6399A11FB; Mon, 3 Jul 2023 06:54:31 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DF28C3F73F; Mon, 3 Jul 2023 06:53:46 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , Matthew Wilcox , "Kirill A. Shutemov" , Yin Fengwei , David Hildenbrand , Yu Zhao , Catalin Marinas , Will Deacon , Anshuman Khandual , Yang Shi Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 3/5] mm: Default implementation of arch_wants_pte_order() Date: Mon, 3 Jul 2023 14:53:28 +0100 Message-Id: <20230703135330.1865927-4-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230703135330.1865927-1-ryan.roberts@arm.com> References: <20230703135330.1865927-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770408273875915329?= X-GMAIL-MSGID: =?utf-8?q?1770408273875915329?= 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. Signed-off-by: Ryan Roberts 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) != 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 large folios + * 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,