From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 63F5144B675 for ; Wed, 15 Jul 2026 12:08:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784117307; cv=none; b=YePo/fI+GojyEYTVDE6WN2Bdp1N1GGgy+i58PVD+PvwcVGYQ9m0/Hc0wQyO81q28Q9s+oe/biovlkfLvbVYoCRfvgtxNH4X9XZeDEJ8luGW2oX5iqXoxx1P6s2jStpC3/emzQGO0U625qIcPraQCOEM/iTvYMuw0nTt53nnj0/g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784117307; c=relaxed/simple; bh=ZHWtWzrbethbdBb6u6laTzuAaKpN2VgetoH/tyeaPBM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=Cuj1yUgvnZkB/bEVGRodPvculneS8St9KWmDmmcw2k+UQywg9AEpRTtSdUKwKC61vL/EuBZmdRcETJNWq2EgnOYcZRdLLhNfzZTvFnuw3lpMQSFLCOLzLyGbmV/3kR57mDnFfhdXouc2bHBrbLkabtZ9gjBEcjdZJST2PpSKlhU= 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=YJcl3ZRg; arc=none smtp.client-ip=209.85.214.180 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="YJcl3ZRg" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2cc6dd436c6so24142335ad.2 for ; Wed, 15 Jul 2026 05:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784117303; x=1784722103; 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=vzsH/LHbJwPhcS/F03MRPLO6wWkth0B2xmqisYYr6kQ=; b=YJcl3ZRgjJ9QBCgOMTerzrDPKkpW6t/nzC/7EOtzSPz7NwmdJT7pCb8AspIyH4sJNE 67z00aBmu0NR23juDy3v0CXYlXwlKnB4dWIa1h0BrF2Jvhlxj97EKELED/NGTzm5nNE2 hR1ICdXdwNFfczkqQnVqbihrC2gRNrpOJgoZVoR7v4Dgrk9EAxmh5xJTQecO4z6OzBZW oHLr3tyEU1EjXw64XwsolNXfWf11NQIhBHabJyPzVQ8Kx5rKR4JhKqzNal7gWWf2vfJt xJfM2/exsUoxFeqiPLgPEy5/G0Ga9HISQCmfH9jIxnQRtKy9gGMdLE8X458i/7zwJHiB gyGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784117303; x=1784722103; 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=vzsH/LHbJwPhcS/F03MRPLO6wWkth0B2xmqisYYr6kQ=; b=ZhD/5mcgTUDkb63nQeidb3rQTFNXskgp57L04sWko5UTSeZxWZfeXprp5+Zgd0pU7S QKg0kFrnAZ+p7t1K6wT8O1i0aHzqfCIEG4vpXvFAq3EUj5rCIMQeCoTxylwh++dB3HOP k3sNDKUJQFUPXWKI3vBiybtHVkiTWNQoATRyi7Ncfcjedx8dIAnSIY4Gbtnfs0XuC47J 0xHUUCc3hWW4uCFhzBKDJquOSya3pu8ZULKLyRwjhoq+VDBrqn63QmB+Y3dI2uV5k3RC xWnVea70bNkeoeKcUF1ne2//9fCKR9s3/qfyW+al9l1K4l0PVjoHQTujG8qeokkJkPxi joaA== X-Forwarded-Encrypted: i=1; AHgh+RqQLlD4NmOxDhXTDTyFv9A5HwT0MVQ/l4zl2D+65TRJXWE5i30wBiVMirNbfshX988tveXl7XNs+yaq4Mw=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2EMPwz4O3//Wq3NM62+O3OjQHzqC8cQMBWAElSgq2iVsTI5OE XDeZtdvg/usc6s5aEhTEyOmTZ5TYrYolOzZaYpS+mXRZDVKG3/3CWK6p X-Gm-Gg: AfdE7ckwyAHvxGaXGGC4HrmS3EULE+GHrfPBrK2HXRMMiexomCCQ3B0ksd0815gg2On rx6bXyLX3T9OClhsRiVV9/DFNL/o9+v6K/8Je+IobYc6zpgoqkeweUhsiE/wG7In4Ja47NpZFKp s6eFqWSK3tg74UyWowQrN0p9dFpHseQgf8oRW9/XsgarjVin5eECCsdsW0b6TmRSF7mbzRjR9sK 8KIdHASwCXV/EiKopnsGh/arygCoRUv7TiL2O8cxjlQyAmgalRz/RRnXsjIFZzNyG7W35tlIcB0 rrdCKNbWkcuN0txYwIFR9qSgrYmiNTAh5Dp0iEajCwctv+Xd+5UQUp7xjK0pj4A2JO3noFn05jl t+2Auov2rEhyplwvHvgAIxTQwgu8dhLHkZ/c6E6h023upC25EX+ZADETtFTtGcQvGsSzlJazlXu 0+nwEPMwPIyOFG8tVWh6eVzmwa+iDgzp69f3Q= X-Received: by 2002:a17:902:d552:b0:2cb:2b53:559f with SMTP id d9443c01a7336-2ce9f3a4910mr175721715ad.35.1784117302761; Wed, 15 Jul 2026 05:08:22 -0700 (PDT) Received: from mi-OptiPlex-7060.mioffice.cn ([43.224.245.234]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf105bc642sm1216325ad.63.2026.07.15.05.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2026 05:08:22 -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, baohua@kernel.org, Wen Jiang Subject: [PATCH v7 0/7] mm/vmalloc: Speed up ioremap, vmalloc and vmap with contiguous memory Date: Wed, 15 Jul 2026 20:08:06 +0800 Message-Id: <20260715120813.3609949-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 for 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(). Patch 5 extracts vm_shift() to consolidate vmalloc mapping shift selection for reuse in the batching path. Patches 6-7 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.53 us) * 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 v6: - Add a clarifying comment about the reuse of hugetlb helpers by non-hugetlbfs(vmalloc) mm code (patch 1) - Expand the arm64/vmalloc commit message and comment to clarify that multi-CONT_PTE_SIZE values are vmalloc mapping spans, not HugeTLB hstate sizes (patch 2) - Move the local steps variable change in vmap_pte_range() into the vmap_set_ptes() extraction patch (patch 3) - Propagate vmap_pages_pte_range() errors through the upper vmap_pages_*() levels instead of returning -ENOMEM for all failures (patch 4) - Add a preparatory vm_shift() helper patch before the batching patch (patch 5) - Guard the PFN alignment clamp in get_vmap_batch_order() against PFN 0 before calling __ffs() (patch 6) - Fix kmsan_vmap_pages_range_noflush() indentation in the batching path (patch 6) 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 (2): mm/vmalloc: Extract vmap_set_ptes() to consolidate PTE mapping logic mm/vmalloc: Extract vm_shift() to consolidate mapping shift selection arch/arm64/include/asm/vmalloc.h | 8 +- arch/arm64/mm/hugetlbpage.c | 15 ++ mm/vmalloc.c | 264 ++++++++++++++++++++++++------- 3 files changed, 229 insertions(+), 58 deletions(-) -- 2.34.1