mirror of
https://github.com/RhapsodiOS/RhapsodiOS.git
synced 2026-11-03 22:01:40 -07:00
[GH-ISSUE #60] kernel: data written through a shared mapping and never msync'd is lost at unmount (UFS, msdosfs) #53
Labels
No labels
bug
documentation
enhancement
enhancement
good first issue
help wanted
help wanted
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github-starred/RhapsodiOS#53
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @raynorpat on GitHub (Oct 16, 2026).
Original GitHub issue: https://github.com/RhapsodiOS/RhapsodiOS/issues/60
Symptom
Data written to a file through a
MAP_SHAREDmapping and nevermsynced is lost when the file system is unmounted. Aftermunmap,close,sync,umountandmount, the file reads back as all zeros.d6aad145f).No truncate is involved, so this is separate from #59.
Reproduce
The same sequence with
msyncbeforemunmap, or withwrite()instead of the mapping, keeps the data.Where to look
Probably the same discard as #59's UFS half, reached at unmount:
vnode_pager_umount→vnode_uncachemakes the file's VM object non-persistent.vm_object_terminate(vm/vm_object.c~469) frees the object's pages without writing the dirty ones back.syncdoesn't push dirty mapped pages that aren't on a pageout queue yet, so they are still only in memory at unmount.The fix should push dirty pages to the pager (or flush the object) before an uncache or terminate drops them, at unmount, and anywhere else that path is reached.
Impact
Silent data loss for any program that writes through a shared mapping and relies on
munmap/closeand a clean unmount (or shutdown), rather than an explicitmsync, to get the data to disk.Found while verifying #59. Related: #59, #43 (msync).
@raynorpat commented on GitHub (Oct 17, 2026):
Fixed in
1f72ab1e9(issue-60), merged intoffs-perfas2d59e84a0.Root cause:
vnode_pager_umount→vnode_uncache→vm_object_terminate(vm/vm_object.c) freed a file object's resident pages without writing back the ones dirtied through a shared mapping. Any other terminate of a file object (cache trim, cache clear, unlink's uncache) took the same path.Fix: before
vm_object_terminatewaits for paging and frees the pages, it pushes every dirty, non-busy page of a file-backed (non-device, non-swapfile) object throughvm_pager_put. This mirrors the msync path invm_synchronize.c.Verification (i386 QEMU guest, clean kernel built from the commit, cksum
1203060887 1857496, with the #47 and #59 fixes present):sync; /sbin/rebootwith no umount, check after bootstress-mmapshared/mixed/private/truncext2_mmap_truncate_testvm_object_terminatedropping 8 dirty pages per file at unmount, and pushing them with the fix.make check-mmappasses.fsck(UFS) andfsck_msdos(FAT16) are clean after the runs.