Skip to content
BSD syscall#65

svc · unix #65

msync

Flushes dirty pages of a file-backed mapping back to the underlying vnode.

Prototype

int msync(caddr_t addr, size_t len, int flags);

Returns: int

Arguments

NameTypeDirDescription
addrcaddr_t-
lensize_t-
flagsint-

Version history

XNU tagmacOS#
xnu-1456.1.26macOS 10.6 Snow Leopard65
xnu-1486.2.1165
xnu-1504.15.365
xnu-1504.3.1265
xnu-1504.7.465
xnu-1504.9.1765
xnu-1504.9.2665
xnu-1504.9.3765

Examples

C — synchronous flush

msync(map, len, MS_SYNC);

Notes

msync(2) supports MS_ASYNC (queue the I/O), MS_SYNC (block until completion) and MS_INVALIDATE (drop clean cached pages and force a re-read). For anonymous mappings it is a no-op. macOS routes the write-back through the ubc (unified buffer cache), so the data is visible to subsequent read(2) calls on the same vnode.

Related APIs

mmapmunmapfsyncfdatasyncmadvise