[llvm] [CAS] Add MappedFileRegionBumpPtr (PR #114099)

Steven Wu via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 5 10:56:48 PDT 2025


================
@@ -0,0 +1,321 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+/// \file Implements MappedFileRegionBumpPtr.
+///
+/// A bump pointer allocator, backed by a memory-mapped file.
+///
+/// The effect we want is:
+///
+/// 1. If it doesn't exist, create the file with an initial size.
+/// 2. Reserve virtual memory large enough for the max file size.
+/// 3. Map the file into memory in the reserved region.
+/// 4. Increase the file size and update the mapping when necessary.
+///
+/// However, updating the mapping is challenging when it needs to work portably,
+/// and across multiple processes without locking for every read. Our current
+/// implementation strategy is:
+///
+/// 1. Use \c sys::fs::resize_file_sparse to grow the file to its max size
+///    (typically several GB). If the file system doesn't support sparse file,
+///    this may return a fully allocated file.
+/// 2. Call \c sys::fs::mapped_file_region to map the entire file.
+/// 3. [Automatic as part of 2.]
----------------
cachemeifyoucan wrote:

This is corresponding to 1-4 in the previous section. 

https://github.com/llvm/llvm-project/pull/114099


More information about the llvm-commits mailing list