From patchwork Tue May 21 11:36:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13668882 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30668C25B77 for ; Tue, 21 May 2024 03:28:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 901C96B009A; Mon, 20 May 2024 23:28:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B0B66B009B; Mon, 20 May 2024 23:28:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7039B6B009D; Mon, 20 May 2024 23:28:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4E8876B009A for ; Mon, 20 May 2024 23:28:26 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D0D8180535 for ; Tue, 21 May 2024 03:28:25 +0000 (UTC) X-FDA: 82140970170.15.3CB3122 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2085.outbound.protection.outlook.com [40.107.6.85]) by imf30.hostedemail.com (Postfix) with ESMTP id 1A9DA80008 for ; Tue, 21 May 2024 03:28:21 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=nxp.com header.s=selector2 header.b=MQr3FTER; spf=pass (imf30.hostedemail.com: domain of xu.yang_2@nxp.com designates 40.107.6.85 as permitted sender) smtp.mailfrom=xu.yang_2@nxp.com; dmarc=pass (policy=none) header.from=nxp.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716262102; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=kpBy7C2LF/T+5wMu59RClHeVqnf8zCo0un+Q8AuCxaU=; b=54JXMos/kFrbtenS/z7PXDxtlfCzFSjMNIyaS8DXOdj0u/JPfnY+bw8FTGzTTrFnnT2Yzd lKJqGDOjO9j/QNzORI+ykmfT+KPP9osFqz90bFNleA0L+6Xi0Rs+eln9Zcyr4uGWriPa+U VrfUh96eGF3j1pNv/DfPQos41Y4DiR8= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1716262102; a=rsa-sha256; cv=pass; b=EccCq0GPiRfFajuzeniOZqI/ajV5wZICCy3gr4KdEUpUK8LJbsSysSvAz4Wr2T6q5ddeVf Rrf9T2u+cGAu8juq/s1giAfJBZlGv229Nf2M2kTdocYToDrHPUJo87NFW1GKeIflUkD9gj ShnguhJJTYogTrx0ofdc/KRHLujGYsg= ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=nxp.com header.s=selector2 header.b=MQr3FTER; spf=pass (imf30.hostedemail.com: domain of xu.yang_2@nxp.com designates 40.107.6.85 as permitted sender) smtp.mailfrom=xu.yang_2@nxp.com; dmarc=pass (policy=none) header.from=nxp.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nijPkSngFQNVgoKCip/wvwaImX8FBtfm2lSk+q5XpBeDBBg/nJtT0ExFe4UhuWBqOndn25/ItB/gjapKYvK8GBn3l9ZGwy/Gql7vMX6WwUrxaoNLXIzAwbBzUFcR8odIArvnf+nT946AYoebKdf5v/vevjiO1ucvj0oC6xkc/3HrAuT7GSTeLOvEZRfrxNC5WaKmBIVJOLxlx6EDzp6T2Ng41l7seKqL1L+v7Q+tyQMrvvOkCf/+iG2T2q0t0gD2rxeezwuYgPoW0wQLwJpdPbL7JS5xgtsQb4hgp1W42Pd0O+XnS6D7TnwBSxPBCGJyTPG+A31aPtt4/tJAyE0u0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kpBy7C2LF/T+5wMu59RClHeVqnf8zCo0un+Q8AuCxaU=; b=WtYJMm25M4CuGDYhVz9C0y7pqexxoMWLOhWV0xqgpXYgX6FCKeCV6VJQkXKIWV+/22oFFcdoGJV82hjivqc5VqR5Vvf5nTdLBTEHeYte7haUfAv2iuoUfzwwO2pjgPTrf7aDc5c9OHKeV4hv239gxXcH4gP0Jb11HseXEP6cVw4ZufMGYmCi9YvONC0Dfr/yt7fNDE+AOrunU/VNGjNU0iZ9INuxqMmCpSlRNeu7nfLnXAZ+zWo8n8kKUBNq2chKmBFLWyNTjqNtC+9AT9wqfnpMfqU0FJ+KpPHBrLkzjc7/Gn5+UjR1nxzNLl5Dc5XK1yXtjhQoERaTuX3oD/G3kA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kpBy7C2LF/T+5wMu59RClHeVqnf8zCo0un+Q8AuCxaU=; b=MQr3FTERt+hhmosTGCOlrnF1jQDhIrAVj7j+4wSoDCz+QBcxrIHTokvuoMHuSsHSql6g5Xhnnkd18nqGn5c86pKaHnJGsh+/iEQ+xqkfIMbEolwGQUymzWsJkhIuwV9DlJT2oR0C3iSAIfGcCGPvrUyjC1d5fbkMI3hNdRSjzIQ= Received: from DU2PR04MB8822.eurprd04.prod.outlook.com (2603:10a6:10:2e1::11) by PAXPR04MB8606.eurprd04.prod.outlook.com (2603:10a6:102:219::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.36; Tue, 21 May 2024 03:28:18 +0000 Received: from DU2PR04MB8822.eurprd04.prod.outlook.com ([fe80::8d2f:ac7e:966a:2f5f]) by DU2PR04MB8822.eurprd04.prod.outlook.com ([fe80::8d2f:ac7e:966a:2f5f%6]) with mapi id 15.20.7587.035; Tue, 21 May 2024 03:28:18 +0000 From: Xu Yang To: brauner@kernel.org, djwong@kernel.org, willy@infradead.org, kpm@linux-foundation.org Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, jun.li@nxp.com Subject: [PATCH v4 1/2] filemap: add helper mapping_max_folio_size() Date: Tue, 21 May 2024 19:36:23 +0800 Message-Id: <20240521113624.2538951-1-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI2P153CA0022.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::8) To DU2PR04MB8822.eurprd04.prod.outlook.com (2603:10a6:10:2e1::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8822:EE_|PAXPR04MB8606:EE_ X-MS-Office365-Filtering-Correlation-Id: d1fb49b4-2882-485c-6407-08dc79460ea8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|52116005|366007|38350700005; X-Microsoft-Antispam-Message-Info: CQ5jYG8iMWR9o+4uQbMBHbj4FBT4c3ibyQKDewZ9xekaHrkbeorVBubKPt+xg7bZO8Rzu7A5O0398eSba1NpJkpzsju63Tee+I7bIQhSw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/NUJSL0VDgOCbj0CTlCLm10Elj0Nm2rTn6l2AmMweHJ7lDXZyiGm9/iL+BVqwlc2eBosVxyGzNMu8ynybYEiEjSkMGFatLoaQB52/AEwERSpBNui6JjmS1TE11szSTWrxZJ8Gh3KT1n2hyyIouF2hah66dPtUq3iTd51V3FUwjdbsi+DD1Czmgd7+qpyMcKcdU26Xf+9FQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8822.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(52116005)(366007)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ILXP/AiSf49y27eq0OFLsww+ISEGzfXx5abrXvUEVdQ+WPmf7LjMEQlqN6yL74SrxDUU8oIVpSFrV0KNVFqvm4h6RW3Np5E3i+inclCQYtq2EC5rZ+VKrOizHluuUGzMyTNrT25J/u6aZhc9jqKacCdsL701z2NGfJYwzO1m/MdC01R1wcf2j8A3iW8/Lpy55rlsU8e3ZE56y09f8e3Q0QHQAUPNm61Z0r4LzAp5YH7u4QmCnplWgU3EFs5ZfaUv/XvpLdyxPmRiiMXDnmKbJ+ah4pfA4Zaj2upQN9Ha3oxF64dlOA4KgiGLtNyyi6Xul5M1sQoiIrTRXeBesVLoROqrjRBac+3u6qHFPEhD9OYmB47CmMgOWotRPC4+Tdc4e+4ElnSRhaO6agyuuhiOhOKXM37fiotpwGCPur7J4OHJNcGoZCpZGLeTJTHzhib7oxFKuVLVPW02/NNu1kQ3h48LKDTPn9et31kQMt7Yt9ybKGBUXH+rJnkGrg19oCxU35/XMAUHzrMwgDrxUIF1ygi+ti20eNYY7mm9y6RX8KLcr0s/rVEaxgSatQjiYlxyeb8p4BYD1R71ziXjDMD5fbTmM6JPVEDLDKOp1PXP+KcxAogMgOjP2XTflEbgdytBCARHwaQ4He1eWk5Vg5TQNHe99mYcX6kpdUUzRnqKI1r8YaJdlUHDLUJ+CAuKc0twNEAkGjp5njk0h+IPZ97rjYQuckABQ94Piz8/1m5OpmGI0lILzleb6k9hAqKG8PtxQO9zTMuTO8Y6KgrCyohFKUukeW5rllIQYVaPT2EcSu9OokXbJx7LEl/67BzToD0GHJoHk9DrhIUqtVsoxFQv9dgtj7mS0B4GzXcSKkaAyxQEnOX98IFwDWXJ5zaoDemmKX3kpNgW0GQL/Hp7kmX2gzdKFgSZfnB0rDR7C+pIwpN12JjFK0ohXHJayV12MdOgzcUpLP2d01o9LegEprg8ACkicah3CmIfGX/PMxs7pTxlvPxs8Mal3/hjvpIZsPd3v6FtjL2+nG36UBQOpseg0oECm+6ugBOemTGu2FbGrJsoILa+lRnqiPhVS6lJ7RjD8CU0Yd/0lcWK3pd60w61SRjZ3fP42xXsl9/d31B2nw/dDNYxezJ+gFOD1+q+Ys34yUkdCaBgzX/zSBW/FKJ1+XgG1QwPkbScPLAQ1qcLmggl+aiBIPGgBTKlz0VHWL2Lx6gOK8rTJHwfcXdLknn4RrX1ewauW9S+sXVt42Dy6z7Pt3N+B2Lf6lb3ryj5QSG76Oz5gJFRG6mJ7InU4oxWjgHFmK7uvGJ3qxftzp2RljcI/arrh7NmCReVAkk7Rl2CNikx+IYGF0euRh1l2w/JqtI72dk7+t06cedPGXJPxZBPW6/XWN9XHTYvqireoBv71m+pE4F3AW6//RqUm6FaLVtuDDucbNu3GqXJXABIvymVPlSajVFta5jh+UtRe3rSx9Gjag7LL8AWWjXyULD76KPMNvpmxzyy2CjW/Kx0pqmx9fYheu+oQjJgG2TJORPmDRjuMohJ9dPeO2VGTlGxU5g6tu24sa5y/3K6RecSkWDZXtJvajIubAqpSVNDOnHp X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d1fb49b4-2882-485c-6407-08dc79460ea8 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8822.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2024 03:28:18.3103 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Bc/eXfTkVaPo3+QDNkP7voklK9LySVId3XEXlowdszw7Fc3PWuM3TtKSF5aVScUC0nMttd2nHCYTvwskAIQ3Ng== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8606 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 1A9DA80008 X-Rspam-User: X-Stat-Signature: i7h4ga7fp478x3mmstngqwg1c57py3j5 X-HE-Tag: 1716262101-670836 X-HE-Meta: U2FsdGVkX18Blq1BXfF6mH676B7Anc4GGbDPNVYOzz3YOpTqPizVhgs8NrCwuQqBvokY1dor40POi6pVkQgRbGQ4uTwsF6bGYPdZV29iMoWtp7EvIq9sDZCND1EjauT4rfIPguyTVHYnFOoFRC+aVmxvzo5kGx+UhmE1OIsCZtgRbdK88tna8CSduiJcXPOStm6QN3ZZRCYk/41c3opNG74gXWmq66s6PIAKkl7aAu/D7obUq7BN57mA/+3M82ISdzlEECUnywExd7CvUyEow8i7rEf8jzpi93fZ0XHKcQ3FuEzTQjHs4chasEqaIse4aevULahHAmUhFAoBGkb1LsFKTsUmGkw1tNKB46eTr4a0BT/jh2qE9vyolRmXozO2YU3z0/vusmuktsFaJEFWJbAX0JRDG88iEF0TT0lSy4xdYbC/MygesMYsHlEivNqaRvH73jTJ35oAMIi44izmQcEnmUdmXPxAS2XGVvr1W695wJjPL5VhtsV5D48+d9rMhQo1Bd9r0NCL0oOPGKErzR8FXBxiB/X9kTk4/EJNTgXCo0UrfDiqJXKQRakifkE27LCUCf96TBygvOglN4bquVIo+2S8g14JzzNr4BAuJEKzATPYACJk2o28ngtyDXANB4dnUaFarOWXIRu8V02oVdHtVGH7DYbuB4m90dUrdqQDa3y2OTNTWPfgIKeSg9vgsU93qH3jf7v99OquKbPljKQfrtYF9xZ6bTVAtjGUDAFqIn/QFSa9I6T9quJ1wlPcoTUoy+I9eHWCjywoyp1dyjX5IKT5yDNHc+0iSCUuUKeeKJrUcY56TKREJkEnPCqhZri3OdaulqjBubDTZMVW88ZNJRgF5hFQvu/UKe7wzAM9bbYYz/OfNGo3iJVRoKnplM+WBoOSEyoG/uxizTQrPbI8Jbj2Xr4aOt/JUd7sCcnjBdykD6yDrVrM2GEMMIwVsMi8YAkQOE89k/LajCH E2e3anaa GbilG87dhw8olLSBT5M60ULJNcuIqAFP3NcfC4obgFOyfnQUB2mKh8+yAcVXNcSQ0oCU2ulwPcxewME9+giz/1voVZbvsB1S23PBxQBepBaYazCid6UKWb8j7n76pg61FYpne0ZtKyXtEXqgOBPYtH0XzAGCobxsFrN7dahQbOdkRCXm8atTinbeQgXObvia1sa+hnSK7KJ6j9lkJZIWOKgn0xbDFkRY9iJ/okRuSc6pzTdEz9LU5bHWe8GROVcAkuOtu0HUqNPEDv7MXiN3Kbh9ooZkfGKDdVKALPDs45v7+uZ/GsmoqTlLwhAg8dYTUWBhpXowae8OAlpG7W++9MqaO7ukLN0FDheXufSSeepN20Ho6LCdwW1s57+ThVuuKqLTq X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add mapping_max_folio_size() to get the maximum folio size for this pagecache mapping. Reviewed-by: Darrick J. Wong Signed-off-by: Xu Yang --- Changes in v4: - split the mapping_max_folio_size() from v3 - adjust mapping_max_folio_size() comment - add Rb tag --- include/linux/pagemap.h | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index c5e33e2ca48a..d43cf36bb68b 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -346,6 +346,19 @@ static inline void mapping_set_gfp_mask(struct address_space *m, gfp_t mask) m->gfp_mask = mask; } +/* + * There are some parts of the kernel which assume that PMD entries + * are exactly HPAGE_PMD_ORDER. Those should be fixed, but until then, + * limit the maximum allocation order to PMD size. I'm not aware of any + * assumptions about maximum order if THP are disabled, but 8 seems like + * a good order (that's 1MB if you're using 4kB pages) + */ +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +#define MAX_PAGECACHE_ORDER HPAGE_PMD_ORDER +#else +#define MAX_PAGECACHE_ORDER 8 +#endif + /** * mapping_set_large_folios() - Indicate the file supports large folios. * @mapping: The file. @@ -372,6 +385,14 @@ static inline bool mapping_large_folio_support(struct address_space *mapping) test_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); } +/* Return the maximum folio size for this pagecache mapping, in bytes. */ +static inline size_t mapping_max_folio_size(struct address_space *mapping) +{ + if (mapping_large_folio_support(mapping)) + return PAGE_SIZE << MAX_PAGECACHE_ORDER; + return PAGE_SIZE; +} + static inline int filemap_nr_thps(struct address_space *mapping) { #ifdef CONFIG_READ_ONLY_THP_FOR_FS @@ -530,19 +551,6 @@ static inline void *detach_page_private(struct page *page) return folio_detach_private(page_folio(page)); } -/* - * There are some parts of the kernel which assume that PMD entries - * are exactly HPAGE_PMD_ORDER. Those should be fixed, but until then, - * limit the maximum allocation order to PMD size. I'm not aware of any - * assumptions about maximum order if THP are disabled, but 8 seems like - * a good order (that's 1MB if you're using 4kB pages) - */ -#ifdef CONFIG_TRANSPARENT_HUGEPAGE -#define MAX_PAGECACHE_ORDER HPAGE_PMD_ORDER -#else -#define MAX_PAGECACHE_ORDER 8 -#endif - #ifdef CONFIG_NUMA struct folio *filemap_alloc_folio(gfp_t gfp, unsigned int order); #else