Skip to content

Add guide to mmap - #805

Draft
lanceu0128 wants to merge 7 commits into
Blosc:mainfrom
lanceu0128:mmap-guide
Draft

lanceu0128 wants to merge 7 commits into
Blosc:mainfrom
lanceu0128:mmap-guide

Conversation

@lanceu0128

@lanceu0128 lanceu0128 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #719

@FrancescAlted

Copy link
Copy Markdown
Member

That's a very nice starting point! The structure and topic are great additions to the docs, and I like the graphics that you are adding. Meanwhile, some notes:

  • Line 59: mmap_mode=r is missing quotes — should be mmap_mode="r".
  • Line 28 ("mmap_mode overrides mode"): True for SChunk/NDArray, but EmbedStore, BatchArray, and CTable only accept mmap_mode="r" together with mode="r" (raising ValueError otherwise). Also worth explicitly noting that blosc2.open(..., mmap_mode="w+") raises ValueError ("w+" is constructor-only) and that urlpath is required.
  • Concurrency section: Should explicitly call out that mmap_mode="r" is for concurrent readers, and that file locking (locking=True) cannot be combined with mmap_mode (raises ValueError, while BLOSC_LOCKING is ignored). Also worth summarizing the RSS vs. USS measurement caveat when profiling mmap memory (already noted in sharing_across_processes.md), since this guide has a memory-profiling section.

Keep the good work!

@FrancescAlted

Copy link
Copy Markdown
Member

Thanks for addressing all the previous notes; you new additions are looking great!

Since the PR is still a draft, I assume you are planning to fill in the first two sections (How out-of-core mmap reads work and Memory profiling for standard vs. mmap reads) next. While you finish those up, one important technical correction and a few small nits on the existing sections:

  • Concurrency section — SWMR vs. concurrent read-only readers: The sentence "for giving multiple concurrent readers SWMR access, using mmap_mode="r" is recommended" is misleading. Memory-mapped readers (mmap_mode="r") do not follow live SWMR growth/mutations from a concurrent writer (refresh() does not remap a read-only mapping when the file grows, whereas regular file I/O does). Please rephrase this to recommend mmap_mode="r" for multiple concurrent readers of a static / read-only file (which matches "concurrent read-only access" two paragraphs later).
  • Modes {tip}: DictStore (and TreeStore) also enforce the same read-only rule (mmap_mode="r" with mode="r") alongside EmbedStore, BatchArray, and CTable.
  • Small fix: "Consider USS alongside RSS, which is nearly identical for both access types in multi-reader examples." → "which" reads as referring to RSS instead of USS; e.g., "Consider USS (which is nearly identical for both access types in multi-reader examples) alongside RSS."
  • Links: Link mmap_block_locality.py (similar to how tip_10_mmap_many_readers.py is linked), and consider using relative .md links instead of hardcoded https://blosc.org/... URLs for the internal guide links (optimization_tips.md and sharing_across_processes.md).

Note on CI: the current pre-commit.ci and ubuntu-24.04-arm failures are unrelated to this PR (pre-existing on main); your files pass all checks cleanly.

Keep up the great work!

memory-mapping the file. This mode reads the compressed chunks through
OS-managed pages, rather than copying the chunks to intermediate buffers.
Opening containers through mmap is generally recommended for workloads with
random read patterns and/or concurrent read-only access. This article

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

article -> guide

a syscall and buffer copy for every block read. Although the improvement
is modest, this makes mmap a default for concurrent read-only access.
a syscall and buffer copy for every block read. Although the speed
improvement is modest, this makes mmap a default for concurrent read-only

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using 'default' is ambiguous here. How about:

Although the speed improvement is modest, for concurrent read-only access, we recommend opening the file with mmap_mode="r".

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GUIDE] Zero-Copy Out-of-Core Processing with Memory-Mapped Files (mmap)

2 participants