Skip to content

feat(core): runtime-toggleable memory-mapped file I/O (MMapEnabled) - #565

Merged
got3nks merged 1 commit into
amule-org:masterfrom
got3nks:feat/mmap-runtime
Jul 23, 2026
Merged

feat(core): runtime-toggleable memory-mapped file I/O (MMapEnabled)#565
got3nks merged 1 commit into
amule-org:masterfrom
got3nks:feat/mmap-runtime

Conversation

@got3nks

@got3nks got3nks commented Jul 23, 2026

Copy link
Copy Markdown

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.cmake probed munmap but never mmap, so HAVE_MMAP was never set, and ENABLE_MMAP was never passed to the compiler — so USE_MMAP could never be true even with -DENABLE_MMAP=YES. This adds the missing mmap/sigaction probes and a single MMAP_SUPPORTED capability macro (set when mmap+munmap+sysconf+_SC_PAGESIZE+sigaction are all present) that gates the code path, the preferences checkbox, and the EC tag. ENABLE_MMAP becomes a default-ON build opt-out (no external dependency — all libc).

Runtime toggle

  • CFileArea reads an atomic flag in 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 — an in-flight block always finishes in its original mode.
  • The SIGSEGV/SIGBUS recovery handler installs once, when mmap is first enabled (not per read/write, and never when off), so it cannot collide with sanitizers/debuggers/crash reporters.
  • Advanced tab checkbox ("Use MMAP: …"). Capability is 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. a Windows GUI driving a Linux daemon).

4 GiB cap (forum 16444)

Relaxed: the offEnd < 4 GiB guard only matters with 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 (write via mmap, read-back via pread, 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.

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
got3nks marked this pull request as ready for review July 23, 2026 17:14
@got3nks
got3nks merged commit 546dc3c into amule-org:master Jul 23, 2026
14 checks passed
@got3nks
got3nks deleted the feat/mmap-runtime branch July 23, 2026 17:16
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).
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.

1 participant