4 * Copyright (C) 1994-1999 Linus Torvalds
8 * The msync() system call.
12 #include <linux/mman.h>
13 #include <linux/file.h>
14 #include <linux/syscalls.h>
17 * MS_SYNC syncs the entire file - including mappings.
19 * MS_ASYNC does not start I/O (it used to, up to 2.5.67).
20 * Nor does it marks the relevant pages dirty (it used to up to 2.6.17).
21 * Now it doesn't do anything, since dirty pages are properly tracked.
23 * The application may now run fsync() to
24 * write out the dirty pages and wait on the writeout and check the result.
25 * Or the application may run fadvise(FADV_DONTNEED) against the fd to start
26 * async writeout immediately.
27 * So by _not_ starting I/O in MS_ASYNC we provide complete flexibility to
30 asmlinkage long sys_msync(unsigned long start, size_t len, int flags)
33 struct mm_struct *mm = current->mm;
34 struct vm_area_struct *vma;
35 int unmapped_error = 0;
38 if (flags & ~(MS_ASYNC | MS_INVALIDATE | MS_SYNC))
40 if (start & ~PAGE_MASK)
42 if ((flags & MS_ASYNC) && (flags & MS_SYNC))
45 len = (len + ~PAGE_MASK) & PAGE_MASK;
53 * If the interval [start,end) covers some unmapped address ranges,
54 * just ignore them, but return -ENOMEM at the end.
56 down_read(&mm->mmap_sem);
57 vma = find_vma(mm, start);
61 /* Still start < end. */
65 /* Here start < vma->vm_end. */
66 if (start < vma->vm_start) {
67 start = vma->vm_start;
70 unmapped_error = -ENOMEM;
72 /* Here vma->vm_start <= start < vma->vm_end. */
73 if ((flags & MS_INVALIDATE) &&
74 (vma->vm_flags & VM_LOCKED)) {
80 if ((flags & MS_SYNC) && file &&
81 (vma->vm_flags & VM_SHARED)) {
83 up_read(&mm->mmap_sem);
84 error = do_fsync(file, 0);
86 if (error || start >= end)
88 down_read(&mm->mmap_sem);
89 vma = find_vma(mm, start);
99 up_read(&mm->mmap_sem);
101 return error ? : unmapped_error;