From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E21C6339853 for ; Thu, 9 Jul 2026 07:38:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783582717; cv=none; b=Sfffz0oCEEzFLytzJyBBxEWv95a9pybYPCdgL45u6wcJCTEd7zxNk5z7T78ig21UqxLYWfiyJn7uAHx7DeyhYFBWVn0UXncZd3S5bOkGMN/DBbvcWlsdbpRLZPbGoWOuloLTkSdO+e8FVeKV7CdnPPqKbH2r7ljZdvFuPFAixMQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783582717; c=relaxed/simple; bh=OIEe799ajdfpWiA5JhAwwIyKstyXUONjohXppolB4aw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=HE63JtbwSnTiigXxijOizF1CSwwMoCfuUI94ficum6D+2fEE78CpewnwG0wJ9k5nl+m0K0xpVpe0RiFPST4/xv8y3jP1QsJk5SfK3ZppgOsOJPkqdtp4WLkhLZcQ8yyybquZo7W0iITfVAvSb+EkHzo7ez+li10b+Ml8jul0Ez0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=P/H+7805; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P/H+7805" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-84864b41100so43745b3a.3 for ; Thu, 09 Jul 2026 00:38:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783582715; x=1784187515; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=3jsvYVzwglzJMfEkbvRTmSIJAXcUa+wxxqNcA1GNkcI=; b=P/H+78054HChkbvudg4pzPht1DWHRBUyNOP2AzInI+Rc4kXYNwWsmWlXlE50wnVd+7 uPftoD5QgPu2if2XKdsHUkjpmK8xFNky2lJHVThw8OPo2q+SV7dtIla/h/cyGFbfyw93 iqh7mk78ikc9xu+mOfWL0qXKB+tsnrBSoyNHoqU+4TCZL+kuByvZcnbPBUPqRGM1Oxub UAUwKv3EVvJkUB3rp9GMjMpP6R73ujiX8I0gbTbSy7HLZ6JV8HZsYU/NI/7jlDKtcURH Eu92bCGhqWqo6WxBnKOk/Fpnz+CwirfmtKL02cn18oESTFu4m9Ya+GbDzMREJ7zyrQ9u h7Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783582715; x=1784187515; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=3jsvYVzwglzJMfEkbvRTmSIJAXcUa+wxxqNcA1GNkcI=; b=cyUIDax3eVDgtKV5LKOkLOG1aHwDpyEDl44SofMs3ecEVouW1gD/FDyCxPciqXzTk+ gPv/4DTSHiione7GEuGeh9bJGUGM2jtAz61cFaxuVzcLMDQFK8RDZ6Mm0l7h4+Zm/eIW fEgMH8Wsp+nWb7INENrChN+WksreKGclvHpbaO6J3o0q88hh6q5ADIpDh3+oD16Hh9BX y3nDb/0CwkYZOeQ8e9T2ijDq56BcDWAVdnrmphBayLh20wAd+HYrilV+9ig7o3JVz7sC /Sq3IRg88fjAohFEHSdUcPANTXYR0wdXFWhqi/VCosA2sl1oPnEKDvjIXqpfLiUDbDuv RGgA== X-Forwarded-Encrypted: i=1; AHgh+RoXbITEhVBkbgqsZ6ry/0cDeyAQqHnyX8p48aB/YLmXwoOB0YdIktu30escYOtXNGLNS9BoYBSq9vF9P9g=@vger.kernel.org X-Gm-Message-State: AOJu0YxKsx1z3+N4EQOdkrnejZ3ukSx3TmZgi6lZsVoBQSf93Ru4912z 6QP9qxvr0aSYD13zwDddwNLeEPvW3VA6qD57IyOTGNMIxAEw6aAz5175 X-Gm-Gg: AfdE7ckR8xaveRa/slD1sGC7X9nhpTysSl0yq9Sy4aqeOjX+M+/sov4MbWl/Sdhj6X4 ZYEtffSvyEZgNdFFNJtZ4LQETVMfi2Jyz/WBEMH81EaxAGQuRQxMkMvE8dTSCVsCc2nqd5nqjY8 2XQvdlDdXN/iB1V82n6bk4aw9D22PlxCZuzqP1xyRWQKu2d0kx0uqJl03hjIJy2DJ92kyjI7uxa F1Oe002ey3kOT4AlczzKhQjL33yJfUp4aOQ0ZnwP11CUzGFJ7MmJBEJRl0ueSsLTPpfXHWHWT9I RdUOOOOWV83CQ4vSY/f8x+jlAafi8y44t1CG/cWaiPlyrWp6kdL3E6dCLAL865Z5qKv3kOK+NQC SlcXP1Ij5hVWST9PhIV/FK+BR1Wp+RAfZUwptTK3TXLZPpWYL5dg6JDAuaXWC73oByAUzAxptMc zbOyGV0GaPFjSpcqGOa4vttee614BAMIJWZFo= X-Received: by 2002:a05:6a00:a228:b0:847:904c:8452 with SMTP id d2e1a72fcca58-84842fd47edmr5989663b3a.38.1783582715184; Thu, 09 Jul 2026 00:38:35 -0700 (PDT) Received: from mi-OptiPlex-7060.mioffice.cn ([43.224.245.234]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ca5b3162a49sm3334902a12.15.2026.07.09.00.38.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2026 00:38:34 -0700 (PDT) From: Wen Jiang X-Google-Original-From: Wen Jiang To: akpm@linux-foundation.org, catalin.marinas@arm.com, linux-mm@kvack.org, urezki@gmail.com, will@kernel.org Cc: Xueyuan.chen21@gmail.com, ajd@linux.ibm.com, anshuman.khandual@arm.com, david@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, rppt@kernel.org, ryan.roberts@arm.com, dev.jain@arm.com, Wen Jiang Subject: [PATCH v6 0/6] mm/vmalloc: Speed up ioremap, vmalloc and vmap with contiguous memory Date: Thu, 9 Jul 2026 15:38:17 +0800 Message-Id: <20260709073823.6643-1-jiangwen6@xiaomi.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patchset accelerates ioremap, vmalloc, and vmap when the memory is physically fully or partially contiguous. Two techniques are used: 1. Avoid page table rewalk when setting PTEs/PMDs for multiple memory segments 2. Use batched mappings wherever possible in both vmalloc and ARM64 layers Besides accelerating the mapping path, this also enables large mappings (PMD and cont-PTE) for vmap, which are currently not supported. Patches 1-2 extend ARM64 vmalloc CONT-PTE mapping to support multiple CONT-PTE regions instead of just one. Patch 3 extracts a common helper vmap_set_ptes() that consolidates PTE mapping logic between the ioremap and vmalloc/vmap paths, handling both CONT_PTE and regular PTE mappings. This prepares for the next patch. Patch 4 extends the page table walk path to support page shifts other than PAGE_SHIFT and eliminates the page table rewalk for huge vmalloc mappings. The function is renamed from vmap_small_pages_range_noflush() to vmap_pages_range_noflush_walk(). Patches 5-6 add huge vmap support for contiguous pages, including support for non-compound pages with pfn alignment verification. On the RK3588 8-core ARM64 SoC, with tasks pinned to a little core and the performance CPUfreq policy enabled, benchmark results: * ioremap(1 MB): 1.35x faster (3407 ns -> 2526 ns) * vmalloc(1 MB) mapping time (excluding allocation) with VM_ALLOW_HUGE_VMAP: 1.42x faster (5.00 us -> 3.53us) * vmap(100MB) with order-8 pages: 8.3x faster (1235 us -> 149 us) Many thanks to Xueyuan Chen for his testing efforts on RK3588 boards. Large vmap() mappings were also tested by Leo Yan with ARM trace buffer units, including TRBE and SPE. These units use the CPU page tables for address translation when writing trace data to DRAM, so using larger vmap() mapping granules can reduce TLB pressure on the trace writer. The TRBE test used a 1G CoreSight ETM AUX buffer. Across five runs on an isolated CPU, the average results were: * dtlb_walk: 68.4 -> 59.4 (-13.16%) * l1d_tlb_refill: 155.8 -> 119.6 (-23.23%) * l2d_tlb_refill: 161435.8 -> 495.0 (-99.69%) The SPE test used a 512M ARM SPE AUX buffer. Across five runs on an isolated CPU, the average results were: * dtlb_walk: 1710.4 -> 1315.6 (-23.08%) * l1d_tlb_refill: 16000.0 -> 15950.2 (-0.31%) * l2d_tlb_refill: 4796.0 -> 2931.2 (-38.88%) These results show that enabling larger vmap() mappings can materially reduce page table walks and TLB refills for large trace buffers. Many thanks to Leo Yan for his testing efforts on ARM trace buffers. Changes since v5: - No code changes. - Pick up Reviewed-by and Tested-by tags from Dev, Leo and Uladzislau. Many thanks! - Add TRBE/SPE large vmap() test results from Leo Yan to the cover letter. Changes since v4: - Move pgsize update before contig_ptes check (patch 1) - Use rounddown_pow_of_two instead of __fls in arch_vmap_pte_range_map_size (patch 2) - Reword comment to avoid mentioning cont_pte and remove if in vmap_set_ptes (patch 3) - Rename vmap_batched() to vmap_pages_range_batched() (patch 5) - Use batch_end as the batching cursor to avoid an unused start variable (patch 5) - Check arch_vmap_pmd_supported before PMD mapping (patch 6) Changes since v3: - Squash vmap_pte_range() loop variable fix into patch 4 (patch 3, 4) - Use shift >= PMD_SHIFT and fix *nr increment in vmap_pages_pmd_range() (patch 4) - Pass page_shift directly without capping at PMD_SHIFT (patch 4, 5) - Add vm_shift() helper and pass pgprot_t to get_vmap_batch_order() (patch 5) - Use min(order, __ffs(pfn)) for graceful pfn alignment degradation, replacing IS_ALIGNED check (patch 5) - Remove irrelevant ioremap_max_page_shift early-exit (patch 5) - Add __get_vm_area_node_aligned_caller() wrapper, rename to vmap_get_aligned_vm_area() (patch 6) Changes since v2: - Use __fls instead of fls in arch_vmap_pte_range_map_size (patch 2) - Add WARN_ON checks in vmap_pages_pmd_range (patch 4) - Fix flush_cache_vmap to use saved start address instead of the already-advanced addr (patch 5) - Rename __vmap_huge() to vmap_batched() (patch 5) - Add caller parameter and unroll while(1) loop (patch 5) - Squash patch 7 into patch 5 (stop scanning for compound pages after encountering small pages) Changes since v1: - Fix condition order and use PMD_SIZE instead of CONT_PMD_SIZE in patch 1 (Dev Jain) - Squash patch 3+4 and patch 5+7 (Dev Jain) - Replace "zigzag" with "page table rewalk" in commit messages (Dev Jain) - Rename vmap_small_pages_range_noflush() to vmap_pages_range_noflush_walk() (Dev Jain) - Extract vmap_set_ptes() as a new patch to consolidate PTE mapping logic between vmap_pte_range() and vmap_pages_pte_range(), handling both CONT_PTE and regular mappings (Mike Rapoport) - Support non-compound pages in get_vmap_batch_order() by falling back to physical contiguity scanning with pfn alignment check (Dev Jain, Uladzislau Rezki) - In get_vmap_batch_order(), filter out orders that the architecture cannot batch by checking arch_vmap_pte_supported_shift() directly. This avoids overhead for orders 1-3 on ARM64 CONT_PTE with 4K pages. (patch 5) Barry Song (Xiaomi) (5): arm64/hugetlb: Extend batching of multiple CONT_PTE in a single PTE setup arm64/vmalloc: Allow arch_vmap_pte_range_map_size to batch multiple CONT_PTE mm/vmalloc: Extend page table walk to support larger page_shift sizes and eliminate page table rewalk mm/vmalloc: map contiguous pages in batches for vmap() if possible mm/vmalloc: align vm_area so vmap() can batch mappings Wen Jiang (1): mm/vmalloc: Extract vmap_set_ptes() to consolidate PTE mapping logic arch/arm64/include/asm/vmalloc.h | 6 +- arch/arm64/mm/hugetlbpage.c | 10 ++ mm/vmalloc.c | 243 ++++++++++++++++++++++++------- 3 files changed, 209 insertions(+), 50 deletions(-) -- 2.34.1