From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Hugh Dickins <hughd@google.com>
Subject: [PATCH 1/2] msync: support syncing a small part of the file
Date: Thu, 31 May 2012 22:43:54 +0200 [thread overview]
Message-ID: <1338497035-13014-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1338497035-13014-1-git-send-email-pbonzini@redhat.com>
msync does not need to flush changes to the entire file, even with MS_SYNC.
Instead, it can use vfs_fsync_range to only synchronize a part of the file.
In addition, not all metadata has to be synced; msync is closer to
fdatasync than it is to msync. So, pass 1 to vfs_fsync_range.
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
mm/msync.c | 13 ++++++++++---
1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/mm/msync.c b/mm/msync.c
index 632df45..505fe99 100644
--- a/mm/msync.c
+++ b/mm/msync.c
@@ -15,7 +15,7 @@
#include <linux/sched.h>
/*
- * MS_SYNC syncs the entire file - including mappings.
+ * MS_SYNC syncs the specified range - including mappings.
*
* MS_ASYNC does not start I/O (it used to, up to 2.5.67).
* Nor does it marks the relevant pages dirty (it used to up to 2.6.17).
@@ -58,6 +58,8 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
vma = find_vma(mm, start);
for (;;) {
struct file *file;
+ unsigned long next;
+ loff_t file_offset;
/* Still start < end. */
error = -ENOMEM;
@@ -77,18 +79,23 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
goto out_unlock;
}
file = vma->vm_file;
- start = vma->vm_end;
+ next = min(end, vma->vm_end);
if ((flags & MS_SYNC) && file &&
(vma->vm_flags & VM_SHARED)) {
+ file_offset = vma->vm_pgoff * PAGE_SIZE;
get_file(file);
up_read(&mm->mmap_sem);
- error = vfs_fsync(file, 0);
+ error = vfs_fsync_range(file,
+ start - vma->vm_start + file_offset,
+ next - vma->vm_start + file_offset, 1);
fput(file);
+ start = next;
if (error || start >= end)
goto out;
down_read(&mm->mmap_sem);
vma = find_vma(mm, start);
} else {
+ start = next;
if (start >= end) {
error = 0;
goto out_unlock;
--
1.7.1
next prev parent reply other threads:[~2012-05-31 20:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-31 20:43 [PATCH 0/2] msync improvements Paolo Bonzini
2012-05-31 20:43 ` Paolo Bonzini [this message]
2012-06-13 21:26 ` [PATCH 1/2] msync: support syncing a small part of the file Andrew Morton
2012-06-13 21:51 ` Zan Lynx
2012-06-13 22:08 ` Andrew Morton
2012-06-14 8:57 ` Paolo Bonzini
2012-05-31 20:43 ` [PATCH 2/2] msync: start async writeout when MS_ASYNC Paolo Bonzini
2012-06-13 21:29 ` Andrew Morton
2012-06-14 9:02 ` Paolo Bonzini
2012-06-14 10:07 ` Andrew Morton
2012-06-14 10:19 ` Paolo Bonzini
2012-06-14 12:24 ` Paolo Bonzini
2012-06-12 15:38 ` [PATCH 0/2] msync improvements Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1338497035-13014-2-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).