feat(core): runtime-toggleable memory-mapped file I/O (MMapEnabled) - #565
Merged
Conversation
Fix the CMake wiring so mmap is actually reachable (amule-project#34): the port never set HAVE_MMAP (glib21.cmake probed munmap, not mmap) and never passed ENABLE_MMAP to the compiler, so USE_MMAP was dead on every CMake build even with -DENABLE_MMAP=YES. Add the missing mmap/sigaction probes and a single MMAP_SUPPORTED capability macro (set when mmap/munmap/sysconf/_SC_PAGESIZE/ sigaction are all present) gating the code path, the preferences checkbox and the EC tag. ENABLE_MMAP becomes a default-ON build opt-out (no external dependency; all libc). Make mmap use a runtime preference (MMapEnabled, default OFF): - CFileArea reads an atomic flag at ReadAt/StartWriteAt; the per-area mode is captured in m_mmap_buffer so FlushAt/Close stay state-driven -- safe to flip live with active downloads and uploads (in-flight blocks finish in their original mode). - The SIGSEGV/SIGBUS recovery handler installs once, when mmap is first enabled, rather than per read/write and never when off, so it cannot collide with sanitizers/debuggers/crash reporters. - Advanced-tab checkbox; capability negotiated over EC (EC_TAG_FILES_MMAP_ SUPPORTED/_ENABLED) so amulegui/amulecmd/amuleweb/amuleapi show the toggle only when the connected daemon supports mmap (tag-presence == capability; works cross-platform, e.g. Windows GUI to a Linux daemon). Relax the 4 GiB per-area cap (forum 16444): it only guards a 32-bit off_t. On 64-bit off_t -- every modern LFS build, including 32-bit-with-LFS (aMule inherits _FILE_OFFSET_BITS=64 from wx) -- mmap handles large offsets natively, verified against a >4 GiB region, so large files get mmap for their whole length; the cap remains only for a (wx-precluded) non-LFS 32-bit build.
got3nks
marked this pull request as ready for review
July 23, 2026 17:14
This was referenced Jul 23, 2026
got3nks
added a commit
that referenced
this pull request
Jul 23, 2026
Follow-up to #565: surface the memory-mapped file I/O preference on the REST API. files.mmap_supported is a read-only daemon capability (mirrors upnp_available), read from the EC_TAG_FILES_MMAP_SUPPORTED tag; files.mmap_enabled is the runtime value. A PATCH that sets mmap_enabled is rejected with 409 when the connected daemon lacks mmap support, so the option is only writable against a core that can actually use it. Updates docs/api/REFERENCE.md and the 15-preferences-patch curl smoke (round-trip on a mmap-capable daemon; the 409 capability gate otherwise).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes memory-mapped part-file I/O a runtime preference (
MMapEnabled, default OFF) instead of a compile-time feature, and fixes the CMake wiring that made mmap unreachable in the first place (#34).The #34 root cause
mmap was dead code in every CMake build:
glib21.cmakeprobedmunmapbut nevermmap, soHAVE_MMAPwas never set, andENABLE_MMAPwas never passed to the compiler — soUSE_MMAPcould never be true even with-DENABLE_MMAP=YES. This adds the missingmmap/sigactionprobes and a singleMMAP_SUPPORTEDcapability macro (set whenmmap+munmap+sysconf+_SC_PAGESIZE+sigactionare all present) that gates the code path, the preferences checkbox, and the EC tag.ENABLE_MMAPbecomes a default-ON build opt-out (no external dependency — all libc).Runtime toggle
CFileAreareads an atomic flag inReadAt/StartWriteAt; the per-area mode is captured inm_mmap_buffer, soFlushAt/Closestay state-driven. Safe to flip live with active downloads and uploads — an in-flight block always finishes in its original mode.EC_TAG_FILES_MMAP_SUPPORTED/_ENABLED) so amulegui/amulecmd/amuleweb/amuleapi show the toggle only when the connected daemon supports mmap (tag-presence == capability; works cross-platform, e.g. a Windows GUI driving a Linux daemon).4 GiB cap (forum 16444)
Relaxed: the
offEnd < 4 GiBguard only matters with a 32-bitoff_t. On 64-bitoff_t— every modern LFS build, including 32-bit-with-LFS (aMule inherits_FILE_OFFSET_BITS=64from wx) — mmap handles large offsets natively, verified against a >4 GiB region (write via mmap, read-back viapread, 0 mismatches). So large files now get mmap for their whole length; the cap remains only for a (wx-precluded) non-LFS 32-bit build.Testing
Builds clean across monolithic/amulegui/amuled/amulecmd; clang-format + clang-tidy (both tiers) clean. Runtime functional testing (mmap activation + RSS drop; remote show/hide over EC) is in progress — draft until that's done.