LATX, fix: Release SMC backing after the last mapping disappears - #476
Open
LaurenIsACoder wants to merge 1 commit into
Open
LATX, fix: Release SMC backing after the last mapping disappears#476LaurenIsACoder wants to merge 1 commit into
LaurenIsACoder wants to merge 1 commit into
Conversation
The process-global SMC memfd grows monotonically and retains backing for pages whose guest and shadow mappings have already disappeared. Truncating that file would also damage mappings still owned by fork descendants. Use one backing file per converted host page and close its descriptor after creating the guest and shadow mappings. The kernel retains the backing until its last mapping disappears, including mappings inherited by a child. Clean up preparatory failures and use the existing fallback; a failed guest MAP_FIXED remains fatal because the original mapping may already be gone. Handle fd 0 and do not retry Linux close(EINTR). Add real memfd/mmap/fork regressions for aliasing, child ownership and failure cleanup. The old allocator fails the retained-descriptor check; the fixed branch passed 25 lat-pr-fast tests and sanitizer checks. A 520-cycle guest SMC workload also preserved child execution after parent unmap. Unavailable guest integration tests were skipped. Keep LATX_SMC=0 as the default. Per-page file creation has an unmeasured throughput cost when shared backing is enabled. Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
This was referenced Sep 8, 2026
LaurenIsACoder
force-pushed
the
latx-smc-backing-lifetime
branch
from
September 8, 2026 07:07
cd334a7 to
dad647f
Compare
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.
Scope
Based on upstream
bfe17ae7c1. Replace the append-only, process-global SMC memfd allocator with one backing file per converted host page. Close the descriptor after creating the guest and shadow mappings; the kernel retains the backing while any mapping, including a fork descendant's mapping, still owns it.This prevents unmapped pages from retaining their contents in an ever-growing open memfd. It does not punch holes or truncate backing that a child may still use. Preparatory memfd/ftruncate/shadow-mmap failures clean up and use the existing fallback; guest MAP_FIXED failure remains fatal because the original mapping may already have been removed. Handle fd 0 and do not retry Linux close(EINTR).
The default
LATX_SMC=0is unchanged. Per-page memfd/ftruncate/close operations have an unmeasured throughput cost when this optional shared-backing mode is enabled; this is a resource-lifetime fix, not a speedup claim.Author self-review and combined validation
The actual published diffs were reviewed individually and checked against the local candidates. Follow-up corrections were folded into their existing commits; author/sign-off metadata updates preserved the per-PR source trees. The series remains six commits across #472, #473, #474, #475 and #476.
All five branches merge without conflicts on
bfe17ae7c1. The combined source tree80aaaaf13688387640f528d1c0bccb6a800f8d6ebuilds and passes 33/33 lat-pr-fast tests. On that combined binary, the 500-cycle KZT unload and retained-handle checks, 520-cycle SMC/fork checks, and 512 successful TSYNC operations alongside thread creation also complete successfully. A tests-disabled configuration registers no tests.The integration suite still reports 27 skips, including after selecting the available guest sysroot with
LATX_X86_64_SYSROOT: 25 require clang and two require the x86 cross compiler. These are not passes. This author self-review does not substitute for the upstream CI matrix, maintainer review or real-application acceptance.Validation
LoongArch64, GCC 15.3, x86_64-linux-user, LAT O1, KZT compiled in, release:
LATX_AOT=0,LATX_KZT=0,LATX_SMC=2. The final live sample has two SMC mappings and no retained SMC descriptor; after unmap it has zero mappings. After fork and parent unmap, the child still executes result 2, writes the code and executes result 3, then exits successfully. TheLATX_SMC=0control also succeeds.Independent of the other memory-lifetime PRs. No installed runtime replacement or application restart.