MSYNC(2)
πΎ MSYNC(2) β the manual page, bestie edition πΎ
okay so this is msync, a system call from the System Calls Manual, and it's literally the "hey file system, catch up bestie" button. let's get into it π«Ά
β¨ NAME β¨
msync β synchronize a mapped region
no cap, that's the whole job description.
π LIBRARY π
Standard C Library (libc, -lc)
πΈ SYNOPSIS πΈ
#include <sys/mman.h>
int
msync(void *addr, size_t len, int flags);
π DESCRIPTION π
The msync() system call writes any modified pages back to the file system and updates the file modification time. it's giving "flushed and timestamped, mwah" π
now here's the tea about len:
- if
lenis0, all modified pages within the region containingaddrwill be flushed. - if
lenis non-zero, only those pages containingaddrandlen-1succeeding locations will be examined.
The flags argument may be specified as follows:
MS_ASYNCβ Return immediately (girl said "I'll deal with it later, bye" π¨)MS_SYNCβ Perform synchronous writes (she stays. she waits. she's committed πͺ)MS_INVALIDATEβ Invalidate all cached data (yanking the cache out of existence, iconic behavior)
π RETURN VALUES π
The msync() function returns the value 0 if successful. otherwise, the value -1 is returned and the global variable errno is set to indicate the error. so basically 0 = slay, -1 = check errno, bestie π
π₯ ERRORS π₯
The msync() system call will fail if:
[EBUSY]β Some or all of the pages in the specified region are locked andMS_INVALIDATEis specified. (you asked to nuke the cache but the pages are literally holding on. rude.)[EINVAL]β Theaddrargument is not a multiple of the hardware page size. (alignment check said no π)[ENOMEM]β The addresses in the range starting ataddrand continuing forlenbytes are outside the range allowed for the address space of a process, or specify one or more pages that are not mapped. (that address is not in your house, ma'am π)[EINVAL]β Theflagsargument was bothMS_ASYNCandMS_INVALIDATE. Only one of these flags is allowed. (pick a lane, babe. you cannot be both.)[EIO]β An error occurred while writing at least one of the pages in the specified region. (the write itself fumbled. not your fault. probably.)
π¦ SEE ALSO π¦
madvise(2), mincore(2), mlock(2), mprotect(2), munmap(2)
the whole mmap friend group, honestly. go read them too, iykyk β¨
π HISTORY π
The msync() system call first appeared in 4.4BSD. a true vintage queen, older than basically everyone reading this π
π BUGS π
The msync() system call is usually not needed, since BSD implements a coherent file system buffer cache. so like, she's a little extra sometimes. π
However, it may be used to associate dirty VM pages with file system buffers and thus cause them to be flushed to physical media sooner rather than later. so when you do need her, she's the one making sure your stuff actually hits the disk before the lights go out. main character energy tbh.
and that's the page, bestie!! π this version came from the Debian distro's man pages, dated March 18, 2012, and it's page MSYNC(2) β go forth and flush responsibly π«Άβ¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms