From: Ingo Molnar <mingo@elte.hu>

The attached patch, written by Andrew Morton, fixes long scheduling
latencies in filemap_sync().

Has been tested as part of the -VP patchset.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/mm/msync.c |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletion(-)

diff -puN mm/msync.c~sched-mm-fix-scheduling-latencies-in-filemap_sync mm/msync.c
--- 25/mm/msync.c~sched-mm-fix-scheduling-latencies-in-filemap_sync	Fri Nov  5 16:06:40 2004
+++ 25-akpm/mm/msync.c	Fri Nov  5 16:07:10 2004
@@ -115,7 +115,7 @@ static inline int filemap_sync_pgd_range
 	return error;
 }
 
-static int filemap_sync(struct vm_area_struct *vma, unsigned long address,
+static int __filemap_sync(struct vm_area_struct *vma, unsigned long address,
 			size_t size, unsigned int flags)
 {
 	pml4_t *pml4;
@@ -159,6 +159,31 @@ static int filemap_sync(struct vm_area_s
 	return error;
 }
 
+#ifdef CONFIG_PREEMPT
+static int filemap_sync(struct vm_area_struct *vma, unsigned long address,
+			size_t size, unsigned int flags)
+{
+	const size_t chunk = 64 * 1024;	/* bytes */
+	int error = 0;
+
+	while (size) {
+		size_t sz = min(size, chunk);
+
+		error |= __filemap_sync(vma, address, sz, flags);
+		cond_resched();
+		address += sz;
+		size -= sz;
+	}
+	return error;
+}
+#else
+static int filemap_sync(struct vm_area_struct *vma, unsigned long address,
+			size_t size, unsigned int flags)
+{
+	return __filemap_sync(vma, address, size, flags);
+}
+#endif
+
 /*
  * MS_SYNC syncs the entire file - including mappings.
  *
_