From patchwork Thu Feb 10 19:33:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 12742391 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5EC97D for ; Thu, 10 Feb 2022 19:34:30 +0000 (UTC) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21AJ2Kfq017470; Thu, 10 Feb 2022 19:34:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=hrIAx00ltq5uyB5+dfUERGseD5CmKDJ3dpseYB57s/c=; b=EMfYlMCp3++7RwUMXyMhFQhHe9CKaE8lsbmnORNYzglStcLbTDwD9tUYIhevbOsJDlEn dObYh0SrlzaWEG/Wi3dsLGbXPrgT54AxstLeJzr10GBJORqLTWa1wJYEm1XXUcG5qPZZ 4t8VwN/dmaylRI0QqI73bOOQfuO52nmjL5GVuDFZFgXTax5Z1bg1TEXSgbRVaA1tzVIN LU3j1jF/5LIYwHdAJY9osAgwHCG5sEWkEqODC/0jpWhhvdbz425RBsvEgxpQoeFEn8/l joJZLSWMi49rc1nkO1k9Kqonz50M1rmfoNsW2Pw4sgNV0aw0tKzzlf19BvkqylK0jTJa Sw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3e3h28s2t3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Feb 2022 19:34:16 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 21AJUVqh120792; Thu, 10 Feb 2022 19:34:14 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2175.outbound.protection.outlook.com [104.47.58.175]) by userp3020.oracle.com with ESMTP id 3e1jpw3cje-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Feb 2022 19:34:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fZWAYLfJBnWfIsOCniKPdMZJfwS+xfp9SoszAVlmAlwug+LWw/ignsqTrosniL3QErdoIKavNU7EPAwxELjEIzuuFY+60JLddV0mb2uzBugZqa9zyVErPrH5BLKpB6Oku0JNRdyTWSCt6phnFf9OIyjs111TryWRcjLKwR+qkxYpAULLRFHnlZRz1vFVncbsSuS32VExym2TSXaw86MTfuYaQ9BLK6Ek5KO3lk8J1V5AELfwQj/iTgH6BOj0+7BInL0ADOn1MB3rlTIh06xfz266IfnjhcaNRpzn+gk2xOWwGK4D1bXHs/p3PYqJsQwJ41EbLncjw9I8CLiFno/n5Q== 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=hrIAx00ltq5uyB5+dfUERGseD5CmKDJ3dpseYB57s/c=; b=SJ0531LXAemNZ1GIz5sagE2xgSkBMXVxcEIlJmddwuN628L8g0zk2ppIdHivRqYPPfZ46RNCHTimtxacwWLcMSpLS83seuPQjVOE7UGjc/KSWE6RzBbi9ymVm+uHWrI+9hQ8Ba95eIBxG4KePIj7bLhgtJq8bNsXSZJe5MhF7Nl/jDQFkT7LlJmZ7TEm0z8FYb3vgm8WNP0NjFwMEB1o59q4MIlbPmFcV84qN8YRpxoTJTgdOu8Pg/otGEPza0fe4nyBy3fFBDzMlfNWr59TNvnZ6qGsUkVCgHl7pP4Y7D5cddmR4XFmlzjICHUnikGwGRLx3NrWWEEIzkdY4U+6vg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hrIAx00ltq5uyB5+dfUERGseD5CmKDJ3dpseYB57s/c=; b=wJ6rIX2vzZGOjyZY//tIO3WnVuoHpAjWWJrMn7rnrVH6heZ+mWL6fazUVKcAMQeHv0VHdSBESyfDd2Zr5HnRRDG/V0zyOT0peN0UnESkvk6+B3fAXRFQcjTR2NUoloaOQSTZoTydCMy/WwvZdG68b1HXa87qAQVOmJblpd3i+jA= Received: from BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) by BN7PR10MB2514.namprd10.prod.outlook.com (2603:10b6:406:bd::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11; Thu, 10 Feb 2022 19:34:11 +0000 Received: from BLAPR10MB4835.namprd10.prod.outlook.com ([fe80::4910:964a:4156:242a]) by BLAPR10MB4835.namprd10.prod.outlook.com ([fe80::4910:964a:4156:242a%5]) with mapi id 15.20.4975.011; Thu, 10 Feb 2022 19:34:11 +0000 From: Joao Martins To: linux-mm@kvack.org Cc: Dan Williams , Vishal Verma , Matthew Wilcox , Jason Gunthorpe , Jane Chu , Muchun Song , Mike Kravetz , Andrew Morton , Jonathan Corbet , Christoph Hellwig , nvdimm@lists.linux.dev, linux-doc@vger.kernel.org, Joao Martins Subject: [PATCH v5 1/5] mm/sparse-vmemmap: add a pgmap argument to section activation Date: Thu, 10 Feb 2022 19:33:41 +0000 Message-Id: <20220210193345.23628-2-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220210193345.23628-1-joao.m.martins@oracle.com> References: <20220210193345.23628-1-joao.m.martins@oracle.com> X-ClientProxiedBy: LO2P265CA0170.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::14) To BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 04972d93-4dde-4cea-b7e4-08d9eccc5050 X-MS-TrafficTypeDiagnostic: BN7PR10MB2514:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NE14zuPA3pWZMm0MPGWCpUu2L0xWNH+Cg+sakIrFMbASIf19QSrz3Ke/hY4J02Vvj3hEHctK/EnsBr1bIrr0+hoy6VG1es90lZVPGJ0Jgu4n7kqo2eUT5e5XJkO3jqnawGb304nr9xrKkPskfLcMJvwxmu68rM3BN3VKn2zW8hNGNX20Lb/+DdpuYCKN6TT7N5sMgZYRrARNCrqRv6+lrwE0FMoAeafLxrBmuiNwP2Sx8mNWcywQuX8RZrWwcu03PCPRreaBbliXZ836IWHcJDOffO2R9UiPL2lFTLw/Xmtbe9pGPUydJLuK/NkUtuE6A9Ys6z6RUe8CSKVgROF3BC6iQSmtn4E5iqlqD1LcCYkWBnYqGiv3+C3c/EL7Xv6HZ2DYrTrRfVh4aQMpOwvoQsGxD3hS7einm9p4IcPM0IWnx4hOaznv4uzZ5bL9EC4at6PGejclheRdTYZnCQeNKrEw1DPiiFj1y7MHK+Sf1+fbwSXASs9gmhX6nHrDNJ4cICj3+wi6ZqRzGBMmO941ct7t784/ePGRRSpiGemI4wAmESZ32TzpArBBY5XZuCcom4wiTxn7hrIixlD77SXKMQg2s2ZK0pjRfwzmLZvewSCchhxmRLudmuuBqOJlAPgqKH+Jut9ZCwM17GM8GppcUa0YOqXW9V4WRaMbwhIwp8ohJOfaveOfYK7IVHzuEBPSLRyGRR4a4kcn/05aEAsmnx7Kn6tiXWm6UCdc8ycz7rjWcGgWamY5yhbE/qLzRnHhYRhvkHtBHEBaFqSRa4u1U7cYXuwVMcBzTpHvcLbxmVg= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BLAPR10MB4835.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(103116003)(66946007)(36756003)(66556008)(8676002)(2616005)(8936002)(316002)(7416002)(5660300002)(66476007)(83380400001)(4326008)(186003)(107886003)(26005)(54906003)(6916009)(1076003)(6506007)(2906002)(86362001)(508600001)(38100700002)(52116002)(38350700002)(6666004)(6486002)(6512007)(966005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: n/IPk+g58GHyp1rUoszCNU1EDHcvmmQxF/M7fYwOBerbKF76ymSBkoAjQOPgSy02GB/sStrABg3ByQTdiM7m0HBqxPnIVJNFg2/SGuh3UT0j7KkVnNU4QzAIo2NvDUQ3KDESAsVvjLFYhI3w9SVYuZohFXaLSlFr/lTdwUMTXTbazgRLFDgpXFCqQwwHL4TFX3xJ5hyZGh4PQpU+O/lLcZwD9/gtWlcnvojkbBPKVv07WcTIdM0uxKj5lqqt4Cb4VS2JhdlW3Y10E69S4YvJHvU4gnxJK1IKXnMoWeGoyO+smulBZIhRqLk58ZIrDD6IHLXWZqNYF+aorrrxfkCP8zA/FMKaCI+oio9ALGtfm5WhXOLDZLhC5mtLdRU04sE6SFUhS/UbQi+guBVN5/rJJ2G93T3GNUD6mJFjspSLdx+XfE090htndkWPBQ0CuoO07NauAyQM3Ng6SBlkIV2DFVqTZWZpzBcTppExflGVXtCJ8GFujUpxgt41QQwcNubG9zJCjye2XoQDN6ju7v2rV+1xD29Rw5tOMy0T5PsyMnGL5eNT7GLuB0pIrXzaDpofkMrRb6is3ryED3mrqx9dPTQOgDg1F6RNaNnF+oaqqwEkT5pvKvwQ6kB3Nei83YRFI3Oy2AqtLLuTNw3HgVLtRZYXMZMh9K+pLJCUZm8lWMxlnZSF7m5hLSEEJlhOJmgppt8OHU4mmS6n3x/W+DuNwvTM/VVRGZdSnKhR3vl9MwPzj2NLDSzo7fVfX4DO/p++djPT2h6R/W3wSdKLeOqJos4eyfkxxVllTa0giLCF7EfvZ/SvlW7VwBgUZnHz9kp3SvVdHqe8cWWYOWNfhsXbAt4p84FDXFTnQZtOU9xMDTThZTi/OmFhO2xZvI3Dp9VhW1tp9ig3Z7zljDbdRMLkcUCLBp1WwJMdSXRz0RT7UzOCeJjaBH1MmkjRvBd4GkJe39EJ1ULzb1qMdUUB5xjvyfIhLyjQtnRj4qvsm2dBcWvNC8kQXau3sKW3jJdM/N7Pw1LxvQcFUr6/j3rFiu7mEKM8jf1sPQXplH3Oc7SUvHi94GW5qLAGXNnARn+uxI9RWQAH6j+3/LM7RcpRa8qF4en9jLFsS0nDBZ1r/0//GZmNMILA8ZX6t+2uXxRpvubVKPMfLUqU3GOIjYpwxwUyNwA8y4iyFTWX6lblnNTx8IZNotfBQK2vJRgUogZcBjvm9IKlbBpOo6fE3HVbF+uQU7h0/tXxUYLwliH2nUm/S3qAhyC4iGjSTVIVItov7s3sO+0uXcLnkC/kQ2pCIuYYc73+5M/BHp4gOn8AL42oIAL21ty9M6UrCRaNa9S39QcKHLBNdKOMOpg0P2mabLDiFFMH505J2rl2gMAdWo52kapBbFjbwBjHl/Tq42w7j7LlbjCvrABsm2D9tkN90Z0diFgDoinIzRgDhN4rVofOsLGLZ+akApBUafvWyylQZ7pOeTIouDiP0I0JLticTfUE3zsxLQEdyWWAyBqmwDvALvZcYKvLWgPmbJKy7TZF1NfkELyU4a+gSjHNE6ZKgqSAh+A35eQqWnGFAxwYyEdvlMLhoqVL6RuU1lx0Kykn9Hs+fqB3rrg0Ee37txIi8kX9SlvsttMlc1NH6EoMDW0Rr7tJQYRx4XuzIlc7/1bC1E19NwS4P8bbsKbpvzvDk2LLWQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04972d93-4dde-4cea-b7e4-08d9eccc5050 X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB4835.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2022 19:34:11.6773 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: sziny4His2ayvklgfu+a6wOo+FIocaGxW6iQwI+d0os/zG6G08LkikOIL8HQhj8mZ4YAZkMadd08Li3pBcGNrHT2aR5/UVG7zDuTDfIGmdg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR10MB2514 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10254 signatures=673431 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 bulkscore=0 malwarescore=0 suspectscore=0 phishscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202100103 X-Proofpoint-ORIG-GUID: TjnM3-i_AHvgx35Ub_HK6WtDMOfEq2ff X-Proofpoint-GUID: TjnM3-i_AHvgx35Ub_HK6WtDMOfEq2ff In support of using compound pages for devmap mappings, plumb the pgmap down to the vmemmap_populate implementation. Note that while altmap is retrievable from pgmap the memory hotplug code passes altmap without pgmap[*], so both need to be independently plumbed. So in addition to @altmap, pass @pgmap to sparse section populate functions namely: sparse_add_section section_activate populate_section_memmap __populate_section_memmap Passing @pgmap allows __populate_section_memmap() to both fetch the vmemmap_shift in which memmap metadata is created for and also to let sparse-vmemmap fetch pgmap ranges to co-relate to a given section and pick whether to just reuse tail pages from past onlined sections. While at it, fix the kdoc for @altmap for sparse_add_section(). [*] https://lore.kernel.org/linux-mm/20210319092635.6214-1-osalvador@suse.de/ Signed-off-by: Joao Martins Reviewed-by: Dan Williams Reviewed-by: Muchun Song --- include/linux/memory_hotplug.h | 5 ++++- include/linux/mm.h | 3 ++- mm/memory_hotplug.c | 3 ++- mm/sparse-vmemmap.c | 3 ++- mm/sparse.c | 26 ++++++++++++++++---------- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 76bf2de86def..405aa2b4ae4f 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -15,6 +15,7 @@ struct memory_block; struct memory_group; struct resource; struct vmem_altmap; +struct dev_pagemap; #ifdef CONFIG_HAVE_ARCH_NODEDATA_EXTENSION /* @@ -122,6 +123,7 @@ typedef int __bitwise mhp_t; struct mhp_params { struct vmem_altmap *altmap; pgprot_t pgprot; + struct dev_pagemap *pgmap; }; bool mhp_range_allowed(u64 start, u64 size, bool need_mapping); @@ -335,7 +337,8 @@ extern void remove_pfn_range_from_zone(struct zone *zone, unsigned long nr_pages); extern bool is_memblock_offlined(struct memory_block *mem); extern int sparse_add_section(int nid, unsigned long pfn, - unsigned long nr_pages, struct vmem_altmap *altmap); + unsigned long nr_pages, struct vmem_altmap *altmap, + struct dev_pagemap *pgmap); extern void sparse_remove_section(struct mem_section *ms, unsigned long pfn, unsigned long nr_pages, unsigned long map_offset, struct vmem_altmap *altmap); diff --git a/include/linux/mm.h b/include/linux/mm.h index bf60d947503e..f6a439582f63 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3165,7 +3165,8 @@ int vmemmap_remap_alloc(unsigned long start, unsigned long end, void *sparse_buffer_alloc(unsigned long size); struct page * __populate_section_memmap(unsigned long pfn, - unsigned long nr_pages, int nid, struct vmem_altmap *altmap); + unsigned long nr_pages, int nid, struct vmem_altmap *altmap, + struct dev_pagemap *pgmap); pgd_t *vmemmap_pgd_populate(unsigned long addr, int node); p4d_t *vmemmap_p4d_populate(pgd_t *pgd, unsigned long addr, int node); pud_t *vmemmap_pud_populate(p4d_t *p4d, unsigned long addr, int node); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index ce68098832aa..79e96b6a9036 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -328,7 +328,8 @@ int __ref __add_pages(int nid, unsigned long pfn, unsigned long nr_pages, /* Select all remaining pages up to the next section boundary */ cur_nr_pages = min(end_pfn - pfn, SECTION_ALIGN_UP(pfn + 1) - pfn); - err = sparse_add_section(nid, pfn, cur_nr_pages, altmap); + err = sparse_add_section(nid, pfn, cur_nr_pages, altmap, + params->pgmap); if (err) break; cond_resched(); diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c index 8aecd6b3896c..c506f77cff23 100644 --- a/mm/sparse-vmemmap.c +++ b/mm/sparse-vmemmap.c @@ -641,7 +641,8 @@ int __meminit vmemmap_populate_basepages(unsigned long start, unsigned long end, } struct page * __meminit __populate_section_memmap(unsigned long pfn, - unsigned long nr_pages, int nid, struct vmem_altmap *altmap) + unsigned long nr_pages, int nid, struct vmem_altmap *altmap, + struct dev_pagemap *pgmap) { unsigned long start = (unsigned long) pfn_to_page(pfn); unsigned long end = start + nr_pages * sizeof(struct page); diff --git a/mm/sparse.c b/mm/sparse.c index 952f06d8f373..d2d76d158b39 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -427,7 +427,8 @@ static unsigned long __init section_map_size(void) } struct page __init *__populate_section_memmap(unsigned long pfn, - unsigned long nr_pages, int nid, struct vmem_altmap *altmap) + unsigned long nr_pages, int nid, struct vmem_altmap *altmap, + struct dev_pagemap *pgmap) { unsigned long size = section_map_size(); struct page *map = sparse_buffer_alloc(size); @@ -524,7 +525,7 @@ static void __init sparse_init_nid(int nid, unsigned long pnum_begin, break; map = __populate_section_memmap(pfn, PAGES_PER_SECTION, - nid, NULL); + nid, NULL, NULL); if (!map) { pr_err("%s: node[%d] memory map backing failed. Some memory will not be available.", __func__, nid); @@ -629,9 +630,10 @@ void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn) #ifdef CONFIG_SPARSEMEM_VMEMMAP static struct page * __meminit populate_section_memmap(unsigned long pfn, - unsigned long nr_pages, int nid, struct vmem_altmap *altmap) + unsigned long nr_pages, int nid, struct vmem_altmap *altmap, + struct dev_pagemap *pgmap) { - return __populate_section_memmap(pfn, nr_pages, nid, altmap); + return __populate_section_memmap(pfn, nr_pages, nid, altmap, pgmap); } static void depopulate_section_memmap(unsigned long pfn, unsigned long nr_pages, @@ -700,7 +702,8 @@ static int fill_subsection_map(unsigned long pfn, unsigned long nr_pages) } #else struct page * __meminit populate_section_memmap(unsigned long pfn, - unsigned long nr_pages, int nid, struct vmem_altmap *altmap) + unsigned long nr_pages, int nid, struct vmem_altmap *altmap, + struct dev_pagemap *pgmap) { return kvmalloc_node(array_size(sizeof(struct page), PAGES_PER_SECTION), GFP_KERNEL, nid); @@ -823,7 +826,8 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, } static struct page * __meminit section_activate(int nid, unsigned long pfn, - unsigned long nr_pages, struct vmem_altmap *altmap) + unsigned long nr_pages, struct vmem_altmap *altmap, + struct dev_pagemap *pgmap) { struct mem_section *ms = __pfn_to_section(pfn); struct mem_section_usage *usage = NULL; @@ -855,7 +859,7 @@ static struct page * __meminit section_activate(int nid, unsigned long pfn, if (nr_pages < PAGES_PER_SECTION && early_section(ms)) return pfn_to_page(pfn); - memmap = populate_section_memmap(pfn, nr_pages, nid, altmap); + memmap = populate_section_memmap(pfn, nr_pages, nid, altmap, pgmap); if (!memmap) { section_deactivate(pfn, nr_pages, altmap); return ERR_PTR(-ENOMEM); @@ -869,7 +873,8 @@ static struct page * __meminit section_activate(int nid, unsigned long pfn, * @nid: The node to add section on * @start_pfn: start pfn of the memory range * @nr_pages: number of pfns to add in the section - * @altmap: device page map + * @altmap: alternate pfns to allocate the memmap backing store + * @pgmap: alternate compound page geometry for devmap mappings * * This is only intended for hotplug. * @@ -883,7 +888,8 @@ static struct page * __meminit section_activate(int nid, unsigned long pfn, * * -ENOMEM - Out of memory. */ int __meminit sparse_add_section(int nid, unsigned long start_pfn, - unsigned long nr_pages, struct vmem_altmap *altmap) + unsigned long nr_pages, struct vmem_altmap *altmap, + struct dev_pagemap *pgmap) { unsigned long section_nr = pfn_to_section_nr(start_pfn); struct mem_section *ms; @@ -894,7 +900,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn, if (ret < 0) return ret; - memmap = section_activate(nid, start_pfn, nr_pages, altmap); + memmap = section_activate(nid, start_pfn, nr_pages, altmap, pgmap); if (IS_ERR(memmap)) return PTR_ERR(memmap); From patchwork Thu Feb 10 19:33:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 12742393 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B41332C9C for ; Thu, 10 Feb 2022 19:34:31 +0000 (UTC) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21AIgT8p008856; Thu, 10 Feb 2022 19:34:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=PwnPQYIZdOCPjNf7fzJaR+OCsfM2kLlldnauC3kDIjQ=; b=xgIiGVOpMk88rWKhu5oUiZZX6sRVe9j+FhwngDrTRNhDKhUY5PydpIuMF9Mpaaxv5oWq wvUuHIv1WOoT07FH7CK5Ton4FYkLQo6E2rNRHr9DDMT/Ro7rb7pv1SRZTmjzEGAHGLhN xmxmZWY9AcXwNNyNyLSH00M4vO6RAUDmXKliyoJCO7YQfl+ofWU+/IqSOOWNcgky0Hxl kMXzuq8hzJvtQMLowTLaPTPmLV1DGgy/C/AU04CheLPvJXpWfjs0XnuiS6iEuGuSe2XE C+OIg9eKzI6rD6zMVn2TM0CrLkLlElZlfFJE6GNsQT6ripnhTHAc5L30IoJmsleLWdMc aw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3e3fpgscat-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Feb 2022 19:34:18 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 21AJUWth120837; Thu, 10 Feb 2022 19:34:16 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2175.outbound.protection.outlook.com [104.47.58.175]) by userp3020.oracle.com with ESMTP id 3e1jpw3cks-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Feb 2022 19:34:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cGofokYmvceonay8XXRjdTtbS8NSPFuVeqQuCWJLZ1hgQ7Nk9GVm4MOAjrVM+isbgX2daJNKmgBI4tcOWqxn3wSu7yij53RuYl/Lpbx3k3lf7q7QgrsZfRJ+iOifMihHVDnyPNLlPWmGHxOP/f7+T3hU+n+JZjtr9qjzhAY/8vqZNRcKAd/t29HYq78mF4rCVh5daV9+6Ke3eO2EpoLqhAJC6f6S0OgAkM33PXgo4o7nmh1Kg4+e0t7vQ2FNI8sHuHxNxGPeA+GCfPWo2CnYLuEHX7p80g7FPV4zRgDemfBIz7b+2k40qUhY4dXwktyLdTJAXcddQFquCAngbhEPZg== 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=PwnPQYIZdOCPjNf7fzJaR+OCsfM2kLlldnauC3kDIjQ=; b=ARjR8udiRmYMEztLNUH/0CyjySIL1OAax2HeoJ5jYc7WBPhOkd/BVk3JsGv3CKfQKsFtUyOF3Qk7KHeyu53fAyipXahYhmbBUspKYEPgQYHYQ11ABtWz+MdzRwFfe0v5uS0WT2MYrCzA50+wDjw9Y/NhpKll+cFAAyX6TEz6772C78gp9KpKtqIbykDCYtxqizbHlsThxfEOSYo6HRbgdLOSX4snJWxAVngWVdgUIDu9UyjkKV4ZhW0tD/9GhoxqAwFaRgXw2XZeEIb8H4dTp5iFSvJ0eYDqEt/ysW7KuSQvEcRGXByLGOIVQjdgkpy/369p2PvLN7u4rRknskNfXg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PwnPQYIZdOCPjNf7fzJaR+OCsfM2kLlldnauC3kDIjQ=; b=Y3gHuVOsO/8pTP5luC0/x0QqtS/GwDVZ6zEqZtXfDUwsLWkqqrukI5jWD3QFlWu4HWiKEZwWK2OAXAqK7k7F7xjW70LgVrxCqF60C80SKvgE3DOT0/5zgI5QZlNHx3E2+VXgnZCv8LJZQ2H+JR5NbRL8KUN1xd9J69Tkz3OdJ3c= Received: from BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) by BN7PR10MB2514.namprd10.prod.outlook.com (2603:10b6:406:bd::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11; Thu, 10 Feb 2022 19:34:14 +0000 Received: from BLAPR10MB4835.namprd10.prod.outlook.com ([fe80::4910:964a:4156:242a]) by BLAPR10MB4835.namprd10.prod.outlook.com ([fe80::4910:964a:4156:242a%5]) with mapi id 15.20.4975.011; Thu, 10 Feb 2022 19:34:14 +0000 From: Joao Martins To: linux-mm@kvack.org Cc: Dan Williams , Vishal Verma , Matthew Wilcox , Jason Gunthorpe , Jane Chu , Muchun Song , Mike Kravetz , Andrew Morton , Jonathan Corbet , Christoph Hellwig , nvdimm@lists.linux.dev, linux-doc@vger.kernel.org, Joao Martins Subject: [PATCH v5 2/5] mm/sparse-vmemmap: refactor core of vmemmap_populate_basepages() to helper Date: Thu, 10 Feb 2022 19:33:42 +0000 Message-Id: <20220210193345.23628-3-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220210193345.23628-1-joao.m.martins@oracle.com> References: <20220210193345.23628-1-joao.m.martins@oracle.com> X-ClientProxiedBy: LO2P265CA0170.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::14) To BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7f1f4f99-4bd6-4f77-54ea-08d9eccc51b6 X-MS-TrafficTypeDiagnostic: BN7PR10MB2514:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3631; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WR4HTiH7AclO07Zs66qh9Q/MKEQ0zcNcIdYDClN62QOU0Gon2dw/ZMQDUHyQNBYbVNCPqLvN1LvSlQlEoyTZW03BGiNTw2Vk0kEl6Kq6TLMz56h8na5fGKmcF+hn/kHFcV+riwD/C7v5445mnUGUQg8lFbiro5NG4xILlSI5gJAckiAN/IFBYAEapspRrD4Hc5ShIAC2OCA/wx6+ao7gp7f2J6deseGlvgCnpiTD+hlwbnsLrTbxXsUllrDo+iEp45gTfkcfmSB2slPHpVzpIIf0e7GdPq/DLiXaWEBgblpcKhqoFcNDi/hCCkD3NIwLAnlXvxpPjVAt0fkuYDut5G59FIPdEOvVt5kmGOGOBXluc9uPdH0DtybaitfHmrG43+PFa7g+D4FbfwUd6P2v5ETlujvfbvHoYs4NUKoitiEBto86CReVXJZXch2ROq1VR8V83pse+TvZ4c4tUQjDTWKHuLb/4N22Jm6SjEiUg2gUTGmBF/osscBFz6vUVdA/S+K3+1wrM+S7THNqBjnG+p9xDdLGYSfIzJvXgBYd/MHckWzdcBbkPnzbKGlqLWJV6U4I9W/bAX0EVoNblr2SjL2P0HprhxgMEklvooNPrqm8v/HNTOAcr5Qn5aTWhykP9GBTI6BWBviNMeoFN2iYbZtPGRqb/cmcH7+egV+orZ9n2MeGUKRara+E8bnZ5KPDygcGAKpWiB1MS/0txuXumQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BLAPR10MB4835.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(103116003)(66946007)(36756003)(66556008)(8676002)(2616005)(8936002)(316002)(7416002)(5660300002)(66476007)(83380400001)(4326008)(186003)(107886003)(26005)(54906003)(6916009)(1076003)(6506007)(2906002)(86362001)(508600001)(38100700002)(52116002)(38350700002)(6666004)(6486002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Z1NlGhtf1iRHF+HVVMRVFGG9MRGy8OLQn0kQEsU4heOEnav4SihARxbX87xnL2aW+iTihAjxL6qHZEEeJJcyCsROxLdzrUsg8JtJ/8EW4RzrylC2QpJMOZv+wGjj3myobuj75+Lao9I1EsaWaYiP1b/RHtpT4ZzpCYkEEOCaCsXV4TqXOClFB3+QrflsImxzFUoB/ttfwfT1V2tXOQf2w5jTxVBcLS13pEuCDPvhSZQ3DiedrlIw3aOP94+Gf02l//+HiVzrjMK0Fe2R1Ev5dD+4frYNny88HAo203NGPUNkOVzBPfz+dyvC97jtaTd8oYtpqufxaKX5GWvC6i2bDWSWsK/Wy+58XfusFU9ZocUxA4CMiPVEqMayV1Vz+bpYncKtsU/SiFPlAf0hQXKaRaazgm3EP/nqke6MNKRHzF14IRIi4tETduGzEKDL9RpTgrZqC/CxT2Pp8L+6j3aBeCy2jirYTHxbTP5nwM0Nuz2AcaerKG3YHjaiW1tzTUprcV05mjrHhrsl0Po8ehWBx4Hw4q6Yp4duLGe4MSbWo2TzBRy6//EjxlUUuLykLHwJmRpwUbLKfW9CVMmadchVfNd1damZXtk9SdSj5EXEEo9kpzjiNGVZigzet31PLxmWKiJc1zWzryw7StSLiD7y+wXrZ253rTlwLtlb+lJrfMxy49HWHg/Fk1o3D8B0wty3iNe4sNGf0RI7Wik0vXYigs6doalRwVeAzL9vNxvJdmG2aW7kVDh0Hd0MjX+57MeKB1AM4VCUG7+zcPVBYnKt1MBM7nc6GZtK+2MFLnxONc6jh/G9H/pI6X2nHGUay2q/80PTnn5BAlZ6Ll020ij2DC5TDE55BhDrdPuIQAlWoSvSQJIcsklgyXkMtNUoH2aW5D6LGfZJXayN/aZmD28CBcH3zDat3qHVxJbN52q8557WtWPVSQZ3mCgpdxTTm2dWKUxKfGG+Ibed9XnHo60+2n+hhcqXTyllYpahiXTeT+W2Bg2j8kO+0j18IJfY5HXGN1Wq3GIJ/XLZO2mBIHdMK2AuIV92jMX4F8MK2ABeWMO9B3g6Cj5NOFtCxz+zFMJIKoO3vISzrQZh+/wIRbW/DqtAHyDauzGxTBPSoSGLNRvrQOUtBlhBdN7U4M199/8RgCbQkHs6qEAL6FeCacYaCjh5hpzwYhVMBZmhwt/1XKhJqH9gQHVlYOkDZYEtQ+bSfwIxncH42NabiwiCVpsYEWlpJndFK8s2t9xywHwhrFaV+y44tNpFq67bOKAGLbPshJgLkVpgMMYzmH4HJ8DUso/y+KzhUB/ZojGAvxWBikU+vaP/gsWbz7uKwUI3T/xZTm5GzYALWsyLLVfCak1cP3+SJDy/ynx2ft/0HnbCBqOGNkvnEDQozIXnjpWR4OUU/vMRX2aKs8Z1Tf+AdSG6U23zw2Ug0faOL8YLsUv/CclSuYeC0ozDUoVEUkoavED4GrzU1nvqw7eTboLwlOe7yYrSCC9/8M/R6IO08JVQfCkqyeCMe8z+MoQ/1L19FelcMm1G+dAByII61poa2TWtc7OZGmg9hix1f/L+sWxJ05TUjFDlx8EEQnAIEcUm4/jHDUAxvJ+VkWtsEUYoWAc/5ElSOWm7/FWqXV8R/AIy/gQAgFZ/bRFNnfP06RWAeembRwmrh0zs7euYDWB8HR/nfQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f1f4f99-4bd6-4f77-54ea-08d9eccc51b6 X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB4835.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2022 19:34:14.0378 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DL0Lb5qMjLEoABWmDI+25Xlk5lmonm+tkj1puNgjcSWzEUBpPWOAjUsjwnIKwS88lzcqm9BKFmmLuZxQuPDhc4laoAqU2L8eRJFtj1NjhnE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR10MB2514 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10254 signatures=673431 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=974 mlxscore=0 bulkscore=0 malwarescore=0 suspectscore=0 phishscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202100103 X-Proofpoint-GUID: 3DQoNGBrEwfav0q-baaaFoOoq0K3OpEH X-Proofpoint-ORIG-GUID: 3DQoNGBrEwfav0q-baaaFoOoq0K3OpEH In preparation for describing a memmap with compound pages, move the actual pte population logic into a separate function vmemmap_populate_address() and have vmemmap_populate_basepages() walk through all base pages it needs to populate. Signed-off-by: Joao Martins --- mm/sparse-vmemmap.c | 51 ++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c index c506f77cff23..e7be2ef4454b 100644 --- a/mm/sparse-vmemmap.c +++ b/mm/sparse-vmemmap.c @@ -608,33 +608,46 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node) return pgd; } -int __meminit vmemmap_populate_basepages(unsigned long start, unsigned long end, - int node, struct vmem_altmap *altmap) +static int __meminit vmemmap_populate_address(unsigned long addr, int node, + struct vmem_altmap *altmap) { - unsigned long addr = start; pgd_t *pgd; p4d_t *p4d; pud_t *pud; pmd_t *pmd; pte_t *pte; + pgd = vmemmap_pgd_populate(addr, node); + if (!pgd) + return -ENOMEM; + p4d = vmemmap_p4d_populate(pgd, addr, node); + if (!p4d) + return -ENOMEM; + pud = vmemmap_pud_populate(p4d, addr, node); + if (!pud) + return -ENOMEM; + pmd = vmemmap_pmd_populate(pud, addr, node); + if (!pmd) + return -ENOMEM; + pte = vmemmap_pte_populate(pmd, addr, node, altmap); + if (!pte) + return -ENOMEM; + vmemmap_verify(pte, node, addr, addr + PAGE_SIZE); + + return 0; +} + +int __meminit vmemmap_populate_basepages(unsigned long start, unsigned long end, + int node, struct vmem_altmap *altmap) +{ + unsigned long addr = start; + int rc; + for (; addr < end; addr += PAGE_SIZE) { - pgd = vmemmap_pgd_populate(addr, node); - if (!pgd) - return -ENOMEM; - p4d = vmemmap_p4d_populate(pgd, addr, node); - if (!p4d) - return -ENOMEM; - pud = vmemmap_pud_populate(p4d, addr, node); - if (!pud) - return -ENOMEM; - pmd = vmemmap_pmd_populate(pud, addr, node); - if (!pmd) - return -ENOMEM; - pte = vmemmap_pte_populate(pmd, addr, node, altmap); - if (!pte) - return -ENOMEM; - vmemmap_verify(pte, node, addr, addr + PAGE_SIZE); + rc = vmemmap_populate_address(addr, node, altmap); + if (rc) + return rc; + } return 0; From patchwork Thu Feb 10 19:33:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 12742396 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 274C42CA7 for ; Thu, 10 Feb 2022 19:34:33 +0000 (UTC) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21AHhrLY013393; Thu, 10 Feb 2022 19:34:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=rBZFKXBhUVcGaQee2IQyxW+Dj+TwY1lOwgsfsaR1Dgs=; b=h9iiemJXgAHtCnZbOUqbjEZrX+1jMccVF+3i6Ihza+BCbJRAV6vodC7md+inIyv+VnY+ J2PD9Bab5Gbe1YmRrnTUee9PVqMopmVE8osT78yMp4dcITaxi5oZA+v5qPwCriBm9efI ziPAPAZzhJk3I1ZGwxJqbAbbqMO9mIfR6Z3D7fOCrCv3ykKZau3hJFlrRpcMdqiKrbM3 mBwVQONufDW4h8+wdPsr5r4Zox/sr0fZfMpWPVGavlTwcns8C4G/e30BT8KdjUGpiS7A W7i5WonsPcUA2kkjU2Jluwpdbbe74hL8+MlwK3g/wqPdryOgayMlHBxmz6VkXLQjJz1K gA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3e368u254b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Feb 2022 19:34:20 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 21AJWDqx001616; Thu, 10 Feb 2022 19:34:19 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2170.outbound.protection.outlook.com [104.47.58.170]) by aserp3030.oracle.com with ESMTP id 3e51rtw73h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Feb 2022 19:34:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YEyvHE+l0QS6tSoYL+SmLoJtJseUUabfjTW0D/0QELcDs0fmFW2+jFr0QonRmd7re9V/9i/KxStEG/5XPqQFSKCOKNq9QbmdO8TmM1bjCWIO7fjkgVAvKoLpCVo6HQ1fokJ2550McUsw61+DURh74XYwaYIPxHygC4ZpISq9PHXp/3kCnfsScscvqmArIAvDwKaQNpbVKcIjXIlePHU6AYeqpc1PLLdOQDPynymGJ6rwhKweylHADQRMBtZeaWw2dMsJWwceQT8HAi3dmdto+kZ5Yku6uJ7Q5ZGuFMivQGCc5aJib9sk1Bpc2VcDJ6PgZjIpsc/EAoGIvIdfEKLq6w== 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=rBZFKXBhUVcGaQee2IQyxW+Dj+TwY1lOwgsfsaR1Dgs=; b=dcicEJmedNfzBC6+aaQrTw0PdtisZGLXHpNovMQHVoOaYhLn3fK+xDK5UqX1Vg/IFckqEmSBHecINl7u61Mb7SD0Ua0TeP0iIXvPb4HFQI1e6Pa/oni+OjPS+X/Z2e8MO742Tgy7G08gXKKOYHY0hvc9gxHHzNhYwC0JnWh7t7WLVBiSpvtOwokBlFToF6WYfjhSV8shofeAj9ykmrvVeVJsyNpOd5ZuGHbPfETqVMvQ/zS+ktUoFHhHyTmctYKqUvaGn61jhcSI4J44P5AnYoICwRtKcWIwJ36bWr/B9Si+pwklQ0P7nubodvYRdt0fge3M8nNliV9nvdwUqUvpEA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rBZFKXBhUVcGaQee2IQyxW+Dj+TwY1lOwgsfsaR1Dgs=; b=fxpuVKVDcmwCpBYmV+FixmSzmyQiTnIF12hlasWrvrk9k1BMKlTEIzWKxbpeBLutojSSTukENzYwCBHDJyzJjpS0s9PSaU2YpcfBi0yzPTibPZ/mG43pHEgY5t7oa+uBp1EJwTY6qdciwo8SvXMYR0xbWp0s3G58yhuHT0rTtjQ= Received: from BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) by BN7PR10MB2514.namprd10.prod.outlook.com (2603:10b6:406:bd::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11; Thu, 10 Feb 2022 19:34:16 +0000 Received: from BLAPR10MB4835.namprd10.prod.outlook.com ([fe80::4910:964a:4156:242a]) by BLAPR10MB4835.namprd10.prod.outlook.com ([fe80::4910:964a:4156:242a%5]) with mapi id 15.20.4975.011; Thu, 10 Feb 2022 19:34:16 +0000 From: Joao Martins To: linux-mm@kvack.org Cc: Dan Williams , Vishal Verma , Matthew Wilcox , Jason Gunthorpe , Jane Chu , Muchun Song , Mike Kravetz , Andrew Morton , Jonathan Corbet , Christoph Hellwig , nvdimm@lists.linux.dev, linux-doc@vger.kernel.org, Joao Martins Subject: [PATCH v5 3/5] mm/hugetlb_vmemmap: move comment block to Documentation/vm Date: Thu, 10 Feb 2022 19:33:43 +0000 Message-Id: <20220210193345.23628-4-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220210193345.23628-1-joao.m.martins@oracle.com> References: <20220210193345.23628-1-joao.m.martins@oracle.com> X-ClientProxiedBy: LO2P265CA0170.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::14) To BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7f1739e5-d985-47ad-c346-08d9eccc5350 X-MS-TrafficTypeDiagnostic: BN7PR10MB2514:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qsU0KR4YXh7zPEbObvxjbWihcZ/RTX9jIZyKaCxc9gryQcLeISQRC2/TKGyO7TMpQMokOSHjr7s6aotrHKP88OUpZy/dpllsnrur6zE1j0qIGVjMbhZsuAW8k+/mvNF4l3feffAcfKLDEJqNPpL7iNiSCKUSLk6iAYab8EbazDT/z4+UFhUs/VNTjhikts7xn0ZL6M+IBUiKj4Pm9vCm/cnWmJ4rltbIaIg7OUPo8f1NT46CbeYVRTCxDjW+lP2giQnRfPsTeajqpuNfG89jAM8IMDNWDQs4bIwDM8sE1et8P7jMhei8GuDQZd+k0/a+Scfao4ADI3c3JBcr/yw21bBnbEjfqqwQwHFnZ3k8Z/OZktvjBWL9A6KkgSzSkBenR2Cn+j3oHJENV41g7f6+56zCCDBeldrELuiNNh2KyTC5sGSWVlmgbXOfbwFa/8HfpWUVKY/6NIyLvAKto1Uve1hpOenV7iqAZUvSIwz3nMmQZKcdvOqr4a2/Xk27K2HUDmKRqP5mTLCVYl4VJljydK0tNRNlbbR+iXwMEvDUUBnIFpfmg00QkZIzFIOBbKwXVeUZqkMcNmq7JejnB5h/6VtC1NM7xtgIoerzB9+pgS5NVDyY3bvRarKf4IbMYwG4hujP00T6bShOEhiCSQyqinbMh8vaHxAypv/tKvsEnFsB149pCPlzPde17spAZ0LpJFmdGhfTsM+WHY1rUWW+pA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BLAPR10MB4835.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(103116003)(66946007)(36756003)(66556008)(8676002)(2616005)(8936002)(316002)(7416002)(5660300002)(66476007)(30864003)(83380400001)(4326008)(186003)(107886003)(26005)(54906003)(6916009)(1076003)(6506007)(2906002)(86362001)(508600001)(38100700002)(52116002)(38350700002)(6666004)(6486002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mITWNu8dMMSaQcAvBUOlOBaBjrpt7hMKJaJ3CWfdCnCLC3sHAOGjWBm3Yo9TN+mzsKi8dIQ/sDAUgOBKo2d4x0wbDy1qAy6db7SxKxkukKBnwsKzWTdsUQW9RNmXftUB9vhOXxdkRaCp3HR9HBiOU/b0f6gKh/0MTwyqEhIyu4vXUjmx5dfqe3FwM4Lcq24QvuyMzHZTvD+Id9Ms0GslomhQfB/vkbB1sVsa1VrmRkIooP+ZQRqTNGI4WdX6ZliUJt7peVkmfAJ0Bx+L8nHZ6dTa32r52oE/68xzZcuE4N/b1u0B54nKsk+SMpcvCWlA0+yrEfRizOegrgSq1f3oxINwkzMtfiWdYU6w4krc/GxcUsD/iFPZkfyayDktPeq0+TS8tkzQ85+xsR3ntYdjViY1ht5kv09xDnSWVP03GGrMRSkfiz6+6SL53Y8feJgFQjKpvsB8nEiSA/Os7YysgEy362ENKnquDU8TJ7PllwPqyFsizR9Fa+hTZTqirE37SuHHEtgJI8jqxa5kfuSP5mZKV1i7mOIVNGl42oRwoW4Sws7Jq7xzHSe4k5Qi9WAPf5gWyKHI3WD3mTxq0rcvZSbSUuzUAii82Jj6FE6x5vppCmQRd416Tz12bo4eYlIe25TThk4j6EkaZjz8xzAsJ7tKup5OCetZrK68QVcJANveLHlWMy4993dtoirVsNOkZVkSfNjiigy5fsEZK2rO3dc4nYcC+HEZI7ruhTbbJAPP+1OeifqPaCV83NKfd9aIiC59oiJTZp0cU51ZqcUjNKf5rc84J5Os1ha7ciPFirJE22yphJMyld4RpDXvBPvcDpHAPDb9L9Vb/0Xg704mLQfVJ9kXPvo/Wa9xD0aCxhQookyh3kCFybWwoZYvh4AZND9GuQCkaKR4giPGpF0zoebALApLGS9gBxGDAVUqa+/GZrcln+SyMO04ZNJKwDiYqk2iVu6I90+SRS2n5fSSgAnq+0A7mAcdAaTLbA7ltQzdiE+foHH4LdZWqdpzgCEvk0Z+rxSAZ36lwjw+oPbgECJz7wLJKd0Fm/ixEOvKDxkrgO/PDV3DeJ2r59DViuPt0F68Xz3sdUnUd4KqAJ51VfwcYr3Vmym6ynoUZDZjH/egKd7RSeSIRa+Gmrch7AFBfHZ16/eCy2Jtxg1FpoMDPfe/tznw2/v6GwJGhIjie3jsTZdKelKDP+VhktwH9yJ0jpTcEuZ6cqItbZ9dadTZ4W+j5gEvOMMXtkkDSh9j94BJ4CLnstHpFNOkYCQalM8kEj2KmRQCTUfOYjWzSz+QS34j4COM4UMU73p6xB6ukIr5AZuw/D2WxYun1UipqNy0NRvhGfeOwAuZOsje+C8DerZfsPl9NJDa2li+jownOJcpTGOPfo2hSn/XbL/NHkWnIW7ObL76McWLdn6fyu6uBa015AQX/yMWAzT3Of6BJdtnLNPeaU8fOWGL6ABaXjnCQ24yBoHb7gb8pirPpvm+Xr+iuie/OWI8MBLJE+1YlI898XHCz7XDYBKRXhpNV/vjnHRzpTe/cNN5jNylQa2lRk+criz5iG9hnv7uuuJTcFotrOvw9rDo1U6Gt1TmKKt/I99Ei9VJSWLkrumwp0z+QvhI7j3QhSqunHtYDQhdfHBMinCk3EzEjgwuPNP5FgUJ07iKsx0yA8A2p3BOrmLMOg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f1739e5-d985-47ad-c346-08d9eccc5350 X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB4835.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2022 19:34:16.7732 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LCQCrK/J2MS/bO1v2pNfUGc6HTiSFhdjX8/k55HblN1UvHyWaC9y7VKPK3BnBsBl0Zyug00q/HjYgBPJa0Z/p4Ku1igm23bqW8XOPj2B1Tg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR10MB2514 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10254 signatures=673431 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 suspectscore=0 adultscore=0 malwarescore=0 bulkscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202100103 X-Proofpoint-ORIG-GUID: -BpEKEcrf3FNtH14b2Z75BLsG6x6OILU X-Proofpoint-GUID: -BpEKEcrf3FNtH14b2Z75BLsG6x6OILU In preparation for device-dax for using hugetlbfs compound page tail deduplication technique, move the comment block explanation into a common place in Documentation/vm. Cc: Muchun Song Cc: Mike Kravetz Suggested-by: Dan Williams Signed-off-by: Joao Martins Reviewed-by: Muchun Song Reviewed-by: Dan Williams --- Documentation/vm/index.rst | 1 + Documentation/vm/vmemmap_dedup.rst | 175 +++++++++++++++++++++++++++++ mm/hugetlb_vmemmap.c | 168 +-------------------------- 3 files changed, 177 insertions(+), 167 deletions(-) create mode 100644 Documentation/vm/vmemmap_dedup.rst diff --git a/Documentation/vm/index.rst b/Documentation/vm/index.rst index 44365c4574a3..2fb612bb72c9 100644 --- a/Documentation/vm/index.rst +++ b/Documentation/vm/index.rst @@ -37,5 +37,6 @@ algorithms. If you are looking for advice on simply allocating memory, see the transhuge unevictable-lru vmalloced-kernel-stacks + vmemmap_dedup z3fold zsmalloc diff --git a/Documentation/vm/vmemmap_dedup.rst b/Documentation/vm/vmemmap_dedup.rst new file mode 100644 index 000000000000..8143b2ce414d --- /dev/null +++ b/Documentation/vm/vmemmap_dedup.rst @@ -0,0 +1,175 @@ +.. SPDX-License-Identifier: GPL-2.0 + +.. _vmemmap_dedup: + +================================== +Free some vmemmap pages of HugeTLB +================================== + +The struct page structures (page structs) are used to describe a physical +page frame. By default, there is a one-to-one mapping from a page frame to +it's corresponding page struct. + +HugeTLB pages consist of multiple base page size pages and is supported by +many architectures. See hugetlbpage.rst in the Documentation directory for +more details. On the x86-64 architecture, HugeTLB pages of size 2MB and 1GB +are currently supported. Since the base page size on x86 is 4KB, a 2MB +HugeTLB page consists of 512 base pages and a 1GB HugeTLB page consists of +4096 base pages. For each base page, there is a corresponding page struct. + +Within the HugeTLB subsystem, only the first 4 page structs are used to +contain unique information about a HugeTLB page. __NR_USED_SUBPAGE provides +this upper limit. The only 'useful' information in the remaining page structs +is the compound_head field, and this field is the same for all tail pages. + +By removing redundant page structs for HugeTLB pages, memory can be returned +to the buddy allocator for other uses. + +Different architectures support different HugeTLB pages. For example, the +following table is the HugeTLB page size supported by x86 and arm64 +architectures. Because arm64 supports 4k, 16k, and 64k base pages and +supports contiguous entries, so it supports many kinds of sizes of HugeTLB +page. + ++--------------+-----------+-----------------------------------------------+ +| Architecture | Page Size | HugeTLB Page Size | ++--------------+-----------+-----------+-----------+-----------+-----------+ +| x86-64 | 4KB | 2MB | 1GB | | | ++--------------+-----------+-----------+-----------+-----------+-----------+ +| | 4KB | 64KB | 2MB | 32MB | 1GB | +| +-----------+-----------+-----------+-----------+-----------+ +| arm64 | 16KB | 2MB | 32MB | 1GB | | +| +-----------+-----------+-----------+-----------+-----------+ +| | 64KB | 2MB | 512MB | 16GB | | ++--------------+-----------+-----------+-----------+-----------+-----------+ + +When the system boot up, every HugeTLB page has more than one struct page +structs which size is (unit: pages): + + struct_size = HugeTLB_Size / PAGE_SIZE * sizeof(struct page) / PAGE_SIZE + +Where HugeTLB_Size is the size of the HugeTLB page. We know that the size +of the HugeTLB page is always n times PAGE_SIZE. So we can get the following +relationship. + + HugeTLB_Size = n * PAGE_SIZE + +Then, + + struct_size = n * PAGE_SIZE / PAGE_SIZE * sizeof(struct page) / PAGE_SIZE + = n * sizeof(struct page) / PAGE_SIZE + +We can use huge mapping at the pud/pmd level for the HugeTLB page. + +For the HugeTLB page of the pmd level mapping, then + + struct_size = n * sizeof(struct page) / PAGE_SIZE + = PAGE_SIZE / sizeof(pte_t) * sizeof(struct page) / PAGE_SIZE + = sizeof(struct page) / sizeof(pte_t) + = 64 / 8 + = 8 (pages) + +Where n is how many pte entries which one page can contains. So the value of +n is (PAGE_SIZE / sizeof(pte_t)). + +This optimization only supports 64-bit system, so the value of sizeof(pte_t) +is 8. And this optimization also applicable only when the size of struct page +is a power of two. In most cases, the size of struct page is 64 bytes (e.g. +x86-64 and arm64). So if we use pmd level mapping for a HugeTLB page, the +size of struct page structs of it is 8 page frames which size depends on the +size of the base page. + +For the HugeTLB page of the pud level mapping, then + + struct_size = PAGE_SIZE / sizeof(pmd_t) * struct_size(pmd) + = PAGE_SIZE / 8 * 8 (pages) + = PAGE_SIZE (pages) + +Where the struct_size(pmd) is the size of the struct page structs of a +HugeTLB page of the pmd level mapping. + +E.g.: A 2MB HugeTLB page on x86_64 consists in 8 page frames while 1GB +HugeTLB page consists in 4096. + +Next, we take the pmd level mapping of the HugeTLB page as an example to +show the internal implementation of this optimization. There are 8 pages +struct page structs associated with a HugeTLB page which is pmd mapped. + +Here is how things look before optimization. + + HugeTLB struct pages(8 pages) page frame(8 pages) + +-----------+ ---virt_to_page---> +-----------+ mapping to +-----------+ + | | | 0 | -------------> | 0 | + | | +-----------+ +-----------+ + | | | 1 | -------------> | 1 | + | | +-----------+ +-----------+ + | | | 2 | -------------> | 2 | + | | +-----------+ +-----------+ + | | | 3 | -------------> | 3 | + | | +-----------+ +-----------+ + | | | 4 | -------------> | 4 | + | PMD | +-----------+ +-----------+ + | level | | 5 | -------------> | 5 | + | mapping | +-----------+ +-----------+ + | | | 6 | -------------> | 6 | + | | +-----------+ +-----------+ + | | | 7 | -------------> | 7 | + | | +-----------+ +-----------+ + | | + | | + | | + +-----------+ + +The value of page->compound_head is the same for all tail pages. The first +page of page structs (page 0) associated with the HugeTLB page contains the 4 +page structs necessary to describe the HugeTLB. The only use of the remaining +pages of page structs (page 1 to page 7) is to point to page->compound_head. +Therefore, we can remap pages 1 to 7 to page 0. Only 1 page of page structs +will be used for each HugeTLB page. This will allow us to free the remaining +7 pages to the buddy allocator. + +Here is how things look after remapping. + + HugeTLB struct pages(8 pages) page frame(8 pages) + +-----------+ ---virt_to_page---> +-----------+ mapping to +-----------+ + | | | 0 | -------------> | 0 | + | | +-----------+ +-----------+ + | | | 1 | ---------------^ ^ ^ ^ ^ ^ ^ + | | +-----------+ | | | | | | + | | | 2 | -----------------+ | | | | | + | | +-----------+ | | | | | + | | | 3 | -------------------+ | | | | + | | +-----------+ | | | | + | | | 4 | ---------------------+ | | | + | PMD | +-----------+ | | | + | level | | 5 | -----------------------+ | | + | mapping | +-----------+ | | + | | | 6 | -------------------------+ | + | | +-----------+ | + | | | 7 | ---------------------------+ + | | +-----------+ + | | + | | + | | + +-----------+ + +When a HugeTLB is freed to the buddy system, we should allocate 7 pages for +vmemmap pages and restore the previous mapping relationship. + +For the HugeTLB page of the pud level mapping. It is similar to the former. +We also can use this approach to free (PAGE_SIZE - 1) vmemmap pages. + +Apart from the HugeTLB page of the pmd/pud level mapping, some architectures +(e.g. aarch64) provides a contiguous bit in the translation table entries +that hints to the MMU to indicate that it is one of a contiguous set of +entries that can be cached in a single TLB entry. + +The contiguous bit is used to increase the mapping size at the pmd and pte +(last) level. So this type of HugeTLB page can be optimized only when its +size of the struct page structs is greater than 1 page. + +Notice: The head vmemmap page is not freed to the buddy allocator and all +tail vmemmap pages are mapped to the head vmemmap page frame. So we can see +more than one struct page struct with PG_head (e.g. 8 per 2 MB HugeTLB page) +associated with each HugeTLB page. The compound_head() can handle this +correctly (more details refer to the comment above compound_head()). diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 791626983c2e..dbaa837b19c6 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -6,173 +6,7 @@ * * Author: Muchun Song * - * The struct page structures (page structs) are used to describe a physical - * page frame. By default, there is a one-to-one mapping from a page frame to - * it's corresponding page struct. - * - * HugeTLB pages consist of multiple base page size pages and is supported by - * many architectures. See hugetlbpage.rst in the Documentation directory for - * more details. On the x86-64 architecture, HugeTLB pages of size 2MB and 1GB - * are currently supported. Since the base page size on x86 is 4KB, a 2MB - * HugeTLB page consists of 512 base pages and a 1GB HugeTLB page consists of - * 4096 base pages. For each base page, there is a corresponding page struct. - * - * Within the HugeTLB subsystem, only the first 4 page structs are used to - * contain unique information about a HugeTLB page. __NR_USED_SUBPAGE provides - * this upper limit. The only 'useful' information in the remaining page structs - * is the compound_head field, and this field is the same for all tail pages. - * - * By removing redundant page structs for HugeTLB pages, memory can be returned - * to the buddy allocator for other uses. - * - * Different architectures support different HugeTLB pages. For example, the - * following table is the HugeTLB page size supported by x86 and arm64 - * architectures. Because arm64 supports 4k, 16k, and 64k base pages and - * supports contiguous entries, so it supports many kinds of sizes of HugeTLB - * page. - * - * +--------------+-----------+-----------------------------------------------+ - * | Architecture | Page Size | HugeTLB Page Size | - * +--------------+-----------+-----------+-----------+-----------+-----------+ - * | x86-64 | 4KB | 2MB | 1GB | | | - * +--------------+-----------+-----------+-----------+-----------+-----------+ - * | | 4KB | 64KB | 2MB | 32MB | 1GB | - * | +-----------+-----------+-----------+-----------+-----------+ - * | arm64 | 16KB | 2MB | 32MB | 1GB | | - * | +-----------+-----------+-----------+-----------+-----------+ - * | | 64KB | 2MB | 512MB | 16GB | | - * +--------------+-----------+-----------+-----------+-----------+-----------+ - * - * When the system boot up, every HugeTLB page has more than one struct page - * structs which size is (unit: pages): - * - * struct_size = HugeTLB_Size / PAGE_SIZE * sizeof(struct page) / PAGE_SIZE - * - * Where HugeTLB_Size is the size of the HugeTLB page. We know that the size - * of the HugeTLB page is always n times PAGE_SIZE. So we can get the following - * relationship. - * - * HugeTLB_Size = n * PAGE_SIZE - * - * Then, - * - * struct_size = n * PAGE_SIZE / PAGE_SIZE * sizeof(struct page) / PAGE_SIZE - * = n * sizeof(struct page) / PAGE_SIZE - * - * We can use huge mapping at the pud/pmd level for the HugeTLB page. - * - * For the HugeTLB page of the pmd level mapping, then - * - * struct_size = n * sizeof(struct page) / PAGE_SIZE - * = PAGE_SIZE / sizeof(pte_t) * sizeof(struct page) / PAGE_SIZE - * = sizeof(struct page) / sizeof(pte_t) - * = 64 / 8 - * = 8 (pages) - * - * Where n is how many pte entries which one page can contains. So the value of - * n is (PAGE_SIZE / sizeof(pte_t)). - * - * This optimization only supports 64-bit system, so the value of sizeof(pte_t) - * is 8. And this optimization also applicable only when the size of struct page - * is a power of two. In most cases, the size of struct page is 64 bytes (e.g. - * x86-64 and arm64). So if we use pmd level mapping for a HugeTLB page, the - * size of struct page structs of it is 8 page frames which size depends on the - * size of the base page. - * - * For the HugeTLB page of the pud level mapping, then - * - * struct_size = PAGE_SIZE / sizeof(pmd_t) * struct_size(pmd) - * = PAGE_SIZE / 8 * 8 (pages) - * = PAGE_SIZE (pages) - * - * Where the struct_size(pmd) is the size of the struct page structs of a - * HugeTLB page of the pmd level mapping. - * - * E.g.: A 2MB HugeTLB page on x86_64 consists in 8 page frames while 1GB - * HugeTLB page consists in 4096. - * - * Next, we take the pmd level mapping of the HugeTLB page as an example to - * show the internal implementation of this optimization. There are 8 pages - * struct page structs associated with a HugeTLB page which is pmd mapped. - * - * Here is how things look before optimization. - * - * HugeTLB struct pages(8 pages) page frame(8 pages) - * +-----------+ ---virt_to_page---> +-----------+ mapping to +-----------+ - * | | | 0 | -------------> | 0 | - * | | +-----------+ +-----------+ - * | | | 1 | -------------> | 1 | - * | | +-----------+ +-----------+ - * | | | 2 | -------------> | 2 | - * | | +-----------+ +-----------+ - * | | | 3 | -------------> | 3 | - * | | +-----------+ +-----------+ - * | | | 4 | -------------> | 4 | - * | PMD | +-----------+ +-----------+ - * | level | | 5 | -------------> | 5 | - * | mapping | +-----------+ +-----------+ - * | | | 6 | -------------> | 6 | - * | | +-----------+ +-----------+ - * | | | 7 | -------------> | 7 | - * | | +-----------+ +-----------+ - * | | - * | | - * | | - * +-----------+ - * - * The value of page->compound_head is the same for all tail pages. The first - * page of page structs (page 0) associated with the HugeTLB page contains the 4 - * page structs necessary to describe the HugeTLB. The only use of the remaining - * pages of page structs (page 1 to page 7) is to point to page->compound_head. - * Therefore, we can remap pages 1 to 7 to page 0. Only 1 page of page structs - * will be used for each HugeTLB page. This will allow us to free the remaining - * 7 pages to the buddy allocator. - * - * Here is how things look after remapping. - * - * HugeTLB struct pages(8 pages) page frame(8 pages) - * +-----------+ ---virt_to_page---> +-----------+ mapping to +-----------+ - * | | | 0 | -------------> | 0 | - * | | +-----------+ +-----------+ - * | | | 1 | ---------------^ ^ ^ ^ ^ ^ ^ - * | | +-----------+ | | | | | | - * | | | 2 | -----------------+ | | | | | - * | | +-----------+ | | | | | - * | | | 3 | -------------------+ | | | | - * | | +-----------+ | | | | - * | | | 4 | ---------------------+ | | | - * | PMD | +-----------+ | | | - * | level | | 5 | -----------------------+ | | - * | mapping | +-----------+ | | - * | | | 6 | -------------------------+ | - * | | +-----------+ | - * | | | 7 | ---------------------------+ - * | | +-----------+ - * | | - * | | - * | | - * +-----------+ - * - * When a HugeTLB is freed to the buddy system, we should allocate 7 pages for - * vmemmap pages and restore the previous mapping relationship. - * - * For the HugeTLB page of the pud level mapping. It is similar to the former. - * We also can use this approach to free (PAGE_SIZE - 1) vmemmap pages. - * - * Apart from the HugeTLB page of the pmd/pud level mapping, some architectures - * (e.g. aarch64) provides a contiguous bit in the translation table entries - * that hints to the MMU to indicate that it is one of a contiguous set of - * entries that can be cached in a single TLB entry. - * - * The contiguous bit is used to increase the mapping size at the pmd and pte - * (last) level. So this type of HugeTLB page can be optimized only when its - * size of the struct page structs is greater than 1 page. - * - * Notice: The head vmemmap page is not freed to the buddy allocator and all - * tail vmemmap pages are mapped to the head vmemmap page frame. So we can see - * more than one struct page struct with PG_head (e.g. 8 per 2 MB HugeTLB page) - * associated with each HugeTLB page. The compound_head() can handle this - * correctly (more details refer to the comment above compound_head()). + * See Documentation/vm/vmemmap_dedup.rst */ #define pr_fmt(fmt) "HugeTLB: " fmt From patchwork Thu Feb 10 19:33:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 12742394 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC56E2CA5 for ; Thu, 10 Feb 2022 19:34:32 +0000 (UTC) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21AHIRYM026356; Thu, 10 Feb 2022 19:34:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=8co4H0jZZNMhD6hU/mlqQ0kW32xrtx8PNIOW0EmnwCo=; b=HxUDrIhq1MIK5y1bbGLwYbmWd/I3y7Oo1Afnf3wtXlyp4IGMS4rbVz2p7HXH/71ONH0Y 0zGrlbqx0/CXyhmmwCkxu5VGnjRN/Tup80cRVQ8kY359VjvEn17vyqJJG42gvj8bAGNA iKij/Ynj5nuaigWxndqJZKoHApLcO7UML99rySqbOJeM/2ZEmRsnFQQYNIJq3+9NNzna tYEv1Q7QscUeEzc077s69TwMGJen/jaS8wFQgvDLvhX2ZcQjWpJ7p67zColmS4zD5Hlx U2BZ9iiuW7NRm1USBOiQZKJn3v/WU17qgAE+i5L+tN2KJsr1Vs+ugXzB6YmbtbUIDPih HA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3e54ykgtwm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Feb 2022 19:34:24 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 21AJVgLQ144273; Thu, 10 Feb 2022 19:34:23 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2172.outbound.protection.outlook.com [104.47.58.172]) by aserp3020.oracle.com with ESMTP id 3e1h2axsaj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Feb 2022 19:34:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NQZFZmn4UBshuz6iiPAv3rdlmtGVuRr/7rHkYg38GscyTHADngXt9xI5qzR2iCD2LJcQTb34Y3dfn1n8/x1Hlo6cVlO5SUVOpe6l+4cKpKvVFtcd4SDrTGSp7xom5B7Jg2Az5xw2wRLl6sYg7XU2R9mQ023rwTOdk8rXzBrOV+vregght/I70XlaZyvRR2rGOJEBDgYnRnYq2ceAvdwb7GGGyg+5J88S3ITL6wOeopl7BxsKhyHOWeKHW528n3o4f3DrdLjRYbR5VPjHLxVlT4PhhVfmLvRTlOUXNC7NRo4kpWRhzvcvoatof6gRKu4Jc00mxch1UBdsMVDKYfYHjQ== 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=8co4H0jZZNMhD6hU/mlqQ0kW32xrtx8PNIOW0EmnwCo=; b=AQBmT14fhos42JtC05vwlmjrcDHub3ki+E4sNNKp9tql2jxZn5ZLQSnx+jVMo9vnhfCatcsUU1CYip7fIowQSjS3JF0lJ6OVxWxMphSJnFCs/Nta9XkOhWeYpHvmTPunciK9sd6PmndD2LQporqSShoIk8cL2EAmz4DudMa9bkFd0zr19Rp9u1UzJ248yhg9qrEF2vpbXHq/CJeQTr1VCztGr+GFwf/xPatg5OGopLe3fGL9b58hk/+rjzISMBEioQ5B9GaFz5Ir6+qIxdMm4rtX34hf2BfWzNky1JldIadObSYsd1s9YScKJ2bYzm7LLIBwpUocAUxBFe7uKOILYA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8co4H0jZZNMhD6hU/mlqQ0kW32xrtx8PNIOW0EmnwCo=; b=v1SYJ1/n+xD51hdeo1cDnCdIgn4IHOJUk4mpV+fYalt4KjMHxpqsAgPWAjpHBeUlGGFXFSGoo21syIYwUXgXKBcNWh+yEOJQOnlDdy9grFbDnT0uf2qoiCCbn34K3rQadDDaVqFRPc6GmwZZmj+Yw63BJgYwbKPIwP0QLszmPsw= Received: from BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) by BN7PR10MB2514.namprd10.prod.outlook.com (2603:10b6:406:bd::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11; Thu, 10 Feb 2022 19:34:19 +0000 Received: from BLAPR10MB4835.namprd10.prod.outlook.com ([fe80::4910:964a:4156:242a]) by BLAPR10MB4835.namprd10.prod.outlook.com ([fe80::4910:964a:4156:242a%5]) with mapi id 15.20.4975.011; Thu, 10 Feb 2022 19:34:19 +0000 From: Joao Martins To: linux-mm@kvack.org Cc: Dan Williams , Vishal Verma , Matthew Wilcox , Jason Gunthorpe , Jane Chu , Muchun Song , Mike Kravetz , Andrew Morton , Jonathan Corbet , Christoph Hellwig , nvdimm@lists.linux.dev, linux-doc@vger.kernel.org, Joao Martins Subject: [PATCH v5 4/5] mm/sparse-vmemmap: improve memory savings for compound devmaps Date: Thu, 10 Feb 2022 19:33:44 +0000 Message-Id: <20220210193345.23628-5-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220210193345.23628-1-joao.m.martins@oracle.com> References: <20220210193345.23628-1-joao.m.martins@oracle.com> X-ClientProxiedBy: LO2P265CA0170.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::14) To BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 05baa233-67ce-4dfc-d257-08d9eccc54c4 X-MS-TrafficTypeDiagnostic: BN7PR10MB2514:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bElo7FAc/RfsWk+IkX+x3mEzOKPBJUUGHwkAnm3yKExwizPMUFuRM8D4cfPbJVDzo1OeZiAfBdAvMd/7mvW+RApZUoy5IN6eJOYD08l21j9aKay54JuWjQgdyAaHHuxkLOC4vYWydmePuKCCSgBb7G7dCh/YFcq2BkbAs4Wqi6NYXERWn8fCtf7S8EfMA09TK1/03R4+oH4Y+EAbNZ3JuUqZAN/Pw1HQLzUYOGhNKzIuXBoAnxWjp2Vv6yFV6RWThXoUTvTKdqzlurL6yd/0YBgU/2wSe5rYwe20TKvzTs+yPKbA24SGv9DKUxLzNh0bv+j3Sximh1gPeB4dC8tciB1z2QQkSsMukUWaxMKP1QBts0leI1nlKoCgr0boukvugNpJEOoVkT4qPKpMmsqrdPoZsZVW26SSLMHzIDXvXF2Ump0kqk5zeElzKFoUsARhmFSWo16pwloNwuKcGdiDrF6PSJHW1HsWNAtgl2l5PTldHOkPGsFv46ZA4FHMyQm0G2LVaXHMJNRdUCCDo2H9Uy9EHAlUtZlKq8D59Uo+wUlQXapssQMSAVAinB30OMcic+zAS93uIZRMgEeARNw44HNm6zWZY8hmKF4TfhdHygwdtp9ol+p6swaILoBj7nsSQ3bTJa9OgoPz01eMV9jXl+jcuSIE+KUI+S/MXrzzV3+BynNJMeqJHGfoLQN36lLUPW+lEHpt6gLJEo66QKCq2Feu+t0Hk/IQ+QbQtgfu/EI= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BLAPR10MB4835.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(103116003)(66946007)(36756003)(66556008)(8676002)(2616005)(8936002)(316002)(7416002)(5660300002)(66476007)(30864003)(83380400001)(4326008)(186003)(107886003)(26005)(54906003)(6916009)(1076003)(6506007)(2906002)(86362001)(508600001)(38100700002)(52116002)(38350700002)(6666004)(6486002)(6512007)(25903002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: I2Mx7RVtOWLR0y/L3SSd7wQVd7GJ8rtDMoQDuugpu8Wi4q+uOIuyvw7pQk1cLCZyO/YvSex23GNztCRKO9gJA2SayWKTOIRSIpOIr53gkjvhrBnAyF2d7BEjbgbdq335LTB5EQ2WFVy6db04FIuB0Sw8aBcw/6v4pOi00zkx4Xhx882heX9LLQKpDm7gzKWYwABszW+hsSbhErUs9ueorXg5ykf+ZxaRBPoi7oCWAuFB1ZKhZRSJhwHVwiNmT3pa6orKYXcA9qsOtZ3cNkTTePjU56evHMNWjTRzlms0muH8yE7A9jB2DkyomhCu5lbpIRY00dpX102rOtsjlOyVBj/sX9N4SlxbSQPMH8iizsJYSoPLBRcKaEbOCca2VwFt/tn/zvBo4x2gmnMOhYb5Z5o504e3lrzvMDyvc9RYUHaDGawPsxKjN83oDbD4r5hg6uOZLccl54VK0wL/ee1rdXGgpXCPrq2qbO31X464lbrb7QALFMlmYD/FSI6WnCZBXjgECdQpMD4Y5CLtkhGvp3l8ZxSKcRBbI2L7kXg34pRZh6+Qoy1DPE7fdNnqlb6PJheR8hprnAYrLt6PqkgTqUXpLAnwH/s6ochl3vvRyZ+PSZheqYHgbowweodQFS4XdKnbX4AULBhyQbbAG9FfXk4t+mMZ6JYB7U+BNSNwjWwrcICguM+ECMiai/ltRuDe2H37Gve+NQfnwGs8xFD7AhnSTe4UKqQSFAmjzw/bYWsKGeGj0ylRVjg66iqIT6SAe97MQAl9j9JilHFJnqUWceKqx95TTzbz1Ry9NLQFbTxo1jUxb6SYF+gGxbWuA6nw7tQptrTAlfSOCjxnSvJpvt/sW0ppgLhaKgTybazVqWSuJjGKz18bH3YEn3S+Ku7q+OX4giTg7yFbLsVNOMjAu0aEiJOnlIcY6p/DEErprEq0/Erp6spN2MrCVF2i8BZOdHw0XJflb5TKuYPEREDfhq2S+hFNRff4Q+YUtq0fe8m6nGb8ev4YkdIiLeSud5qS0/4/E3am0rdejwwU0bXHtgJgiPd+WoA4q5GOM4iteAuHAmddDSJNTyauvEp3pjSatDCxTd1Y4SelXmyVGy6KFl3Pv5c/kXI/b/eHVv9fZio5yyyLIw2LgwtOqlPdKv6ADoqmmTv4BGGWzYVmE1puKnZ7qEoosy2MbA+3EOOoZIvf5zOXkBXWYhtJmCQ+1D2mx06pVPUF08abH2BW0T2Y6RoqVY9w6gg8SGXUpCpIsFm9J11nfQPe4XJZp+WFgRifyq1okumckqtEBRNnH8654i/sZvzv3OgeWJ3moNkE/zpB8sqPSFz3njTLViL4to2eHU7jFRh3hRM1H+J/fKVO8QpRHLJAgMBAt+aJ7qcnvQ9+S44CNSY/Bxc1tbhRFeRqiX06y1asDcjk6TS+IP86JkHGNSF6YLik5clsOCfKRXWuFb/DcmFzvf6AMOD7hDfdgVpJWpjoKvjgKUyQhgYisuwXZ9TU9dSWh4AHKkBamyHmmaNxFgl0iGLy/9tqoxm1PnvxEtuLi/P6roEMQF/iM3MrPMIkS50Ts6iLCwi+I32ETjdtzlRgrv+L0LlM9/QJeHrj8wMorj1P2zpJsqhfPSh1/5F83I0wD9dX9dzz5vXuu11QF7CxiPOoafrc47MykiOzOPkCjgJ6jGw8Mw2SHg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 05baa233-67ce-4dfc-d257-08d9eccc54c4 X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB4835.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2022 19:34:19.1803 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: U3UU7Yq5Co0hRqwCR09KN/Ewtbm8vm2O/+lXEwVqJU2gYnpB9dkUbxqYMuK6hsTPEWST0bN3i01ppCintm6et1FHOzWd6WD0LMZaYTMEc/Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR10MB2514 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10254 signatures=673431 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 bulkscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202100103 X-Proofpoint-GUID: LJHzM0EF1ZHuhHriwNkShIv-FmuEs73m X-Proofpoint-ORIG-GUID: LJHzM0EF1ZHuhHriwNkShIv-FmuEs73m A compound devmap is a dev_pagemap with @vmemmap_shift > 0 and it means that pages are mapped at a given huge page alignment and utilize uses compound pages as opposed to order-0 pages. Take advantage of the fact that most tail pages look the same (except the first two) to minimize struct page overhead. Allocate a separate page for the vmemmap area which contains the head page and separate for the next 64 pages. The rest of the subsections then reuse this tail vmemmap page to initialize the rest of the tail pages. Sections are arch-dependent (e.g. on x86 it's 64M, 128M or 512M) and when initializing compound devmap with big enough @vmemmap_shift (e.g. 1G PUD) it may cross multiple sections. The vmemmap code needs to consult @pgmap so that multiple sections that all map the same tail data can refer back to the first copy of that data for a given gigantic page. On compound devmaps with 2M align, this mechanism lets 6 pages be saved out of the 8 necessary PFNs necessary to set the subsection's 512 struct pages being mapped. On a 1G compound devmap it saves 4094 pages. Altmap isn't supported yet, given various restrictions in altmap pfn allocator, thus fallback to the already in use vmemmap_populate(). It is worth noting that altmap for devmap mappings was there to relieve the pressure of inordinate amounts of memmap space to map terabytes of pmem. With compound pages the motivation for altmaps for pmem gets reduced. Signed-off-by: Joao Martins --- Documentation/vm/vmemmap_dedup.rst | 56 ++++++++++- include/linux/mm.h | 2 +- mm/memremap.c | 1 + mm/sparse-vmemmap.c | 150 +++++++++++++++++++++++++++-- 4 files changed, 197 insertions(+), 12 deletions(-) diff --git a/Documentation/vm/vmemmap_dedup.rst b/Documentation/vm/vmemmap_dedup.rst index 8143b2ce414d..de958bbbf78c 100644 --- a/Documentation/vm/vmemmap_dedup.rst +++ b/Documentation/vm/vmemmap_dedup.rst @@ -2,9 +2,12 @@ .. _vmemmap_dedup: -================================== -Free some vmemmap pages of HugeTLB -================================== +========================================= +A vmemmap diet for HugeTLB and Device DAX +========================================= + +HugeTLB +======= The struct page structures (page structs) are used to describe a physical page frame. By default, there is a one-to-one mapping from a page frame to @@ -173,3 +176,50 @@ tail vmemmap pages are mapped to the head vmemmap page frame. So we can see more than one struct page struct with PG_head (e.g. 8 per 2 MB HugeTLB page) associated with each HugeTLB page. The compound_head() can handle this correctly (more details refer to the comment above compound_head()). + +Device DAX +========== + +The device-dax interface uses the same tail deduplication technique explained +in the previous chapter, except when used with the vmemmap in +the device (altmap). + +The following page sizes are supported in DAX: PAGE_SIZE (4K on x86_64), +PMD_SIZE (2M on x86_64) and PUD_SIZE (1G on x86_64). + +The differences with HugeTLB are relatively minor. + +It only use 3 page structs for storing all information as opposed +to 4 on HugeTLB pages. + +There's no remapping of vmemmap given that device-dax memory is not part of +System RAM ranges initialized at boot. Thus the tail page deduplication +happens at a later stage when we populate the sections. HugeTLB reuses the +the head vmemmap page representing, whereas device-dax reuses the tail +vmemmap page. This results in only half of the savings compared to HugeTLB. + +Deduplicated tail pages are not mapped read-only. + +Here's how things look like on device-dax after the sections are populated: + + +-----------+ ---virt_to_page---> +-----------+ mapping to +-----------+ + | | | 0 | -------------> | 0 | + | | +-----------+ +-----------+ + | | | 1 | -------------> | 1 | + | | +-----------+ +-----------+ + | | | 2 | ----------------^ ^ ^ ^ ^ ^ + | | +-----------+ | | | | | + | | | 3 | ------------------+ | | | | + | | +-----------+ | | | | + | | | 4 | --------------------+ | | | + | PMD | +-----------+ | | | + | level | | 5 | ----------------------+ | | + | mapping | +-----------+ | | + | | | 6 | ------------------------+ | + | | +-----------+ | + | | | 7 | --------------------------+ + | | +-----------+ + | | + | | + | | + +-----------+ diff --git a/include/linux/mm.h b/include/linux/mm.h index f6a439582f63..0b7028b9ff2f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3172,7 +3172,7 @@ p4d_t *vmemmap_p4d_populate(pgd_t *pgd, unsigned long addr, int node); pud_t *vmemmap_pud_populate(p4d_t *p4d, unsigned long addr, int node); pmd_t *vmemmap_pmd_populate(pud_t *pud, unsigned long addr, int node); pte_t *vmemmap_pte_populate(pmd_t *pmd, unsigned long addr, int node, - struct vmem_altmap *altmap); + struct vmem_altmap *altmap, struct page *block); void *vmemmap_alloc_block(unsigned long size, int node); struct vmem_altmap; void *vmemmap_alloc_block_buf(unsigned long size, int node, diff --git a/mm/memremap.c b/mm/memremap.c index 71b8d42d820c..a0ef95f09397 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -323,6 +323,7 @@ void *memremap_pages(struct dev_pagemap *pgmap, int nid) { struct mhp_params params = { .altmap = pgmap_altmap(pgmap), + .pgmap = pgmap, .pgprot = PAGE_KERNEL, }; const int nr_range = pgmap->nr_range; diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c index e7be2ef4454b..2e2b063ed285 100644 --- a/mm/sparse-vmemmap.c +++ b/mm/sparse-vmemmap.c @@ -533,16 +533,31 @@ void __meminit vmemmap_verify(pte_t *pte, int node, } pte_t * __meminit vmemmap_pte_populate(pmd_t *pmd, unsigned long addr, int node, - struct vmem_altmap *altmap) + struct vmem_altmap *altmap, + struct page *block) { pte_t *pte = pte_offset_kernel(pmd, addr); if (pte_none(*pte)) { pte_t entry; void *p; - p = vmemmap_alloc_block_buf(PAGE_SIZE, node, altmap); - if (!p) - return NULL; + if (!block) { + p = vmemmap_alloc_block_buf(PAGE_SIZE, node, altmap); + if (!p) + return NULL; + } else { + /* + * When a PTE/PMD entry is freed from the init_mm + * there's a a free_pages() call to this page allocated + * above. Thus this get_page() is paired with the + * put_page_testzero() on the freeing path. + * This can only called by certain ZONE_DEVICE path, + * and through vmemmap_populate_compound_pages() when + * slab is available. + */ + get_page(block); + p = page_to_virt(block); + } entry = pfn_pte(__pa(p) >> PAGE_SHIFT, PAGE_KERNEL); set_pte_at(&init_mm, addr, pte, entry); } @@ -609,7 +624,8 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node) } static int __meminit vmemmap_populate_address(unsigned long addr, int node, - struct vmem_altmap *altmap) + struct vmem_altmap *altmap, + struct page *reuse, struct page **page) { pgd_t *pgd; p4d_t *p4d; @@ -629,11 +645,13 @@ static int __meminit vmemmap_populate_address(unsigned long addr, int node, pmd = vmemmap_pmd_populate(pud, addr, node); if (!pmd) return -ENOMEM; - pte = vmemmap_pte_populate(pmd, addr, node, altmap); + pte = vmemmap_pte_populate(pmd, addr, node, altmap, reuse); if (!pte) return -ENOMEM; vmemmap_verify(pte, node, addr, addr + PAGE_SIZE); + if (page) + *page = pte_page(*pte); return 0; } @@ -644,10 +662,120 @@ int __meminit vmemmap_populate_basepages(unsigned long start, unsigned long end, int rc; for (; addr < end; addr += PAGE_SIZE) { - rc = vmemmap_populate_address(addr, node, altmap); + rc = vmemmap_populate_address(addr, node, altmap, NULL, NULL); if (rc) return rc; + } + + return 0; +} + +static int __meminit vmemmap_populate_range(unsigned long start, + unsigned long end, + int node, struct page *page) +{ + unsigned long addr = start; + int rc; + for (; addr < end; addr += PAGE_SIZE) { + rc = vmemmap_populate_address(addr, node, NULL, page, NULL); + if (rc) + return rc; + } + + return 0; +} + +static inline int __meminit vmemmap_populate_page(unsigned long addr, int node, + struct page **page) +{ + return vmemmap_populate_address(addr, node, NULL, NULL, page); +} + +/* + * For compound pages bigger than section size (e.g. x86 1G compound + * pages with 2M subsection size) fill the rest of sections as tail + * pages. + * + * Note that memremap_pages() resets @nr_range value and will increment + * it after each range successful onlining. Thus the value or @nr_range + * at section memmap populate corresponds to the in-progress range + * being onlined here. + */ +static bool __meminit reuse_compound_section(unsigned long start_pfn, + struct dev_pagemap *pgmap) +{ + unsigned long nr_pages = pgmap_vmemmap_nr(pgmap); + unsigned long offset = start_pfn - + PHYS_PFN(pgmap->ranges[pgmap->nr_range].start); + + return !IS_ALIGNED(offset, nr_pages) && nr_pages > PAGES_PER_SUBSECTION; +} + +static struct page * __meminit compound_section_tail_page(unsigned long addr) +{ + pte_t *ptep; + + addr -= PAGE_SIZE; + + /* + * Assuming sections are populated sequentially, the previous section's + * page data can be reused. + */ + ptep = pte_offset_kernel(pmd_off_k(addr), addr); + if (!ptep) + return NULL; + + return pte_page(*ptep); +} + +static int __meminit vmemmap_populate_compound_pages(unsigned long start_pfn, + unsigned long start, + unsigned long end, int node, + struct dev_pagemap *pgmap) +{ + unsigned long size, addr; + + if (reuse_compound_section(start_pfn, pgmap)) { + struct page *page; + + page = compound_section_tail_page(start); + if (!page) + return -ENOMEM; + + /* + * Reuse the page that was populated in the prior iteration + * with just tail struct pages. + */ + return vmemmap_populate_range(start, end, node, page); + } + + size = min(end - start, pgmap_vmemmap_nr(pgmap) * sizeof(struct page)); + for (addr = start; addr < end; addr += size) { + unsigned long next = addr, last = addr + size; + struct page *block; + int rc; + + /* Populate the head page vmemmap page */ + rc = vmemmap_populate_page(addr, node, NULL); + if (rc) + return rc; + + /* Populate the tail pages vmemmap page */ + block = NULL; + next = addr + PAGE_SIZE; + rc = vmemmap_populate_page(next, node, &block); + if (rc) + return rc; + + /* + * Reuse the previous page for the rest of tail pages + * See layout diagram in Documentation/vm/vmemmap_dedup.rst + */ + next += PAGE_SIZE; + rc = vmemmap_populate_range(next, last, node, block); + if (rc) + return rc; } return 0; @@ -659,12 +787,18 @@ struct page * __meminit __populate_section_memmap(unsigned long pfn, { unsigned long start = (unsigned long) pfn_to_page(pfn); unsigned long end = start + nr_pages * sizeof(struct page); + int r; if (WARN_ON_ONCE(!IS_ALIGNED(pfn, PAGES_PER_SUBSECTION) || !IS_ALIGNED(nr_pages, PAGES_PER_SUBSECTION))) return NULL; - if (vmemmap_populate(start, end, nid, altmap)) + if (pgmap && pgmap_vmemmap_nr(pgmap) > 1 && !altmap) + r = vmemmap_populate_compound_pages(pfn, start, end, nid, pgmap); + else + r = vmemmap_populate(start, end, nid, altmap); + + if (r < 0) return NULL; return pfn_to_page(pfn); From patchwork Thu Feb 10 19:33:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 12742395 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73AB82C9D for ; Thu, 10 Feb 2022 19:34:32 +0000 (UTC) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21AJ2Pe0017445; Thu, 10 Feb 2022 19:34:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=jfW6myF/vYu2yff8Flpm0N/3fFb+8EbngzE0SqXUJgw=; b=tsIfEg2Q5Hfee1yjEYdmSoW9nz7+w4cyUusqyV5i+t8S3LQA8UOPdcZvKx5oJxomJJ08 DrobTrWh0iFQ8G5UUbvPom9itEKx7WgU6xzbOqsC2vHpv8ezYx52jBPbgfrPh5iISE7Z b17bi7N8gfhiem2NfMXlWMGVAx59+NrGytzZNrM7oUS7UgBRCceccuF4RnYK1BBex82v 8XneMkqvSr0Jitjk0/pWWnS5t3Hj+hOxEAJPFlzC4u/XMRmLLNsLClY9ruOxug3WJwVj gwLiRHNZvMta8VPSHkUjQricLr1J2SdYFvmhpTFL2l8btdNSflyeObaXEx71bWaY7+EE eA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3e3h28s2u0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Feb 2022 19:34:26 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 21AJVfDI144080; Thu, 10 Feb 2022 19:34:25 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2175.outbound.protection.outlook.com [104.47.58.175]) by aserp3020.oracle.com with ESMTP id 3e1h2axsc2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Feb 2022 19:34:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A98KR6UFPG6QI6G7yZEJp0wML7qX5zgr8KFJO63OfMyA3Z/U0v3aX+rJpLqDJYFBJZrxSQFnqP7IggcdDHj/OgTkl3+0pWFl5Dpl6gvNO89gASeyu5+ag5E3V0jTZYz3lacCLpuMSr9bwx2XByhYurnuTEDoO2TtNOVMsy0kTJFZZGKF6f7fBGq3SLTlWz5aTKEzDyNbABP+V5A8rI9Jhvv/PPiUxH49GoF374Fg8nq9xSzhWdbpVQF4MlztpVIv/+mIMEjK2gIdtoAi9wQSaqaG2TXIJ/tzjkzKVzdF9tTBhwvfKGcRis7lZNf8kR/GpdNOVuqrXmQRnykfn/7lGg== 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=jfW6myF/vYu2yff8Flpm0N/3fFb+8EbngzE0SqXUJgw=; b=dl34yY03Y5UXm8lXuSZD64JhsqVbjIGSgZnJlIqJ1cN4WLrv8ZNCx8G65RNrDBJcNZDB8EF3wStqetlhEOWPtEBeGL3RwwTe9wvm+DZqpE9UI1arkTG0yJBixdUzu6j6BzMwPeF17xPyCE2+YWFmRH6c2NU59zt37BVvOS5WGGaIWqV5kyHzTfPGEAQ+7zCaWNZefNFtheuyVoMJt0oE6GV24NbP1aj4muU/hRGB0vwlT9rOEPnm81cVxZJ6LCuphgnLB+fm2NODdxKExVoMugUAe0YT16PLnFZd6LA6JqiTNzb5+WobjSF7pP4NnzriSJ81uFh/0KdJ5m9IpNrqSg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jfW6myF/vYu2yff8Flpm0N/3fFb+8EbngzE0SqXUJgw=; b=PLmh8ZTGwgZz0KCXLuBIuatW9z5FzU4r3Kc4NCnbCINrCna+KiWcNPRTYDKtWMvtpJKc8k8UB6Xn17hDFYWBG69JtDkrreac8akthZUSmhI6fLmPUkMmWQ/UMi6KxL7yhI0g/6A3+ZwY1uhkLA9O7EE9f7oYk+ksRAFXgxiye3Y= Received: from BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) by BN7PR10MB2514.namprd10.prod.outlook.com (2603:10b6:406:bd::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11; Thu, 10 Feb 2022 19:34:22 +0000 Received: from BLAPR10MB4835.namprd10.prod.outlook.com ([fe80::4910:964a:4156:242a]) by BLAPR10MB4835.namprd10.prod.outlook.com ([fe80::4910:964a:4156:242a%5]) with mapi id 15.20.4975.011; Thu, 10 Feb 2022 19:34:21 +0000 From: Joao Martins To: linux-mm@kvack.org Cc: Dan Williams , Vishal Verma , Matthew Wilcox , Jason Gunthorpe , Jane Chu , Muchun Song , Mike Kravetz , Andrew Morton , Jonathan Corbet , Christoph Hellwig , nvdimm@lists.linux.dev, linux-doc@vger.kernel.org, Joao Martins Subject: [PATCH v5 5/5] mm/page_alloc: reuse tail struct pages for compound devmaps Date: Thu, 10 Feb 2022 19:33:45 +0000 Message-Id: <20220210193345.23628-6-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220210193345.23628-1-joao.m.martins@oracle.com> References: <20220210193345.23628-1-joao.m.martins@oracle.com> X-ClientProxiedBy: LO2P265CA0170.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::14) To BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2b9cca63-d450-4351-bbe5-08d9eccc5631 X-MS-TrafficTypeDiagnostic: BN7PR10MB2514:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PmMLJ/Y+aESr4iIRgmQu2jQUpq1LEkUG7yP8FJUk2vZKLTznIRn52xYrgMys8zVlsCdBxwyDg8IoB+MUFCCeWBu1FoINQ5S4qQYkrgQgdL+vZKc+WgobgVLI2IegDxRI25Ep3dnTtASppIip+J2zuHPfovJdFug4G/ivBfCJFQ6GCAEwL+SxiLDbYTf21IKtieGoxbw+TMPwxG1A1dYJITT7GjXPmwmo0pjTzGTTHO3Qpn3glqvvi+9tDcqvyFrnl5/KgJ8H2VDNBEfi3BDBO0Cm5zOe0qf8oGM3YjaqhFYBogNXNxIHrCv6F8O6/uLJEvVk6hMyklQku8U9kLKcoRSp57rs2PQDlciFgkbGqicc6N/0x6LdjcAJL2G6ConQcDuWEHvf3f063cTgUsDpOGTSkhtgQ+fTo5adXTgksPFgkgJ7g1agQq7NtcPr4pvpOuYAB/8HCxz5aaphj4mAa/MBMGo7AzWzjwsgjVBb2u73Xzy2B6+Qb917d8hC2FgBchSPdUHPOR+vojgVQ9PBxOZy9qu2/WNh5BS1CK0rC08YM2wrnvLqFoxTcQPpA+BsPa/9/ofDSyPUjQe0Wz0tQpVg7cjw2TVL13UogSN7B56quCcGcBuDYpxiYQGESRXBOCeyS9St2envY2wvjmdxPwnSV7kp65DDa5TKVZ42QyHrR8aazO8gJkcoXZYL/yQFBeJUjP1HuU/kVFKJcJZmzA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BLAPR10MB4835.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(103116003)(66946007)(36756003)(66556008)(8676002)(2616005)(8936002)(316002)(7416002)(5660300002)(66476007)(83380400001)(4326008)(186003)(107886003)(26005)(54906003)(6916009)(1076003)(6506007)(2906002)(86362001)(508600001)(38100700002)(52116002)(38350700002)(6666004)(6486002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: peCuIl8A+o0fbmaqBZvPMnqx9rNqU2A2oDcrnqFuF9kGy06EDKHXypwWholkoKq5RH59MFrFXXH/8PPHdZOHSOcudS/5MjM2JCA0AoB4ivdud9sxAgBZzcdIfgkoRCwgI56VbY1MdUyGpPkY6jK8MKey8ga3diSwnDpt7tmiU8Hq/FQLsB7ZEmBMA6qmHNXPwe6CotVhUBIzc26LEe9FCWAoFYJPLb6S6IXnsYR//HwAn5TF5nhG0lTlv+hrTxhGU2Qw2AEVpp8HWw1p4imh0otcn3pQa8D1peDacUCecwTkC1DquzZiG0fw5/RUqojcLbI0b0HjeMkxNVkWrekCwipaOSa/2rgvmjcOBk3X9yKEaqkKFNHblkgx1pmLQMDsw0vQdb+22LN2YFb+XhG8qIN8woge/Ec9cRnUWh//YIAU5kYY/3wmUihhdkB4kjF9wyNPRDbbdR7/3lUAhW2ee0kA9KnybN4WIIFrnhicn/WB6/u+5yqZSqJrykMIeRAw9P69G31j2O9XmnhuwWbxh+0TLd9RwBHD3NO6jbiN4DtaHzS2YUClwdYCR+6l93lTYfIWvvJshiR281p0ecDrVy9TE8+RLeKjmAOp8rv/AwvSuKzKI2UUfDSe0OLkwvb7PUZWajhrWjlrlHd//dZKQ35pgCh6Lkvdra7/l5s4UdZBWRjLGqHdDDe1SD8dXLIDm8x3WRNyUIjZiq3BRM/4zEJeuTHKQ1SJBn/4zNlknaw6SvVDGYwt62YRJWUdno/Zsqt9NeTlr8n8prAY+Q6+xFnvdmYfFF+buW6zRGvAfS4ZXmUgYy8GKXL3vG3g/vlqYX7PXbVxFboFS9pjpJry4C2AyoY7QNmnTp3QPlH5+ahEGWbLGjo+rnvFj0ONdieq1xc4L9jlxmgiUUq82zP6lpI4d5+1th1BuOOCzE/isdyngSBhbG/yE4b/P0NHE4bMauNXQgEbnZ1KAZWsLakXdexVJydvVLFLmwwFFyFlrh28D8zl4sP/i9zUxGO5byI1rsKBGW+Vpip8yQA6saH3z447zSBvzSN5tA+bu+EKKT6J8MKnsE54R8J9l9TtGQBCDqLqa4kdiCITrXLGFhgvvWTSkN1tJ/UHZf4lFoxDsu3CHfnrREli3MASb1vfHCNu1+PZr5YzdyYYXowd/JP8McKOSDcGRQNPyz7oWOSGwFTVVcX1MKRY9oYOmfbw/V10wffcjWwC+JACzKej5VNju7+8fWg/uWbrEjs6BtnoiTKmvj1RvcVBySlVphzryIeK+gpu1iBoqsDSvJxLXeMaRhF8GTirAAdtMu7ggwuxNI62MELwM7Xfx7SRt9Ybp9u+bORmd05xl87+kuqTQyzLaNXZ6EyX6k5tmKK92VoxmAHN4sCf0g3wV2X7VyzwAoRGhMy8ORNAOX2CK/fOUJXDakpDavw43icTRdtj6aTVY+uYySTKCkgT+u83ZoTQJxZVnfeOtVBsgDirruly4mauST3Hev7mswZd7YG6PL+MbCfmV8uY9zaREOplBa7gcTRepqoeYGH4szDQQ6MhK5JHlvRRfxxWbBkB296gmDTt7Lp8oZjXYJlODclQJojit4SsbMpRNJEfo8lnKL/zTO/mJaWs8EnaIrZCtQ9OmwsIj+a/phViwdhGCIlm3NqYuYECzaTQGKFNlTnCFWGLKTmtJQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b9cca63-d450-4351-bbe5-08d9eccc5631 X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB4835.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2022 19:34:21.5250 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /NM8Dgs/AbTzsIPFgENwxdosxb8PfiN1rae3lfZt1030DCUx3rx0GnxdJcvtMvojCSq8vXHa58q/nAEsaDqcaB/1YdSUevS/OyHpiPUMmN4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR10MB2514 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10254 signatures=673431 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 bulkscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202100103 X-Proofpoint-ORIG-GUID: 44neGnJGT_99Olj2MkfcFeqtEFJJhkNH X-Proofpoint-GUID: 44neGnJGT_99Olj2MkfcFeqtEFJJhkNH Currently memmap_init_zone_device() ends up initializing 32768 pages when it only needs to initialize 128 given tail page reuse. That number is worse with 1GB compound pages, 262144 instead of 128. Update memmap_init_zone_device() to skip redundant initialization, detailed below. When a pgmap @vmemmap_shift is set, all pages are mapped at a given huge page alignment and use compound pages to describe them as opposed to a struct per 4K. With @vmemmap_shift > 0 and when struct pages are stored in ram (!altmap) most tail pages are reused. Consequently, the amount of unique struct pages is a lot smaller that the total amount of struct pages being mapped. The altmap path is left alone since it does not support memory savings based on compound pages devmap. Signed-off-by: Joao Martins --- mm/page_alloc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index cface1d38093..c10df2fd0ec2 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6666,6 +6666,20 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn, } } +/* + * With compound page geometry and when struct pages are stored in ram most + * tail pages are reused. Consequently, the amount of unique struct pages to + * initialize is a lot smaller that the total amount of struct pages being + * mapped. This is a paired / mild layering violation with explicit knowledge + * of how the sparse_vmemmap internals handle compound pages in the lack + * of an altmap. See vmemmap_populate_compound_pages(). + */ +static inline unsigned long compound_nr_pages(struct vmem_altmap *altmap, + unsigned long nr_pages) +{ + return !altmap ? 2 * (PAGE_SIZE/sizeof(struct page)) : nr_pages; +} + static void __ref memmap_init_compound(struct page *head, unsigned long head_pfn, unsigned long zone_idx, int nid, @@ -6730,7 +6744,7 @@ void __ref memmap_init_zone_device(struct zone *zone, continue; memmap_init_compound(page, pfn, zone_idx, nid, pgmap, - pfns_per_compound); + compound_nr_pages(altmap, pfns_per_compound)); } pr_info("%s initialised %lu pages in %ums\n", __func__,