From patchwork Fri Jul 14 16:17:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 120566 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp2641736vqm; Fri, 14 Jul 2023 10:12:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlFdw8YXil49fIce3xg2+k0ZyA6TXIFWDCOLODj06FrlrimB0fww8KwXgwlfDAUAz5fH//qo X-Received: by 2002:a2e:b609:0:b0:2b6:e2c2:d234 with SMTP id r9-20020a2eb609000000b002b6e2c2d234mr4026396ljn.33.1689354741020; Fri, 14 Jul 2023 10:12:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689354740; cv=none; d=google.com; s=arc-20160816; b=WqYbNlbxHFSlda1JjerXSWQue4m4NiR+Pf9R7dZsNS6nVFqplG5C5spIBOLs65AHY2 dd07xg/+pQDHxy2biUrfItRApRLrNallfCXslRTtSuzEi9v+7TJt8HLAgb6HVN430vXh jnPIAXMu+Gil1djPPBi3KkDt+asmEOLxYG7oZwM6dXfwOOSzZSeviBkalYvHCuADTyaX Wc1nSqY6wuUDI812U5dlMI4fOtjo1GqZ+MKUophYJ1OcVCz7kyldUGw93m5QpeTJMcch RWE3jP3Olty2KdrtolBE0D2lYoE7G4X20rqViGRTLTIJHDnPp/BsjLI0B5fihprb8EE/ TSNA== 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=RwsmSgL54KvIcN9UUxItjXrDFbdgmMPuqsBrxLvJGfQ=; fh=KUn9/czOF/CUegSsbpumpb8eTeZtYrbN2VF58YsSKuI=; b=SzRdjeLpQFBxd3cGUxPK+H9F0DBwUlpaqeaS0c33t40cGmLXt2vTODcwhVnR3+eDEE PvmQmsaBc6ebIsbLrfqM/vLHdYkHcWV+gvAK6+14fVltmB0alorT7spebLoMiMXpWAYu 97St+0JR4raKfM88OhhDIGIZqIgPetA1x5DOhgoVNvc3zVMRWtF62ugu8P61gf7DtgtM XZBrv1GcxEB5bwwAJZjtu224j2fF7XgNv/mA8GxvtavyxAKMUcLyDwD8rIOM0VZYcVDd FGH9TwMbebZIDyJRVz6FRjWqfccho+kE6mYbFJ1+0SYnQjTTKN+5vugKLh6M56zrJTp8 Wh8g== 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 qk3-20020a170906d9c300b009928faf13e4si9332304ejb.70.2023.07.14.10.11.56; Fri, 14 Jul 2023 10:12:20 -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 S236134AbjGNQSJ (ORCPT + 99 others); Fri, 14 Jul 2023 12:18:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236296AbjGNQRt (ORCPT ); Fri, 14 Jul 2023 12:17:49 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F3B0535B3 for ; Fri, 14 Jul 2023 09:17:46 -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 9EB8E1576; Fri, 14 Jul 2023 09:18:28 -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 527963F740; Fri, 14 Jul 2023 09:17:44 -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 , "Huang, Ying" , Zi Yan , Luis Chamberlain Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 2/4] mm: Default implementation of arch_wants_pte_order() Date: Fri, 14 Jul 2023 17:17:31 +0100 Message-Id: <20230714161733.4144503-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230714160407.4142030-1-ryan.roberts@arm.com> References: <20230714160407.4142030-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: INBOX X-GMAIL-THRID: 1771416836787531126 X-GMAIL-MSGID: 1771416836787531126 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 -1, implying that the HW has no preference. In this case, mm will choose it's own default order. Signed-off-by: Ryan Roberts Reviewed-by: Yu Zhao Reviewed-by: Yin Fengwei --- include/linux/pgtable.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 5063b482e34f..2a1d83775837 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -313,6 +313,19 @@ 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. Negative value implies that the HW has no preference + * and mm will choose it's own default order. + */ +static inline int arch_wants_pte_order(void) +{ + return -1; +} +#endif + #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long address,